Skip to content

Commit 78e36ed

Browse files
committed
Fixing some tests
1 parent c8ec9a8 commit 78e36ed

File tree

19 files changed

+119
-106
lines changed

19 files changed

+119
-106
lines changed

src/bloqade/cirq_utils/emit/qubit.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@
1010
class EmitCirqQubitMethods(MethodTable):
1111
@impl(qubit.New)
1212
def new(self, emit: EmitCirq, frame: EmitCirqFrame, stmt: qubit.New):
13-
13+
print("emitting new qubit")
1414
if frame.qubits is not None:
1515
cirq_qubit = frame.qubits[frame.qubit_index]
1616
else:
1717
cirq_qubit = cirq.LineQubit(frame.qubit_index)
1818

19-
frame.has_allocations = True
2019
frame.qubit_index += 1
2120
return (cirq_qubit,)
2221

src/bloqade/cirq_utils/lowering.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,19 @@ def main():
142142
body=body,
143143
)
144144

145-
return ir.Method(
145+
mt = ir.Method(
146146
mod=None,
147147
py_func=None,
148148
sym_name=kernel_name,
149149
arg_names=arg_names,
150150
dialects=dialects,
151151
code=code,
152152
)
153+
mt.print()
154+
assert (run_pass := kernel.run_pass) is not None
155+
run_pass(mt, typeinfer=True)
156+
157+
return mt
153158

154159

155160
CirqNode = (
@@ -384,8 +389,16 @@ def bool_op_or(x: bool, y: bool) -> bool:
384389
# NOTE: remove stmt from parent block
385390
then_stmt.detach()
386391
then_body = ir.Block((then_stmt,))
392+
then_body.args.append_from(types.Bool, name="cond")
393+
then_body.stmts.append(scf.Yield())
394+
395+
else_body = ir.Block(())
396+
else_body.args.append_from(types.Bool, name="cond")
397+
else_body.stmts.append(scf.Yield())
387398

388-
return state.current_frame.push(scf.IfElse(condition, then_body=then_body))
399+
return state.current_frame.push(
400+
scf.IfElse(condition, then_body=then_body, else_body=else_body)
401+
)
389402

390403
def visit_MeasurementGate(
391404
self, state: lowering.State[cirq.Circuit], node: cirq.GateOperation

src/bloqade/squin/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
noise as noise,
44
qubit as qubit,
55
analysis as analysis,
6-
_typeinfer as _typeinfer,
76
)
87
from .groups import kernel as kernel
98
from .stdlib.qubit import qalloc as qalloc

src/bloqade/squin/stdlib/broadcast/noise.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ def correlated_qubit_loss(
120120
represents a group of qubits to which a correlated loss channel is applied.
121121
122122
Example:
123-
>>> q1 = squin.qubit.new(3) # First group: qubits 0, 1, 2
124-
>>> q2 = squin.qubit.new(3) # Second group: qubits 3, 4, 5
123+
>>> q1 = squin.qalloc(3) # First group: qubits 0, 1, 2
124+
>>> q2 = squin.qalloc(3) # Second group: qubits 3, 4, 5
125125
>>> squin.broadcast.correlated_qubit_loss(0.5, [q1, q2])
126126
# Each group has 50% chance: either all qubits lost or none lost.
127127
# Group 1 and Group 2 outcomes are independent.

src/bloqade/stim/passes/squin_to_stim.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def unsafe_run(self, mt: Method) -> RewriteResult:
102102
rewrite_result = Walk(PyConstantToStim()).rewrite(mt.code).join(rewrite_result)
103103

104104
# clear up leftover stmts
105-
# - remove any squin.qubit.new that's left around
105+
# - remove any squin.qalloc that's left around
106106
rewrite_result = (
107107
Fixpoint(
108108
Walk(

test/analysis/address/test_qubit_analysis.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ def test_tuple_address():
1111

1212
@squin.kernel
1313
def test():
14-
q1 = squin.qubit.new(5)
15-
q2 = squin.qubit.new(10)
14+
q1 = squin.qalloc(5)
15+
q2 = squin.qalloc(10)
1616
squin.broadcast.y(q1)
1717
squin.x(q2[2]) # desugar creates a new ilist here
1818
# natural to expect two AddressTuple types
@@ -37,7 +37,7 @@ def test_get_item():
3737

3838
@squin.kernel
3939
def test():
40-
q = squin.qubit.new(5)
40+
q = squin.qalloc(5)
4141
squin.broadcast.y(q)
4242
x = (q[0], q[3]) # -> AddressTuple(AddressQubit, AddressQubit)
4343
y = q[2] # getitem on ilist # -> AddressQubit
@@ -66,7 +66,7 @@ def extract_qubits(qubits):
6666

6767
@squin.kernel
6868
def test():
69-
q = squin.qubit.new(5)
69+
q = squin.qalloc(5)
7070
squin.broadcast.y(q)
7171
return extract_qubits(q)
7272

@@ -84,7 +84,7 @@ def test_slice():
8484

8585
@squin.kernel
8686
def main():
87-
q = squin.qubit.new(4)
87+
q = squin.qalloc(4)
8888
# get the middle qubits out and apply to them
8989
sub_q = q[1:3]
9090
squin.broadcast.x(sub_q)
@@ -115,7 +115,7 @@ def main():
115115
def test_for_loop_idx():
116116
@squin.kernel
117117
def main():
118-
q = squin.qubit.new(3)
118+
q = squin.qalloc(3)
119119
for i in range(3):
120120
squin.x(q[i])
121121

test/analysis/measure_id/test_measure_id.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ def test_add():
1818
@squin.kernel
1919
def test():
2020

21-
ql1 = squin.qubit.new(5)
22-
ql2 = squin.qubit.new(5)
21+
ql1 = squin.qalloc(5)
22+
ql2 = squin.qalloc(5)
2323
squin.broadcast.x(ql1)
2424
squin.broadcast.x(ql2)
2525
ml1 = squin.qubit.measure(ql1)
@@ -43,7 +43,7 @@ def test_measure_alias():
4343

4444
@squin.kernel
4545
def test():
46-
ql = squin.qubit.new(5)
46+
ql = squin.qalloc(5)
4747
ml = squin.qubit.measure(ql)
4848
ml_alias = ml
4949

@@ -74,7 +74,7 @@ def test_measure_count_at_if_else():
7474

7575
@squin.kernel
7676
def test():
77-
q = squin.qubit.new(5)
77+
q = squin.qalloc(5)
7878
squin.x(q[2])
7979
ms = squin.qubit.measure(q)
8080

@@ -95,7 +95,7 @@ def test():
9595
def test_scf_cond_true():
9696
@squin.kernel
9797
def test():
98-
q = squin.qubit.new(1)
98+
q = squin.qalloc(1)
9999
squin.x(q[2])
100100

101101
ms = None
@@ -125,7 +125,7 @@ def test_scf_cond_false():
125125

126126
@squin.kernel
127127
def test():
128-
q = squin.qubit.new(5)
128+
q = squin.qalloc(5)
129129
squin.x(q[2])
130130

131131
ms = None
@@ -152,7 +152,7 @@ def test():
152152
def test_slice():
153153
@squin.kernel
154154
def test():
155-
q = squin.qubit.new(6)
155+
q = squin.qalloc(6)
156156
squin.x(q[2])
157157

158158
ms = squin.qubit.measure(q)
@@ -180,7 +180,7 @@ def test():
180180
def test_getitem_no_hint():
181181
@squin.kernel
182182
def test(idx):
183-
q = squin.qubit.new(6)
183+
q = squin.qalloc(6)
184184
ms = squin.qubit.measure(q)
185185

186186
return ms[idx]
@@ -195,7 +195,7 @@ def test(idx):
195195
def test_getitem_invalid_hint():
196196
@squin.kernel
197197
def test():
198-
q = squin.qubit.new(6)
198+
q = squin.qalloc(6)
199199
ms = squin.qubit.measure(q)
200200

201201
return ms["x"]
@@ -211,7 +211,7 @@ def test_getitem_propagate_invalid_measure():
211211

212212
@squin.kernel
213213
def test():
214-
q = squin.qubit.new(6)
214+
q = squin.qalloc(6)
215215
ms = squin.qubit.measure(q)
216216
# this will return an InvalidMeasureId
217217
invalid_ms = ms["x"]

test/cirq_utils/test_cirq_to_squin.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ def test_ghz_simulation():
344344
# manually written kernel
345345
@squin.kernel
346346
def manual():
347-
q = squin.qubit.new(2)
347+
q = squin.qalloc(2)
348348
squin.broadcast.s_adj(q)
349349
squin.broadcast.rx(math.pi / 2, q)
350350
squin.broadcast.s(q)
@@ -374,7 +374,7 @@ def test_kernel_with_args():
374374

375375
@squin.kernel
376376
def main(n: int):
377-
q = squin.qubit.new(n)
377+
q = squin.qalloc(n)
378378
for i in range(n):
379379
squin.x(q[i])
380380

@@ -393,7 +393,7 @@ def main(n: int):
393393

394394
@squin.kernel
395395
def multi_arg(n: int, p: float):
396-
q = squin.qubit.new(n)
396+
q = squin.qalloc(n)
397397
squin.h(q[0])
398398

399399
if p > 0:

test/cirq_utils/test_clifford_to_cirq.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
def test_pauli():
1616
@squin.kernel
1717
def main():
18-
q = squin.qubit.new(2)
19-
q2 = squin.qubit.new(4)
18+
q = squin.qalloc(2)
19+
q2 = squin.qalloc(4)
2020
squin.x(q[0])
2121
squin.y(q2[0])
2222
squin.z(q2[3])
@@ -291,7 +291,7 @@ def coinflip():
291291
def test_qalloc_subroutines():
292292
@squin.kernel
293293
def subroutine():
294-
q = squin.qubit.new(1)
294+
q = squin.qalloc(1)
295295
squin.h(q[0])
296296
return q[0]
297297

@@ -330,7 +330,7 @@ def reset(qubits: ilist.IList[Qubit, Any]) -> None: ...
330330

331331
@squin.kernel
332332
def main():
333-
q = squin.qubit.new(4)
333+
q = squin.qalloc(4)
334334
squin.broadcast.x(q)
335335
reset(q)
336336
return squin.qubit.measure(q)

test/cirq_utils/test_squin_noise_to_cirq.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
def test_pauli_channel(run_sim: bool = False):
88
@squin.kernel
99
def main():
10-
q = squin.qubit.new(2)
10+
q = squin.qalloc(2)
1111
squin.h(q[0])
1212
squin.depolarize(0.1, q[0])
1313
squin.cx(q[0], q[1])

0 commit comments

Comments
 (0)