Skip to content
This repository has been archived by the owner on Feb 5, 2024. It is now read-only.

Commit

Permalink
Parametrize couple parallel tests over stateprep.
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentmr committed Aug 22, 2023
1 parent 8abdced commit dca175b
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions mpitests/test_adjoint_jacobian.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ def test_unsupported_hermitian_expectation(self, isBatch_obs):
@pytest.mark.parametrize("theta", np.linspace(-2 * np.pi, 2 * np.pi, 7))
@pytest.mark.parametrize("G", [qml.RX, qml.RY, qml.RZ])
@pytest.mark.parametrize("isBatch_obs", [False, True])
def test_pauli_rotation_gradient(self, G, theta, tol, isBatch_obs, request):
@pytest.mark.parametrize("stateprep", [qml.QubitStateVector, qml.StatePrep])
def test_pauli_rotation_gradient(self, stateprep, G, theta, tol, isBatch_obs, request):
"""Tests that the automatic gradients of Pauli rotations are correct."""

num_wires = 3
Expand All @@ -188,7 +189,7 @@ def test_pauli_rotation_gradient(self, G, theta, tol, isBatch_obs, request):
dev_cpu = qml.device("default.qubit", wires=3)

with qml.tape.QuantumTape() as tape:
qml.StatePrep(np.array([1.0, -1.0]) / np.sqrt(2), wires=0)
stateprep(np.array([1.0, -1.0]) / np.sqrt(2), wires=0)
G(theta, wires=[0])
qml.expval(qml.PauliZ(0))

Expand All @@ -202,7 +203,8 @@ def test_pauli_rotation_gradient(self, G, theta, tol, isBatch_obs, request):
@pytest.fixture(params=[np.complex64, np.complex128])
@pytest.mark.parametrize("theta", np.linspace(-2 * np.pi, 2 * np.pi, 7))
@pytest.mark.parametrize("isBatch_obs", [False, True])
def test_Rot_gradient(self, theta, tol, isBatch_obs, request):
@pytest.mark.parametrize("stateprep", [qml.QubitStateVector, qml.StatePrep])
def test_Rot_gradient(self, stateprep, theta, tol, isBatch_obs, request):
"""Tests that the device gradient of an arbitrary Euler-angle-parameterized gate is
correct."""
num_wires = 3
Expand All @@ -218,7 +220,7 @@ def test_Rot_gradient(self, theta, tol, isBatch_obs, request):
params = np.array([theta, theta**3, np.sqrt(2) * theta])

with qml.tape.QuantumTape() as tape:
qml.StatePrep(np.array([1.0, -1.0]) / np.sqrt(2), wires=0)
stateprep(np.array([1.0, -1.0]) / np.sqrt(2), wires=0)
qml.Rot(*params, wires=[0])
qml.expval(qml.PauliZ(0))

Expand Down

0 comments on commit dca175b

Please sign in to comment.