Skip to content

✨ Support for the powering modifier of OpenQASM 3.0 #27

@burgholzer

Description

@burgholzer

OpenQASM 3 introduces gate modifiers in order to more efficiently describe quantum circuits. Any modifier mod can be applied to a gate g via mod @ g. For more details, see Section 4.2 in https://arxiv.org/pdf/2104.14722.pdf or the Live Specification.

The powering modifier pow(r) can be used to represent the r-th power of any gate g via pow(r) @ g, where r can either be an integer or a floating point number.

The case where r is a floating-point number needs to be handled by computing the principal logarithm of the unitary that represents g. This might be tricky in general.

The case where r is an integer can be naively solved by repeatedly applying g. If r <0, pow(r) @ g can be translated to inv @ pow(-r) @ g. Several simplifications might be possible here, e.g., the powers of phase gates can easily be computed by appropriately scaling the respective parameter. In its simplest form, pow(2) @ s = z.

At the very least, support for the case where r is an integer shall be provided, which provides much greater flexibility for describing circuits in a standardized way.

MQT Core's OpenQASM parser is already capable of correctly parsing the pow modifier, but lacks support for actually translating it to an appropriate operation in MQT Core:

core/src/qasm3/Importer.cpp

Lines 577 to 580 in d88d1f0

} else {
throw CompilerError("Only ctrl/negctrl/inv modifiers are supported.",
gateCallStatement->debugInfo);
}

It should be possible to handle this pretty similarly to the mqt.core.ir.operations.Operation.invert and the mqt.core.ir.operations.Operation.get_inverted methods.

For the actual implementation, it would be reasonable to consider how Qiskit is handling this, e.g.

I also like this trick for the Python bindings:
https://github.com/Qiskit/qiskit/blob/511ecbf74e5f251e5d1e0607e646e132c9d87d5b/qiskit/circuit/gate.py#L96-L97

Metadata

Metadata

Assignees

No one assigned

    Labels

    CoreAnything related to the Core library and IRenhancementNew feature or requestgood first issueGood for newcomersunitaryHackIssues and PRs intended for unitaryHack

    Projects

    Status

    Todo

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions