|q⟩ Bad Qubits

advanced · Programming · Capstone Projects

Project: A Full QEC Demo

A single error-correcting gate is not error correction — a real demo runs the full cycle: encode a logical qubit, let an error strike, extract a syndrome without disturbing the encoded information, and apply the correction the syndrome names. This capstone wires all four stages together for the three-qubit bit-flip code, the simplest code that actually fixes an error.

The code and its codewords

The bit-flip code spreads one logical qubit across three physical qubits:

∣0L⟩=∣000⟩,∣1L⟩=∣111⟩.|0_L\rangle = |000\rangle, \qquad |1_L\rangle = |111\rangle.

A general logical state α∣0L⟩+β∣1L⟩\alpha|0_L\rangle + \beta|1_L\rangle is encoded from a prepared data qubit by two CNOTs. Here we encode the logical ∣+L⟩|+_L\rangle:

∣+L⟩=12(∣000⟩+∣111⟩),|+_L\rangle = \frac{1}{\sqrt{2}}\bigl(|000\rangle + |111\rangle\bigr),

built by H(0); CX(0,1); CX(0,2).

Syndrome extraction without measurement collapse

The stabilizers are Z0Z1Z_0Z_1 and Z1Z2Z_1Z_2. Rather than measuring the data qubits (which would collapse the superposition), we copy each parity onto a fresh ancilla with CNOTs:

Z0Z1⟶ancilla 3,Z1Z2⟶ancilla 4.Z_0Z_1 \longrightarrow \text{ancilla } 3, \qquad Z_1Z_2 \longrightarrow \text{ancilla } 4.

Each ancilla flips once per data qubit involved in its check. The encoded superposition is left intact because the parity of a valid codeword is identical across both branches ∣000⟩|000\rangle and ∣111⟩|111\rangle — the ancilla learns only the error, not the logical amplitude.

A worked round

Inject X1X_1 on the middle data qubit. It participates in both checks, so both ancillas flip, giving syndrome (1,1)(1,1). The decoder for this code maps (1,1)↦(1,1) \mapsto "flip qubit 1," and applying X1X_1 again restores the codeword:

X1 X1 ∣+L⟩=∣+L⟩.X_1\, X_1\, |+_L\rangle = |+_L\rangle.

Try it

Build the four stages — encode, inject X1X_1, extract the syndrome, correct — on the 5-qubit register. The grader checks the final statevector: the data block back in ∣+L⟩|+_L\rangle and the ancillas holding the syndrome (1,1)(1,1).

Run your code to see the quantum state.

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