The Quantum Circuit Model

A piece of sheet music is a wall of dots until someone teaches you to read it: staves run left to right, notes stack top to bottom, and you play them in order. A quantum circuit is read the same way. Horizontal lines are qubits, boxes strung along them are gates, and you apply them one after another as your eye sweeps left to right. Learn this one convention and every quantum algorithm — from a two-line demo to Shor's factoring — becomes a diagram you can actually read.

The anatomy of a circuit

Every quantum circuit is built from just four kinds of thing:

By convention the qubits usually start in |0\rangle, so an n-qubit circuit begins in the all-zeros state |0\cdots0\rangle. The gates then transform that starting vector, step by step, until the meters collapse it to an answer.

A circuit you can read

Here is the most famous two-qubit circuit of all — the one that builds a Bell pair. Step through it and watch it being assembled the way you would read a bar of music: the H box on the top wire acts first, then the CNOT, then the two meters.

Notice the payoff of the convention: nothing about the picture is ambiguous. You know the H happens before the CNOT because it is to its left, and you know the measurements happen last because they are at the far right.

The whole circuit is one big unitary

A gate is a matrix, and applying gates in sequence is just multiplying matrices. So a circuit made of gates U_1, U_2, \dots, U_k (in time order, left to right) is itself a single unitary operator

U \;=\; U_k \, U_{k-1} \cdots U_2 \, U_1,

and the circuit's job is simply to compute U\,|0\cdots0\rangle. Read that product carefully: because a matrix acts on the vector to its right, the gate that runs first in time (U_1) sits rightmost in the formula, right next to the state. The drawing order and the matrix order run opposite ways. For our Bell circuit that means

U_{\text{Bell}} \;=\; \text{CNOT}\,\big(H \otimes I\big),

with the CNOT on the left (it acts second) and the Hadamard layer H\otimes I on the right (it acts first). Every quantum algorithm, however sprawling its diagram, collapses to one unitary U like this — followed by measurement.

Worked example 1: tracing the Bell circuit

Let us push the input |00\rangle through the circuit gate by gate and see the Bell state appear. Step 1 — the Hadamard. It acts on q_0 only (with the identity on q_1), turning |0\rangle into an equal superposition:

(H \otimes I)\,|00\rangle = \big(H|0\rangle\big)\otimes|0\rangle = \tfrac{1}{\sqrt2}\big(|0\rangle+|1\rangle\big)\otimes|0\rangle = \tfrac{1}{\sqrt2}\big(|00\rangle + |10\rangle\big).

Step 2 — the CNOT. It flips q_1 exactly when q_0 is 1, so it leaves |00\rangle alone and sends |10\rangle \mapsto |11\rangle:

\text{CNOT}\;\tfrac{1}{\sqrt2}\big(|00\rangle + |10\rangle\big) = \tfrac{1}{\sqrt2}\big(|00\rangle + |11\rangle\big) = |\Phi^+\rangle.

Out comes |\Phi^+\rangle, the entangled Bell state. If we now hit the two meters, the only possible readouts are 00 and 11, each with probability \big|\tfrac{1}{\sqrt2}\big|^2 = \tfrac12 — the qubits always agree.

Worked example 2: order matters

Because U = U_k\cdots U_1 is a product of matrices, and matrix multiplication does not commute, swapping two gates generally changes the whole circuit. Watch what happens if we run the same two gates in the other order — CNOT first, then the Hadamard — again starting from |00\rangle. The CNOT sees q_0 = 0, so it does nothing:

\text{CNOT}\,|00\rangle = |00\rangle,

and only then does the Hadamard act on the top qubit:

(H\otimes I)\,|00\rangle = \tfrac{1}{\sqrt2}\big(|00\rangle + |10\rangle\big).

The result \tfrac{1}{\sqrt2}(|00\rangle+|10\rangle) = |{+}\rangle\otimes|0\rangle is a plain product state — not entangled at all! The same two gates in the opposite order gave a completely different physics. This is why the left-to-right reading is not a nicety but the whole meaning of the diagram: as operators, \text{CNOT}\,(H\otimes I) \neq (H\otimes I)\,\text{CNOT}.

The shape of nearly every algorithm

Once you can read circuits, you start to notice that almost all of them share the same four-part silhouette:

  1. Initialise — set every qubit to |0\rangle.
  2. Hadamard layer — a wall of H gates puts the register into a superposition over all inputs at once.
  3. Oracle / unitary — a problem-specific block U_f that computes or marks something across that superposition.
  4. Interference — more gates (often another Hadamard layer) so the amplitudes of wrong answers cancel and the right answer's amplitude grows.
  5. Measure — read out, now overwhelmingly likely to see the useful answer.

You can see this skeleton in Deutsch–Jozsa, Grover's search, and the rest: superpose, transform, interfere, measure.

One convenient fact makes circuits easier to reason about: the principle of deferred measurement. Any measurement made partway through a circuit — say, to decide whether to apply a later gate — can be pushed to the very end without changing the statistics of the final outcome, provided the classical result is instead carried by a controlled quantum gate. That is why we can always draw the meters as the last column: everything before them is pure, reversible unitary evolution, and only the final readout is irreversible.

The analogy is worth taking seriously. On a stave, the horizontal direction is time and the vertical direction is which instrument (or pitch) plays; you read left to right, and notes stacked in the same column sound together. A quantum circuit is identical: the horizontal direction is time, each wire is a "voice" (a qubit), and gates in the same vertical column happen simultaneously. A two-qubit gate like CNOT is a chord tying two voices together. Once the mapping clicks, a dense circuit stops being a thicket of symbols and becomes a score you can play through in your head — one column at a time, top to bottom, start to finish.

The single most common slip is to write the gates' matrices in the order you see them. They go the other way. In the picture the Hadamard is on the left, so it acts first; but in the product U = \text{CNOT}\,(H\otimes I) the Hadamard sits on the right, because a matrix hits the vector to its right, and the first thing to touch the state |00\rangle must be the rightmost factor. Read a circuit left→right in time, but write its matrix product right→left. A second thing to keep straight: every box before the meters is a reversible unitary — no information is lost and you could run it backwards. It is only the measurement at the end that is irreversible and random. So "the circuit is one big unitary" is true right up until the final meters, and not a step further.