ViewWiki

The world, a little closer

Quantum computing.

A qubit can be 0 and 1 at once, yet reading it gives only one bit. So how can a quantum computer find an answer faster than guessing?

Explore the scene Interactive article

01 / The experiment

Turn the arrow. Then read it.

Apply a gate and watch the arrow turn, step to Measure to read it 40 times, then step to Search and add rounds.

Still of the Quantum computing 3D scene, which explores: If measuring a qubit gives only 0 or 1, what does a quantum computer gain?
Interactive scene

Loading the interactive version…

The explanation below is available while the scene loads.

One ideal qubit with no noise; every gate acts on a fresh qubit that starts at |0⟩. The search has one marked answer.The sphere is a picture of the qubit's state, not something you could see on the chip. Bars move in straight lines between the exact states at the ends of each step.

02 / Three searches

Bigger haystacks take more turns, but far fewer than guesses.

Each diagram shows the search's arrow after the best number of rounds, with a tick at the end of every round, and the amplitude of every item at that point. The answer is orange.

Two qubits01
wrong answersanswer 104 amplitudes

4 items

Each round turns the arrow a third of the way round, so one round lands exactly on the answer. Guessing would take 2.5 tries on average.

Blind guessing
2.5 tries on average
Arrow turns per round
120°
Best number of rounds
1
Chance of finding the answer
100%
Four qubits02
wrong answersanswer 101116 amplitudes

16 items

Three rounds bring the arrow to just past the answer, close enough to find it 96 times in 100. A fourth would carry it well beyond.

Blind guessing
8.5 tries on average
Arrow turns per round
58°
Best number of rounds
3
Chance of finding the answer
96%
Six qubits03
wrong answersanswer 10110164 amplitudes

64 items

Smaller turns, more of them: six rounds put the arrow almost exactly on the answer, while guessing would need 32.5 tries on average.

Blind guessing
32.5 tries on average
Arrow turns per round
29°
Best number of rounds
6
Chance of finding the answer
99.6%
The big idea

A quantum computer does not try every answer at once and read them all. It uses interference: each round shifts amplitude from the wrong answers to the right one, so the arrow turns towards it by a fixed angle. Searching N items takes about (π/4)√N rounds, where guessing takes about N/2 tries.

k ≈ (π/4)√N

A bit, and a qubit

An ordinary bit is a switch: 0 or 1, and you can look at it as often as you like without changing it. A qubit is the quantum version. In the chip at the bottom of the Scene it is a tiny loop of superconducting metal, cooled to a hundredth of a degree above absolute zero, whose current can settle into two distinct states that we call |0⟩ and |1⟩ (read “ket zero” and “ket one”). Other machines use single trapped atoms, photons or electron spins; the idea is the same.

What makes it more than a bit is what it can do between those two states. Its state is described by two numbers, called amplitudes, one for |0⟩ and one for |1⟩. A neat way to draw them is the Bloch sphere: the state is an arrow from the centre to the surface. Straight up is |0⟩, straight down is |1⟩, and every other point is a superposition, a definite state that is neither one nor the other. The height of the arrow says how the chances of reading 0 and 1 are split; the direction it faces around the equator, called the phase, is a second thing a bit simply does not have.

Gates turn the arrow

A quantum program is a list of gates, and each gate turns the sphere. On a superconducting chip a gate is a short pulse of microwaves, lasting a few tens of nanoseconds, sent down the cable to the qubit.

The X gate is half a turn about the left–right axis: it carries |0⟩ down to |1⟩ and |1⟩ back up, so it does what NOT does to a bit. The H (Hadamard) gate is half a turn about an axis tilted halfway between up and right. It takes |0⟩ to the point on the equator labelled |+⟩, an equal superposition. The Z gate is half a turn about the vertical axis. It leaves |0⟩ and |1⟩ alone but swings an arrow on the equator round to the opposite side, from |+⟩ to |−⟩: same height, opposite phase.

Try it: under Gate, choose X (NOT), then H, then H, then Z. The dotted trail shows the path each gate turns the arrow along, starting from |0⟩ every time.

Back to the experiment

Measuring gives one bit

Step Measure and search to Measure. Each glowing bead is one run of the experiment: prepare the qubit, apply the gate, and measure it. A measurement can only ever answer 0 or 1, and the qubit is left in the state it reported, so a superposition cannot be read off in one go. The arrow’s height sets the odds instead: the chance of reading 1 is (1 − z)/2, where z is the arrow’s height on a sphere of radius 1. This is the Born rule.

With H the tubes fill about half and half, and the rings mark exactly 50%. Any 40 shots wander around that: 18 and 22 is nearly as likely as 20 and 20. With H, then Z the tubes look just the same, because a measurement of 0 or 1 cannot see the phase. So far a qubit looks like an expensive coin.

Phase makes interference

Now choose H, then H. If H were a coin toss, doing it twice would still give a coin toss. Instead the qubit reads 0 every time. The second H carries the arrow the rest of the way round its circle and back to the top.

In terms of amplitudes, there are two routes from |0⟩ to |1⟩ through the two gates, and they arrive with opposite signs, so they cancel. The two routes to |0⟩ arrive with the same sign and add up. That is interference, the same effect that makes light and dark fringes when waves overlap, and it is the resource quantum algorithms use. The phase that a single measurement cannot see decides what the next gate does. A quantum algorithm is a sequence of gates arranged so that the routes to wrong answers cancel and the routes to the right answer reinforce before anything is measured.

Interference finds the answer

Step on to Search. The board shows Lov Grover’s search algorithm from 1996 on a register of 4 qubits, which together have 16 possible values, from 0000 to 1111. One of them, 1011, is the answer, and the only way to recognise it is a test, called the oracle, that marks it. Classically you would test items one at a time, about 8 tries on average and 16 at worst.

The search starts by applying H to every qubit, which gives all 16 values the same amplitude, a quarter each. Measuring now is a blind guess with a 1 in 16 chance. Each round then does two things to the whole register at once:

  1. The oracle flips the sign of the answer’s amplitude. Its bar dips below the line; nothing a measurement could see has changed yet.
  2. A second step, the diffusion, reflects every amplitude about the average, drawn as a dotted line. Because the answer’s bar is now below the average, it is thrown far above it, and every other bar shrinks a little.

After one round the chance of finding 1011 is 47%, after two 91% and after three 96%. Meanwhile the arrow on the sphere tells the same story. With the top relabelled “every wrong answer” and the bottom “the answer”, the whole register behaves like one qubit, and every round turns the arrow by the same angle towards the answer. Its height still gives the chance of finding it.

Try it: slide Search size up to 6 qubits, 64 items, and raise Search rounds from 0. Six rounds bring the chance above 99%, where testing one item at a time would take about 32 tries on average.

Back to the experiment

Too much of a good thing

Keep adding rounds and the chance falls again: with 16 items, 4 rounds give 58% and 6 give 2%. Each round is the same turn, so the arrow swings past the answer and heads back towards the wrong ones. The best number of rounds is about (π/4)√N for N items, so the search takes about √N rounds where testing items one by one takes about N/2 tries. For a million items that is about 785 rounds instead of half a million tries.

That square-root speed-up is real but modest, and it is the most a quantum computer can do for a search with no structure to exploit; this was proved in 1997. Larger gains come from problems with hidden patterns that interference can pick out, such as Peter Shor’s 1994 method for finding the factors of large numbers, which threatens some of today’s encryption, and simulating molecules and materials, which are quantum systems themselves.

What this model leaves out

The Scene shows a perfect qubit. Real qubits are disturbed by heat, stray fields and their own wiring, and lose their phase in roughly a ten-thousandth to a thousandth of a second on today’s superconducting chips, so every gate also adds a small error. Useful machines will need quantum error correction, many physical qubits working together as one reliable one, and building that is the main engineering challenge.

The Bloch sphere is a map of a single qubit’s state, not an object inside the chip; nothing physical spins. Several qubits together can be entangled, sharing a state that no set of separate arrows can describe, which the search uses but the Scene does not draw. The search’s sphere works because Grover’s state always stays in the plane of “the answer” and “everything else”. Midway through a step the bars move in straight lines between the exact states at its ends, which shows where the step goes rather than the path a real register takes, and the measurement shots come from a fixed list of random draws.

Reuse with credit to ViewWiki and a link to this page.

04 / Learn this in a course

Practise it, step by step.

This lesson teaches the topic with checked questions.

  1. Qubits and search Computer science · Computing in the real world