Skip to content

Commit 91371f6

Browse files
authored
Fix seed usage in OpenQASM noise tests (#3080)
This uses the seed parameter to `openqasm.run` rather than the global seed for running noise validation tests.
1 parent a076c96 commit 91371f6

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

source/pip/tests/test_qasm.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from qsharp import (
88
init,
99
TargetProfile,
10-
set_quantum_seed,
1110
BitFlipNoise,
1211
CircuitGenerationMethod,
1312
QSharpError,
@@ -34,7 +33,6 @@
3433

3534

3635
def test_run_with_noise_produces_noisy_results() -> None:
37-
set_quantum_seed(0)
3836
result = run(
3937
"""
4038
include "stdgates.inc";
@@ -54,6 +52,7 @@ def test_run_with_noise_produces_noisy_results() -> None:
5452
""",
5553
shots=1,
5654
noise=BitFlipNoise(0.1),
55+
seed=0,
5756
)
5857
assert result[0] > 5
5958
result = run(
@@ -69,12 +68,12 @@ def test_run_with_noise_produces_noisy_results() -> None:
6968
""",
7069
shots=1,
7170
noise=BitFlipNoise(0.1),
71+
seed=0,
7272
)
7373
assert result[0] > 5
7474

7575

7676
def test_run_with_qubit_loss_produces_lossy_results() -> None:
77-
set_quantum_seed(0)
7877
result = run(
7978
"""
8079
qubit q1;
@@ -83,12 +82,12 @@ def test_run_with_qubit_loss_produces_lossy_results() -> None:
8382
""",
8483
shots=1,
8584
qubit_loss=1.0,
85+
seed=0,
8686
)
8787
assert result[0] == Result.Loss
8888

8989

9090
def test_run_with_qubit_loss_detects_loss_with_mresetzchecked() -> None:
91-
set_quantum_seed(0)
9291
result = run(
9392
"""
9493
include "qdk.inc";
@@ -98,12 +97,12 @@ def test_run_with_qubit_loss_detects_loss_with_mresetzchecked() -> None:
9897
""",
9998
shots=1,
10099
qubit_loss=1.0,
100+
seed=0,
101101
)
102102
assert result[0] == 2
103103

104104

105105
def test_run_without_qubit_loss_does_not_detect_loss_with_mresetzchecked() -> None:
106-
set_quantum_seed(0)
107106
result = run(
108107
"""
109108
include "qdk.inc";
@@ -112,12 +111,12 @@ def test_run_without_qubit_loss_does_not_detect_loss_with_mresetzchecked() -> No
112111
r = mresetz_checked(q1);
113112
""",
114113
shots=1,
114+
seed=0,
115115
)
116116
assert result[0] == 0
117117

118118

119119
def test_mresetzchecked_not_present_without_qdk_inc() -> None:
120-
set_quantum_seed(0)
121120
with pytest.raises(QasmError) as excinfo:
122121
run(
123122
"""
@@ -127,6 +126,7 @@ def test_mresetzchecked_not_present_without_qdk_inc() -> None:
127126
r = mresetz_checked(q1);
128127
""",
129128
shots=1,
129+
seed=0,
130130
)
131131
assert "undefined symbol: mresetz_checked" in str(excinfo.value)
132132

@@ -179,7 +179,6 @@ def test_import_can_declare_files_with_namespaces() -> None:
179179

180180
def test_run_imported_with_noise_produces_noisy_results() -> None:
181181
init()
182-
set_quantum_seed(0)
183182
import_openqasm(
184183
"""
185184
include "stdgates.inc";
@@ -203,6 +202,7 @@ def test_run_imported_with_noise_produces_noisy_results() -> None:
203202
"{ use (q1, q2) = (Qubit(), Qubit()); Program0(q1, q2) }",
204203
shots=1,
205204
noise=BitFlipNoise(0.1),
205+
seed=0,
206206
)
207207
assert result[0] > 5
208208

0 commit comments

Comments
 (0)