Skip to content

Commit

Permalink
test_autograd
Browse files Browse the repository at this point in the history
  • Loading branch information
Qottmann committed Apr 8, 2024
1 parent bcc882d commit f8e2e0e
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/interfaces/test_autograd.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,36 @@ def test_no_batch_transform(self, mocker):
assert isinstance(res[0], np.ndarray)
assert res[0].shape == ()
assert np.allclose(res[0], np.cos(y), atol=0.1)

@pytest.mark.usefixtures("use_legacy_opmath")
def test_no_batch_transform_legacy_opmath(self, mocker):
"""Test functionality to enable and disable"""
dev = qml.device("default.qubit.legacy", wires=2, shots=100000)

H = qml.PauliZ(0) @ qml.PauliZ(1) - qml.PauliX(0)
x = 0.6
y = 0.2

with qml.queuing.AnnotatedQueue() as q:
qml.RX(x, wires=0)
qml.RY(y, wires=1)
qml.CNOT(wires=[0, 1])
qml.expval(H)

tape = qml.tape.QuantumScript.from_queue(q)
spy = mocker.spy(dev, "batch_transform")

with pytest.raises(AssertionError, match="Hamiltonian must be used with shots=None"):
res = qml.execute([tape], dev, None, device_batch_transform=False)

spy.assert_not_called()

res = qml.execute([tape], dev, None, device_batch_transform=True)
spy.assert_called()

assert isinstance(res[0], np.ndarray)
assert res[0].shape == ()
assert np.allclose(res[0], np.cos(y), atol=0.1)

def test_batch_transform_dynamic_shots(self):
"""Tests that the batch transform considers the number of shots for the execution, not those
Expand Down

0 comments on commit f8e2e0e

Please sign in to comment.