uniqc.compile.decompose module¶
IR-level decomposition of OriginIR-native gates to lower-level equivalents.
Two decomposition targets share the same helper infrastructure:
- QASM 2.0 target (
decompose_for_qasm2()) Rewrites
RPhi,RPhi90,RPhi180,PHASE2Q,UU15into gates inqelib1.incso that cloud parsers (Quafu / QuarkStudio / IBM) accept the output without customgate ... { ... }blocks.- Official OriginIR target (
decompose_for_originir()) Rewrites all OriginIR-ext gates (above plus
ECR,ISWAP,XX,YY,ZZ,XY) into the strict official OriginIR gate set (H,X,Y,Z,S,SX,T,I,RX,RY,RZ,U1,U2,U3,CNOT,CZ,SWAP,TOFFOLI,CSWAP) for submission to OriginQ cloud.
Gate |
Replacement (official OriginIR opcode names) |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
The decomposition preserves the dagger flag by reversing the
replacement sequence and negating angle parameters where appropriate.
Gate instances wrapped with control_qubits are not currently
decomposed; doing so requires lifting each replacement gate to its
controlled form, which is out of scope for this pass — call compile()
explicitly first if you need that.
- uniqc.compile.decompose.decompose_for_originir(circuit)[source]¶
Return a new
Circuitwith OriginIR-ext gates decomposed.All OriginIR-ext-only gates (ECR, ISWAP, XX, YY, ZZ, XY, RPhi, RPhi90, RPhi180, PHASE2Q, UU15) are rewritten into mathematically equivalent sequences of official OriginIR gates. The original circuit is not mutated.
When the input contains no extended gate, the original circuit is returned unchanged (no copy).
Examples
>>> from uniqc.circuit_builder import Circuit >>> c = Circuit(2) >>> c.iswap(0, 1) >>> c.xx(0, 1, 0.5) >>> c2 = decompose_for_originir(c) >>> {op[0] for op in c2.opcode_list}.isdisjoint(ORIGINIR_EXT_DECOMPOSABLE_GATES) True
- uniqc.compile.decompose.decompose_for_qasm2(circuit)[source]¶
Return a new
Circuitwith QASM2-unrepresentable gates rewritten.The original circuit is not mutated. When the input contains no gate in
QASM2_UNREPRESENTABLE_GATES, this returns a shallow copy.Examples
>>> from uniqc.circuit_builder import Circuit >>> c = Circuit(2) >>> c.rphi(0, 0.4, 0.7) >>> c.add_gate("PHASE2Q", [0, 1], params=[0.1, 0.2, 0.3]) >>> c2 = decompose_for_qasm2(c) >>> {op[0] for op in c2.opcode_list}.isdisjoint({"RPhi", "PHASE2Q"}) True
- uniqc.compile.decompose.decompose_opcode_for_originir(op)[source]¶
Return replacement opcodes for
opif it is an OriginIR-ext-only gate.Returns
[op]unchanged whenopis already an official OriginIR gate. RaisesNotImplementedErrorwhen the gate is extended but wrapped withcontrol_qubits.
- uniqc.compile.decompose.decompose_opcode_for_qasm2(op)[source]¶
Return replacement opcodes for
opif it is QASM2-unrepresentable.Returns
[op]unchanged whenopis already a QASM2-friendly opcode. RaisesNotImplementedErrorwhen the gate is inQASM2_UNREPRESENTABLE_GATESbut is wrapped withcontrol_qubits(controlled-RPhi / controlled-UU15 etc. require a more general lift that this lightweight pass does not provide).