|q⟩ Bad Qubits

beginner · Programming · Building & Reading Quantum Circuits

Circuit Diagrams

Quantum algorithms are written and reasoned about as circuit diagrams — a standard graphical notation that makes the flow of computation immediately visible. Before building more complex programs, it is worth learning to read these diagrams fluently.

Wires carry qubits through time

Each horizontal line in a circuit diagram represents one qubit. Time flows from left to right: the left end of a wire is the qubit's initial state (almost always 0|0\rangle), and the right end is the qubit just before it is either measured or discarded.

Wires are not wires in the electrical sense — no current flows. They are a bookkeeping device that tracks which qubit a gate acts on. A single-qubit system has one wire; an nn-qubit system has nn wires, typically labelled q0,q1,,qn1q_0, q_1, \ldots, q_{n-1} from top to bottom.

Gates are boxes on wires

An operation applied to a qubit appears as a labelled box sitting on the corresponding wire. A single-qubit gate straddles exactly one wire. For example, the Hadamard gate HH is drawn as a box containing the letter HH, and the Pauli XX gate (a quantum NOT) appears as a box labelled XX.

Two-qubit gates span two wires. The CNOT (controlled-NOT) uses a filled circle on the control wire and an \oplus symbol on the target wire, connected by a vertical line. The convention immediately tells you which qubit controls the operation and which qubit gets flipped.

Reading time order

Gates are applied in the order they appear from left to right. A circuit that first applies HH to qubit 0 and then applies a CNOT (qubit 0 as control, qubit 1 as target) is written with the HH box to the left of the CNOT. If two gates act on different wires and share no qubit, they can be drawn at the same horizontal position — they commute in the sense that neither depends on the other, and the diagram makes that independence visible at a glance.

Measurement

Measurement is shown by a special symbol at the right end of a wire — often a box with a dial, or simply the letter MM. A double line emerging from a measurement box represents a classical bit: the deterministic 0 or 1 that the measurement records. In many diagrams, classical wires are drawn thicker or with two parallel lines to distinguish them from quantum wires.

Putting it together

A two-qubit Bell-state circuit is a useful example to practice reading:

  1. Wire q0q_0 starts in 0|0\rangle. A box labelled HH appears on q0q_0 — apply the Hadamard.
  2. Immediately to the right, a CNOT spans both wires: the filled circle sits on q0q_0 (control) and \oplus sits on q1q_1 (target).
  3. Both wires then terminate at measurement symbols.

Reading left to right, you reconstruct the algorithm: first create superposition on q0q_0, then entangle the two qubits, then measure. The diagram encodes exactly the same information as the code c.h(0); c.cx(0, 1); c.measure(); but in a form that highlights structure rather than syntax.

With this reading skill in hand, you are ready to work through circuits of any size — the rest of this module builds the vocabulary of gates and idioms that fill those boxes.

Sign in on the full site to ask questions and join the discussion.