|q⟩ Bad Qubits

intermediate · Programming · Quantum Error Detection (Intro)

The Three-Qubit Bit-Flip Code

Classical computers guard data against hardware faults by repeating bits: instead of storing 0, a hard drive stores 000, and a majority vote corrects any single bit flip. The quantum world is more constrained — we cannot clone an unknown state, and measuring to check for errors would collapse the superposition we are trying to protect. Yet the spirit of repetition still works, at least for one type of noise.

Errors in quantum channels

A bit-flip error is a Pauli XX acting on a qubit without our knowledge:

Xψ=X(α0+β1)=α1+β0.X|\psi\rangle = X(\alpha|0\rangle + \beta|1\rangle) = \alpha|1\rangle + \beta|0\rangle.

If we store ψ|\psi\rangle in a single physical qubit, one such error scrambles the information irreversibly. The three-qubit bit-flip code spreads the logical information across three physical qubits so that any single XX error can be detected and corrected by syndrome measurement.

Logical codewords

Define the logical basis states:

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

An arbitrary logical qubit ψL=α0L+β1L|\psi_L\rangle = \alpha|0_L\rangle + \beta|1_L\rangle then becomes

ψL=α000+β111.|\psi_L\rangle = \alpha|000\rangle + \beta|111\rangle.

The encoding circuit

Start with qubit q0=ψ=α0+β1q_0 = |\psi\rangle = \alpha|0\rangle + \beta|1\rangle and ancilla qubits q1=q2=0q_1 = q_2 = |0\rangle. Two CNOT gates — each controlled on q0q_0 — propagate q0q_0's computational-basis value to the ancillas:

(α0+β1)00CNOT01α000+β110CNOT02α000+β111.(\alpha|0\rangle + \beta|1\rangle)|00\rangle \xrightarrow{\text{CNOT}_{0\to1}} \alpha|000\rangle + \beta|110\rangle \xrightarrow{\text{CNOT}_{0\to2}} \alpha|000\rangle + \beta|111\rangle.

The result is exactly α0L+β1L\alpha|0_L\rangle + \beta|1_L\rangle.

Why does this not violate no-cloning? Because the circuit does not copy α\alpha and β\beta — it creates an entangled state in which both amplitudes are still encoded together. There is no way to extract ψ|\psi\rangle from any single qubit without disturbing the others.

Error correction (preview)

After a potential bit-flip channel, we measure two parity checks — comparisons between pairs of qubits — without ever touching the logical information:

| Syndrome (q0q1q_0 q_1, q1q2q_1 q_2) | Error | |---|---| | 00 | None | | 10 | Flip on q0q_0 | | 11 | Flip on q1q_1 | | 01 | Flip on q2q_2 |

The syndrome tells us which qubit flipped, so we apply a corrective XX to that qubit and the logical state is restored. The amplitudes α\alpha and β\beta are never revealed.

Try it

Prepare qubit 0 in +=12(0+1)|+\rangle = \tfrac{1}{\sqrt{2}}(|0\rangle+|1\rangle) (so both logical codewords are equally weighted), then apply the two CNOT gates to encode it. The encoded state should be 12(000+111)\tfrac{1}{\sqrt{2}}(|000\rangle + |111\rangle). The grader checks the full statevector.

Run your code to see the quantum state.

After running, inspect the Statevector panel: only amplitudes 000|000\rangle and 111|111\rangle should be non-zero, each with magnitude 120.707\tfrac{1}{\sqrt{2}} \approx 0.707.

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