1- from typing import Any , Optional
21from dataclasses import dataclass
32
4- from kirin .dialects import ilist
5-
63from bloqade .pyqrack import PyQrackQubit
74
85
96@dataclass
107class OperatorRuntimeABC :
11- target_index : int
12-
13- def apply (self , qubits : ilist .IList [PyQrackQubit , Any ]) -> None :
8+ def apply (self , * qubits : PyQrackQubit ) -> None :
149 raise NotImplementedError (
1510 "Operator runtime base class should not be called directly, override the method"
1611 )
@@ -19,18 +14,27 @@ def apply(self, qubits: ilist.IList[PyQrackQubit, Any]) -> None:
1914@dataclass
2015class OperatorRuntime (OperatorRuntimeABC ):
2116 method_name : str
22- ctrl_index : Optional [list [int ]] = None
2317
2418 def apply (
2519 self ,
26- qubits : ilist .IList [PyQrackQubit , Any ],
27- ):
28- target_qubit = qubits [self .target_index ]
29- if self .ctrl_index is not None :
30- ctrls = [qubits [i ].addr for i in self .ctrl_index ]
31- getattr (target_qubit .sim_reg , self .method_name )(ctrls , target_qubit .addr )
32- else :
33- getattr (target_qubit .sim_reg , self .method_name )(target_qubit .addr )
20+ * qubits : PyQrackQubit ,
21+ ) -> None :
22+ getattr (qubits [- 1 ].sim_reg , self .method_name )(qubits [- 1 ].addr )
23+
24+
25+ @dataclass
26+ class ControlRuntime (OperatorRuntimeABC ):
27+ method_name : str
28+ n_controls : int
29+
30+ def apply (
31+ self ,
32+ * qubits : PyQrackQubit ,
33+ ) -> None :
34+ # NOTE: this is a bit odd, since you can "skip" qubits by making n_controls < len(qubits)
35+ ctrls = [qbit .addr for qbit in qubits [: self .n_controls ]]
36+ target = qubits [- 1 ]
37+ getattr (target .sim_reg , self .method_name )(ctrls , target .addr )
3438
3539
3640@dataclass
@@ -39,16 +43,15 @@ class ProjectorRuntime(OperatorRuntimeABC):
3943
4044 def apply (
4145 self ,
42- qubits : ilist .IList [PyQrackQubit , Any ],
43- ):
44- target_qubit = qubits [self .target_index ]
45- target_qubit .sim_reg .force_m (target_qubit .addr , self .to_state )
46+ * qubits : PyQrackQubit ,
47+ ) -> None :
48+ qubits [- 1 ].sim_reg .force_m (qubits [- 1 ].addr , self .to_state )
4649
4750
4851@dataclass
4952class IdentityRuntime (OperatorRuntimeABC ):
5053 # TODO: do we even need sites? The apply never does anything
5154 sites : int
5255
53- def apply (self , qubits : ilist . IList [ PyQrackQubit , Any ]) :
56+ def apply (self , * qubits : PyQrackQubit ) -> None :
5457 pass
0 commit comments