About this simulation

This simulation implements the 3-qubit bit-flip repetition code, the simplest quantum error-correcting code. A logical qubit |0⟩ or |1⟩ is encoded as |000⟩ or |111⟩ using two CNOT gates, then each physical qubit passes through a noisy channel that flips it independently with probability p. Two parity checks (stabilizers) S1 = Z⊗Z⊗I and S2 = I⊗Z⊗Z are measured without collapsing the logical information, and the resulting syndrome (S1, S2) is looked up in a table to locate — and flip back — the single erroneous qubit. A majority vote then decodes the corrected triple back to a logical bit, and the simulator tracks how often this whole pipeline still fails.

🔬 What it shows

A live 5-stage circuit diagram — Encode, Channel, Syndrome, Correct, Decode — for the 3-qubit bit-flip code, plus a threshold plot comparing the logical error rate p_L = 3p²(1-p) + p³ against the physical error rate p. Below the code's ~0.5 threshold, encoding always reduces the error rate; above it, encoding makes things worse.

🎮 How to use

Set the per-qubit error probability p and the error type (bit-flip X or phase-flip Z, though this code only truly protects against X errors), choose the logical state |0⟩ or |1⟩, then click Run Round to see one trial's syndrome, error location and correction on the circuit diagram, or 1000 Trials to get a statistically meaningful logical error rate plotted against theory.

💡 Did you know?

The syndrome table used here is exactly the classical Hamming-style parity logic: S1=1,S2=0 means qubit 1 flipped; S1=1,S2=1 means qubit 2 flipped; S1=0,S2=1 means qubit 3 flipped; S1=0,S2=0 means no error. This code can only fix a single bit-flip per block — if two or three of the three qubits flip simultaneously, the majority vote is fooled and a logical error slips through, which is exactly the 3p²(1-p)+p³ term the threshold graph plots.

Frequently asked questions

What is the 3-qubit bit-flip code?

It is the simplest quantum error-correcting code, encoding one logical qubit into three physical qubits via |0⟩→|000⟩ and |1⟩→|111⟩ using two CNOT gates from the first qubit. It protects against independent bit-flip (X) errors on any single qubit in the block, at the cost of using three physical qubits per logical qubit.

How does syndrome measurement work without destroying the encoded information?

The stabilizers S1 = Z⊗Z⊗I and S2 = I⊗Z⊗Z are parity checks that compare pairs of qubits (q1 with q2, and q2 with q3) without measuring their individual values. Because they commute with the logical operators, measuring them reveals only whether an odd number of qubits differ from their neighbours — the error syndrome — while leaving the encoded logical state undisturbed.

How does the simulator decide which qubit to correct?

It reads the two-bit syndrome (S1, S2) from a fixed lookup table: (1,0) points to an error on qubit 1, (1,1) to qubit 2, (0,1) to qubit 3, and (0,0) means no error was detected. The identified qubit is then flipped back, after which a majority vote across all three qubits decodes the corrected block to a single logical bit.

What is the error threshold shown in the graph?

The logical error rate after correction is p_L = 3p²(1-p) + p³, the probability that two or three of the three qubits flip (which the code cannot fix), while the physical, uncoded error rate is simply p. The two curves cross at p ≈ 0.5: below that threshold the code reduces the effective error rate, and above it correction backfires because multi-qubit errors become more likely than the code can handle.

Why does the phase-flip option behave the same as bit-flip in this simulator?

The 3-qubit repetition code demonstrated here is built specifically to correct X (bit-flip) errors — its stabilizers are Z-type, which only detect flips in the computational basis. A true Z (phase-flip) error would need a code built in the Hadamard-rotated basis instead. The simulator keeps the same Z-stabilizer syndrome logic for the phase-flip toggle for pedagogical comparison, which is why real fault-tolerant architectures such as Shor's 9-qubit code concatenate a bit-flip code with a phase-flip code to handle both error types simultaneously.