Feature Description
Currently, the squin visitor always returns None from the converted QIR function. We need to implement support for returning measurement results from specified qubits when the return_measurements parameter is provided.
Blocked by:
- Measurement operations need to be stable in the
squin package before this can be implemented
Implementation (Optional)
Location: qbraid_qir/squin/visitor.py (lines 124-154)
Proposed changes:
-
Validate qubit indices - Ensure requested qubits are within valid range [0, num_qubits)
-
Check measurement existence - Verify that the requested qubits were actually measured during the circuit execution
-
Return measurement results:
- Single qubit: Return the measurement result directly
- Multiple qubits: Create a
py.tuple.New with all measurement results and return the tuple
-
Track measurements - The target object needs to maintain a measurement_results dictionary mapping qubit IDs to their measurement result values
Code outline:
if return_measurements and len(return_measurements) > 0:
measurement_results = []
for qid in return_measurements:
# Validate qubit index
# Check if qubit was measured
# Append result to measurement_results
if len(measurement_results) == 1:
return_value = measurement_results[0]
else:
tuple_stmt = py.tuple.New(values=tuple(measurement_results))
body.blocks[0].stmts.append(tuple_stmt)
return_value = tuple_stmt.result
else:
return_value = func.ConstantNone()
Feature Description
Currently, the squin visitor always returns
Nonefrom the converted QIR function. We need to implement support for returning measurement results from specified qubits when thereturn_measurementsparameter is provided.Blocked by:
squinpackage before this can be implementedImplementation (Optional)
Location:
qbraid_qir/squin/visitor.py(lines 124-154)Proposed changes:
Validate qubit indices - Ensure requested qubits are within valid range
[0, num_qubits)Check measurement existence - Verify that the requested qubits were actually measured during the circuit execution
Return measurement results:
py.tuple.Newwith all measurement results and return the tupleTrack measurements - The
targetobject needs to maintain ameasurement_resultsdictionary mapping qubit IDs to their measurement result valuesCode outline: