21
21
from typing import List , Dict , Tuple , Optional
22
22
23
23
from . import Circuit
24
- from .gates import Gate , qasm_gate_table
24
+ from .gates import Gate , qasm_gate_table , Measurement
25
25
from ..utils import settings
26
26
27
27
@@ -140,7 +140,18 @@ def extract_command_parts(self, c: str) -> Tuple[str,List[Fraction],List[str]]:
140
140
def parse_command (self , c : str , registers : Dict [str ,Tuple [int ,int ]]) -> List [Gate ]:
141
141
gates : List [Gate ] = []
142
142
name , phases , args = self .extract_command_parts (c )
143
- if name in ("barrier" ,"creg" ,"measure" , "id" ): return gates
143
+ if name in ("barrier" ,"creg" , "id" ): return gates
144
+ if name == "measure" :
145
+ target , result_bit = args [0 ].split (' -> ' )
146
+ # Extract the register name and index separately for both target and result
147
+ _ , target_idx = target .split ('[' )
148
+ _ , result_idx = result_bit .split ('[' )
149
+ # Remove the trailing ']' and convert to int
150
+ target_qbit = int (target_idx [:- 1 ])
151
+ result_register = int (result_idx [:- 1 ])
152
+ gate = Measurement (target_qbit , result_register )
153
+ gates .append (gate )
154
+ return gates
144
155
if name in ("opaque" , "if" ):
145
156
raise TypeError ("Unsupported operation {}" .format (c ))
146
157
if name == "qreg" :
@@ -154,9 +165,12 @@ def parse_command(self, c: str, registers: Dict[str,Tuple[int,int]]) -> List[Gat
154
165
dim = 1
155
166
for a in args :
156
167
if "[" in a :
168
+ # Split at the first '[' to handle multi-character register names
157
169
regname , valp = a .split ("[" ,1 )
170
+ # Remove the trailing ']' before converting to int
158
171
val = int (valp [:- 1 ])
159
- if regname not in registers : raise TypeError ("Invalid register {}" .format (regname ))
172
+ if regname not in registers :
173
+ raise TypeError ("Invalid register {}" .format (regname ))
160
174
qubit_values .append ([registers [regname ][0 ]+ val ])
161
175
else :
162
176
if is_range :
0 commit comments