|
7 | 7 | - `kirin.dialects.ilist`: provides the `ilist.IListType` type for lists of qubits. |
8 | 8 | """ |
9 | 9 |
|
10 | | -from typing import Any |
| 10 | +from typing import Any, overload |
11 | 11 |
|
12 | 12 | from kirin import ir, types, lowering |
13 | 13 | from kirin.decl import info, statement |
@@ -42,7 +42,27 @@ class Broadcast(ir.Statement): |
42 | 42 |
|
43 | 43 |
|
44 | 44 | @statement(dialect=dialect) |
45 | | -class Measure(ir.Statement): |
| 45 | +class MeasureAny(ir.Statement): |
| 46 | + name = "measure" |
| 47 | + |
| 48 | + traits = frozenset({lowering.FromPythonCall()}) |
| 49 | + inputs: ir.SSAValue = info.argument(types.Any) |
| 50 | + result: ir.ResultValue = info.result(types.Any) |
| 51 | + |
| 52 | + |
| 53 | +@statement(dialect=dialect) |
| 54 | +class MeasureQubit(ir.Statement): |
| 55 | + name = "measure.qubit" |
| 56 | + |
| 57 | + traits = frozenset({lowering.FromPythonCall()}) |
| 58 | + qubits: ir.SSAValue = info.argument(ilist.IListType[QubitType]) |
| 59 | + result: ir.ResultValue = info.result(ilist.IListType[types.Bool]) |
| 60 | + |
| 61 | + |
| 62 | +@statement(dialect=dialect) |
| 63 | +class MeasureReg(ir.Statement): |
| 64 | + name = "measure.reg" |
| 65 | + |
46 | 66 | traits = frozenset({lowering.FromPythonCall()}) |
47 | 67 | qubits: ir.SSAValue = info.argument(ilist.IListType[QubitType]) |
48 | 68 | result: ir.ResultValue = info.result(ilist.IListType[types.Bool]) |
@@ -89,9 +109,15 @@ def apply(operator: Op, qubits: ilist.IList[Qubit, Any] | list[Qubit]) -> None: |
89 | 109 | ... |
90 | 110 |
|
91 | 111 |
|
92 | | -@wraps(Measure) |
93 | | -def measure(qubits: ilist.IList[Qubit, Any]) -> int: |
94 | | - """Measure the qubits in the list." |
| 112 | +@overload |
| 113 | +def measure(qubit: Qubit) -> bool: ... |
| 114 | +@overload |
| 115 | +def measure(qubit: ilist.IList[Qubit, Any] | list[Qubit]) -> list[bool]: ... |
| 116 | + |
| 117 | + |
| 118 | +@wraps(MeasureAny) |
| 119 | +def measure(qubit: Any) -> Any: |
| 120 | + """Measure a qubit or qubits in the list." |
95 | 121 |
|
96 | 122 | Args: |
97 | 123 | qubits: The list of qubits to measure. |
|
0 commit comments