From 8a391f6897aab0bb8a9a2387b274bb5cc0bac13d Mon Sep 17 00:00:00 2001 From: Austin Huang Date: Thu, 25 Apr 2024 17:52:44 -0400 Subject: [PATCH] formatting --- tests/test_base_device.py | 27 +++++++++++---------------- tests/test_qiskit_device.py | 20 ++++++++++---------- 2 files changed, 21 insertions(+), 26 deletions(-) diff --git a/tests/test_base_device.py b/tests/test_base_device.py index a66461b49..9e486de3c 100644 --- a/tests/test_base_device.py +++ b/tests/test_base_device.py @@ -86,8 +86,7 @@ def run(self, *args, **kwargs): @property def target(self): return self._target - - + class MockedBackendLegacy(BackendV1): def __init__(self, num_qubits=10, name="mocked_backend_legacy"): self._configuration = Configuration(num_qubits, backend_name=name) @@ -107,7 +106,6 @@ def run(self, *args, **kwargs): def options(self): return self._options - class MockSession: def __init__(self, backend, max_time=None): self.backend = backend @@ -137,7 +135,6 @@ def options_for_testing(): options.resilience_level = 1 return options - class TestSupportForV1andV2: """Tests compatibility with BackendV1 and BackendV2""" @@ -152,32 +149,30 @@ def test_v1_and_v2_mocked(self, backend): """Test that device initializes with no error mocked""" dev = QiskitDevice2(wires=10, backend=backend, use_primitives=True) assert dev._backend == backend + - @pytest.mark.skip( - reason="Fake backends do not have attribute _service, should address in (SC 55725)" - ) + @pytest.mark.skip(reason="Fake backends do not have attribute _service, should address in (SC 55725)") @pytest.mark.parametrize( - "backend", - [ - FakeManila(), - FakeManilaV2(), - ], + "backend", + [ + FakeManila(), + FakeManilaV2(), + ] ) def test_v1_and_v2_manila(self, backend): """Test that device initializes with no error with V1 and V2 backends by Qiskit""" dev = QiskitDevice2(wires=5, backend=backend, use_primitives=True) - + @qml.qnode(dev) def circuit(x): qml.RX(x, wires=[0]) qml.CNOT(wires=[0, 1]) return qml.sample(qml.PauliZ(0)) - - res = circuit(np.pi / 2) + + res = circuit(np.pi/2) assert isinstance(res, np.ndarray) assert np.shape(res) == (1024,) - class TestDeviceInitialization: def test_compile_backend_kwarg(self): """Test that the compile_backend is set correctly if passed, and the main diff --git a/tests/test_qiskit_device.py b/tests/test_qiskit_device.py index 5f136e00a..5aec93c91 100644 --- a/tests/test_qiskit_device.py +++ b/tests/test_qiskit_device.py @@ -5,7 +5,7 @@ from pennylane_qiskit import AerDevice from pennylane_qiskit.qiskit_device import QiskitDevice from qiskit_aer import noise -from qiskit.providers import BackendV1, BackendV2 +from qiskit.providers import BackendV1, BackendV2 from qiskit_ibm_runtime.fake_provider import FakeManila, FakeManilaV2 from unittest.mock import Mock from qiskit_ibm_runtime.options import Options @@ -92,25 +92,25 @@ def test_v1_and_v2_mocked(self, backend): """Test that device initializes with no error mocked""" dev = qml.device("qiskit.remote", wires=10, backend=backend, use_primitives=True) assert dev._backend == backend - + @pytest.mark.parametrize( - "backend", - [ - FakeManila(), - FakeManilaV2(), - ], + "backend", + [ + FakeManila(), + FakeManilaV2(), + ] ) def test_v1_and_v2_manila(self, backend): """Test that device initializes with no error with V1 and V2 backends by Qiskit""" dev = qml.device("qiskit.remote", wires=5, backend=backend, use_primitives=True) - + @qml.qnode(dev) def circuit(x): qml.RX(x, wires=[0]) qml.CNOT(wires=[0, 1]) return qml.sample(qml.PauliZ(0)) - - res = circuit(np.pi / 2) + + res = circuit(np.pi/2) assert isinstance(res, np.ndarray) assert np.shape(res) == (1024,)