-
-
Notifications
You must be signed in to change notification settings - Fork 48
Labels
MLIRAnything related to MLIRAnything related to MLIRc++Anything related to C++ codeAnything related to C++ codefeatureNew feature or requestNew feature or request
Milestone
Description
Background
OpenQASM 3 introduces gate modifiers to concisely express transformations on quantum gates/blocks (see https://openqasm.com/versions/3.0/language/gates.html#quantum-gate-modifiers). Common modifiers include inv (adjoint), pow(r), and ctrl/negctrl.
In our stack today:
- Controls: handled lazily via the unitary operation interface in both MQT Core IR and MLIR. No separate modifier op required right now.
- Inversion: supported eagerly in MQT Core IR (see
Operation::invert/Operation::get_inverted), but not yet modeled in MLIR and not available in a lazy evaluation scheme - Power: not supported in either MQT Core IR or MLIR, though the OQ3 parser recognizes the syntax. Support for adding that to the MQT Core IR is tracked in ✨ Support for the powering modifier of OpenQASM 3.0 #27
MLIR concept of “modifiers”
A quick LLM summary about the general concept:
In MLIR, gate modifiers can be represented using one or more of the following approaches:
- Op attributes on the modified op (e.g.,
mqtref.gate {inv}or{pow = r}) with canonicalizations that eliminate attributes by rewriting to equivalent ops. - Wrapper ops that own a region containing the target op(s) (e.g.,
mqtref.inv { ... }), enabling region-level transforms like reversing order and inverting contained ops. - Function- or region-level modifiers for block-wise semantics (e.g., to invert a block of unitary ops), verified via traits (e.g., "unitary-only region").
We’ll introduce a single, consistent framework that:
- Defines a common modifier abstraction.
- Verifies legality via traits/interfaces (e.g., only unitary ops permit
inv/pow). - Provides canonicalizations to eliminate modifiers when possible (e.g.,
inv(Rz(θ)) -> Rz(-θ)).
Problem
We lack a unified representation for gate modifiers in MLIR; inversion isn’t modeled yet, and pow is missing entirely. We need IR constructs, verifiers, and canonicalizations consistent with frontend semantics and downstream lowerings.
Proposal:
- Introduce modifier attributes and wrapper ops in MQTRef:
- Attributes:
inv: unit,pow: <integer|float>, reservedcontrol(deferred). - Wrapper ops:
mqtref.inv(region-level), optionalmqtref.powerif region application is needed.
- Attributes:
- Define traits/interfaces that mark ops and regions as unitary-only and thus eligible for modifiers.
- Add canonicalizations and legality checks (e.g., prohibit
powon non-unitary ops, allowinvonly on unitary sequences). - Provide lowering guidance for
invandpow(see sub-issues below): eager rewrites where possible; otherwise preserve modifier until a later pass.
Examples:
- Attribute form on a single op
// Conceptual attribute usage (to be legalized by canonicalizations) %q = ... : !mqtref.qubit mqtref.rz %q, %theta {inv} : (!mqtref.qubit, f64) -> ()
- Region form for inverse of a block
mqtref.inv { // quantum-only region mqtref.h %q : !mqtref.qubit mqtref.cz %q0, %q1 : !mqtref.qubit, !mqtref.qubit } // Canonicalization: reverse order and invert each op
Acceptance criteria:
- Common modifier abstraction exists (attributes + region wrapper), with verifiers and traits.
- Canonicalizations for standard gates (e.g., adjoint of rotations, power-of-phase simplifications) are defined at framework level for reuse.
- Documentation added to
docs/mlir.mdcovering the modifier model.
Sub-issues
Metadata
Metadata
Assignees
Labels
MLIRAnything related to MLIRAnything related to MLIRc++Anything related to C++ codeAnything related to C++ codefeatureNew feature or requestNew feature or request