โ๏ธ Gate Decomposition
Physical quantum computers only support a limited set of native operations, called basis gates. Any high-level quantum gate not natively supported must be decomposed (translated) into equivalent sequences of these basis gates. This is handled by Decomposer in decomposer.py.
๐ฏ Native Gate Sets (Basis Gates)
The default target architecture basis gate set is:
id: Identity gate (delay/no-op).rz: Parameterized Z-axis rotation.sx: Square-root of X ().x: Pauli-X gate (Not).cx: Controlled-NOT (CNOT).
These gates form a universal gate set, meaning any multi-qubit unitary transformation can be approximated using only these operations.
๐งฎ Toffoli (CCX) Gate Decomposition
The Toffoli (or Controlled-Controlled-NOT) gate is a 3-qubit gate. If both control qubits () are in the state, the target qubit () is flipped.
Because physical architectures do not support 3-qubit interactions natively, the Toffoli gate must be decomposed into 1-qubit and 2-qubit gates. The Decomposer translates ccx or toffoli into a sequence of gates:
The 15-Gate Sequence:
Hon target qubit ().CXwith control and target .Rz(-ฯ/4)(or ) on target .CXwith control and target .Rz(ฯ/4)(or ) on target .CXwith control and target .Rz(-ฯ/4)on target .CXwith control and target .Rz(ฯ/4)on control .Rz(ฯ/4)on target .Hon target .CXwith control and target .Rz(ฯ/4)on control .Rz(-ฯ/4)on control .CXwith control and target .
This sequence requires CNOT gates, Hadamard gates, and single-qubit rotations.
๐ Preserving Control Flow Metadata
A key feature of the QVM Decomposer is that it preserves control flow metadata. If a high-level gate is conditional, the decomposed gates inherit the same condition.
For example, if the Toffoli gate is conditional:
if (c == 1) {
ccx q[0], q[1], q[2];
}The decomposed sequence is generated with the same condition applied to each gate:
cond = op.get("condition")
decomposition = [
{"name": "h", "qubits": [t], "params": [], "condition": cond},
{"name": "cx", "qubits": [c2, t], "params": [], "condition": cond},
# ... all 15 gates are registered with the condition
]This ensures that the simulator's control-flow engine correctly applies the condition to the entire decomposed sequence.