Curriculum / Noise & Error Correction / Bit-Flip Errors

Lesson 2 of 14Code challengePro+125 XP

Bit-Flip Errors

Simulate and detect bit-flip errors in quantum circuits.

Bit-Flip Errors

A bit-flip error is the simplest quantum error: some time during your computation, the environment applies an unwanted X gate to one of your qubits. Before the error, the qubit was in α|0⟩ + β|1⟩; after the error, it is in β|0⟩ + α|1⟩. The two amplitudes have swapped. Viewed from the Bloch sphere, the state has been reflected through the X axis.

Mathematically this is exactly the same as a stray X gate appearing in your circuit where you did not want one. Physically it can be caused by thermal excitations, stray microwave photons, or cosmic rays passing through the chip. Whatever the cause, the effect is identical, a swap of the |0⟩ and |1⟩ amplitudes on the affected qubit, with no sign change.

The Gate Matrix

The Pauli X gate is simply:

X = [[0, 1],
     [1, 0]]

Its action on the computational basis is X|0⟩ = |1⟩ and X|1⟩ = |0⟩. X² = I, so two bit-flips in a row cancel. That means a single bit-flip is correctable if we can figure out which qubit flipped: just apply X to that qubit again.

The 3-Qubit Repetition Code

The cleanest way to see bit-flip protection in action is the 3-qubit repetition code. The idea is borrowed from classical error correction: store each logical bit in three physical bits and take a majority vote on readout. In the quantum version:

  1. 1.Encode. Start with the logical state α|0⟩ + β|1⟩ on qubit 0 and |0⟩ on qubits 1 and 2. Apply CNOT(0→1) and CNOT(0→2). The state becomes α|000⟩ + β|111⟩. This is not cloning (which no-cloning forbids), it's an entangled superposition over the two logical codewords.
  2. 2.Wait. Noise happens. Suppose a bit-flip hits qubit 1: the state becomes α|010⟩ + β|101⟩.
  3. 3.Decode. Measure all three qubits in the computational basis. Both branches of the superposition now have the same error pattern: qubit 1 disagrees with qubits 0 and 2. The majority bit is the logical value; the odd qubit is the one that flipped.

This is the opening of the lesson. The full walkthrough, the interactive circuit, and the graded challenge continue inside myqubit.

How this lesson works

A hands-on coding challenge. You write Qiskit-compatible Python in the browser editor, run it instantly via WebAssembly, watch the circuit and Bloch sphere react, and pass automatic output checks. The AI tutor Qubitus gives Socratic hints if you get stuck.

Part of: Noise & Error Correction

Understand quantum noise and build error correction codes to protect quantum information.

This lesson is part of Pro

Unlock Noise & Error Correction and all 10 tracks with Pro: $12.99/month, $79/year, or $97 lifetime. Start with the free track first if you are new.