Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[testing] Fix for IQM mock server when generating sample results #2604

Merged
merged 2 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
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
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
Loading