Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions python/tests/backends/test_Infleqtion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -179,31 +179,28 @@ def kernel2(s: cudaq.State):


def test_state_preparation():
shots = 10000
shots = 100
Comment thread
khalatepradnya marked this conversation as resolved.

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

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()
Comment thread
khalatepradnya marked this conversation as resolved.
assert assert_close(shots / 2, counts["00"], shots / 10)
assert assert_close(shots / 2, counts["10"], shots / 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(shots / 2, counts["00"], shots / 10)
assert assert_close(shots / 2, counts["10"], shots / 10)


def test_exp_pauli():
Expand Down
Loading