Skip to content

Commit

Permalink
🎨 refactored part of the IBM backend handling and the respective test
Browse files Browse the repository at this point in the history
  • Loading branch information
nquetschlich committed Aug 22, 2024
1 parent 2dd2d98 commit 051788d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 24 deletions.
21 changes: 3 additions & 18 deletions src/mqt/bench/devices/ibm.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
if TYPE_CHECKING:
from pathlib import Path

from qiskit.providers import BackendV2
from qiskit.transpiler import Target

from qiskit.providers import BackendV2

from mqt.bench.devices import Device, DeviceCalibration, Provider

Expand Down Expand Up @@ -145,8 +145,8 @@ def __import_target(cls, target: Target) -> DeviceCalibration:
return calibration

@classmethod
def __import_backend_v2(cls, backend: BackendV2) -> Device:
"""Import device data from a Qiskit `BackendV2` object.
def import_qiskit_backend(cls, backend: BackendV2) -> Device:
"""Import device data from a Qiskit `Backend` object.
Arguments:
backend: the Qiskit `BackendV2` object.
Expand All @@ -160,18 +160,3 @@ def __import_backend_v2(cls, backend: BackendV2) -> Device:
device.coupling_map = backend.coupling_map.get_edges()
device.calibration = cls.__import_target(backend.target)
return device

@classmethod
def import_qiskit_backend(cls, backend: BackendV2) -> Device:
"""Import device data from a Qiskit `Backend` object.
Arguments:
backend: the Qiskit `Backend` object.
Returns:
Collection of device data
"""
if isinstance(backend, BackendV2):
return cls.__import_backend_v2(backend)
msg = f"Unsupported backend type {type(backend)}"
raise TypeError(msg)
6 changes: 0 additions & 6 deletions tests/devices/test_ibm_device_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,3 @@ def test_get_ibmq_montreal_device() -> None:
for gate in two_qubit_gates:
assert 0 <= device.get_two_qubit_gate_fidelity(gate, q0, q1) <= 1
assert device.get_two_qubit_gate_duration(gate, q0, q1) >= 0


def test_import_unsupported_backend() -> None:
"""Test importing an unsupported backend type."""
with pytest.raises(TypeError, match="Unsupported backend type <class 'str'>"):
IBMProvider.import_qiskit_backend("V3")

0 comments on commit 051788d

Please sign in to comment.