Skip to content

Commit d57a9dc

Browse files
[testing] Fix for IQM mock server when generating sample results (#2604)
Signed-off-by: Pradnya Khalate <[email protected]> Co-authored-by: Ben Howe <[email protected]>
1 parent 4370495 commit d57a9dc

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

python/tests/backends/test_IQM.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ def startUpMockServer():
6565
pytest.exit("Mock server did not start in time, skipping tests.",
6666
returncode=1)
6767

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

229230
counts = cudaq.sample(basic_x)
230-
counts.dump()
231-
# Gives result like { 1:999 0:0 }
231+
# Gives result like { 0:0 1:1000 }
232232
assert counts['0'] == 0
233233

234234
@cudaq.kernel
@@ -237,8 +237,8 @@ def basic_h():
237237
custom_h(qubit)
238238

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

243243
@cudaq.kernel
244244
def bell():
@@ -247,7 +247,7 @@ def bell():
247247
custom_x.ctrl(qubits[0], qubits[1])
248248

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

253253

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

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

270270
cudaq.register_operation(
@@ -281,7 +281,7 @@ def ctrl_z_kernel():
281281
x(controls)
282282

283283
counts = cudaq.sample(ctrl_z_kernel)
284-
assert counts["0010011"] == 999
284+
assert counts["0010011"] == 1000
285285

286286

287287
# leave for gdb debugging

utils/mock_qpu/iqm/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ def _simulate_circuit(instructions: list[iqm_client.Instruction],
237237
measurement_qubits_positions)
238238
probabilities = np.diag(partial_trace)
239239
return {
240-
ms: int(prob * shots) for ms, prob in zip(
240+
ms: int(round(prob * shots)) for ms, prob in zip(
241241
_generate_measurement_strings(len(measurement_qubits_positions)),
242242
probabilities,
243243
)

0 commit comments

Comments
 (0)