-
-
Notifications
You must be signed in to change notification settings - Fork 50
Closed
Copy link
Labels
MLIRAnything related to MLIRAnything related to MLIRc++Anything related to C++ codeAnything related to C++ codedocumentationImprovements or additions to documentationImprovements or additions to documentationenhancementImprovement of existing featureImprovement of existing feature
Milestone
Description
Background
Frontends like OpenQASM 3, Qiskit, or our own MQT Core IR allow both scalar captures (bit c = measure q;) and writes into bit arrays (c[0] = measure q[0];). MLIR favors SSA values, while QIR and frontends often assume reference/memory semantics for classical bits.
Problem
We need a consistent representation across MQTRef and MQTOpt that enables import, optimization, classical control, and QIR lowering without losing the intended number of observable outputs.
A quantum program requesting a classical register of size N will expect (at least) N classical values to be available.
Proposal:
- Default:
measurereturnsi1(SSA), as it does at the moment. When a classical register is needed (because it is part of the input program), store the result into amemref<?xi1>at the appropriate index. This keeps MQTOpt value-semantics-friendly and uses MLIR-nativememreffor storage. - Alternative: A memory-writing measure form (
measure %q, %mem, %idx) for direct stores where desirable (optional extension).
Examples:
- Scalar SSA result
%c = mqtref.measure %q : !mqtref.qubit -> i1
- Store into classical register
%cReg = memref.alloc(%n) : memref<?xi1> memref.store %c, %cReg[%i] : memref<?xi1>
- Load from classical register for control flow
%cond = memref.load %cReg[%i] : memref<?xi1> scf.if %cond { /* ... */ }
Acceptance criteria:
- Decision note committed in docs (e.g.,
docs/mlir.md) detailing the rationale behind the decision being made here QuantumComputationwith classical registers can be faithfully mapped to MLIR
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
MLIRAnything related to MLIRAnything related to MLIRc++Anything related to C++ codeAnything related to C++ codedocumentationImprovements or additions to documentationImprovements or additions to documentationenhancementImprovement of existing featureImprovement of existing feature