Skip to content

Commit 95fa7ec

Browse files
ehua7365johnzl-777
andauthored
Add squin.noise.Depolarize2 statement and rewrite to stim (#368)
Also add rewrite to stim depolarize2 --------- Co-authored-by: John Long <[email protected]>
1 parent 9f7b388 commit 95fa7ec

File tree

6 files changed

+47
-1
lines changed

6 files changed

+47
-1
lines changed

src/bloqade/squin/noise/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
pp_error as pp_error,
55
depolarize as depolarize,
66
qubit_loss as qubit_loss,
7+
depolarize2 as depolarize2,
78
pauli_error as pauli_error,
89
two_qubit_pauli_channel as two_qubit_pauli_channel,
910
single_qubit_pauli_channel as single_qubit_pauli_channel,

src/bloqade/squin/noise/_wrapper.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ def pp_error(op: Op, p: float) -> Op: ...
2020
def depolarize(p: float) -> Op: ...
2121

2222

23+
@wraps(stmts.Depolarize2)
24+
def depolarize2(p: float) -> Op: ...
25+
26+
2327
@wraps(stmts.SingleQubitPauliChannel)
2428
def single_qubit_pauli_channel(
2529
params: ilist.IList[float, Literal[3]] | list[float] | tuple[float, float, float],

src/bloqade/squin/noise/stmts.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,16 @@ class PPError(NoiseChannel):
3333
@statement(dialect=dialect)
3434
class Depolarize(NoiseChannel):
3535
"""
36-
Apply depolarize error to qubit
36+
Apply depolarize error to single qubit
37+
"""
38+
39+
p: ir.SSAValue = info.argument(types.Float)
40+
41+
42+
@statement(dialect=dialect)
43+
class Depolarize2(NoiseChannel):
44+
"""
45+
Apply correlated depolarize error to two qubit
3746
"""
3847

3948
p: ir.SSAValue = info.argument(types.Float)

src/bloqade/stim/rewrite/squin_noise.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,23 @@ def rewrite_TwoQubitPauliChannel(
140140
)
141141
return stim_stmt
142142

143+
def rewrite_Depolarize2(
144+
self,
145+
stmt: qubit.Apply | qubit.Broadcast | wire.Broadcast | wire.Apply,
146+
qubit_idx_ssas: Tuple[SSAValue],
147+
) -> Statement:
148+
"""Rewrite squin.noise.Depolarize2 to stim.Depolarize2."""
149+
150+
squin_channel = stmt.operator.owner
151+
assert isinstance(squin_channel, squin_noise.stmts.Depolarize2)
152+
153+
p = get_const_value(float, squin_channel.p)
154+
p_stmt = py.Constant(p)
155+
p_stmt.insert_before(stmt)
156+
157+
stim_stmt = stim_noise.Depolarize2(targets=qubit_idx_ssas, p=p_stmt.result)
158+
return stim_stmt
159+
143160
def rewrite_Depolarize(
144161
self,
145162
stmt: qubit.Apply | qubit.Broadcast | wire.Broadcast | wire.Apply,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DEPOLARIZE2(0.01500000) 0 1

test/stim/passes/test_squin_noise_to_stim.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,20 @@ def test():
150150
assert codegen(test) == expected_stim_program
151151

152152

153+
def test_broadcast_depolarize2():
154+
155+
@kernel
156+
def test():
157+
q = qubit.new(2)
158+
channel = noise.depolarize2(p=0.015)
159+
qubit.broadcast(channel, q)
160+
return
161+
162+
run_address_and_stim_passes(test)
163+
expected_stim_program = load_reference_program("broadcast_depolarize2.stim")
164+
assert codegen(test) == expected_stim_program
165+
166+
153167
def test_apply_depolarize1():
154168

155169
@kernel

0 commit comments

Comments
 (0)