Circuit State Step by Step
Track the full list of amplitudes after every gate: each gate consumes the current list and produces the next one. Most circuit bugs become obvious the moment you compare the amplitudes you expected at a step with the ones you actually get.
Why step through the state at all?
The state of a quantum register is the complete list of amplitudes — one amplitude per possible readout combination. An amplitude is a number whose square gives the probability of that combination appearing when you measure.
Two qubits have four combinations, so the state is a list of four numbers. We write each combination as a bitstring with q0 as the rightmost digit: 00, 01 (q0 is 1), 10 (q1 is 1), 11.
Each gate is a small, exact rule that turns the current list into the next list. Debugging a circuit is therefore the same discipline as debugging any program: inspect the state after each instruction and find the first step where reality departs from your expectation.
Worked example: the Bell circuit, one gate at a time
Circuit: H on q0, then CX with control q0 and target q1.
- Start: amplitude 1 on
00; the other three entries are 0. - After
Hon q0: the amplitude splits between q0's two values — 0.7071 on00and 0.7071 on01. (0.7071 is 1/√2; its square is 0.5.) - After
CX: in every part of the state where q0 is 1, q1 flips. The entry on01moves to11. Final list: 0.7071 on00, 0.7071 on11, zero elsewhere.
Squaring: 0.7071 × 0.7071 = 0.5 for each. Prediction for 1000 shots: about 500 read 00, about 500 read 11, and 01 and 10 never appear.
Run it and check the prediction
Worked example: same gates, opposite order
Now reverse the two operations: CX first, then H.
- Start: amplitude 1 on
00. CX(control q0, target q1): the control is 0 in the entire state, so nothing flips. The list is unchanged — still amplitude 1 on00.Hon q0: 0.7071 on00and 0.7071 on01.
Squares: 0.5 and 0.5 — but now on 00 and 01. The probability of 11 went from 50% in the original order to exactly 0% here. Same two gates, different order, different program: gates are applied as matrix operations — a matrix is just the fixed grid of numbers that encodes a gate's rewrite rule — and matrix order is not interchangeable, because each gate rewrites the list the previous gate produced.
Compare: CX before H
Compare with the run above: 11 vanishes — q1 now reads 0 in every shot while q0 stays 50/50.
Is measurement just another step?
No — and the distinction matters when you step through a circuit. Every gate is unitary, which in plain words means reversible and probability-preserving: no information is lost, and some later gate could always undo it.
Measurement is different. It forces one concrete outcome, keeps that, and discards the rest of the amplitude list. You cannot undo a measurement, which is why it is drawn with its own symbol and why the Lab applies it once, at the very end, to every qubit.
So when your predicted amplitudes and the observed counts disagree, check three suspects in order: did you get a control/target pair backwards, are you reading the bitstring in the right digit order, and did a measurement happen earlier than you intended?
Takeaway
The state is a list of amplitudes; each gate rewrites the list; measurement collapses it to one row. Stepping through that list after every operation is the fastest way to localise a circuit bug — far faster than staring at final counts.
Practise it now: rebuild both orderings in the Lab and watch the state view change gate by gate. The next lesson, Single-Qubit Circuit Patterns, turns these steps into reusable building blocks.