mimiqcircuits.decomposition.basis.qasm¶
OpenQASM 2.0 decomposition basis.
Classes
Decomposition basis targeting the OpenQASM 2.0 gate library. |
- class mimiqcircuits.decomposition.basis.qasm.QASMBasis[source]¶
Bases:
DecompositionBasisDecomposition basis targeting the OpenQASM 2.0 gate library.
The terminal gates are the OpenQASM 2.0 built-ins and the gates of the
qelib1.incinclude file that have a direct MIMIQ counterpart, so a decomposed circuit can be written as OpenQASM 2.0 and read back by any parser that ships the standardqelib1.inc.Terminal Operations¶
- Fundamental gates (OpenQASM 2.0 built-in):
GateU,GateCX
- Single-qubit gates from qelib1.inc:
Legacy U gates:
GateU3,GateU2,GateU1Pauli:
GateID,GateX,GateY,GateZHadamard:
GateHPhase:
GateS,GateSDG,GateT,GateTDGRotations:
GateRX,GateRY,GateRZ
- Two-qubit gates from qelib1.inc:
Controlled Paulis and Hadamard:
GateCY,GateCZ,GateCHControlled rotations:
GateCRX,GateCRY,GateCRZGateSWAPIsing couplings:
GateRXX,GateRZZ
- Three- and four-qubit gates from qelib1.inc:
GateCCX,GateCSWAP,GateC3X
- Non-unitary operations:
Measure,Reset,BarrierIfStatementwhose inner operation is terminal
- Custom gates:
GateCallwhose declaration contains only terminal operations
Every other operation is decomposed through
CanonicalRewrite. Operations that OpenQASM 2.0 cannot express and that have no decomposition into the gates above (noise channels, classical operations, annotations, Z-register operations, …) raiseDecompositionError.MeasureResetdecomposes intoMeasurefollowed byReset. This leaves the same state and bit as its canonical decomposition, a measurement and anXconditioned on its outcome, and unlike that conditional it can be written for a circuit of any number of bits. OpenQASM 2.0 has no loops, soWhileStatementraisesDecompositionError.Example
>>> from mimiqcircuits import Circuit, GateH, GateCCX >>> from mimiqcircuits.decomposition import decompose, QASMBasis >>> c = Circuit() >>> c.push(GateH(), 0) 1-qubit circuit with 1 instruction: └── H @ q[0] >>> c.push(GateCCX(), 0, 1, 2) 3-qubit circuit with 2 instructions: ├── H @ q[0] └── C₂X @ q[0:1], q[2] >>> # Decompose to QASM-compatible gates >>> qasm_circuit = decompose(c, QASMBasis())
See also
CanonicalBasis,CliffordTBasis,StimBasis- decompose(op, qubits, bits, zvars)[source]¶
Decompose a non-terminal operation using canonical rewrite.
- Parameters:
- Returns:
A Circuit containing the decomposed instructions.
- Raises:
DecompositionError – If the operation cannot be decomposed.
- Return type: