Skip to content

[FEATURE] Support measurements in the QIR -> Squin Converter #256

@TheGupta2012

Description

@TheGupta2012

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:

  1. Validate qubit indices - Ensure requested qubits are within valid range [0, num_qubits)

  2. Check measurement existence - Verify that the requested qubits were actually measured during the circuit execution

  3. 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
  4. 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()

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions