Background
OpenQASM 3 allows pow(r) @ g where r is integer or float. The OQ3 parser in MQT Core recognizes pow but doesn’t lower it to operations. Qiskit offers a reference implementation pattern for powering gates with simplifications.
Problem
Introduce MLIR support for gate powering with a clear initial target (integer r) and a path for future floating-point r (principal logarithm of unitary), plus importer support from OQ3.
Proposal:
- Scope v1 to integer
r:
r > 0: repeat g r times or apply gate-specific simplifications (e.g., pow(2) @ s = z; scale angles for phase families).
r = 0: replace with no-op (identity) where legal.
r < 0: rewrite to inv @ pow(-r) @ g.
- Represent as:
- Attribute on op:
{pow = r} with canonicalization to repeated/simplified gates; or
- Wrapper op
mqtref.power(%r) { ... } for region-level application, if needed.
- Defer float
r: document that floating exponents require the principal logarithm of the unitary; keep as a TODO with clear error/diagnostic if encountered.
- Importer: translate OQ3
pow(r) @ g to the MLIR representation; for integers, perform eager canonicalization where obvious.
Depending on how #1130 turns out to be implemented, the implementation strategy here might be adapted.
Examples:
// Integer r > 0 (conceptual; to be canonicalized)
%q = ... : !mqtref.qubit
mqtref.rz %q, %theta {pow = 3} : (!mqtref.qubit, f64) -> ()
// Canonicalization: either repeat 3x Rz or compute equivalent parameter
// Negative r
// pow(-k) @ g ==> inv @ pow(k) @ g
Acceptance criteria:
- Integer
r powering supported with verifier and canonicalizations (repeat or simplify).
- Importer handles OQ3
pow(r) (integers) and rejects/defer floats with a clear diagnostic.
- Tests for powering on standard gates (incl. simplifications); docs updated with examples and limitations.
Background
OpenQASM 3 allows
pow(r) @ gwhereris integer or float. The OQ3 parser in MQT Core recognizespowbut doesn’t lower it to operations. Qiskit offers a reference implementation pattern for powering gates with simplifications.Problem
Introduce MLIR support for gate powering with a clear initial target (integer
r) and a path for future floating-pointr(principal logarithm of unitary), plus importer support from OQ3.Proposal:
r:r > 0: repeatgrtimes or apply gate-specific simplifications (e.g.,pow(2) @ s = z; scale angles for phase families).r = 0: replace with no-op (identity) where legal.r < 0: rewrite toinv @ pow(-r) @ g.{pow = r}with canonicalization to repeated/simplified gates; ormqtref.power(%r) { ... }for region-level application, if needed.r: document that floating exponents require the principal logarithm of the unitary; keep as a TODO with clear error/diagnostic if encountered.pow(r) @ gto the MLIR representation; for integers, perform eager canonicalization where obvious.Depending on how #1130 turns out to be implemented, the implementation strategy here might be adapted.
Examples:
Acceptance criteria:
rpowering supported with verifier and canonicalizations (repeat or simplify).pow(r)(integers) and rejects/defer floats with a clear diagnostic.