Skip to main content

Quantum information · institution-dependent · Interactive lesson

Algorithms, decoherence and error correction

Three questions close the course. What can a quantum register do faster, and by how much? Why does the hardware lose the interference the answer depends on? And how can a code fix errors it is forbidden to look at? Grover, Shor, T₁ and T₂, the three-qubit code and the threshold theorem answer them in that order.

UPV-20.09 · Lesson 9 of 9 in this unit. Position is not a completion score.
Starting model: Algorithms, decoherence and error correctionLeft: the Grover rotation in the plane of the marked |w⟩ (up) and |w⊥⟩ (right). Dashed is the start |s⟩ at θ = 1.79°; the arrow is the state after k = 25 iterates, at (2k+1)θ = 91.3° and shortened to √((1 − p)^k), so the square of its |w⟩ component is the coherent part of P(w). Right: P(w) against k for N = 1024; the dashed vertical marks k_opt and the dot this k.|w⟩|w⊥⟩state angle (2k+1)θ = 91.3°θ = 1.79° N = 1024 dashed: |s⟩P(w) vs k, kₒₚₜ = 25P = 1k: 0 to 40 iterates
Start with a picture. Change the model in the lab below.

Quantum information · institution-dependent. Your university determines the required depth of these quantum topics, including the use of operators, differential equations and computation. Institution-dependent does not automatically mean optional.

1

Build the model

Interference is the algorithm; decoherence is the tax; the code is how you stop paying it.

The key idea

A quantum algorithm arranges interference so that one readout of a 2ⁿ-amplitude register returns a useful n-bit string with high probability; error correction keeps that interference alive by measuring stabilisers that reveal the error but not the logical state.

Example. Searching N = 1024 = 2¹⁰ strings, θ = asin(1/32) = 1.79° and each Grover iterate rotates the state by 3.58°, so k = 25 oracle calls lift the marked string to sin²(51 × 1.79°) = 0.999, where 25 classical probes would find it with probability 25/1024 = 0.024.

The complete physical model and assumptions

An n-qubit register is a unit vector in C(2ⁿ) with 2ⁿ amplitudes, but one measurement returns one n-bit string, so a quantum algorithm is not a parallel evaluation but a unitary sequence that piles amplitude onto the strings worth reading. Grover's search works in the real plane spanned by the marked state |w⟩ and the uniform superposition |s⟩. The oracle O = I − 2|w⟩⟨w| reflects across |w⊥⟩, the diffusion D = 2|s⟩⟨s| − I reflects across |s⟩, and two reflections compose to a rotation by 2θ with sin θ = 1/√N, so after k calls the amplitude on |w⟩ is sin((2k+1)θ): it peaks near k = (π/4)√N and then falls. The BBBV bound, Ω(√N) calls for any oracle algorithm, makes that quadratic gain final. Shor's factoring is a different kind of gain: order finding through the QFT costs O(n³) gates against a classical best growing sub-exponentially in n = log₂ M. Both are paid for in coherence. Idling damps the off-diagonal elements of ρ as e(−t/T₂), each gate misfires with probability p, and a 10⁶-gate circuit on 10⁻³ hardware ends maximally mixed. Error correction restores the algebra by encoding a logical qubit in several physical ones and measuring stabilisers that reveal the error without reading the logical state: a distance-3 code turns p into cp², and concatenation drives the logical rate to zero once p sits below the threshold 1/c. Above it, correcting only adds errors.

1The register holds 2ⁿ amplitudes and returns n bits

Ten qubits live in C² ⊗ … ⊗ C² = C¹⁰²⁴, and H⊗¹⁰ on |0…0⟩ gives |s⟩ = 2(−5) Σₓ |x⟩, a vector with 1024 equal amplitudes. A reversible oracle Uf|x⟩|0⟩ = |x⟩|f(x)⟩ then evaluates f on every x in one pass — and that is the sentence that misleads. The Born rule returns one string x with probability |⟨x|ψ⟩|², after which the register sits on |x⟩|f(x)⟩ and the other 1023 evaluations are gone; you have learnt f at one random point, which a classical machine does in one call. The Holevo bound makes it a theorem: n qubits deliver at most n classical bits to a reader. So an algorithm is a unitary sequence arranged so that amplitudes on wrong strings cancel and amplitudes on right strings add before the readout. In NumPy the register is ψ = np.zeros(2**n, dtype=complex) with ψ[0] = 1, H⊗ⁿ is reduce(np.kron, [H]*n), and a shot is rng.choice(2**n, p=abs(ψ)**2) — one integer. At n = 20 that vector is 16 MB; at n = 30 it is 16 GB, and the classical cost of simulating the interference is exactly why the speed-ups matter.

2Grover: two reflections make a rotation

Write |s⟩ = sin θ|w⟩ + cos θ|w⊥⟩, where |w⊥⟩ is the normalised sum of the N − 1 unmarked strings and sin θ = ⟨w|s⟩ = 1/√N. The oracle O = I − 2|w⟩⟨w| flips the sign of the |w⟩ component, a reflection across |w⊥⟩; on hardware it is the phase kickback of a function oracle acting on an ancilla in |−⟩, so f is queried but never read. The diffusion D = 2|s⟩⟨s| − I = H⊗ⁿ(2|0⟩⟨0| − I)H⊗ⁿ reflects across |s⟩ and needs no oracle at all. Two reflections about lines θ apart compose to a rotation by 2θ, so G = DO turns the state through 2θ per call and Gk|s⟩ sits at angle (2k+1)θ from |w⊥⟩. Take N = 8: θ = asin(1/√8) = 20.70°. One call: 3θ = 62.11°, P(w) = sin² = 0.781. Two: 5θ = 103.5°, P = 0.945. Three: 7θ = 144.9°, P = 0.330 — the state has swung past |w⟩ and is heading back. In code, D = 2*np.outer(s, s) - np.eye(N) and O = np.eye(N) - 2*np.outer(w, w), and numpy.linalg.matrix_power(D @ O, k) @ s reproduces every number above.

3Count the calls, then name the gain honestly

The peak sits where (2k+1)θ is closest to π/2, so kₒₚₜ = round(π/(4θ) − ½), and for large N, θ ≈ 1/√N gives kₒₚₜ ≈ (π/4)√N. For N = 2²⁰ = 1 048 576, θ = 1/1024 rad and kₒₚₜ = 804: the state angle is 1609/1024 = 1.5713 rad and P(w) = sin²(1.5713) = 1.00000 to six figures. A classical search needs N/2 = 524 288 probes on average, so the ratio is about 650. Keep going and the rotation continues: at k = 1608 the angle is 3217/1024 = 3.1416 rad ≈ π and P(w) ≈ 0. Two honest qualifiers belong next to the 650. Bennett, Bernstein, Brassard and Vazirani proved in 1997 that any quantum oracle algorithm needs Ω(√N) queries to find w with bounded error, so Grover is optimal and unstructured search can never be exponentially faster. And the count assumes one marked item: with M of them sin θ = √(M/N) and kₒₚₜ ≈ (π/4)√(N/M), so an unknown M has to be estimated first by quantum counting, or k drawn at random from a growing range, or the algorithm overshoots.

4Shor: turn a period into a Fourier peak

To factor M, pick a coprime a and find the order r, the least r with aʳ ≡ 1 (mod M). For M = 15 and a = 7: 7, 49 ≡ 4, 28 ≡ 13, 91 ≡ 1, so r = 4; r is even and 7² ≡ 4 ≢ −1, so the factors are gcd(4 − 1, 15) = 3 and gcd(4 + 1, 15) = 5. Every step there is classical and cheap except finding r, which is what the register does. Put m = 2n qubits in |s⟩, compute aˣ mod M into a second register, and measure it: the first register collapses to the x sharing one value of aˣ, a comb with period r. The QFT on m qubits, |j⟩ → Q(−1/2) Σₖ e(2πi jk/Q)|k⟩ with Q = 2ᵐ, needs m(m+1)/2 Hadamards and controlled phases and turns a comb of period r into peaks at k ≈ jQ/r; one measured k gives r by continued fractions. The modular exponentiation costs O(n³) gates and dominates, so the run is polynomial in n = log₂ M, while the number field sieve takes exp(O(n¹⁄³(ln n)²⁄³)). Two cautions: the comparison is against the best known classical algorithm, not a proven lower bound; and the 2048-bit moduli behind RSA need thousands of logical qubits, which is why the rest of this lesson exists.

5Decoherence: where the off-diagonal terms go

Couple one qubit to an environment and trace the environment out; what remains is a map on ρ. Amplitude damping with Kraus operators E₀ = diag(1, √(1 − γ)) and E₁ = √γ |0⟩⟨1|, γ = 1 − e(−t/T₁), sends the excited population ρ₁₁ to ρ₁₁e(−t/T₁) and the coherence ρ₀₁ to ρ₀₁e(−t/2T₁). Pure dephasing multiplies ρ₀₁ by exp(−t/Tφ) and leaves the populations alone. Together 1/T₂ = 1/(2T₁) + 1/Tφ, so T₂ ≤ 2T₁: the coherence can never outlive twice the population lifetime, and dephasing usually makes it the first casualty — and interference is nothing but ρ₀₁. Numbers: a transmon with T₁ = 100 μs and T₂ = 80 μs running a 40 ns two-qubit gate loses (40 × 10⁻⁹ s)/(80 × 10⁻⁶ s) = 5 × 10⁻⁴ of its coherence per gate from idling alone; a measured gate error of 3 × 10⁻³ says control errors dominate. Now cost Grover for N = 2²⁰: 804 iterates of a few hundred gates each is 10⁵ to 10⁶ gates, and at p = 10⁻³ per gate the expected number of faults is 10² to 10³. The figure below models each iterate as succeeding with probability 1 − p and otherwise dumping the register into I/N, P(w) = (1 − p)k sin²((2k+1)θ) + (1 − (1 − p)k)/N; at p = 0.05 the N = 1024 peak drops from 0.999 to 0.33.

6Error correction measures the error, not the state

No-cloning forbids a backup, so redundancy is spread rather than copied: two CNOTs take α|0⟩ + β|1⟩ to |ψL⟩ = α|000⟩ + β|111⟩. The stabilisers Z₁Z₂ and Z₂Z₃ return +1 on both |000⟩ and |111⟩, so measuring them reveals nothing about α and β; a bit flip X₂ makes both −1, X₁ gives (−1, +1) and X₃ gives (+1, −1), and each syndrome names one correction. Measuring also discretises a small rotation e(−iεX₂), a superposition of I and X₂, into one of the two. Two or more flips defeat it: pL = 3p²(1 − p) + p³, so p = 0.01 becomes 2.98 × 10⁻⁴. Phase flips need the same code in the |±⟩ basis with X₁X₂ and X₂X₃; Shor's 9-qubit code nests the two and corrects any single-qubit error, since every error is a combination of I, X, Y and Z. With fault-tolerant gadgets a distance-3 code gives pL ≈ cp² and ℓ concatenations give (1/c)(cp)(2^ℓ): below pₜₕ = 1/c the logical error falls doubly exponentially while qubits grow only as 7^ℓ for the 7-qubit Steane code. The surface code, with local checks only, has pₜₕ ≈ 10⁻² and pL ≈ 0.1(p/pₜₕ)(t+1), where t = (d − 1)/2 is the number of correctable errors: at p = 10⁻³, d = 25 gives t + 1 = 13 and 10⁻¹⁴ per cycle for 2d² − 1 = 1249 physical qubits.

2

Key equations

Read the units, assumptions and limits before substituting.

Grover iterate as two reflections

G = D O, O = I − 2|w⟩⟨w|, D = 2|s⟩⟨s| − I

Two reflections about lines θ apart compose to a rotation by 2θ, so the whole algorithm reduces to 2 × 2 trigonometry in span(|w⟩, |s⟩).

|w⟩ the marked basis state, |s⟩ = N(−1/2) Σₓ |x⟩ the uniform superposition; O and D are dimensionless unitaries on CN

Amplitude after k iterates

sin θ = 1/√N, Gk|s⟩ = cos((2k+1)θ)|w⊥⟩ + sin((2k+1)θ)|w⟩

Gives the success probability at every k, including the fall past the peak: the state keeps rotating, so more calls can mean less.

N = 2ⁿ for n qubits; θ in radians; P(w) = sin²((2k+1)θ) is a dimensionless probability

Optimal count and the BBBV bound

kₒₚₜ = round(π/(4θ) − ½) ≈ (π/4)√Nany oracle algorithm needs Ω(√N) calls

√N against N/2 is a quadratic gain, and the lower bound proves that unstructured search can never be sped up exponentially.

one oracle call per iterate; a classical search needs N/2 calls on average; with M marked items sin θ = √(M/N)

Shor: order finding through the QFT

QFT|j⟩ = Q(−1/2) Σₖ e(2πi jk/Q)|k⟩, Q = 2(2n), cost O(n²) gates

Modular exponentiation dominates at O(n³): polynomial, against the number field sieve's exp(O(n¹⁄³(ln n)²⁄³)), the best known classical algorithm.

n = ⌈log₂ M⌉ for the number M being factored; the order r of a mod M gives factors gcd(a(r/2) ± 1, M) when r is even and a(r/2) ≢ −1 (mod M)

Decoherence of a single qubit

ρ₀₁(t) = ρ₀₁(0) e(−t/T₂), ρ₁₁(t) = ρ₁₁(0) e(−t/T₁), 1/T₂ = 1/(2T₁) + 1/Tφ

Interference lives in ρ₀₁, so T₂ ≤ 2T₁ caps every algorithm: a gate of duration τ carries an error of order τ/T₂ before control imperfections are counted.

T₁ relaxation, Tφ pure dephasing and T₂ total dephasing times in seconds; ρ₀₁ is the coherence, ρ₁₁ the excited population

Logical error and the threshold

pL ≈ c p² (distance 3)after ℓ concatenations pL ≈ (1/c)(c p)(2^ℓ)

Below pₜₕ each level squares the suppression while the qubit count grows only polylogarithmically in 1/pL; above it the correction circuitry adds more errors than it removes.

p physical error per gate and pL logical error, both dimensionless; c counts the uncorrectable fault pairs; threshold pₜₕ = 1/c
3

Interactive lab

Predict first. Explore the model. Compare the result.

Explore the model

10
2 to 10; steps of 1.
25
0 to 40; steps of 1.
0.00
0 to 0.2; steps of 0.01.

Try this. With p = 0, drag k past kₒₚₜ = 25 for N = 1024: the arrow swings beyond |w⟩ and P(w) slides from 0.999 to 0.33 at k = 40 — Grover overshoots. Then set p = 0.05: the arrow shrinks every iterate, the peak moves to about k = 18 and tops out near 0.33, so noise sets the useful depth.

Live results

θ = asin(1/√N)
1.79 °
kₒₚₜ = round(π/(4θ) − ½)
25
P(w) IDEAL AT k
0.999
P(w) WITH NOISE AT k
0.999

Results follow this lesson’s model and assumptions. Displayed values are rounded.

Interactive Physics V modelLeft: the Grover rotation in the plane of the marked |w⟩ (up) and |w⊥⟩ (right). Dashed is the start |s⟩ at θ = 1.79°; the arrow is the state after k = 25 iterates, at (2k+1)θ = 91.3° and shortened to √((1 − p)^k), so the square of its |w⟩ component is the coherent part of P(w). Right: P(w) against k for N = 1024; the dashed vertical marks k_opt and the dot this k.|w⟩|w⊥⟩state angle (2k+1)θ = 91.3°θ = 1.79° N = 1024 dashed: |s⟩P(w) vs k, kₒₚₜ = 25P = 1k: 0 to 40 iterates
Left: the Grover rotation in the plane of the marked |w⟩ (up) and |w⊥⟩ (right). Dashed is the start |s⟩ at θ = 1.79°; the arrow is the state after k = 25 iterates, at (2k+1)θ = 91.3° and shortened to √((1 − p)k), so the square of its |w⟩ component is the coherent part of P(w). Right: P(w) against k for N = 1024; the dashed vertical marks kₒₚₜ and the dot this k.

Predict → change one variable → check

Plan a change before running it. Every other input stays at the saved baseline.

Saved baseline. Register qubits n (N = 2ⁿ): 10; Grover iterates k: 25; Depolarising error per iterate p: 0.00

Baseline 10; choose 2 to 10, in steps of 1.
4. Compared with the saved baseline, this result will…

This experiment is kept only while this page is open. It does not change saved course progress.

4

Catch the common trap

The error is to read H⊗ⁿ followed by Uf as computing f on all 2ⁿ inputs at once and to conclude that a quantum computer is a 2ⁿ-fold parallel machine. The register does hold 2ⁿ amplitudes, but the Born rule hands back one string per shot and the projection destroys the rest, so a plain evaluate-then-measure circuit learns f at one random point, as one classical call would. The Holevo bound caps what n qubits can deliver at n bits. The speed-ups come from structure the algorithm can turn into interference: Grover has none to use beyond a marked state, so the best it can do is rotate through 2θ ≈ 2/√N per call, and the BBBV bound says nothing does better; Shor has a period, which the QFT converts into constructive interference at multiples of Q/r. So unstructured search is quadratic and factoring superpolynomial: the gain is set by the problem's structure, not by the register's size.

5

Practice & worked examples

3 authored examples. Make an attempt, then reveal the reasoning one step at a time.

EasyExample 1

A three-qubit register (N = 8) has one marked string. Find θ, then the state angle and success probability after k = 1, 2 and 3 Grover iterates, and say where to stop. Compare with two classical probes.

Sketch your answer or reasoning, then compare it with the authored solution. Your writing is not automatically graded or saved.

0 of 4 steps revealed.

MediumExample 2

Three physical qubits carry |ψL⟩ = α|000⟩ + β|111⟩ through one memory cycle in which each qubit suffers an independent bit flip with probability p = 0.02. Give the syndrome for a flip on qubit 3, the logical error rate, the gain over an unencoded qubit, and the p above which encoding stops helping.

Sketch your answer or reasoning, then compare it with the authored solution. Your writing is not automatically graded or saved.

0 of 5 steps revealed.

HardExample 3

Run Shor's order finding for M = 15 with a = 7 on a first register of 2n = 8 qubits, so Q = 256. Find r by hand, locate the QFT peaks and their probabilities, extract r from a measured k = 192 by continued fractions, give the factors, and state the probability that a single run succeeds.

Sketch your answer or reasoning, then compare it with the authored solution. Your writing is not automatically graded or saved.

0 of 5 steps revealed.

6

Quick check

Select an answer and explain it before checking.

A Grover search over N = 2¹⁰ = 1024 strings with one marked item is run for k iterates before readout. Which statement about the success probability P(w) is right?
7

Review & continue

A quantum algorithm arranges interference so that one readout of a 2ⁿ-amplitude register returns a useful n-bit string with high probability; error correction keeps that interference alive by measuring stabilisers that reveal the error but not the logical state.

  • Explain the relationship without looking at the equation.
  • Check a sign, a unit and a model assumption in your working.
  • Return to the lab or worked example if a step is still unclear.

Extra challenging questions

Connect several ideas, explore supplied data, and compare your reasoning with a worked solution.