Skip to content

Commit

Permalink
🚨 fixed ruff warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
nquetschlich committed Dec 21, 2024
1 parent 8dbcdac commit d1cb4d7
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 41 deletions.
57 changes: 29 additions & 28 deletions tests/devices/test_devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import annotations

import re
from typing import cast

import pytest
Expand Down Expand Up @@ -41,62 +42,62 @@ def test_device_calibration_errors() -> None:
device = Device(name="test", num_qubits=1, basis_gates=[], coupling_map=[], calibration=None)

# Test all methods with no calibration
with pytest.raises(ValueError, match="Calibration data not available for device test."):
with pytest.raises(ValueError, match=re.escape("Calibration data not available for device test.")):
device.get_single_qubit_gate_fidelity("gate1", 0)
with pytest.raises(ValueError, match="Calibration data not available for device test."):
with pytest.raises(ValueError, match=re.escape("Calibration data not available for device test.")):
device.get_single_qubit_gate_duration("gate1", 0)
with pytest.raises(ValueError, match="Calibration data not available for device test."):
with pytest.raises(ValueError, match=re.escape("Calibration data not available for device test.")):
device.get_two_qubit_gate_fidelity("gate2", 0, 1)
with pytest.raises(ValueError, match="Calibration data not available for device test."):
with pytest.raises(ValueError, match=re.escape("Calibration data not available for device test.")):
device.get_two_qubit_gate_duration("gate2", 0, 1)
with pytest.raises(ValueError, match="Calibration data not available for device test."):
with pytest.raises(ValueError, match=re.escape("Calibration data not available for device test.")):
device.get_readout_fidelity(0)
with pytest.raises(ValueError, match="Calibration data not available for device test."):
with pytest.raises(ValueError, match=re.escape("Calibration data not available for device test.")):
device.get_readout_duration(0)
with pytest.raises(ValueError, match="Calibration data not available for device test."):
with pytest.raises(ValueError, match=re.escape("Calibration data not available for device test.")):
device.sanitize_device()

# Test all methods with missing calibration data
device.calibration = DeviceCalibration()
with pytest.raises(ValueError, match="Gate gate1 not supported by device test."):
with pytest.raises(ValueError, match=re.escape("Gate gate1 not supported by device test.")):
device.get_single_qubit_gate_fidelity("gate1", 0)
with pytest.raises(ValueError, match="Gate gate1 not supported by device test."):
with pytest.raises(ValueError, match=re.escape("Gate gate1 not supported by device test.")):
device.get_single_qubit_gate_duration("gate1", 0)
with pytest.raises(ValueError, match="Gate gate2 not supported by device test."):
with pytest.raises(ValueError, match=re.escape("Gate gate2 not supported by device test.")):
device.get_two_qubit_gate_fidelity("gate2", 0, 1)
with pytest.raises(ValueError, match="Gate gate2 not supported by device test."):
with pytest.raises(ValueError, match=re.escape("Gate gate2 not supported by device test.")):
device.get_two_qubit_gate_duration("gate2", 0, 1)
with pytest.raises(ValueError, match="Readout fidelity values not available."):
with pytest.raises(ValueError, match=re.escape("Readout fidelity values not available.")):
device.get_readout_fidelity(0)
with pytest.raises(ValueError, match="Readout duration values not available."):
with pytest.raises(ValueError, match=re.escape("Readout duration values not available.")):
device.get_readout_duration(0)
with pytest.raises(ValueError, match="Single-qubit gate fidelity values not available."):
with pytest.raises(ValueError, match=re.escape("Single-qubit gate fidelity values not available.")):
device.calibration.get_single_qubit_gate_fidelity("gate_type", 0)
with pytest.raises(ValueError, match="Single-qubit gate duration values not available."):
with pytest.raises(ValueError, match=re.escape("Single-qubit gate duration values not available.")):
device.calibration.get_single_qubit_gate_duration("gate_type", 0)
with pytest.raises(ValueError, match="Two-qubit gate fidelity values not available."):
with pytest.raises(ValueError, match=re.escape("Two-qubit gate fidelity values not available.")):
device.calibration.get_two_qubit_gate_fidelity("gate_type", 0, 1)
with pytest.raises(ValueError, match="Two-qubit gate duration values not available."):
with pytest.raises(ValueError, match=re.escape("Two-qubit gate duration values not available.")):
device.calibration.get_two_qubit_gate_duration("gate_type", 0, 1)
with pytest.raises(ValueError, match="Readout fidelity values not available."):
with pytest.raises(ValueError, match=re.escape("Readout fidelity values not available.")):
device.calibration.get_readout_fidelity(0)
with pytest.raises(ValueError, match="Readout duration values not available."):
with pytest.raises(ValueError, match=re.escape("Readout duration values not available.")):
device.calibration.get_readout_duration(0)
with pytest.raises(ValueError, match="T1 values not available."):
with pytest.raises(ValueError, match=re.escape("T1 values not available.")):
device.calibration.get_t1(0)
with pytest.raises(ValueError, match="T2 values not available."):
with pytest.raises(ValueError, match=re.escape("T2 values not available.")):
device.calibration.get_t2(0)
with pytest.raises(ValueError, match="Single-qubit gate fidelity values not available."):
with pytest.raises(ValueError, match=re.escape("Single-qubit gate fidelity values not available.")):
device.calibration.compute_average_single_qubit_gate_fidelity("gate")
with pytest.raises(ValueError, match="Single-qubit gate duration values not available."):
with pytest.raises(ValueError, match=re.escape("Single-qubit gate duration values not available.")):
device.calibration.compute_average_single_qubit_gate_duration("gate")
with pytest.raises(ValueError, match="Two-qubit gate fidelity values not available."):
with pytest.raises(ValueError, match=re.escape("Two-qubit gate fidelity values not available.")):
device.calibration.compute_average_two_qubit_gate_fidelity("gate")
with pytest.raises(ValueError, match="Two-qubit gate duration values not available."):
with pytest.raises(ValueError, match=re.escape("Two-qubit gate duration values not available.")):
device.calibration.compute_average_two_qubit_gate_duration("gate")
with pytest.raises(ValueError, match="Readout fidelity values not available."):
with pytest.raises(ValueError, match=re.escape("Readout fidelity values not available.")):
device.calibration.compute_average_readout_fidelity()
with pytest.raises(ValueError, match="Readout duration values not available."):
with pytest.raises(ValueError, match=re.escape("Readout duration values not available.")):
device.calibration.compute_average_readout_duration()


Expand All @@ -105,5 +106,5 @@ def test_provider() -> None:
for provider in get_available_providers():
assert provider.provider_name in ["ibm", "rigetti", "oqc", "ionq", "quantinuum", "iqm"]

with pytest.raises(NotFoundError, match="Provider 'test' not found among available providers."):
with pytest.raises(NotFoundError, match=re.escape("Provider 'test' not found among available providers.")):
get_provider_by_name("test")
8 changes: 5 additions & 3 deletions tests/devices/test_ibm_device_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from __future__ import annotations

import re

import pytest
from qiskit_ibm_runtime.fake_provider import FakeMontrealV2

Expand All @@ -14,7 +16,7 @@ def test_ibm_provider_methods() -> None:
assert IBMProvider.get_available_basis_gates() == [["id", "rz", "sx", "x", "cx", "measure", "barrier"]]
assert IBMProvider.get_native_gates() == ["id", "rz", "sx", "x", "cx", "measure", "barrier"]
assert IBMProvider.get_max_qubits() == 127
with pytest.raises(ValueError, match="Device ibm_unknown not found."):
with pytest.raises(ValueError, match=re.escape("Device ibm_unknown not found.")):
IBMProvider.get_device("ibm_unknown")


Expand Down Expand Up @@ -78,7 +80,7 @@ def test_get_ibm_washington_device() -> None:

for gate in single_qubit_gates:
assert 0 <= device.get_single_qubit_gate_fidelity(gate, q) <= 1
with pytest.raises(ValueError, match="Single-qubit gate duration values not available."):
with pytest.raises(ValueError, match=re.escape("Single-qubit gate duration values not available.")):
device.get_single_qubit_gate_duration(gate, q)

for q0, q1 in device.coupling_map:
Expand All @@ -105,7 +107,7 @@ def test_get_ibmq_montreal_device() -> None:

for gate in single_qubit_gates:
assert 0 <= device.get_single_qubit_gate_fidelity(gate, q) <= 1
with pytest.raises(ValueError, match="Single-qubit gate duration values not available."):
with pytest.raises(ValueError, match=re.escape("Single-qubit gate duration values not available.")):
device.get_single_qubit_gate_duration(gate, q)
for q0, q1 in device.coupling_map:
for gate in two_qubit_gates:
Expand Down
4 changes: 3 additions & 1 deletion tests/devices/test_iqm_device_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from __future__ import annotations

import re

import pytest

from mqt.bench.devices import IQMProvider
Expand All @@ -19,7 +21,7 @@ def test_iqm_provider_methods() -> None:
assert IQMProvider.get_available_basis_gates() == [["r", "cz", "measure", "barrier"]]
assert IQMProvider.get_native_gates() == ["r", "cz", "measure", "barrier"]
assert IQMProvider.get_max_qubits() == 20
with pytest.raises(ValueError, match="Device iqm_unknown not found."):
with pytest.raises(ValueError, match=re.escape("Device iqm_unknown not found.")):
IQMProvider.get_device("iqm_unknown")


Expand Down
8 changes: 5 additions & 3 deletions tests/devices/test_oqc_device_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from __future__ import annotations

import re

import pytest

from mqt.bench.devices import OQCProvider
Expand Down Expand Up @@ -29,16 +31,16 @@ def test_oqc_lucy_device() -> None:

for q in range(device.num_qubits):
assert 0 <= device.get_readout_fidelity(q) <= 1
with pytest.raises(ValueError, match="Readout duration values not available."):
with pytest.raises(ValueError, match=re.escape("Readout duration values not available.")):
device.get_readout_duration(q)

for gate in single_qubit_gates:
assert 0 <= device.get_single_qubit_gate_fidelity(gate, q) <= 1
with pytest.raises(ValueError, match="Single-qubit gate duration values not available."):
with pytest.raises(ValueError, match=re.escape("Single-qubit gate duration values not available.")):
device.get_single_qubit_gate_duration(gate, q)

for q0, q1 in device.coupling_map:
for gate in two_qubit_gates:
assert 0 <= device.get_two_qubit_gate_fidelity(gate, q0, q1) <= 1
with pytest.raises(ValueError, match="Two-qubit gate duration values not available."):
with pytest.raises(ValueError, match=re.escape("Two-qubit gate duration values not available.")):
device.get_two_qubit_gate_duration(gate, q0, q1)
8 changes: 5 additions & 3 deletions tests/devices/test_quantinuum_device_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from __future__ import annotations

import re

import pytest

from mqt.bench.devices import QuantinuumProvider
Expand Down Expand Up @@ -29,16 +31,16 @@ def test_quantinuum_h2_device() -> None:

for q in range(device.num_qubits):
assert 0 <= device.get_readout_fidelity(q) <= 1
with pytest.raises(ValueError, match="Readout duration values not available."):
with pytest.raises(ValueError, match=re.match(r"Readout duration values not available.")):
device.get_readout_duration(q)

for gate in single_qubit_gates:
assert 0 <= device.get_single_qubit_gate_fidelity(gate, q) <= 1
with pytest.raises(ValueError, match="Single-qubit gate duration values not available."):
with pytest.raises(ValueError, match=re.match(r"Single-qubit gate duration values not available.")):
device.get_single_qubit_gate_duration(gate, q)

for q0, q1 in device.coupling_map:
for gate in two_qubit_gates:
assert 0 <= device.get_two_qubit_gate_fidelity(gate, q0, q1) <= 1
with pytest.raises(ValueError, match="Two-qubit gate duration values not available."):
with pytest.raises(ValueError, match=re.match(r"Two-qubit gate duration values not available.")):
device.get_two_qubit_gate_duration(gate, q0, q1)
8 changes: 5 additions & 3 deletions tests/devices/test_rigetti_device_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from __future__ import annotations

import re

import pytest

from mqt.bench.devices import RigettiProvider
Expand Down Expand Up @@ -29,16 +31,16 @@ def test_rigetti_aspen_m3_device() -> None:

for q in range(device.num_qubits):
assert 0 <= device.get_readout_fidelity(q) <= 1
with pytest.raises(ValueError, match="Readout duration values not available."):
with pytest.raises(ValueError, match=re.escape("Readout duration values not available.")):
device.get_readout_duration(q)

for gate in single_qubit_gates:
assert 0 <= device.get_single_qubit_gate_fidelity(gate, q) <= 1
with pytest.raises(ValueError, match="Single-qubit gate duration values not available."):
with pytest.raises(ValueError, match=re.escape("Single-qubit gate duration values not available.")):
device.get_single_qubit_gate_duration(gate, q)

for q0, q1 in device.coupling_map:
for gate in two_qubit_gates:
assert 0 <= device.get_two_qubit_gate_fidelity(gate, q0, q1) <= 1
with pytest.raises(ValueError, match="Two-qubit gate duration values not available."):
with pytest.raises(ValueError, match=re.escape("Two-qubit gate duration values not available.")):
device.get_two_qubit_gate_duration(gate, q0, q1)

0 comments on commit d1cb4d7

Please sign in to comment.