Skip to documentation
← Algorithm guides

Algorithm guide · qec

Shor's 9-qubit code

Correct an arbitrary single-qubit error using nine physical qubits and stabilizer measurements.

Circuit size: 10 qubits, 8 classical bits

Before you begin

Bit and phase repetition · Stabilizers · Single-qubit Pauli errors

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 an arbitrary error on any one data qubit by combining bit- and phase-flip protection across nine data wires. Inspect eight syndromes and their same-shot correction.

2. How it works

Three-bit blocks reveal bit-flip locations within each block. Phase checks compare groups of blocks. Separating these diagnoses handles X and Z components; Y has both. Measuring the checks reveals the error syndrome rather than the encoded amplitudes.

  1. Encode

    Build three GHZ-like blocks with relative phases carrying the logical state.

  2. Inject

    Use the no-error, X, Z or Y example; error gates remain editable.

  3. Measure eight checks

    Reuse one ancilla: six within-block Z pair checks and two six-body X checks.

  4. Correct

    Use stored syndromes for the within-block X and between-block Z recovery. The encoded state remains encoded.

3. The mathematics, one idea at a time

|0_L⟩=(|000⟩+|111⟩)^⊗3 / √8; |1_L⟩=(|000⟩−|111⟩)^⊗3 / √8

These two normalized codewords define the logical computational basis.

General single-wire error E=aI+bX+cY+dZ

Syndrome measurement separates correctable Pauli components; correction restores logical information within the single-error assumptions. This is not correcting four simultaneous errors.

Work this through by hand

4. Detect and correct X on q0

Nine data plus one recycled ancilla: ten physical qubits. The template uses eight classical syndrome bits.

Choose Shor 9-qubit (x-q0). The representative template starts with its configured logical input; inspect that input before comparing states.

StageCalculation or stateWhat it means
Within-block checksZ0Z1 flips; Z1Z2 does notThe low pair c1c0=01 locates q0.
Other checksRemaining Z checks and both X checks stay +1A pure X error has no phase component.
RecoveryApply X to q0The encoded logical state is restored; syndrome is retained.

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
00000001100% ideal for the X-on-q0 templateEight syndrome bits, with c0=1.

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.

Selected variant: Shor 9-qubit (x-q0)

  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

This histogram is an error record, not a measurement of the decoded logical qubit. A nonzero syndrome can coexist with successful correction.

The output data remain in an encoded state. Compare the corrected encoded state or add a suitable decode/verification circuit; do not demand a single all-zero nine-data-bit histogram.

c0…c5 record within-block bit checks; c6,c7 record between-block phase checks.

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

  • Nine physical data wires do not represent nine independently recovered unknown qubits.
  • Correcting arbitrary one-qubit noise does not imply correcting arbitrary errors on several wires.

8. Check your understanding

What syndrome should the no-error template produce ideally?

Reveal the reasoning

00000000. All stabilizer signs are +1, stored as zero bits.

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

Available example inputs

Choose a named circuit variant in Algorithms. Each variant fixes its preparation, operations and measurement mapping; the worked variant above is one of them.

  • Shor 9-qubit (no-error)
  • Shor 9-qubit (x-q0)
  • Shor 9-qubit (z-q0)
  • Shor 9-qubit (y-q0)

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.