-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update plugin by removing analytic
argument for device creation
#130
Changes from 3 commits
187498e
dcd9544
3d9103e
92cb68e
6caf57d
e0d31de
3a322eb
2aefab0
1030318
ef6363a
e50fbf5
046a21a
e9fc18e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
qiskit>=0.23.4 | ||
pennylane>=0.14.0 | ||
git+https://github.com/PennyLaneAI/pennylane.git | ||
antalszava marked this conversation as resolved.
Show resolved
Hide resolved
|
||
numpy | ||
networkx>=2.2;python_version>'3.5' | ||
networkx>=2.2,<2.4;python_version=='3.5' |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,8 +26,8 @@ | |
|
||
|
||
@pytest.fixture | ||
def tol(analytic): | ||
if analytic: | ||
def tol(shots): | ||
if not shots: | ||
glassnotes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return {"atol": 0.01, "rtol": 0} | ||
|
||
return {"atol": 0.05, "rtol": 0.1} | ||
|
@@ -42,16 +42,19 @@ def _init_state(n): | |
|
||
return _init_state | ||
|
||
|
||
@pytest.fixture | ||
def skip_unitary(backend): | ||
if backend == "unitary_simulator": | ||
pytest.skip("This test does not support the unitary simulator backend.") | ||
|
||
|
||
@pytest.fixture | ||
def run_only_for_unitary(backend): | ||
if backend != "unitary_simulator": | ||
pytest.skip("This test only supports the unitary simulator.") | ||
|
||
|
||
@pytest.fixture(params=state_backends + hw_backends) | ||
def backend(request): | ||
return request.param | ||
|
@@ -68,22 +71,22 @@ def hardware_backend(request): | |
|
||
|
||
@pytest.fixture(params=[AerDevice, BasicAerDevice]) | ||
def device(request, backend, shots, analytic): | ||
if backend not in state_backends and analytic == True: | ||
def device(request, backend, shots): | ||
if backend not in state_backends and shots is None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Changed) |
||
pytest.skip("Hardware simulators do not support analytic mode") | ||
|
||
def _device(n, device_options=None): | ||
if device_options is None: | ||
device_options = {} | ||
return request.param(wires=n, backend=backend, shots=shots, analytic=analytic, **device_options) | ||
return request.param(wires=n, backend=backend, shots=shots, **device_options) | ||
|
||
return _device | ||
|
||
|
||
@pytest.fixture(params=[AerDevice, BasicAerDevice]) | ||
def state_vector_device(request, statevector_backend, shots, analytic): | ||
def state_vector_device(request, statevector_backend, shots): | ||
def _device(n): | ||
return request.param(wires=n, backend=statevector_backend, shots=shots, analytic=analytic) | ||
return request.param(wires=n, backend=statevector_backend, shots=shots) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (This and the previous two are changed) |
||
|
||
return _device | ||
|
||
|
@@ -94,20 +97,20 @@ def mock_device(monkeypatch): | |
|
||
with monkeypatch.context() as m: | ||
dev = qml.Device | ||
m.setattr(dev, '__abstractmethods__', frozenset()) | ||
m.setattr(dev, "__abstractmethods__", frozenset()) | ||
yield qml.Device() | ||
|
||
|
||
@pytest.fixture(scope="function") | ||
def recorder(): | ||
return qml._queuing.OperationRecorder() | ||
return qml.tape.OperationRecorder() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Changed) |
||
|
||
|
||
@pytest.fixture(scope="function") | ||
def qubit_device_single_wire(): | ||
return qml.device('default.qubit', wires=1) | ||
return qml.device("default.qubit", wires=1) | ||
|
||
|
||
@pytest.fixture(scope="function") | ||
def qubit_device_2_wires(): | ||
return qml.device('default.qubit', wires=2) | ||
return qml.device("default.qubit", wires=2) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,25 +42,18 @@ | |
) | ||
|
||
|
||
single_qubit_operations = [ | ||
qml.PauliX, | ||
qml.PauliY, | ||
qml.PauliZ, | ||
qml.Hadamard, | ||
qml.S, | ||
qml.T | ||
] | ||
single_qubit_operations = [qml.PauliX, qml.PauliY, qml.PauliZ, qml.Hadamard, qml.S, qml.T] | ||
|
||
single_qubit_operations_param = [qml.PhaseShift, qml.RX, qml.RY, qml.RZ] | ||
two_qubit = [qml.CNOT, qml.SWAP, qml.CZ] | ||
two_qubit_param = [qml.CRZ] | ||
three_qubit = [qml.Toffoli, qml.CSWAP] | ||
|
||
@pytest.mark.parametrize("analytic", [True]) | ||
@pytest.mark.parametrize("shots", [8192]) | ||
|
||
@pytest.mark.parametrize("shots", [None]) | ||
@pytest.mark.usefixtures("skip_unitary") | ||
class TestAnalyticApply: | ||
"""Test application of PennyLane operations with analytic attribute set to True.""" | ||
"""Test application of PennyLane operations with analytic calculation.""" | ||
|
||
def test_qubit_state_vector(self, init_state, device, tol): | ||
"""Test that the QubitStateVector operation produces the expected | ||
|
@@ -149,8 +142,8 @@ def test_three_qubit_operations_no_parameters(self, init_state, device, operatio | |
expected = np.abs(applied_operation.matrix @ state) ** 2 | ||
assert np.allclose(res, expected, **tol) | ||
|
||
@pytest.mark.parametrize("analytic", [True]) | ||
@pytest.mark.parametrize("shots", [8192]) | ||
|
||
@pytest.mark.parametrize("shots", [None]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Above 3 diffs were changes |
||
@pytest.mark.usefixtures("run_only_for_unitary") | ||
class TestStateApplyUnitarySimulator: | ||
"""Test application of PennyLane operations to the unitary simulator.""" | ||
|
@@ -161,14 +154,17 @@ def test_invalid_qubit(self, init_state, device): | |
dev = device(1) | ||
state = init_state(1) | ||
|
||
with pytest.raises(qml.DeviceError, match="The QubitStateVector operation is not supported on the unitary simulator backend"): | ||
with pytest.raises( | ||
qml.DeviceError, | ||
match="The QubitStateVector operation is not supported on the unitary simulator backend", | ||
): | ||
dev.apply([qml.QubitStateVector(state, wires=[0])]) | ||
|
||
|
||
@pytest.mark.parametrize("shots", [8192]) | ||
@pytest.mark.parametrize("analytic", [False]) | ||
@pytest.mark.usefixtures("skip_unitary") | ||
class TestNonAnalyticApply: | ||
"""Test application of PennyLane operations with the analytic attribute set to False.""" | ||
"""Test application of PennyLane operations with non-analytic calculation.""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Changed) |
||
|
||
def test_qubit_state_vector(self, init_state, device, tol): | ||
"""Test that the QubitStateVector operation produces the expected | ||
|
@@ -302,4 +298,3 @@ def test_three_qubit_no_parameters(self, init_state, device, operation, tol): | |
res = np.fromiter(dev.probability(), dtype=np.float64) | ||
expected = np.abs(applied_operation.matrix @ state) ** 2 | ||
assert np.allclose(res, expected, **tol) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Failures in the device test suite originated from the fact that the device keyword arguments were ignored by PennyLane core. Therefore, even for
backend=statevector_simulator
we gotqasm_simulator
, though this time withshots=None
, which were then changed to 1024 internally (HW warning branch).