From 7de33a44183a3332971a2d5f45f9292c4b53b2c4 Mon Sep 17 00:00:00 2001 From: Pradnya Khalate Date: Tue, 14 Apr 2026 10:37:20 -0700 Subject: [PATCH 1/3] [testing] Fix Infleqtion tests for state prep Signed-off-by: Pradnya Khalate --- python/tests/backends/test_Infleqtion.py | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/python/tests/backends/test_Infleqtion.py b/python/tests/backends/test_Infleqtion.py index ea9e9427b63..063ab684382 100644 --- a/python/tests/backends/test_Infleqtion.py +++ b/python/tests/backends/test_Infleqtion.py @@ -24,8 +24,8 @@ def set_up_target(): cudaq.reset_target() -def assert_close(got) -> bool: - return got < -1.5 and got > -1.9 +def assert_close(want, got, tolerance=1.0e-5) -> bool: + return abs(want - got) < tolerance def test_simple_kernel(): @@ -179,7 +179,7 @@ def kernel2(s: cudaq.State): def test_state_preparation(): - shots = 10000 + shots = 100 @cudaq.kernel def kernel(vec: list[complex]): @@ -187,23 +187,20 @@ def kernel(vec: list[complex]): state = [1. / np.sqrt(2.), 1. / np.sqrt(2.), 0., 0.] counts = cudaq.sample(kernel, state, shots_count=shots) - assert assert_close(counts["00"], shots / 2, 2) - assert assert_close(counts["10"], shots / 2, 2) - assert assert_close(counts["01"], 0., 2) - assert assert_close(counts["11"], 0., 2) + counts.dump() + assert assert_close(counts["00"], shots / 2, 10) + assert assert_close(counts["10"], shots / 2, 10) def test_state_preparation_builder(): - shots = 10000 + shots = 100 kernel, state = cudaq.make_kernel(list[complex]) qubits = kernel.qalloc(state) state = [1. / np.sqrt(2.), 1. / np.sqrt(2.), 0., 0.] counts = cudaq.sample(kernel, state, shots_count=shots) - assert assert_close(counts["00"], shots / 2, 2) - assert assert_close(counts["10"], shots / 2, 2) - assert assert_close(counts["01"], 0., 2) - assert assert_close(counts["11"], 0., 2) + assert assert_close(counts["00"], shots / 2, 10) + assert assert_close(counts["10"], shots / 2, 10) def test_exp_pauli(): From 5a077914cfd419c2dbf4983f42cbb255ad2b5d9c Mon Sep 17 00:00:00 2001 From: Pradnya Khalate Date: Tue, 14 Apr 2026 16:59:09 -0700 Subject: [PATCH 2/3] * Addressing review comments Signed-off-by: Pradnya Khalate --- python/tests/backends/test_Infleqtion.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/python/tests/backends/test_Infleqtion.py b/python/tests/backends/test_Infleqtion.py index 063ab684382..7a8ddfa9f81 100644 --- a/python/tests/backends/test_Infleqtion.py +++ b/python/tests/backends/test_Infleqtion.py @@ -188,8 +188,8 @@ def kernel(vec: list[complex]): state = [1. / np.sqrt(2.), 1. / np.sqrt(2.), 0., 0.] counts = cudaq.sample(kernel, state, shots_count=shots) counts.dump() - assert assert_close(counts["00"], shots / 2, 10) - assert assert_close(counts["10"], shots / 2, 10) + assert assert_close(shots / 2, counts["00"], 5) + assert assert_close(shots / 2, counts["10"], 5) def test_state_preparation_builder(): @@ -199,8 +199,8 @@ def test_state_preparation_builder(): state = [1. / np.sqrt(2.), 1. / np.sqrt(2.), 0., 0.] counts = cudaq.sample(kernel, state, shots_count=shots) - assert assert_close(counts["00"], shots / 2, 10) - assert assert_close(counts["10"], shots / 2, 10) + assert assert_close(shots / 2, counts["00"], 5) + assert assert_close(shots / 2, counts["10"], 5) def test_exp_pauli(): From 8a014cc2b52bf6cc061597ea7ef0ea5a42c64a6f Mon Sep 17 00:00:00 2001 From: Pradnya Khalate Date: Fri, 17 Apr 2026 15:28:33 -0700 Subject: [PATCH 3/3] Make the tolerance align with values seen in practice ({00: 41, 10: 59}) Signed-off-by: Pradnya Khalate --- python/tests/backends/test_Infleqtion.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/python/tests/backends/test_Infleqtion.py b/python/tests/backends/test_Infleqtion.py index 7a8ddfa9f81..c86a5d9c941 100644 --- a/python/tests/backends/test_Infleqtion.py +++ b/python/tests/backends/test_Infleqtion.py @@ -188,8 +188,8 @@ def kernel(vec: list[complex]): state = [1. / np.sqrt(2.), 1. / np.sqrt(2.), 0., 0.] counts = cudaq.sample(kernel, state, shots_count=shots) counts.dump() - assert assert_close(shots / 2, counts["00"], 5) - assert assert_close(shots / 2, counts["10"], 5) + assert assert_close(shots / 2, counts["00"], shots / 10) + assert assert_close(shots / 2, counts["10"], shots / 10) def test_state_preparation_builder(): @@ -199,8 +199,8 @@ def test_state_preparation_builder(): state = [1. / np.sqrt(2.), 1. / np.sqrt(2.), 0., 0.] counts = cudaq.sample(kernel, state, shots_count=shots) - assert assert_close(shots / 2, counts["00"], 5) - assert assert_close(shots / 2, counts["10"], 5) + assert assert_close(shots / 2, counts["00"], shots / 10) + assert assert_close(shots / 2, counts["10"], shots / 10) def test_exp_pauli():