QVM v0.4.0
[GitHub]
Docs/Gate Decomposition

โš™๏ธ 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: Basisย Gates={id,rz(ฮธ),sx,x,cx}\text{Basis Gates} = \{ \text{id}, \text{rz}(\theta), \text{sx}, \text{x}, \text{cx} \}

  • id: Identity gate (delay/no-op).
  • rz: Parameterized Z-axis rotation.
  • sx: Square-root of X (SX=XSX = \sqrt{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 (c1,c2c_1, c_2) are in the โˆฃ1โŸฉ|1\rangle state, the target qubit (tt) 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 1515 gates:

Rendering diagram...

The 15-Gate Sequence:

  1. H on target qubit (tt).
  2. CX with control c2c_2 and target tt.
  3. Rz(-ฯ€/4) (or Tโ€ T^\dagger) on target tt.
  4. CX with control c1c_1 and target tt.
  5. Rz(ฯ€/4) (or TT) on target tt.
  6. CX with control c2c_2 and target tt.
  7. Rz(-ฯ€/4) on target tt.
  8. CX with control c1c_1 and target tt.
  9. Rz(ฯ€/4) on control c2c_2.
  10. Rz(ฯ€/4) on target tt.
  11. H on target tt.
  12. CX with control c1c_1 and target c2c_2.
  13. Rz(ฯ€/4) on control c1c_1.
  14. Rz(-ฯ€/4) on control c2c_2.
  15. CX with control c1c_1 and target c2c_2.

This sequence requires 66 CNOT gates, 22 Hadamard gates, and 77 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:

qasm
if (c == 1) {
    ccx q[0], q[1], q[2];
}

The decomposed sequence is generated with the same condition applied to each gate:

python
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.