Understanding Quantum Interference
Superposition on its own is indistinguishable from a coin. Amplitudes are signed, they cancel, and that cancellation is the only reason an algorithm lands on the answer you want.
About the author
A qubit in superposition, measured, gives you 0 or 1 at random. Run the circuit a thousand times and you get roughly five hundred of each. One line of Python does the same thing on a laptop, faster, with no queue in front of it.
So the reasonable question after meeting superposition is what the rest of the machine is for.
What is quantum interference?
Quantum interference happens when a circuit can reach the same outcome by more than one route. Every route carries an amplitude, a number with a size and a direction, and the simplest useful case is an amplitude that is just positive or negative. The routes leading to one outcome are added together, and the probability comes from the size of that sum. Routes pointing the same way reinforce each other. Routes pointing opposite ways cancel.
Without cancellation a quantum computer is only a random number generator. Superposition on its own hands you every outcome with some probability, spread flat. Interference lets an algorithm strip probability off the answers it does not want, and every share it removes turns up on the answers it does. Grover's search below takes a one-in-eight guess to a 94.5% hit rate that way, with nothing in play but signs adding and subtracting.
Where interference came from
Interference turned up in light long before anyone built a qubit, and it has been demonstrated in bigger and bigger things ever since.
At Young's bright fringes the light from the two slits arrives in step, and the two contributions add.
The dark bands are the ones that need explaining. Each is a place light can reach through either slit and does not arrive at all, and blocking one of the two slits makes it brighter. The second route subtracts from the first instead of adding to it.
The apparatus changes down that list, from a card to a needle to a crystal to a biprism. Every one of them produces interference from routes that could have been taken.
Taylor dimmed his source to the equivalent of a candle a mile off and left a plate exposed for three months. The fringes came out as sharp as with a bright lamp, so the pattern does not need a crowd of photons pushing against each other. Tonomura's electrons arrived on the screen as separate dots, and the pattern assembled itself out of them over about twenty minutes.
Feynman used the two-slit experiment to introduce the rule the next section is about: add the amplitudes first, and work out the probability from the sum.
Adding before squaring
Probabilities only ever pile up. Two routes to the same outcome, each with a one-in-four chance, give a one-in-two chance of getting there. Two positive numbers do not add to zero, so Young's dark bands cannot come out of arithmetic like this.
A quantum state carries an amplitude for each outcome. Squaring an amplitude's size gives the probability of that outcome, so a negative amplitude and a positive one of the same size are equally likely to be measured. When two routes lead to the same outcome their amplitudes are added first, and the squaring happens to the sum. Amplitudes are complex numbers in general, and the sign is the part of that which this article needs.
Take two routes with amplitudes of +0.5 and −0.5. Add them and the sum is 0, and 0 squared is 0, so the outcome never happens. Square them first and each route gives 0.25, and 0.25 plus 0.25 is 0.5, so the outcome happens half the time. Same two routes, and only the first order produces a dark band.
Cancelling in one place does not lose the probability from the pattern as a whole, which always totals one. Where routes cancel the probability goes down, and where they reinforce it goes up, which is why a bright band is brighter than either slit produces alone. An algorithm arranges this deliberately: cancel the answers you do not want, and what is left concentrates on the ones you do.
The smallest cancellation you can make
Young's experiment is three lines of Python. A Hadamard opens two routes the way the two slits do, and an rz sets how far out of step they are. A second Hadamard brings them back together at the screen.
# 'backend' is pre-created for you in the Qollab Playground.
from math import pi
from qiskit import QuantumCircuit
def zeros(theta):
qc = QuantumCircuit(1, 1)
1 qc.h(0)
2 qc.rz(theta, 0)
3 qc.h(0)
qc.measure(0, 0)
counts = backend.run(qc, shots=1000).result().get_counts()
4 return counts.get('0', 0)
for name, theta in [("0", 0), ("pi/4", pi / 4), ("pi/2", pi / 2), ("3pi/4", 3 * pi / 4), ("pi", pi)]:
5 print(f"rz({name:>5}) -> {zeros(theta)} zeros out of 1000")
- 1One Hadamard. The qubit now has two routes open, the
0 route and the 1 route, and measuring here gives roughly 500 of each. - 2Turn a phase on the
1 route. This moves no probability whatsoever: measure straight after this line and the tally is still about 500 each, whatever angle you passed in. - 3A second Hadamard. Both routes now lead to both answers, so each answer is arrived at twice over, and the two arrivals add or cancel according to the angle above.
- 4How many of the thousand shots read
0. - 5Five runs at five angles. The tally walks from 1000 down to 0 and the only thing changing is a phase.
rz angle | shots reading 0 |
|---|---|
| 0 | 1000 |
| π/4 | ~854 |
| π/2 | ~500 |
| 3π/4 | ~146 |
| π | 0 |
The exact figure is cos²(θ/2) out of a thousand. Read the top and bottom rows together: same three gates, same measurement, and one is a certainty of 0 while the other is a certainty of 1.
random.randint(0, 1) gives you the middle row and nothing else. No parameter on it turns 500 into 1000, because a probability has no sign to flip.
Line three is the screen. The qubit reaches 0 along both routes, the two amplitudes are added there, and θ decides whether they reinforce or cancel. At θ = π they cancel exactly, and all thousand shots land on 1.
Every algorithm below is that arrangement at more qubits. One gate writes signs that no measurement can see, and a later gate turns those signs into where the shots land.
The gates in these circuits
Five gates cover every excerpt on this page.
Hadamard
Takes a qubit sitting at 0 and leaves it with no fixed value: measure it and you get 0 or 1 with equal probability.
The Hadamard is also its own undo, so it bookends every circuit here. One opens the routes and a second closes them, and whatever happened in between decides where the shots land.
A phase rotation. The angle comes before the qubit, and it shifts the 1 half of the state out of step with the 0 half by that much. At π that comes out as a flipped sign, and smaller angles land part of the way there.
An rz changes no probability at all on its own. The counts are identical whether the angle is 0 or π, and the difference only surfaces once another gate brings the two halves back onto each other.
Controlled-Z
Flips the sign of one outcome, the one where both qubits read 1, and leaves the other three alone. Like rz it moves no probability by itself.
For more than two qubits the same job is written as h, a multi-controlled x, then h again on the last qubit. Both Grover circuits below spell it out that way, and Qiskit calls the three-qubit version of that x a ccx.
Swaps 0 and 1 on a single qubit, the ordinary NOT.
On 0 and 1 it does exactly what a classical NOT does. Its use here is aiming: wrap a cz in x gates and you choose which outcome gets the sign flip.
Reads a qubit into an ordinary bit and forces it to a definite 0 or 1. It is the one irreversible step, and it reports probabilities only.
A sign is never in the output, so every circuit here has to turn its signs into probabilities before this line.
A mark that changes none of the odds
Qollab ships a runnable Grover's search. Three qubits give eight possible answers, one of them is the one you want, and a Hadamard on each qubit starts all eight at 12.5%.
The first half of the algorithm is an oracle whose only job is to mark the right answer.
target = "101"
# ── Oracle: phase-flip the target state ──────────────────────────────
def build_oracle(target):
n = len(target)
oracle = QuantumCircuit(n, name="Oracle")
for i, bit in enumerate(reversed(target)):
if bit == "0":
1 oracle.x(i)
if n == 2:
oracle.cz(0, 1)
elif n == 3:
oracle.h(2)
2 oracle.ccx(0, 1, 2)
oracle.h(2)
else:
oracle.h(n - 1)
oracle.mcx(list(range(n - 1)), n - 1)
oracle.h(n - 1)
for i, bit in enumerate(reversed(target)):
if bit == "0":
3 oracle.x(i)
return oracle
- 1Aim the gate below.
101 has a 0 in the middle, so the middle qubit gets flipped and the answer being marked temporarily becomes 111. - 2The mark itself, written as
h, ccx, h, which together flip the sign of the one outcome where all three qubits read 1. One of eight amplitudes becomes negative and the other seven are untouched. - 3Undo the aiming flips, so the sign now sits on
101 where it was wanted.
Nothing in that function moves any probability. Run it on the eight-way superposition and all eight outcomes still sit at 12.5%, exactly as they did before the call.
The answer has been marked in the one way a measurement cannot report, which is the same problem the rz had at the top of this page.
Turning the mark into probability
The second half is called the diffuser, and it is the same h, phase, h arrangement at three qubits.
# ── Diffuser: amplify the marked state ───────────────────────────────
def build_diffuser(n):
diffuser = QuantumCircuit(n, name="Diffuser")
1 diffuser.h(range(n))
diffuser.x(range(n))
if n == 2:
diffuser.cz(0, 1)
elif n == 3:
diffuser.h(2)
2 diffuser.ccx(0, 1, 2)
diffuser.h(2)
else:
diffuser.h(n - 1)
diffuser.mcx(list(range(n - 1)), n - 1)
diffuser.h(n - 1)
diffuser.x(range(n))
3 diffuser.h(range(n))
return diffuser
- 1Open the routes onto each other, the same move as the second Hadamard in the one-qubit listing, run on all three qubits at once.
- 2The same sign flip as the oracle, aimed by the
x layer at the all-zeros outcome this time. The diffuser is the same for every target; only the oracle knows which one. - 3The closing Hadamard layer. Every amplitude is now the same distance from the average as it was, on the other side of it, so the one the oracle pushed below the average comes back furthest above it.
The standard name for those seven lines is inversion about the mean. Seven amplitudes are positive and one is negative, so the average sits just under the positive ones. Reflecting each amplitude through that average sends the negative one far up and barely moves the other seven.
Run the oracle and the diffuser as a pair and the chance of measuring 101 moves like this.
| Grover iterations | chance of reading 101 |
|---|---|
| 0 | 12.5% |
| 1 | 78.1% |
| 2 | 94.5% |
| 3 | 33.0% |
Two iterations take a one-in-eight guess to a 94.5% hit rate, and the only mechanism in play is amplitudes adding and subtracting. The oracle was consulted twice. Checking all eight items by hand takes eight looks, and a classical scan finds it after 4.5 on average.
Too many iterations undo the answer
After three iterations the target is back down to 33.0%. The project computes how many iterations to run instead of guessing.
target = "101"
shots = 1000
num_qubits = len(target)
1num_iterations = int(math.pi / 4 * math.sqrt(2 ** num_qubits))
- 1For three qubits this works out at 2.221, and
int takes it down to 2. The formula is π/4 times the square root of the search space, which is where Grover's quadratic speedup comes from.
Each iteration turns the state by a fixed angle toward the marked answer, and the turning does not stop on arrival. Go past the top and the same interference that concentrated the probability starts spreading it again.
Try this when you fork it. Replace num_iterations with 3 and run. The target falls from 94.5% to about a third, and a fourth iteration takes it to roughly 1%, worse than the 12.5% you started with. Grover's search is a rotation with a stopping point that has to be calculated in advance.
The walk that does not spread like a random one
Grover concentrates probability on one answer. Quantum Advantage Lab's third race shows the same mechanism shaping a whole distribution, and its classical counterpart sits in the same repository.
A classical random walker starts at node 0 and picks a neighbour at each step. The Lab runs a thousand of them.
# For each walker, pick next position based on transition probabilities
new_positions = np.empty(n_trials, dtype=int)
for trial_idx in range(n_trials):
current = positions[trial_idx]
new_positions[trial_idx] = rng.choice(
n_nodes, p=transition[current]
1 )
positions = new_positions
# Build empirical distribution
counts = np.bincount(positions, minlength=n_nodes)
2 distribution = (counts / n_trials).tolist()
- 1A fresh random draw for every walker on every step. A thousand walkers, six steps, six thousand draws, and each one is committed the moment it happens.
- 2Tally where the thousand walkers ended up. This comes out as a bell curve centred on the start, widening as the square root of the number of steps.
The quantum walk draws no random number at any step. It turns a coin qubit and shifts the walker by what the coin says, both as ordinary gates, and nothing is sampled until the finished circuit is measured.
# Initial state: walker at position 0, coin in superposition
if graph_type == "cycle":
1 qc.h(coin_qubits[0])
# ...
for step in range(n_steps):
# Coin
if graph_type == "cycle":
2 _hadamard_coin(qc, coin_qubits[0])
# ...
# Shift
if graph_type == "cycle":
3 _cycle_shift(qc, coin_qubits[0], position_qubits)
- 1The coin starts with no value. Nothing in the walk below ever reads it, so it never acquires one.
- 2Turn the coin again, with another Hadamard. Nothing reads it, so the coin stays undecided and the walk keeps every branch open.
- 3Move the walker by whatever the coin says, both ways at once. The position register is a superposition over every route the walker could have taken, held open until the final measurement.
Six steps in, the classical walker has taken one of sixty-four routes and the tally counts how often each endpoint came up. The quantum walk commits to none of them, and routes that reach the same node out of step cancel before anything is counted.
What comes out is not a bell curve. Routes that reach a node in step pile up there and routes that reach it out of step cancel, so the distribution comes out lopsided and ridged rather than smooth. On a big enough ring, before the walker has gone far enough round to meet itself, it also widens in proportion to the number of steps. The classical one widens with its square root.
Quantum Advantage LabReal-time interactive platform that races four foundational quantum algorithms against their classical counterparts, visualizing each solver's progress step by step.Running a circuit backwards to compare two states
Quantum Regime Radar scores a live market window against five volatility regimes taken from real history, each one stored as a twelve-qubit state. Scoring means comparing two states, and neither state can be read.
The project's answer is to build one state, then run the other's circuit in reverse and see how much comes back.
def _inversion(qc_live: QuantumCircuit, qc_ref: QuantumCircuit) -> QuantumCircuit:
n = qc_live.num_qubits
qc = QuantumCircuit(n, n)
1 qc.compose(qc_live, inplace=True)
2 qc.compose(qc_ref.inverse(), inplace=True)
qc.measure(range(n), range(n))
return qc
- 1Prepare the live market's fingerprint on twelve qubits.
- 2Then the reference regime's circuit, inverted. Every gate in it runs backwards, so this undoes the preparation of the reference exactly.
Four thousand and ninety-six outcomes are possible on twelve qubits, and every one of them is reached by a great many routes through the two circuits. If the live state and the reference are the same, the inverse cancels the preparation and every route recombines on all-zeros. If they differ, the cancellation is partial and shots leak into the other bitstrings.
So the fraction of shots reading all zeros estimates the squared overlap between the two states, measured without either state being inspected.
live = _build(DEMO_PARAMS[ci][REF_FAM[target]])
ref = _build(REF_PARAMS[target])
circuit = transpile(_inversion(live, ref), backend=backend, optimization_level=0)
1 result = backend.run(circuit, shots=shots).result()
counts = result.get_counts()
if isinstance(counts, list): # defensive; single circuit expected
counts = counts[0]
2 K_meas = _zero_frac(counts)
3 sigma = (K_meas * (1.0 - K_meas) / max(shots, 1)) ** 0.5
- 1One job, one circuit. The playground allows a single hardware submission per run, so this cell spends it on one comparison.
- 2The kernel, read straight off the tally as the fraction of all-zero shots.
- 3And its error bar, because a fraction estimated from a finite pile of shots is an estimate.
The inversion test is the same shape as the circuit at the top of this page: prepare, then undo. What differs is that the undoing is done by a second circuit you choose, so how completely it returns to all-zeros measures how well the two agree.
Quantum Regime RadarScores live equity returns against five volatility regimes taken from real market history, using quantum kernels on IonQ.Writing a phase on ten qubits at once
Musiq turns a circuit's output into sound, and one of the things it maps is the statevector's phase, onto oscillator phase.

Musiq's circuit library includes an IQP builder with the same shape as the Grover diffuser.
n = self.n_qubits
# n diagonal Rz params + (n-1)+(n-2) CZ layer = n + 2*n-3 for two CZ "bands"
num_rz = n
params = ParameterVector("λ", num_rz)
qc = QuantumCircuit(n)
1 qc.h(range(n))
for qubit in range(n):
2 qc.rz(params[qubit], qubit)
# Fixed CZ pattern (nearest-neighbor style, no random choice)
for i in range(n):
for j in range(i + 1, min(i + 3, n)):
3 qc.cz(i, j)
4 qc.h(range(n))
qc.measure_all()
- 1Open every route at once. Ten qubits gives 1,024 outcomes, all equally likely at this line.
- 2One phase per qubit, and the parameters are named λ. Ten angles written into the state, none of which changes a single probability.
- 3Phases between pairs of qubits now, on top of the per-qubit ones. Still nothing has moved: every outcome is on 1/1024 going into the next line.
- 4The closing Hadamard layer, and all of it arrives at once. Every phase written above decides where its routes reinforce and where they cancel, and the 1,024 flat probabilities become a distribution shaped by whatever those angles were.
IQP stands for instantaneous quantum polynomial time, and the name points at the middle of that circuit. Everything between the two Hadamard layers is diagonal, which means every gate in it only writes phases.
Measure after the cz loop and the histogram is flat. The whole computation is sitting in the state, none of it is in the output, and the closing Hadamard layer converts it.
In Musiq that conversion has an audible result: the angles you bind into λ decide the spectrum you hear.
MusiqMusiq is a browser-based quantum sonification platform that transforms quantum-circuit outputs into generative audio.What noise takes first
Interference needs the relative phase between two routes to survive from the gate that wrote it to the gate that converts it. A real device does not hold phases that well.
Circuit depth is what that costs. One iteration is an oracle and a diffuser, each carrying a multi-controlled sign flip that hardware does not have as a single operation. Transpiled onto a real backend, each of those becomes a run of two-qubit gates, and the three-qubit search above is already tens of operations deep by its second iteration.
The playground project checks its own result at the end.
target_count = counts.get(target, 0)
success_rate = target_count / shots
print(f"\nTarget |{target}⟩ found: {target_count}/{shots} ({100*success_rate:.1f}%)")
1print(f"Classical random guess would give: {100/2**num_qubits:.1f}%")
2if success_rate > 0.8:
print("✓ Grover's search successful!")
else:
print("⚠ Lower than expected — noise may be affecting results")
- 112.5%, what a uniform random guess would score. The circuit has to beat that for any of the interference to have reached the counts.
- 2A threshold picked by hand, sitting well below the 94.5% the maths predicts. The gap covers gate and readout error, compilation, and the ordinary scatter of a thousand shots.
None of these circuits is faster than a laptop. Eight items is a trivial search, and a classical computer checks all of them before an IonQ job has left the queue. Grover's advantage is quadratic and it needs a search space far larger than anything a current device can hold with its phases intact.
Which makes the reason to run these circuits on hardware a narrow one. A simulator gives you the arc every time, exactly as the arithmetic predicts. The one question it cannot answer is how much of the interference is left by the end of a real run. The gap between 94.5% and whatever comes back is that answer.
Quantum Advantage Lab handles this by storing hardware runs and replaying them rather than re-queuing, which keeps the comparison honest without paying for the queue twice.
Start with Grover
Every circuit on this page writes a sign or a phase that moves no probability. A later gate opens the routes back onto each other, and those signs decide where the shots land. Finding both halves is most of reading a quantum algorithm: in Grover they are the oracle's ccx and the diffuser's closing Hadamards.
Fork Grover's search first. The circuit runs in the Playground with no setup, and the oracle and the diffuser are under forty lines together. Change target to any of the eight bitstrings and the same two functions concentrate on whichever one you name.
Run it, then overshoot it.
Fork Grover's search, run it as shipped, then raise the iteration count by one and watch the answer come apart. Then open any project above and find the line where its phases turn back into counts. Everything here is open and yours to build on.
Stay in the loop.
Get the latest tutorials, demos, and project showcases straight to your inbox. No noise, just the good stuff.
- 1About the author
- 2What is quantum interference?
- 3Where interference came from
- 4Adding before squaring
- 5The smallest cancellation you can make
- 6The gates in these circuits
- 7A mark that changes none of the odds
- 8Turning the mark into probability
- 9The walk that does not spread like a random one
- 10Running a circuit backwards to compare two states
- 11Writing a phase on ten qubits at once
- 12What noise takes first
- 13Start with Grover
