Skip to content

Commit 9e242e7

Browse files
committed
fixing tests
1 parent e670117 commit 9e242e7

File tree

12 files changed

+104
-117
lines changed

12 files changed

+104
-117
lines changed

src/bloqade/pyqrack/noise/native.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
from kirin import interp
44

5-
from bloqade.noise import native
65
from bloqade.pyqrack import PyQrackInterpreter, reg
6+
from bloqade.qasm2.dialects import noise
77

88

9-
@native.dialect.register(key="pyqrack")
9+
@noise.dialect.register(key="pyqrack")
1010
class PyQrackMethods(interp.MethodTable):
1111
def apply_pauli_error(
1212
self,
@@ -27,12 +27,12 @@ def apply_pauli_error(
2727

2828
getattr(qarg.sim_reg, which)(qarg.addr)
2929

30-
@interp.impl(native.PauliChannel)
30+
@interp.impl(noise.PauliChannel)
3131
def single_qubit_error_channel(
3232
self,
3333
interp: PyQrackInterpreter,
3434
frame: interp.Frame,
35-
stmt: native.PauliChannel,
35+
stmt: noise.PauliChannel,
3636
):
3737
qargs: List[reg.PyQrackQubit] = frame.get(stmt.qargs)
3838

@@ -43,12 +43,12 @@ def single_qubit_error_channel(
4343

4444
return ()
4545

46-
@interp.impl(native.CZPauliChannel)
46+
@interp.impl(noise.CZPauliChannel)
4747
def cz_pauli_channel(
4848
self,
4949
interp: PyQrackInterpreter,
5050
frame: interp.Frame,
51-
stmt: native.CZPauliChannel,
51+
stmt: noise.CZPauliChannel,
5252
):
5353

5454
qargs: List[reg.PyQrackQubit] = frame.get(stmt.qargs)
@@ -80,12 +80,12 @@ def cz_pauli_channel(
8080

8181
return ()
8282

83-
@interp.impl(native.AtomLossChannel)
83+
@interp.impl(noise.AtomLossChannel)
8484
def atom_loss_channel(
8585
self,
8686
interp: PyQrackInterpreter,
8787
frame: interp.Frame,
88-
stmt: native.AtomLossChannel,
88+
stmt: noise.AtomLossChannel,
8989
):
9090
qargs: List[reg.PyQrackQubit] = frame.get(stmt.qargs)
9191

src/bloqade/qasm2/passes/noise.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
DeadCodeElimination,
99
)
1010

11-
from bloqade.noise import native
11+
from bloqade.qasm2 import noise
1212
from bloqade.analysis import address
1313
from bloqade.qasm2.passes.lift_qubits import LiftQubits
1414
from bloqade.qasm2.rewrite.heuristic_noise import NoiseRewriteRule
@@ -25,12 +25,9 @@ class NoisePass(Pass):
2525
2626
```
2727
from bloqade import qasm2
28-
from bloqade.noise import native
29-
from bloqade.qasm2.passes.noise import NoisePass
28+
from bloqade.qasm2.passes import NoisePass
3029
31-
noise_main = qasm2.extended.add(native.dialect)
32-
33-
@noise_main
30+
@qasm2.extended
3431
def main():
3532
q = qasm2.qreg(2)
3633
qasm2.h(q[0])
@@ -51,9 +48,7 @@ def main():
5148
5249
"""
5350

54-
noise_model: native.MoveNoiseModelABC = field(
55-
default_factory=native.TwoRowZoneModel
56-
)
51+
noise_model: noise.MoveNoiseModelABC = field(default_factory=noise.TwoRowZoneModel)
5752
address_analysis: address.AddressAnalysis = field(init=False)
5853

5954
def __post_init__(self):

src/bloqade/qasm2/rewrite/heuristic_noise.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
from kirin.rewrite import abc as rewrite_abc
66
from kirin.dialects import ilist
77

8-
from bloqade.noise import native
98
from bloqade.analysis import address
10-
from bloqade.qasm2.dialects import uop, glob, parallel
9+
from bloqade.qasm2.dialects import uop, glob, noise, parallel
1110

1211

1312
@dataclass
@@ -19,9 +18,7 @@ class NoiseRewriteRule(rewrite_abc.RewriteRule):
1918

2019
address_analysis: Dict[ir.SSAValue, address.Address]
2120
qubit_ssa_value: Dict[int, ir.SSAValue]
22-
noise_model: native.MoveNoiseModelABC = field(
23-
default_factory=native.TwoRowZoneModel
24-
)
21+
noise_model: noise.MoveNoiseModelABC = field(default_factory=noise.TwoRowZoneModel)
2522

2623
def rewrite_Statement(self, node: ir.Statement) -> rewrite_abc.RewriteResult:
2724
if isinstance(node, uop.SingleQubitGate):
@@ -43,10 +40,10 @@ def insert_single_qubit_noise(
4340
qargs: ir.SSAValue,
4441
probs: Tuple[float, float, float, float],
4542
):
46-
native.PauliChannel(qargs, px=probs[0], py=probs[1], pz=probs[2]).insert_before(
43+
noise.PauliChannel(qargs, px=probs[0], py=probs[1], pz=probs[2]).insert_before(
4744
node
4845
)
49-
native.AtomLossChannel(qargs, prob=probs[3]).insert_before(node)
46+
noise.AtomLossChannel(qargs, prob=probs[3]).insert_before(node)
5047

5148
return rewrite_abc.RewriteResult(has_done_something=True)
5249

@@ -103,9 +100,9 @@ def move_noise_stmts(
103100
nodes.append(
104101
qargs := ilist.New(tuple(self.qubit_ssa_value[q] for q in qubits))
105102
)
106-
nodes.append(native.AtomLossChannel(qargs.result, prob=probs[3]))
103+
nodes.append(noise.AtomLossChannel(qargs.result, prob=probs[3]))
107104
nodes.append(
108-
native.PauliChannel(qargs.result, px=probs[0], py=probs[1], pz=probs[2])
105+
noise.PauliChannel(qargs.result, px=probs[0], py=probs[1], pz=probs[2])
109106
)
110107

111108
return nodes
@@ -116,7 +113,7 @@ def cz_gate_noise(
116113
qargs: ir.SSAValue,
117114
) -> list[ir.Statement]:
118115
return [
119-
native.CZPauliChannel(
116+
noise.CZPauliChannel(
120117
ctrls,
121118
qargs,
122119
px_ctrl=self.noise_model.cz_paired_gate_px,
@@ -127,7 +124,7 @@ def cz_gate_noise(
127124
pz_qarg=self.noise_model.cz_paired_gate_pz,
128125
paired=True,
129126
),
130-
native.CZPauliChannel(
127+
noise.CZPauliChannel(
131128
ctrls,
132129
qargs,
133130
px_ctrl=self.noise_model.cz_unpaired_gate_px,
@@ -138,8 +135,8 @@ def cz_gate_noise(
138135
pz_qarg=self.noise_model.cz_unpaired_gate_pz,
139136
paired=False,
140137
),
141-
native.AtomLossChannel(ctrls, prob=self.noise_model.cz_gate_loss_prob),
142-
native.AtomLossChannel(qargs, prob=self.noise_model.cz_gate_loss_prob),
138+
noise.AtomLossChannel(ctrls, prob=self.noise_model.cz_gate_loss_prob),
139+
noise.AtomLossChannel(qargs, prob=self.noise_model.cz_gate_loss_prob),
143140
]
144141

145142
def rewrite_cz_gate(self, node: uop.CZ):

src/bloqade/qbraid/lowering.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
from kirin import ir, types, passes
55
from kirin.dialects import func, ilist
66

7-
from bloqade import noise, qasm2
7+
from bloqade import qasm2
88
from bloqade.qbraid import schema
9-
from bloqade.qasm2.dialects import glob, parallel
9+
from bloqade.qasm2.dialects import glob, noise, parallel
1010

1111

1212
@ir.dialect_group(
13-
[func, qasm2.core, qasm2.uop, parallel, glob, qasm2.expr, noise.native, ilist]
13+
[func, qasm2.core, qasm2.uop, parallel, glob, qasm2.expr, noise, ilist]
1414
)
1515
def qbraid_noise(
1616
self,
@@ -192,7 +192,7 @@ def process_cz_pauli_error(
192192
qargs := ilist.New(values=tuple(self.qubit_id_map[q] for q in qubits))
193193
)
194194
self.block_list.append(
195-
noise.native.PauliChannel(px=px, py=py, pz=pz, qargs=qargs.result)
195+
noise.PauliChannel(px=px, py=py, pz=pz, qargs=qargs.result)
196196
)
197197

198198
for (p_ctrl, p_qarg), qubits in paired_layers.items():
@@ -204,7 +204,7 @@ def process_cz_pauli_error(
204204
qargs := ilist.New(values=tuple(self.qubit_id_map[q] for q in qargs))
205205
)
206206
self.block_list.append(
207-
noise.native.CZPauliChannel(
207+
noise.CZPauliChannel(
208208
paired=True,
209209
px_ctrl=p_ctrl[0],
210210
py_ctrl=p_ctrl[1],
@@ -226,7 +226,7 @@ def process_cz_pauli_error(
226226
qargs := ilist.New(values=tuple(self.qubit_id_map[q] for q in qargs))
227227
)
228228
self.block_list.append(
229-
noise.native.CZPauliChannel(
229+
noise.CZPauliChannel(
230230
paired=False,
231231
px_ctrl=p_ctrl[0],
232232
py_ctrl=p_ctrl[1],
@@ -285,7 +285,7 @@ def lower_pauli_errors(self, operator_error: schema.PauliErrorModel):
285285
qargs := ilist.New(values=tuple(self.qubit_id_map[q] for q in qubits))
286286
)
287287
self.block_list.append(
288-
noise.native.PauliChannel(px=px, py=py, pz=pz, qargs=qargs.result)
288+
noise.PauliChannel(px=px, py=py, pz=pz, qargs=qargs.result)
289289
)
290290

291291
def lower_measurement(self, operation: schema.Measurement):
@@ -303,7 +303,7 @@ def lower_atom_loss(self, survival_probs: Tuple[float, ...]):
303303
for survival_prob, qubits in layers.items():
304304
self.block_list.append(qargs := ilist.New(values=qubits))
305305
self.block_list.append(
306-
noise.native.AtomLossChannel(prob=survival_prob, qargs=qargs.result)
306+
noise.AtomLossChannel(prob=survival_prob, qargs=qargs.result)
307307
)
308308

309309
def lower_number(self, value: float | int) -> ir.SSAValue:

test/analysis/fidelity/test_fidelity.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import pytest
44

55
from bloqade import qasm2
6-
from bloqade.noise import native
6+
from bloqade.qasm2 import noise
77
from bloqade.analysis.fidelity import FidelityAnalysis
88
from bloqade.qasm2.passes.noise import NoisePass
99

@@ -15,7 +15,7 @@ def test_atom_loss_analysis():
1515
@qasm2.extended
1616
def main():
1717
q = qasm2.qreg(2)
18-
native.atom_loss_channel([q[0]], prob=p_loss)
18+
noise.atom_loss_channel([q[0]], prob=p_loss)
1919
return q
2020

2121
fid_analysis = FidelityAnalysis(main.dialects)
@@ -32,7 +32,7 @@ def test_cz_noise():
3232
@qasm2.extended
3333
def main():
3434
q = qasm2.qreg(2)
35-
native.cz_pauli_channel(
35+
noise.cz_pauli_channel(
3636
[q[0]],
3737
[q[1]],
3838
px_ctrl=p_ch,
@@ -63,7 +63,7 @@ def test_single_qubit_noise():
6363
@qasm2.extended
6464
def main():
6565
q = qasm2.qreg(2)
66-
native.pauli_channel([q[0]], px=p_ch, py=p_ch, pz=p_ch)
66+
noise.pauli_channel([q[0]], px=p_ch, py=p_ch, pz=p_ch)
6767
return q
6868

6969
main.print()
@@ -77,7 +77,7 @@ def main():
7777
assert math.isclose(fid_analysis.gate_fidelity, expected_fidelity)
7878

7979

80-
class NoiseTestModel(native.MoveNoiseModelABC):
80+
class NoiseTestModel(noise.MoveNoiseModelABC):
8181
def parallel_cz_errors(self, ctrls, qargs, rest):
8282
return {(0.01, 0.01, 0.01, 0.01): ctrls + qargs + rest}
8383

test/pyqrack/runtime/noise/native/test_loss.py renamed to test/pyqrack/runtime/noise/qasm2/test_loss.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from kirin.dialects import ilist
66

77
from bloqade import qasm2
8-
from bloqade.noise import native
8+
from bloqade.qasm2 import noise
99
from bloqade.pyqrack import PyQrackQubit, PyQrackInterpreter, reg
1010
from bloqade.pyqrack.base import MockMemory
1111

@@ -23,8 +23,8 @@ def test_atom_loss():
2323
@qasm2.extended
2424
def test_atom_loss(c: qasm2.CReg):
2525
q = qasm2.qreg(2)
26-
native.atom_loss_channel([q[0]], prob=0.1)
27-
native.atom_loss_channel([q[1]], prob=0.05)
26+
noise.atom_loss_channel([q[0]], prob=0.1)
27+
noise.atom_loss_channel([q[1]], prob=0.05)
2828
qasm2.measure(q[0], c[0])
2929

3030
return q

test/pyqrack/runtime/noise/native/test_pauli.py renamed to test/pyqrack/runtime/noise/qasm2/test_pauli.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from kirin import ir
55

66
from bloqade import qasm2
7-
from bloqade.noise import native
7+
from bloqade.qasm2 import noise
88
from bloqade.pyqrack.base import MockMemory, PyQrackInterpreter
99

1010

@@ -20,13 +20,13 @@ def test_pauli_channel():
2020
@qasm2.extended
2121
def test_atom_loss():
2222
q = qasm2.qreg(2)
23-
native.pauli_channel(
23+
noise.pauli_channel(
2424
[q[0]],
2525
px=0.1,
2626
py=0.4,
2727
pz=0.3,
2828
)
29-
native.pauli_channel(
29+
noise.pauli_channel(
3030
[q[1]],
3131
px=0.1,
3232
py=0.4,
@@ -45,7 +45,7 @@ def test_pauli_probs_check():
4545
@qasm2.extended
4646
def test_atom_loss():
4747
q = qasm2.qreg(2)
48-
native.pauli_channel(
48+
noise.pauli_channel(
4949
[q[0]],
5050
px=0.1,
5151
py=0.4,
@@ -61,9 +61,9 @@ def test_cz_pauli_channel_false():
6161
@qasm2.extended
6262
def test_atom_loss():
6363
q = qasm2.qreg(2)
64-
native.atom_loss_channel([q[0]], prob=0.4)
65-
native.atom_loss_channel([q[1]], prob=0.4)
66-
native.cz_pauli_channel(
64+
noise.atom_loss_channel([q[0]], prob=0.4)
65+
noise.atom_loss_channel([q[1]], prob=0.4)
66+
noise.cz_pauli_channel(
6767
[q[0]],
6868
[q[1]],
6969
px_ctrl=0.1,
@@ -75,9 +75,9 @@ def test_atom_loss():
7575
paired=False,
7676
) # no noise here
7777
qasm2.cz(q[0], q[1])
78-
native.atom_loss_channel([q[0]], prob=0.7)
79-
native.atom_loss_channel([q[1]], prob=0.4)
80-
native.cz_pauli_channel(
78+
noise.atom_loss_channel([q[0]], prob=0.7)
79+
noise.atom_loss_channel([q[1]], prob=0.4)
80+
noise.cz_pauli_channel(
8181
[q[0]],
8282
[q[1]],
8383
px_ctrl=0.1,
@@ -102,9 +102,9 @@ def test_cz_pauli_channel_true():
102102
@qasm2.extended
103103
def test_atom_loss():
104104
q = qasm2.qreg(2)
105-
native.atom_loss_channel([q[0]], prob=0.4)
106-
native.atom_loss_channel([q[1]], prob=0.4)
107-
native.cz_pauli_channel(
105+
noise.atom_loss_channel([q[0]], prob=0.4)
106+
noise.atom_loss_channel([q[1]], prob=0.4)
107+
noise.cz_pauli_channel(
108108
[q[0]],
109109
[q[1]],
110110
px_ctrl=0.1,
@@ -116,9 +116,9 @@ def test_atom_loss():
116116
paired=True,
117117
) # no noise here
118118
qasm2.cz(q[0], q[1])
119-
native.atom_loss_channel([q[0]], prob=0.7)
120-
native.atom_loss_channel([q[1]], prob=0.4)
121-
native.cz_pauli_channel(
119+
noise.atom_loss_channel([q[0]], prob=0.7)
120+
noise.atom_loss_channel([q[1]], prob=0.4)
121+
noise.cz_pauli_channel(
122122
[q[0]],
123123
[q[1]],
124124
px_ctrl=0.1,

0 commit comments

Comments
 (0)