Skip to content

Commit 39cb5d9

Browse files
committed
fixing more tests, working on stim
1 parent 693a94c commit 39cb5d9

File tree

7 files changed

+18
-7
lines changed

7 files changed

+18
-7
lines changed

src/bloqade/analysis/address/impls.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ def from_literal(literal: Any) -> Address:
6060
match collection:
6161
case PartialIList(data) | PartialTuple(data):
6262
return data
63-
case AddressReg(data):
64-
return tuple(map(AddressQubit, data))
63+
case AddressReg():
64+
return collection.qubits
6565
case ConstResult(const.Value(data)) if isinstance(data, Iterable):
6666
return tuple(map(from_literal, data))
6767
case ConstResult(const.PartialTuple(data)):

src/bloqade/analysis/address/lattice.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ class AddressReg(Address):
100100
def is_subseteq(self, other: Address) -> bool:
101101
return isinstance(other, AddressReg) and self.data == other.data
102102

103+
@property
104+
def qubits(self) -> tuple[AddressQubit, ...]:
105+
return tuple(AddressQubit(i) for i in self.data)
106+
103107

104108
@final
105109
@dataclass

src/bloqade/squin/analysis/schedule.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,8 @@ def _update_dag(self, stmt: ir.Statement, addr: address.Address):
210210
if old_stmt is not None:
211211
self.stmt_dag.add_edge(old_stmt, stmt)
212212
self.use_def[idx] = stmt
213-
elif isinstance(addr, address.AddressTuple):
214-
for sub_addr in addr.data:
213+
elif isinstance(addr, address.AddressReg):
214+
for sub_addr in addr.qubits:
215215
self._update_dag(stmt, sub_addr)
216216

217217
def update_dag(self, stmt: ir.Statement, args: Sequence[ir.SSAValue]):

src/bloqade/stim/rewrite/qubit_to_stim.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ def rewrite_SingleQubitGate(
6060
"""
6161

6262
qubit_addr_attr = stmt.qubits.hints.get("address", None)
63-
6463
if qubit_addr_attr is None:
6564
return RewriteResult()
6665

src/bloqade/stim/rewrite/squin_noise.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def rewrite_NoiseChannel(
3030
"""Rewrite NoiseChannel statements to their stim equivalents."""
3131

3232
rewrite_method = getattr(self, f"rewrite_{type(stmt).__name__}", None)
33+
3334
# No rewrite method exists and the rewrite should stop
3435
if rewrite_method is None:
3536
return RewriteResult()
@@ -39,6 +40,7 @@ def rewrite_NoiseChannel(
3940
# support broadcasting for multi-qubit noise channels.
4041
# Therefore, we must expand the broadcast into individual stim statements.
4142
qubit_address_attr = stmt.qubits.hints.get("address", None)
43+
print(qubit_address_attr)
4244
if not isinstance(qubit_address_attr, AddressAttribute):
4345
return RewriteResult()
4446

src/bloqade/stim/rewrite/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def insert_qubit_idx_from_address(
2121
"""
2222
address_data = address.address
2323
qubit_idx_ssas = []
24-
24+
print(address_data)
2525
if isinstance(address_data, AddressReg):
2626
for qubit_idx in address_data.data:
2727
create_and_insert_qubit_idx_stmt(

test/stim/passes/test_squin_noise_to_stim.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,12 +220,18 @@ def test():
220220
q = sq.qalloc(3)
221221
sq.correlated_qubit_loss(0.1, qubits=q[:2])
222222

223-
SquinToStimPass(test.dialects)(test)
223+
frame, ret = AddressAnalysis(kernel).run_analysis(test)
224224

225+
SquinToStimPass(test.dialects)(test)
226+
test.print(analysis=frame.entries)
225227
expected = "I_ERROR[correlated_loss:0](0.10000000) 0 1"
226228
assert codegen(test) == expected
227229

228230

231+
if __name__ == "__main__":
232+
test_correlated_qubit_loss()
233+
234+
229235
def test_broadcast_correlated_qubit_loss():
230236
@kernel
231237
def test():

0 commit comments

Comments
 (0)