Skip to content

Commit 4bfcc64

Browse files
[testing] Fix Infleqtion tests for state prep (#4323)
* Follow-up to PR #3824 * Fix the `assert_close` function. * Manually tested ``` python3 -m pytest -v python/tests/backends/test_Infleqtion.py =================================================================== test session starts =================================================================== platform linux -- Python 3.12.3, pytest-8.3.0, pluggy-1.6.0 -- /usr/bin/python3 cachedir: .pytest_cache rootdir: /workspaces/cuda-quantum configfile: pyproject.toml plugins: anyio-4.13.0, xdist-3.8.0 collected 9 items python/tests/backends/test_Infleqtion.py::test_simple_kernel PASSED [ 11%] python/tests/backends/test_Infleqtion.py::test_all_gates PASSED [ 22%] python/tests/backends/test_Infleqtion.py::test_multiple_qvector PASSED [ 33%] python/tests/backends/test_Infleqtion.py::test_multiple_measure PASSED [ 44%] python/tests/backends/test_Infleqtion.py::test_observe PASSED [ 55%] python/tests/backends/test_Infleqtion.py::test_state_synthesis PASSED [ 66%] python/tests/backends/test_Infleqtion.py::test_state_preparation PASSED [ 77%] python/tests/backends/test_Infleqtion.py::test_state_preparation_builder PASSED [ 88%] python/tests/backends/test_Infleqtion.py::test_exp_pauli PASSED [100%] =================================================================== 9 passed in 18.45s ==================================================================== ``` --------- Signed-off-by: Pradnya Khalate <pkhalate@nvidia.com>
1 parent 1529df7 commit 4bfcc64

1 file changed

Lines changed: 9 additions & 12 deletions

File tree

python/tests/backends/test_Infleqtion.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ def set_up_target():
2424
cudaq.reset_target()
2525

2626

27-
def assert_close(got) -> bool:
28-
return got < -1.5 and got > -1.9
27+
def assert_close(want, got, tolerance=1.0e-5) -> bool:
28+
return abs(want - got) < tolerance
2929

3030

3131
def test_simple_kernel():
@@ -179,31 +179,28 @@ def kernel2(s: cudaq.State):
179179

180180

181181
def test_state_preparation():
182-
shots = 10000
182+
shots = 100
183183

184184
@cudaq.kernel
185185
def kernel(vec: list[complex]):
186186
qubits = cudaq.qvector(vec)
187187

188188
state = [1. / np.sqrt(2.), 1. / np.sqrt(2.), 0., 0.]
189189
counts = cudaq.sample(kernel, state, shots_count=shots)
190-
assert assert_close(counts["00"], shots / 2, 2)
191-
assert assert_close(counts["10"], shots / 2, 2)
192-
assert assert_close(counts["01"], 0., 2)
193-
assert assert_close(counts["11"], 0., 2)
190+
counts.dump()
191+
assert assert_close(shots / 2, counts["00"], shots / 10)
192+
assert assert_close(shots / 2, counts["10"], shots / 10)
194193

195194

196195
def test_state_preparation_builder():
197-
shots = 10000
196+
shots = 100
198197
kernel, state = cudaq.make_kernel(list[complex])
199198
qubits = kernel.qalloc(state)
200199

201200
state = [1. / np.sqrt(2.), 1. / np.sqrt(2.), 0., 0.]
202201
counts = cudaq.sample(kernel, state, shots_count=shots)
203-
assert assert_close(counts["00"], shots / 2, 2)
204-
assert assert_close(counts["10"], shots / 2, 2)
205-
assert assert_close(counts["01"], 0., 2)
206-
assert assert_close(counts["11"], 0., 2)
202+
assert assert_close(shots / 2, counts["00"], shots / 10)
203+
assert assert_close(shots / 2, counts["10"], shots / 10)
207204

208205

209206
def test_exp_pauli():

0 commit comments

Comments
 (0)