| |
| |
| |
| |
| |
|
|
| #ifndef QUANTUM_TYPES |
| #define QUANTUM_TYPES |
|
|
| include "mlir/IR/AttrTypeBase.td" |
| include "mlir/IR/BuiltinTypeInterfaces.td" |
|
|
| |
| |
| |
|
|
| def Quantum_QubitType : TypeDef<"Quantum", "Qubit", [ |
| DeclareTypeInterfaceMethods<MemRefResourceTypeInterface> |
| ]> { |
| let mnemonic = "qubit"; |
| let summary = "A linear qubit resource (no-cloning enforced)"; |
| let description = [{ |
| Represents a single qubit under linear type discipline. |
|
|
| The verifier rejects any use that would: |
| - Duplicate an SSA value holding a qubit (use-def chain has >1 user) |
| - Drop a qubit without measurement or explicit deallocation |
| - Reuse a qubit after measurement without a fresh allocation |
| |
| This is stricter than CUDA-Q Quake, which uses memory semantics |
| (!quake.ref) without enforcement at the type level. |
| }]; |
|
|
| |
| let assemblyFormat = "`qubit`"; |
| } |
|
|
| |
| |
| |
|
|
| def Quantum_QuregType : TypeDef<"Quantum", "Qureg"> { |
| let mnemonic = "qureg"; |
| let parameters = (ins |
| "std::optional<int64_t>":$size |
| ); |
| let assemblyFormat = "`<` (`?`:$size^):($size) `>`"; |
| let summary = "A register of qubits (contiguous allocation)"; |
| let description = [{ |
| Represents a contiguous register of qubits. |
|
|
| If the size is known at compile time, the verifier can check |
| that indexing operations stay within bounds. A dynamic-size |
| register (!quantum.qureg<?>) defers the check to runtime. |
| |
| Qureg values are consumed by entangle/measure ops; slicing |
| produces sub-regions or individual qubits via extract/ref. |
| }]; |
| } |
|
|
| |
| |
| |
|
|
| def Quantum_PauliOperatorType : TypeDef<"Quantum", "PauliOperator"> { |
| let mnemonic = "pauli"; |
| let parameters = (ins |
| "StringAttr":$label, |
| "Attribute":$angle |
| ); |
| let assemblyFormat = "`<` $label (`,` $angle^)? `>`"; |
| let summary = "Non-commutative Pauli / phase operator"; |
| let description = [{ |
| Represents a Pauli operator with an exact algebraic angle. |
|
|
| The label selects the axis: |
| "X" → σ_x (bit flip) |
| "Y" → σ_y (bit + phase flip) |
| "Z" → σ_z (phase flip) |
| "R" → R(θ) = exp(-iθ/2 · σ_z) (rotation) |
|
|
| The angle is stored as a rational or symbolic attribute, |
| not a floating-point approximation. This enables exact |
| algebraic simplification (e.g. R(Ï€) = Z, R(2Ï€) = I). |
|
|
| Use cases: |
| - Exact compilation of Clifford+T circuits |
| - Symbolic parameter optimization (variational algorithms) |
| - Noise-aware compilation where angle precision matters |
| }]; |
| } |
|
|
| |
| |
| |
|
|
| def Quantum_MeasurementResult : TypeDef<"Quantum", "MeasurementResult"> { |
| let mnemonic = "mresult"; |
| let summary = "Classical measurement result (i1 with metadata)"; |
| let description = [{ |
| Wraps a single classical bit (i1) with optional metadata |
| (register name, measurement basis, timestamp). |
| |
| Distinguished from plain i1 to prevent accidental mixing |
| of classical control flow bits with quantum measurement outcomes. |
| }]; |
| } |
|
|
| #endif // QUANTUM_TYPES |
|
|