Skip to documentation
← Algorithm guides

Algorithm guide · qec

Three-Qubit Error Correction

Explore what a repetition code can—and cannot—correct for X, Z, Y, or seeded random errors.

Circuit size: 3 data + 2 syndrome ancillas

Before you begin

Parity checks · Classical feed-forward · Logical versus physical qubits

Review quantum fundamentals →
Notation used in this lesson
|ψ⟩ and ⟨ψ|
A state vector (ket) and its conjugate transpose (bra). ⟨a|b⟩ is their inner product.
α, β and i
α and β are complex amplitudes; i²=−1. A probability is the squared magnitude |α|².
XOR, · and ⊗
XOR adds bits modulo two. In s·x, multiply corresponding bits and XOR them. ⊗ combines registers or operations on different wires.
U†, Σ and Tr
U† is the adjoint (inverse for a unitary). Σ sums terms. Tr is the matrix trace, the sum of diagonal entries.
Probability, shots and angles
Ideal probabilities describe the model; measured shot frequencies fluctuate. Angles inside trigonometric expressions are in radians unless explicitly labeled turns.

1. The problem

Protect one logical qubit against a single bit flip, or choose a changed encoding to protect against a single phase flip. Determine what a syndrome says without measuring away the encoded amplitudes.

2. How it works

Ask whether neighboring data wires agree, rather than asking for their individual logical value. A single flip changes a characteristic pair of parity answers. Correct the indicated wire, decode, then undo the known preparation for a simple verification test.

  1. Encode

    Bit protection maps α|0⟩+β|1⟩ to α|000⟩+β|111⟩. Phase protection applies H to each encoded data wire.

  2. Inject the selected error

    Choose X, Z or Y and a data location; mismatched errors are available as failure demonstrations.

  3. Measure syndromes

    Bit protection checks Z0Z1 and Z1Z2; phase protection uses the corresponding X checks.

  4. Correct, decode, verify

    Apply a classically selected X or Z, decode and undo the selected logical preparation before final data measurement.

3. The mathematics, one idea at a time

s0=q0 XOR q1; s1=q1 XOR q2 (for computational-basis branches)

The actual parity checks work on encoded superpositions without disclosing α and β. Syndrome bits store −1 check outcomes as 1.

Displayed syndrome c1c0: 00→none, 01→q0, 11→q1, 10→q2

These labels locate a single matching-type error. They do not uniquely identify arbitrary multi-qubit errors.

Work this through by hand

4. Correct X on the first data wire

Three data and two syndrome ancillas: five physical qubits in this implementation.

Choose logical |0⟩, Bit protection, X on q0 and correction on.

StageCalculation or stateWhat it means
Encoded state|000⟩Logical zero.
Error on q0q2q1q0=001The rightmost physical data bit flips.
Checkss0=1, s1=0 ⇒ c1c0=01The syndrome selects an X correction on q0.
After correction and verificationData verification bits 000; syndrome remains 01A nonzero record is evidence of the detected error, not failed correction.

Expected outcomes for this example

These are ideal predictions for the stated configuration, not a result already measured by your browser. Rows describing alternative modes or combined events are labeled explicitly.

Outcome or eventIdeal probabilityInterpretation
000|01100% ideal for this configurationc4c3c2 verifies data; c1c0 retains the syndrome.

5. Load the worked example in Composer

The worked example can use smaller or simpler inputs than the gallery defaults. The button below loads the exact circuit used in this lesson.

Logical input state
0
Protected error basis
bit
Introduce a single-qubit error
On
Error type
X
Data qubit receiving the error
0
Enable correction
On
  1. Save any current circuit you want to keep, then open the worked example. Loading it does not execute a paid hardware job.
  2. Trace the preparation, main operations and measurements against the worked table. Check the gate editor for controls, targets and angles.
  3. Start with an ideal noiseless simulator compatible with the circuit. Mid-circuit measurement, reset and feed-forward require support from the chosen backend.
  4. Inspect the live preview. For a recorded experiment, open Execute, set the available backend options and shots, and Run. Sign in when prompted to retain it in My Jobs.
  5. Read the output as described below before changing one setting and repeating. The guide describes the original example; edits can change the answer.

6. Read the output correctly

Split the five-bit Classical bits label into three verification bits and two syndrome bits.

For known-state verification, all-zero data after undoing preparation is the pass condition. It does not mean the original selected logical state was always |0⟩.

Use |+⟩ next to test preservation of coherence. Bit protection cannot correct Z just because the Z-basis histogram looks unchanged.

A bit label is a register value; its bar height is a probability or count. For S shots and observed count k, the sampled frequency is k/S. A typical sampling scale for probability p is √[p(1−p)/S]; this is not a strict error bound. Finite samples do not have to match the ideal percentages exactly.

7. Common mistakes & limits

  • Encoding is not cloning the unknown state into three separate copies.
  • Bit and phase repetition each protect only one error type. Y has both bit and phase components.

8. Check your understanding

Which syndrome detects X on q1?

Reveal the reasoning

Both adjacent checks flip, so c1c0=11.

9. Further study

The lesson’s register mappings, supported inputs and loadable example follow Quantket’s implemented circuit. A reference may use different wire names, bit order or resource conventions.

Gallery reference: defaults, definitions & implementation notes

Inputs & default settings

Choose the logical state |0⟩, |1⟩, |+⟩, |−⟩, |+i⟩ or |−i⟩; whether to introduce an error; its X, Z, Y or seeded-random type; and a data-qubit target or seeded-random target. A seed makes random choices repeatable.

Select bit protection for X errors or phase protection for Z errors.

Switch syndrome-conditioned correction on or off.

logicalState
Gallery default: +
protection
Gallery default: bit
introduceError
Gallery default: true
errorType
Gallery default: X
targetQubit
Gallery default: 0
correctionEnabled
Gallery default: true
seed
Gallery default: 417
rounds
Gallery default: 5
shots
Gallery default: 256
recoveryMode
Gallery default: pauli-frame
physicalErrorRate
Gallery default: 0.002
readoutErrorRate
Gallery default: 0.005

Implementation notes

Choose the protected basis explicitly. Bit repetition corrects one X error; phase repetition corrects one Z error. Mismatched and Y errors remain available as honest failure demonstrations.

Read your saved result

Check the submitted circuit, measured register and execution settings in Run details. Exact results give computed probabilities; sampled results show frequencies from the recorded shots. Edited circuits and noise can change the expected outcome. The algorithm label records the circuit's origin; it does not certify an edited circuit or a measured result.