Skip to content

Commit 75b62f0

Browse files
weinbe58david-pl
andauthored
Adding native noise dialect to the extended dialect by default (#269)
This should enable you guys to program noise inside a kernel by default. cc: @stefan-o @MilanKornjacaQ @Roger-luo --------- Co-authored-by: David Plankensteiner <[email protected]>
1 parent 20fd0ad commit 75b62f0

File tree

5 files changed

+48
-23
lines changed

5 files changed

+48
-23
lines changed

src/bloqade/noise/native/_wrappers.py

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,28 @@
88

99

1010
@wraps(native.AtomLossChannel)
11-
def atom_loss_channel(
12-
qargs: ilist.IList[Qubit, Any] | list, *, prob: float
13-
) -> None: ...
11+
def atom_loss_channel(qargs: ilist.IList[Qubit, Any] | list, *, prob: float) -> None:
12+
"""Apply an atom loss channel to a list of qubits.
13+
14+
Args:
15+
qargs (ilist.IList[Qubit, Any] | list): List of qubits to apply the noise to.
16+
prob (float): The loss probability.
17+
"""
18+
...
1419

1520

1621
@wraps(native.PauliChannel)
1722
def pauli_channel(
1823
qargs: ilist.IList[Qubit, Any] | list, *, px: float, py: float, pz: float
19-
) -> None: ...
24+
) -> None:
25+
"""Apply a Pauli channel to a list of qubits.
26+
27+
Args:
28+
qargs (ilist.IList[Qubit, Any] | list): List of qubits to apply the noise to.
29+
px (float): Probability of X error.
30+
py (float): Probability of Y error.
31+
pz (float): Probability of Z error.
32+
"""
2033

2134

2235
@wraps(native.CZPauliChannel)
@@ -31,4 +44,20 @@ def cz_pauli_channel(
3144
py_qarg: float,
3245
pz_qarg: float,
3346
paired: bool,
34-
) -> None: ...
47+
) -> None:
48+
"""Insert noise for a CZ gate with a Pauli channel on qubits.
49+
50+
Args:
51+
ctrls: List of control qubits.
52+
qarg2: List of target qubits.
53+
px_ctrl: Probability of X error on control qubits.
54+
py_ctrl: Probability of Y error on control qubits.
55+
pz_ctrl: Probability of Z error on control qubits.
56+
px_qarg: Probability of X error on target qubits.
57+
py_qarg: Probability of Y error on target qubits.
58+
pz_qarg: Probability of Z error on target qubits.
59+
paired: If True, the noise is applied to both control and target qubits
60+
are not lost otherwise skip this error. If False Apply the noise on
61+
the whatever qubit is not lost.
62+
"""
63+
...

src/bloqade/qasm2/groups.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from kirin.prelude import structural_no_opt
33
from kirin.dialects import scf, func, ilist, lowering
44

5+
from bloqade.noise import native
56
from bloqade.qasm2.dialects import (
67
uop,
78
core,
@@ -90,6 +91,7 @@ def run_pass(
9091
noise,
9192
parallel,
9293
core,
94+
native,
9395
]
9496
)
9597
)

test/analysis/fidelity/test_fidelity.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
from bloqade.analysis.fidelity import FidelityAnalysis
88
from bloqade.qasm2.passes.noise import NoisePass
99

10-
noise_main = qasm2.extended.add(native.dialect)
11-
1210

1311
class NoiseTestModel(native.MoveNoiseModelABC):
1412
def parallel_cz_errors(self, ctrls, qargs, rest):
@@ -17,7 +15,7 @@ def parallel_cz_errors(self, ctrls, qargs, rest):
1715

1816
def test_basic_noise():
1917

20-
@noise_main
18+
@qasm2.extended
2119
def main():
2220
q = qasm2.qreg(2)
2321
qasm2.x(q[0])
@@ -65,7 +63,7 @@ def main():
6563

6664

6765
def test_c_noise():
68-
@noise_main
66+
@qasm2.extended
6967
def main():
7068
q = qasm2.qreg(2)
7169
qasm2.cz(q[0], q[1])
@@ -118,7 +116,7 @@ def main():
118116
@pytest.mark.xfail
119117
def test_if():
120118

121-
@noise_main
119+
@qasm2.extended
122120
def main():
123121
q = qasm2.qreg(1)
124122
c = qasm2.creg(1)
@@ -129,7 +127,7 @@ def main():
129127

130128
return c
131129

132-
@noise_main
130+
@qasm2.extended
133131
def main_if():
134132
q = qasm2.qreg(1)
135133
c = qasm2.creg(1)
@@ -179,7 +177,7 @@ def main_if():
179177
@pytest.mark.xfail
180178
def test_for():
181179

182-
@noise_main
180+
@qasm2.extended
183181
def main():
184182
q = qasm2.qreg(1)
185183
c = qasm2.creg(1)
@@ -195,7 +193,7 @@ def main():
195193

196194
return c
197195

198-
@noise_main
196+
@qasm2.extended
199197
def main_for():
200198
q = qasm2.qreg(1)
201199
c = qasm2.creg(1)

test/pyqrack/runtime/noise/native/test_loss.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
from bloqade.pyqrack import PyQrackQubit, PyQrackInterpreter, reg
1010
from bloqade.pyqrack.base import MockMemory
1111

12-
simulation = qasm2.extended.add(native)
13-
1412

1513
def run_mock(program: ir.Method, rng_state: Mock | None = None):
1614
PyQrackInterpreter(
@@ -22,7 +20,7 @@ def run_mock(program: ir.Method, rng_state: Mock | None = None):
2220

2321
def test_atom_loss():
2422

25-
@simulation
23+
@qasm2.extended
2624
def test_atom_loss(c: qasm2.CReg):
2725
q = qasm2.qreg(2)
2826
native.atom_loss_channel([q[0]], prob=0.1)
@@ -37,7 +35,7 @@ def test_atom_loss(c: qasm2.CReg):
3735
memory = MockMemory()
3836

3937
result: ilist.IList[PyQrackQubit, Literal[2]] = PyQrackInterpreter(
40-
simulation, memory=memory, rng_state=rng_state
38+
qasm2.extended, memory=memory, rng_state=rng_state
4139
).run(test_atom_loss, (input,))
4240

4341
assert result[0].state is reg.QubitState.Lost

test/pyqrack/runtime/noise/native/test_pauli.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
from bloqade.noise import native
88
from bloqade.pyqrack.base import MockMemory, PyQrackInterpreter
99

10-
simulation = qasm2.extended.add(native)
11-
1210

1311
def run_mock(program: ir.Method, rng_state: Mock | None = None):
1412
PyQrackInterpreter(
@@ -19,7 +17,7 @@ def run_mock(program: ir.Method, rng_state: Mock | None = None):
1917

2018

2119
def test_pauli_channel():
22-
@simulation
20+
@qasm2.extended
2321
def test_atom_loss():
2422
q = qasm2.qreg(2)
2523
native.pauli_channel(
@@ -44,7 +42,7 @@ def test_atom_loss():
4442

4543
@pytest.mark.xfail
4644
def test_pauli_probs_check():
47-
@simulation
45+
@qasm2.extended
4846
def test_atom_loss():
4947
q = qasm2.qreg(2)
5048
native.pauli_channel(
@@ -60,7 +58,7 @@ def test_atom_loss():
6058

6159

6260
def test_cz_pauli_channel_false():
63-
@simulation
61+
@qasm2.extended
6462
def test_atom_loss():
6563
q = qasm2.qreg(2)
6664
native.atom_loss_channel([q[0]], prob=0.4)
@@ -101,7 +99,7 @@ def test_atom_loss():
10199

102100

103101
def test_cz_pauli_channel_true():
104-
@simulation
102+
@qasm2.extended
105103
def test_atom_loss():
106104
q = qasm2.qreg(2)
107105
native.atom_loss_channel([q[0]], prob=0.4)

0 commit comments

Comments
 (0)