Skip to content

Commit

Permalink
[testing] Fix for IQM mock server when generating sample results (#2604)
Browse files Browse the repository at this point in the history
Signed-off-by: Pradnya Khalate <[email protected]>
Co-authored-by: Ben Howe <[email protected]>
  • Loading branch information
khalatepradnya and bmhowe23 authored Feb 12, 2025
1 parent 4370495 commit d57a9dc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions python/tests/backends/test_IQM.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def startUpMockServer():
pytest.exit("Mock server did not start in time, skipping tests.",
returncode=1)

cudaq.set_random_seed(13)
# Set the targeted QPU
os.environ["IQM_TOKENS_FILE"] = tmp_tokens_file.name
kwargs = {"qpu-architecture": "Apollo"}
Expand Down Expand Up @@ -227,8 +228,7 @@ def basic_x():
custom_x(qubit)

counts = cudaq.sample(basic_x)
counts.dump()
# Gives result like { 1:999 0:0 }
# Gives result like { 0:0 1:1000 }
assert counts['0'] == 0

@cudaq.kernel
Expand All @@ -237,8 +237,8 @@ def basic_h():
custom_h(qubit)

counts = cudaq.sample(basic_h)
counts.dump()
assert "0" in counts and "1" in counts
# Gives result like { 0:500 1:500 }
assert counts['0'] > 0 and counts['1'] > 0

@cudaq.kernel
def bell():
Expand All @@ -247,7 +247,7 @@ def bell():
custom_x.ctrl(qubits[0], qubits[1])

counts = cudaq.sample(bell)
# Gives result like { 11:499 10:0 01:0 00:499 }
# Gives result like { 00:500 01:0 10:0 11:500 }
assert counts['01'] == 0 and counts['10'] == 0


Expand All @@ -264,7 +264,7 @@ def bell_pair():
custom_cnot(qubits[0], qubits[1])

counts = cudaq.sample(bell_pair)
# Gives result like { 11:499 10:0 01:0 00:499 }
# Gives result like { 00:500 01:0 10:0 11:500 }
assert counts['01'] == 0 and counts['10'] == 0

cudaq.register_operation(
Expand All @@ -281,7 +281,7 @@ def ctrl_z_kernel():
x(controls)

counts = cudaq.sample(ctrl_z_kernel)
assert counts["0010011"] == 999
assert counts["0010011"] == 1000


# leave for gdb debugging
Expand Down
2 changes: 1 addition & 1 deletion utils/mock_qpu/iqm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def _simulate_circuit(instructions: list[iqm_client.Instruction],
measurement_qubits_positions)
probabilities = np.diag(partial_trace)
return {
ms: int(prob * shots) for ms, prob in zip(
ms: int(round(prob * shots)) for ms, prob in zip(
_generate_measurement_strings(len(measurement_qubits_positions)),
probabilities,
)
Expand Down

0 comments on commit d57a9dc

Please sign in to comment.