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.
Context
The current parser only supports the native Graphix gate set and raises
NotImplementedErrorfor 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
visitGateCallStatementwith a_decompose()method that maps supported OpenQASM gates to equivalent sequences of native Graphix instructions before appending them toself.instructions.Examples of gates that could be supported through decomposition:
u3(θ,φ,λ)/u/URz(φ) · Ry(θ) · Rz(λ)sdgRz(-π/2)tRz(π/4)tdgRz(-π/4)sxRx(π/2)sxdgRx(-π/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.