From dca175bdb93b538577d7d50a7104b4e61e8d41de Mon Sep 17 00:00:00 2001 From: Vincent Michaud-Rioux Date: Tue, 22 Aug 2023 12:51:27 -0700 Subject: [PATCH] Parametrize couple parallel tests over stateprep. --- mpitests/test_adjoint_jacobian.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/mpitests/test_adjoint_jacobian.py b/mpitests/test_adjoint_jacobian.py index 63229c80..738ab4cd 100644 --- a/mpitests/test_adjoint_jacobian.py +++ b/mpitests/test_adjoint_jacobian.py @@ -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 @@ -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)) @@ -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 @@ -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))