Skip to content

feat: add gate decomposition for standard QASM gates #14

@clebrin

Description

@clebrin

Context

The current parser only supports the native Graphix gate set and raises NotImplementedError for unsupported gates. However, several standard OpenQASM gates can be expressed as sequences of native Graphix operations, up to a global phase. Supporting these decompositions would increase the range of circuits that can be translated without requiring additional gate implementations.

Proposal

Extend visitGateCallStatement with a _decompose() method that maps supported OpenQASM gates to equivalent sequences of native Graphix instructions before appending them to self.instructions.

Examples of gates that could be supported through decomposition:

Gate Decomposition
u3(θ,φ,λ) / u / U Rz(φ) · Ry(θ) · Rz(λ)
sdg Rz(-π/2)
t Rz(π/4)
tdg Rz(-π/4)
sx Rx(π/2)
sxdg Rx(-π/2)

Additional decompositions can be added incrementally as needed.

Note

This approach moves the implementation beyond pure parsing, as it rewrites gates during translation. For example, a circuit parsed and then serialized back may not preserve the original gate set.

If a stricter separation of concerns is preferred, this functionality could instead be implemented in a dedicated transpilation layer (e.g. an OpenQASMTranspiler) rather than directly in the parser.

I am ready to work on this and push a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions