Skip to content

Quantum Circuits

A circuit is a diagram of steps. Read it from left to right, and trace what each step does.

From a Table to a Diagram

On the previous page, we made the Bell state with steps described in words and tables: H on q₀, then CNOT.

BeforeThe Bell state is made by H on q₀, then CNOT
NowThose steps have been described in words and tables

How can we write these steps down as a diagram?

You have seen the answer once already. The software stack page drew this same Bell-state circuit, and noticed that a circuit is an instruction, not a state. This page shows how to read that drawing, how to draw your own, and how to trace what each step does.

Reading a Circuit

A circuit diagram has a few parts. Keep them apart:

  • Wire — one line for each qubit, with q₀ on the top.
  • Initial state — what the qubit starts in, written beside its wire.
  • Gate — a labelled box on a wire, or a dot joined to a ⊕ for CNOT.
  • Column — one step. Read the columns from left to right.
  • Measurement symbol — a meter, which ends its wire.

The symbols for the gates you know, and for measurement:

The dot on a CNOT is the control and the ⊕ is the target. Here is a circuit to read: the two wires start in |0⟩.

Read it aloud: “H on q₀, then CNOT with q₀ as the control and q₁ as the target.”

Is the circuit the state?

No. The circuit is the instruction. The state is what the instruction produces from the initial states.

Tracing a Circuit

Tracing a circuit means asking, after each step, what the state is and what its outcome probabilities are. Here is the Bell circuit traced from |00⟩:

Why? H made q₀ an even mix, so 00 and 10 are equally likely. CNOT then flipped q₁ on the part of the state where q₀ is 1, so 10 became 11. The result is the Bell state: 00 and 11, each half the time.

The bars are the probabilities of the outcomes, not results. Tracing is something we do to the circuit on paper. It does not say how an outcome is observed.

Circuit Builder

Choose what each wire starts in. Then choose a gate from the palette, and press a cell to place it. Press a filled cell to remove it. The trace updates after every change, and the page tells you if a placement is not allowed.

1. Choose what each wire starts in

q₀ starts in

q₁ starts in

2. Choose a gate, then press a cell

3. Choose a goal (or play freely)

4. The circuit

5. The trace

The circuit, the trace, the message, and the goal result each sit in their own place. The trace shows the state and its probabilities after each step.

Now try one yourself. Choose goal (d) above: turn |0⟩ into certain 1 without using X. Check it in the builder.

Check your understanding. First, predict before the trace appears:

Then read the order:

What the Diagram Does Not Say

Two things in a diagram are conventions.

Reading order : Circuits are read from left to right, with q₀ on the top wire. These are conventions of this module. Other tools may order wires and bit strings differently.

Physical time : The diagram says what to do and in what order the maths is applied. It does not say when a machine does each step.

Steps in the same column act on different wires, so their order does not matter. Here are two circuits with the same two gates, one with them in the same column and one with them in two columns:

A real machine may run steps at overlapping times, reorder independent ones, or compile them into different steps. That belongs to Module 05, which this page only points to. A diagram is not a timeline.

Beyond the Core

Tracing with amplitudes

At this level, a trace can show the state itself. The builder's trace now lists the four-component vector after each step, and the matrix of the step. For the Bell circuit from \(|00\rangle\), in the order 00, 01, 10, 11:

\[ \begin{pmatrix}1\\0\\0\\0\end{pmatrix} \xrightarrow{\;H\otimes I\;} \frac{1}{\sqrt 2}\begin{pmatrix}1\\0\\1\\0\end{pmatrix} \xrightarrow{\;\mathrm{CNOT}\;} \frac{1}{\sqrt 2}\begin{pmatrix}1\\0\\0\\1\end{pmatrix}. \]

The first factor is q₀, so H on q₀ is \(H\otimes I\). In a circuit that has CNOT with q₁ as the control and q₀ as the target, the matrix exchanges the amplitudes of 01 and 11 instead:

\[ \mathrm{CNOT}_{q_0\to q_1} = \begin{pmatrix}1&0&0&0\\0&1&0&0\\0&0&0&1\\0&0&1&0\end{pmatrix},\qquad \mathrm{CNOT}_{q_1\to q_0} = \begin{pmatrix}1&0&0&0\\0&0&0&1\\0&0&1&0\\0&1&0&0\end{pmatrix}. \]

Two reading orders. The diagram reads left to right, and the matrix product reads right to left. The Bell circuit is H first, then CNOT, so

\[ \mathrm{CNOT}\,(H\otimes I)\,|00\rangle = \frac{|00\rangle + |11\rangle}{\sqrt 2}, \]

with the gate applied first written next to the state.

Parameters and identities

Rotation gates in a circuit. A rotation gate takes an angle, and the builder's palette now offers \(R_X\), \(R_Y\), and \(R_Z\) with an angle slider. For \(R_Y(\theta)\) on q₀ starting in \(|0\rangle\), the probability that q₀ gives 1 is \(\sin^2(\theta/2)\), so \(\theta = 60^\circ\) gives 25%. Try it, and read the vector in the trace.

Two identities. Two circuits can do the same job. Tracing \(|0\rangle\) through H, Z, H gives

\[ |0\rangle \xrightarrow{H} |+\rangle \xrightarrow{Z} |-\rangle \xrightarrow{H} |1\rangle, \]

the same as X does, so \(HZH = X\). Multiplying the matrices confirms it, written right to left:

\[ HZH = \frac{1}{2}\begin{pmatrix}1&1\\1&-1\end{pmatrix}\begin{pmatrix}1&0\\0&-1\end{pmatrix}\begin{pmatrix}1&1\\1&-1\end{pmatrix} = \begin{pmatrix}0&1\\1&0\end{pmatrix}. \]

The other identity is \(HXH = Z\):

\[ |0\rangle \xrightarrow{H} |+\rangle \xrightarrow{X} |+\rangle \xrightarrow{H} |0\rangle,\qquad |1\rangle \xrightarrow{H} |-\rangle \xrightarrow{X} -|-\rangle \xrightarrow{H} -|1\rangle . \]

X leaves \(|+\rangle\) alone and turns \(|-\rangle\) into \(-|-\rangle\), and the result matches \(Z|0\rangle = |0\rangle\) and \(Z|1\rangle = -|1\rangle\). Check both in the builder.

Code export (turning a drawn circuit into a program) is a later addition and is not part of this page.

Naming the formalism

The circuit depth is the number of steps a circuit needs, and it matters because every step takes time on a real machine. Circuit identities such as the two above are a tool for rewriting a circuit into a shorter or simpler one that does the same job. And gates are split into Clifford gates, such as H, S, and CNOT, and non-Clifford gates, such as T, a split that matters for how hard a circuit is to simulate. Later material makes these ideas precise.

From Circuits to Measurement

Compare what you can do now with what is still unknown.

So far
Write the steps as a circuit
Read and build one
Trace the probabilities at each step
Still unknown
See what a measurement returns
See a result rather than a probability
See what happens to the state afterwards

Here is the Bell circuit ending in two measurement symbols, with the probabilities it would give:

A trace shows what a measurement would give. A measurement gives one outcome at a time, and we have not yet looked at what happens when we repeat it.

Takeaway

Steps on wires
↓
Read left to right
↓
Trace the state and its probabilities at each step
↓
Build to a goal, and know the diagram is a convention, not a clock

A circuit is a diagram of steps on wires. Read it from left to right, trace the state and its probabilities after each step, and remember that the diagram says what to do, not when a machine does it.

How do these probabilities turn into the results we actually see?

Next: Measurement → (coming soon)