Skip to content

Commit a4aca8a

Browse files
committed
fix import
1 parent 8f845e2 commit a4aca8a

File tree

5 files changed

+88
-96
lines changed

5 files changed

+88
-96
lines changed

src/bloqade/noise/fidelity.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33

44
from bloqade.analysis.fidelity import FidelityAnalysis
55

6-
from .native import dialect as native
6+
from .native import dialect
77
from .native.stmts import PauliChannel, CZPauliChannel, AtomLossChannel
8-
from ..analysis.address import AddressQubit, AddressTuple
8+
from bloqade.analysis.address import AddressQubit, AddressTuple
99

1010

11-
@native.register(key="circuit.fidelity")
11+
@dialect.register(key="circuit.fidelity")
1212
class FidelityMethodTable(interp.MethodTable):
1313

1414
@interp.impl(PauliChannel)

src/bloqade/noise/native/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""NOTE: This module is not guaranteed to be supported long-term in bloqade. We will be
22
moving towards a more general approach to noise modeling in the future."""
33

4-
from ._emit import NativeNoise as NativeNoise
54
from .model import (
65
GateNoiseParams as GateNoiseParams,
76
TwoRowZoneModel as TwoRowZoneModel,

src/bloqade/noise/native/_emit.py

Lines changed: 0 additions & 91 deletions
This file was deleted.

src/bloqade/noise/native/stmts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from kirin.decl import info, statement
55
from kirin.dialects import ilist
66

7-
from bloqade.qasm2.types import QubitType
7+
from bloqade.types import QubitType
88

99
from ._dialect import dialect
1010

src/bloqade/qasm2/emit/gate.py

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from typing import Any
12
from dataclasses import field, dataclass
23

34
from kirin import ir, types, interp
@@ -7,6 +8,8 @@
78
from bloqade.types import QubitType
89
from bloqade.qasm2.parse import ast
910

11+
from bloqade.noise import native
12+
1013
from .base import EmitError, EmitQASM2Base, EmitQASM2Frame
1114

1215

@@ -86,3 +89,84 @@ def emit_err(self, emit: EmitQASM2Gate, frame: EmitQASM2Frame, stmt):
8689
@interp.impl(func.ConstantNone)
8790
def ignore(self, emit: EmitQASM2Gate, frame: EmitQASM2Frame, stmt):
8891
return ()
92+
93+
94+
@native.dialect.register(key="emit.qasm2.gate")
95+
class NativeNoise(interp.MethodTable):
96+
97+
def _convert(self, node: ast.Bit | ast.Name) -> str:
98+
if isinstance(node, ast.Bit):
99+
return f"{node.name.id}[{node.addr}]"
100+
else:
101+
return f"{node.id}"
102+
103+
@interp.impl(native.CZPauliChannel)
104+
def emit_czp(
105+
self,
106+
emit: EmitQASM2Gate,
107+
frame: EmitQASM2Frame,
108+
stmt: native.CZPauliChannel,
109+
):
110+
paired: bool = stmt.paired
111+
px_ctrl: float = stmt.px_ctrl
112+
py_ctrl: float = stmt.py_ctrl
113+
pz_ctrl: float = stmt.pz_ctrl
114+
px_qarg: float = stmt.pz_qarg
115+
py_qarg: float = stmt.py_qarg
116+
pz_qarg: float = stmt.pz_qarg
117+
ctrls: ilist.IList[ast.Bit, Any] = frame.get(stmt.ctrls)
118+
qargs: ilist.IList[ast.Bit, Any] = frame.get(stmt.qargs)
119+
frame.body.append(
120+
ast.Comment(
121+
text=f"native.CZPauliChannel(paired={paired}, p_ctrl[{px_ctrl}, {py_ctrl}, {pz_ctrl}], p_qarg[{px_qarg}, {py_qarg}, {pz_qarg}])"
122+
)
123+
)
124+
frame.body.append(
125+
ast.Comment(
126+
text=f" -: ctrls: {', '.join([self._convert(q) for q in ctrls])}"
127+
)
128+
)
129+
frame.body.append(
130+
ast.Comment(
131+
text=f" -: qargs: {', '.join([self._convert(q) for q in qargs])}"
132+
)
133+
)
134+
return ()
135+
136+
@interp.impl(native.AtomLossChannel)
137+
def emit_loss(
138+
self,
139+
emit: EmitQASM2Gate,
140+
frame: EmitQASM2Frame,
141+
stmt: native.AtomLossChannel,
142+
):
143+
prob: float = stmt.prob
144+
qargs: ilist.IList[ast.Bit, Any] = frame.get(stmt.qargs)
145+
frame.body.append(ast.Comment(text=f"native.Atomloss(p={prob})"))
146+
frame.body.append(
147+
ast.Comment(
148+
text=f" -: qargs: {', '.join([self._convert(q) for q in qargs])}"
149+
)
150+
)
151+
return ()
152+
153+
@interp.impl(native.PauliChannel)
154+
def emit_pauli(
155+
self,
156+
emit: EmitQASM2Gate,
157+
frame: EmitQASM2Frame,
158+
stmt: native.PauliChannel,
159+
):
160+
px: float = stmt.px
161+
py: float = stmt.py
162+
pz: float = stmt.pz
163+
qargs: ilist.IList[ast.Bit, Any] = frame.get(stmt.qargs)
164+
frame.body.append(
165+
ast.Comment(text=f"native.Atomloss(px={px}, py={py}, pz={pz})")
166+
)
167+
frame.body.append(
168+
ast.Comment(
169+
text=f" -: qargs: {', '.join([self._convert(q) for q in qargs])}"
170+
)
171+
)
172+
return ()

0 commit comments

Comments
 (0)