Skip to content

Commit 52e8828

Browse files
committed
introduce class hiearchy, add broadcast to wire successfully
1 parent 4dbe384 commit 52e8828

File tree

2 files changed

+30
-15
lines changed

2 files changed

+30
-15
lines changed

src/bloqade/squin/qubit.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,28 @@
2020
dialect = ir.Dialect("squin.qubit")
2121

2222

23-
@statement(dialect=dialect)
24-
class New(ir.Statement):
23+
@statement
24+
class MultiQubitStatement(ir.Statement):
2525
traits = frozenset({lowering.FromPythonCall()})
26-
n_qubits: ir.SSAValue = info.argument(types.Int)
27-
result: ir.ResultValue = info.result(ilist.IListType[QubitType, types.Any])
26+
operator: ir.SSAValue = info.argument(OpType)
27+
qubits: ir.SSAValue = info.argument(ilist.IListType[QubitType])
2828

2929

3030
@statement(dialect=dialect)
31-
class Apply(ir.Statement):
32-
traits = frozenset({lowering.FromPythonCall()})
33-
operator: ir.SSAValue = info.argument(OpType)
34-
qubits: ir.SSAValue = info.argument(ilist.IListType[QubitType])
31+
class Apply(MultiQubitStatement):
32+
pass
3533

3634

3735
@statement(dialect=dialect)
38-
class Broadcast(ir.Statement):
36+
class Broadcast(MultiQubitStatement):
37+
pass
38+
39+
40+
@statement(dialect=dialect)
41+
class New(ir.Statement):
3942
traits = frozenset({lowering.FromPythonCall()})
40-
operator: ir.SSAValue = info.argument(OpType)
41-
qubits: ir.SSAValue = info.argument(ilist.IListType[QubitType])
43+
n_qubits: ir.SSAValue = info.argument(types.Int)
44+
result: ir.ResultValue = info.result(ilist.IListType[QubitType, types.Any])
4245

4346

4447
@statement(dialect=dialect)

src/bloqade/squin/wire.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,8 @@ class Unwrap(ir.Statement):
4848
result: ir.ResultValue = info.result(WireType)
4949

5050

51-
# In Quake, you put a wire in and get a wire out when you "apply" an operator
52-
# In this case though we just need to indicate that an operator is applied to list[wires]
53-
@statement(dialect=dialect)
54-
class Apply(ir.Statement): # apply(op, w1, w2, ...)
51+
@statement
52+
class MultiWireStatement(ir.Statement):
5553
traits = frozenset({lowering.FromPythonCall(), ir.Pure()})
5654
operator: ir.SSAValue = info.argument(OpType)
5755
inputs: tuple[ir.SSAValue, ...] = info.argument(WireType)
@@ -68,6 +66,20 @@ def __init__(self, operator: ir.SSAValue, *args: ir.SSAValue):
6866
) # custom lowering required for wrapper to work here
6967

7068

69+
# In Quake, you put a wire in and get a wire out when you "apply" an operator
70+
# In this case though we just need to indicate that an operator is applied to list[wires]
71+
@statement(dialect=dialect)
72+
class Apply(MultiWireStatement): # apply(op, w1, w2, ...)
73+
def __init__(self, operator: ir.SSAValue, *args: ir.SSAValue):
74+
super().__init__(operator, *args)
75+
76+
77+
@statement(dialect=dialect)
78+
class Broadcast(MultiWireStatement):
79+
def __init__(self, operator: ir.SSAValue, *args: ir.SSAValue):
80+
super().__init__(operator, *args)
81+
82+
7183
# NOTE: measurement cannot be pure because they will collapse the state
7284
# of the qubit. The state is a hidden state that is not visible to
7385
# the user in the wire dialect.

0 commit comments

Comments
 (0)