|q⟩ Bad Qubits

advanced · Programming · Fault-Tolerant Gate Synthesis

Magic-State Injection

The TT gate is what makes Clifford+TT universal — but TT is not transversal for the standard fault-tolerant codes, so we cannot apply it directly the way we apply Clifford gates. The standard fault-tolerant solution is magic-state injection: prepare a special resource state ahead of time, then consume it with only Clifford operations to apply a logical TT to live data. This routes the hard, non-transversal work entirely into off-line state preparation.

The magic state

The relevant resource for the TT gate is

A=T+=0+eiπ/412.|A\rangle = T|+\rangle = \frac{|0\rangle + e^{i\pi/4}\,|1\rangle}{\sqrt{2}} .

Equivalently A=TH0|A\rangle = T H |0\rangle. It is called a magic state because, although it is just a fixed single-qubit state, combining it with (free) Clifford gates lifts the Clifford group all the way to universality — Bravyi and Kitaev's foundational result.

A noisy supply of approximate A|A\rangle states can be purified by magic-state distillation: consuming many low-fidelity copies and Clifford operations to output fewer high-fidelity copies. Distillation is the dominant cost of fault-tolerant computing, which is exactly why we count TT gates so carefully.

Gate teleportation: injecting T

Given one copy of A|A\rangle, a logical TT on a data qubit ψ=α0+β1|\psi\rangle = \alpha|0\rangle + \beta|1\rangle is applied by gate teleportation:

  1. Prepare the ancilla in A|A\rangle.
  2. Apply CNOT\mathrm{CNOT} from the data qubit (control) to the ancilla (target).
  3. Measure the ancilla in the computational basis.
  4. If the outcome is 00, the data qubit holds TψT|\psi\rangle — done. If the outcome is 11, it holds STψS^\dagger T|\psi\rangle up to a global phase, so apply the Clifford correction SS to recover TψT|\psi\rangle (since SS=IS\,S^\dagger = I).

Every step except the magic-state preparation uses only Clifford gates, a measurement, and a classically-controlled Clifford correction — all of which are fault-tolerant. The single non-transversal operation has been pushed into preparing A|A\rangle, which can be done off-line and purified by distillation.

Why measurement-and-correct is fault-tolerant

The byproduct operator after teleportation is always a Clifford (a Pauli times possibly SS), and Cliffords can be tracked classically (Gottesman–Knill) or applied transversally. So even though the circuit contains a mid-circuit measurement and a conditional gate, no single fault spreads uncontrollably: the data qubit interacts with the ancilla through exactly one CNOT, satisfying the "one fault, one error per block" rule.

Try it

The simulator here does not perform the mid-circuit measurement and conditional correction, so we focus on the part that carries the "magic": preparing the resource state A=TH0|A\rangle = T H |0\rangle on a single qubit. The grader checks the state vector: amplitude 1/21/\sqrt{2} on 0|0\rangle and eiπ/4/2e^{i\pi/4}/\sqrt{2} on 1|1\rangle.

Run your code to see the quantum state.

Sign in on the full site to ask questions and join the discussion.