From 05f994b2156737bf97e8aeded4249df183fe8454 Mon Sep 17 00:00:00 2001 From: MatteoRobbiati Date: Fri, 2 Feb 2024 09:51:52 +0800 Subject: [PATCH 1/2] fix numpy seed --- tests/test_derivative.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_derivative.py b/tests/test_derivative.py index ec7a501720..e90af942fa 100644 --- a/tests/test_derivative.py +++ b/tests/test_derivative.py @@ -33,6 +33,7 @@ def circuit(nqubits=1): def test_standard_parameter_shift(backend, nshots, atol, scale_factor, grads): # initializing the circuit c = circuit(nqubits=1) + np.random.seed(42) # some parameters # we know the derivative's values with these params @@ -88,6 +89,7 @@ def test_standard_parameter_shift(backend, nshots, atol, scale_factor, grads): def test_finite_differences(backend, step_size): # initializing the circuit c = circuit(nqubits=1) + np.random.seed(42) # some parameters test_params = np.linspace(0.1, 1, 3) From c4fddeae61e96c37b561e672ad1a8ea94a0d698d Mon Sep 17 00:00:00 2001 From: Matteo Robbiati <62071516+MatteoRobbiati@users.noreply.github.com> Date: Fri, 2 Feb 2024 13:03:41 +0800 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Renato Mello --- tests/test_derivative.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_derivative.py b/tests/test_derivative.py index e90af942fa..60ea06244e 100644 --- a/tests/test_derivative.py +++ b/tests/test_derivative.py @@ -33,7 +33,7 @@ def circuit(nqubits=1): def test_standard_parameter_shift(backend, nshots, atol, scale_factor, grads): # initializing the circuit c = circuit(nqubits=1) - np.random.seed(42) + backend.set_seed(42) # some parameters # we know the derivative's values with these params @@ -89,7 +89,7 @@ def test_standard_parameter_shift(backend, nshots, atol, scale_factor, grads): def test_finite_differences(backend, step_size): # initializing the circuit c = circuit(nqubits=1) - np.random.seed(42) + backend.set_seed(42) # some parameters test_params = np.linspace(0.1, 1, 3)