diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 533493232..9267898c2 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -57,7 +57,7 @@ repos: # Python linting and formatting using ruff - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.8.3 + rev: v0.8.4 hooks: - id: ruff args: ["--fix", "--show-fixes"] diff --git a/tests/devices/test_devices.py b/tests/devices/test_devices.py index 647ff3197..3a8e58484 100644 --- a/tests/devices/test_devices.py +++ b/tests/devices/test_devices.py @@ -2,6 +2,7 @@ from __future__ import annotations +import re from typing import cast import pytest @@ -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() @@ -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") diff --git a/tests/devices/test_ibm_device_support.py b/tests/devices/test_ibm_device_support.py index 0e04ed2f1..ebba4f1b8 100644 --- a/tests/devices/test_ibm_device_support.py +++ b/tests/devices/test_ibm_device_support.py @@ -2,6 +2,8 @@ from __future__ import annotations +import re + import pytest from qiskit_ibm_runtime.fake_provider import FakeMontrealV2 @@ -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") @@ -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: @@ -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: diff --git a/tests/devices/test_iqm_device_support.py b/tests/devices/test_iqm_device_support.py index d978d6ea5..d4fb18359 100644 --- a/tests/devices/test_iqm_device_support.py +++ b/tests/devices/test_iqm_device_support.py @@ -2,6 +2,8 @@ from __future__ import annotations +import re + import pytest from mqt.bench.devices import IQMProvider @@ -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") diff --git a/tests/devices/test_oqc_device_support.py b/tests/devices/test_oqc_device_support.py index 1c244df0a..ea8a0e705 100644 --- a/tests/devices/test_oqc_device_support.py +++ b/tests/devices/test_oqc_device_support.py @@ -2,6 +2,8 @@ from __future__ import annotations +import re + import pytest from mqt.bench.devices import OQCProvider @@ -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) diff --git a/tests/devices/test_quantinuum_device_support.py b/tests/devices/test_quantinuum_device_support.py index d14beebdc..753035891 100644 --- a/tests/devices/test_quantinuum_device_support.py +++ b/tests/devices/test_quantinuum_device_support.py @@ -2,6 +2,8 @@ from __future__ import annotations +import re + import pytest from mqt.bench.devices import QuantinuumProvider @@ -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.escape(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.escape(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.escape(r"Two-qubit gate duration values not available.")): device.get_two_qubit_gate_duration(gate, q0, q1) diff --git a/tests/devices/test_rigetti_device_support.py b/tests/devices/test_rigetti_device_support.py index 6764a8927..5f86bd58b 100644 --- a/tests/devices/test_rigetti_device_support.py +++ b/tests/devices/test_rigetti_device_support.py @@ -2,6 +2,8 @@ from __future__ import annotations +import re + import pytest from mqt.bench.devices import RigettiProvider @@ -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)