Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
austingmhuang committed Apr 25, 2024
1 parent 6eea970 commit 8a391f6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 26 deletions.
27 changes: 11 additions & 16 deletions tests/test_base_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -137,7 +135,6 @@ def options_for_testing():
options.resilience_level = 1
return options


class TestSupportForV1andV2:
"""Tests compatibility with BackendV1 and BackendV2"""

Expand All @@ -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
Expand Down
20 changes: 10 additions & 10 deletions tests/test_qiskit_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,)

Expand Down

0 comments on commit 8a391f6

Please sign in to comment.