Skip to content

Commit fb4e3a3

Browse files
committed
Add unit test with multiple corr errors and move roundtrip test
1 parent 709f662 commit fb4e3a3

File tree

2 files changed

+47
-26
lines changed

2 files changed

+47
-26
lines changed

test/stim/dialects/stim/emit/test_stim_noise.py

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
from bloqade import stim
2+
from bloqade.stim.emit import EmitStimMain
3+
from bloqade.stim.parse import loads
4+
from bloqade.stim.dialects import noise
25

3-
from .base import codegen
6+
emit = EmitStimMain()
7+
8+
9+
def codegen(mt):
10+
# method should not have any arguments!
11+
emit.initialize()
12+
emit.run(mt=mt, args=())
13+
return emit.get_output()
414

515

616
def test_noise():
@@ -49,3 +59,39 @@ def test_correlated_qubit_loss():
4959

5060
out = codegen(test_correlated_qubit_loss)
5161
assert out.strip() == "I_ERROR[correlated_loss:0](0.10000000) 0 1 2"
62+
63+
64+
def test_correlated_qubit_loss_multiple():
65+
66+
@stim.main
67+
def test_correlated_qubit_loss_multiple():
68+
stim.correlated_qubit_loss(probs=(0.1,), targets=(0, 1))
69+
stim.correlated_qubit_loss(probs=(0.1,), targets=(2, 3))
70+
71+
for i in range(2): # repeat the test to ensure the identifier is reset each time
72+
out = codegen(test_correlated_qubit_loss_multiple).strip()
73+
print(out)
74+
assert (
75+
out.strip()
76+
== "I_ERROR[correlated_loss:0](0.10000000) 0 1\n"
77+
+ "I_ERROR[correlated_loss:1](0.10000000) 2 3"
78+
)
79+
80+
81+
def test_correlated_qubit_codegen_roundtrip():
82+
@stim.main
83+
def test():
84+
stim.correlated_qubit_loss(probs=(0.1,), targets=(0, 1, 2))
85+
stim.qubit_loss(probs=(0.2,), targets=(2,))
86+
stim.correlated_qubit_loss(probs=(0.3,), targets=(3, 4))
87+
88+
stim_str = codegen(test)
89+
90+
mt = loads(
91+
stim_str,
92+
nonstim_noise_ops={
93+
"loss": noise.QubitLoss,
94+
"correlated_loss": noise.CorrelatedQubitLoss,
95+
},
96+
)
97+
assert codegen(mt) == stim_str

test/stim/passes/test_squin_noise_to_stim.py

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@
1010
from bloqade.squin import noise, kernel
1111
from bloqade.types import Qubit, QubitType
1212
from bloqade.stim.emit import EmitStimMain
13-
from bloqade.stim.parse import loads
1413
from bloqade.stim.passes import SquinToStimPass, flatten
1514
from bloqade.stim.rewrite import SquinNoiseToStim
1615
from bloqade.squin.rewrite import WrapAddressAnalysis
17-
from bloqade.stim.dialects import noise as stim_noise
1816
from bloqade.analysis.address import AddressAnalysis
1917

2018

@@ -244,29 +242,6 @@ def test():
244242
assert codegen(test) == expected
245243

246244

247-
def test_correlated_qubit_loss_codegen_roundtrip():
248-
249-
@kernel
250-
def test():
251-
q = sq.qalloc(4)
252-
sq.correlated_qubit_loss(0.1, qubits=q[:2])
253-
sq.qubit_loss(0.2, qubit=q[2])
254-
sq.broadcast.qubit_loss(0.3, qubits=q)
255-
sq.broadcast.correlated_qubit_loss(0.1, qubits=[q[:2], q[2:]])
256-
257-
SquinToStimPass(test.dialects)(test)
258-
stim_str = codegen(test)
259-
260-
mt = loads(
261-
stim_str,
262-
nonstim_noise_ops={
263-
"loss": stim_noise.QubitLoss,
264-
"correlated_loss": stim_noise.CorrelatedQubitLoss,
265-
},
266-
)
267-
assert codegen(mt) == stim_str
268-
269-
270245
def test_correlated_qubit_loss_codegen_with_offset():
271246

272247
@kernel

0 commit comments

Comments
 (0)