cs.thefarshad
medium

Quantum Circuits

How to read circuit diagrams and compose gates into circuits that act on one or two qubits.

A quantum circuit is a recipe: horizontal wires carry qubits through time (left to right), and gates are the boxes you drop onto those wires. Reading one is like reading sheet music — each column is a moment, and the symbols tell you which operation happens to which qubit.

Build a circuit below by adding gates, then step through it. The diagram lights up gate by gate while the state vector and probabilities update underneath. The default H then CNOT is the standard way to create an entangled Bell pair.

add gate:
q0
HM
q1
M
|00⟩
100.0%
|01⟩
0.0%
|10⟩
0.0%
|11⟩
0.0%
start |00⟩
state: 1.000|00⟩
0/2 gates applied · negative amplitudes shown in rose

Reading the diagram

  • Each wire is one qubit, labeled q0, q1, …, starting in 0|0\rangle.
  • A boxed letter (H, X, Z) is a single-qubit gate applied at that moment.
  • CNOT is drawn as a filled dot (the control) connected to a \oplus (the target). When the control is 11, the target flips.
  • The M at the right edge is measurement, which collapses the state to a classical bitstring.

Time flows left to right, so the circuit 0HZ|0\rangle \xrightarrow{H} \xrightarrow{Z} means “apply HH, then ZZ” — order matters, because gates generally do not commute.

Composing single-qubit gates

Stacking gates on one wire just multiplies their effects. Try H then Z then H on q0: the surrounding Hadamards turn the otherwise invisible phase flip into a visible bit flip, ending in 1|1\rangle. This HZH=XHZH = X identity is a first taste of how interference is engineered by sequencing gates.

Two-qubit states

With two qubits the state vector has four amplitudes, ordered 00,01,10,11|00\rangle, |01\rangle, |10\rangle, |11\rangle:

ψ=c0000+c0101+c1010+c1111|\psi\rangle = c_{00}|00\rangle + c_{01}|01\rangle + c_{10}|10\rangle + c_{11}|11\rangle

Apply H on q0 and the amplitude spreads across 00|00\rangle and 10|10\rangle. Add CNOT and those become 00|00\rangle and 11|11\rangle — a state you cannot factor into “q0 does this, q1 does that.” That non-factorable result is entanglement, produced by a circuit just two gates long.

Building intuition

A few patterns worth trying in the builder:

  1. X q1 alone → the state moves to 01|01\rangle (remember q0 is the left digit).
  2. H q0, H q1 → all four outcomes equally likely (uniform superposition).
  3. H q0, CNOT → the Bell state: only 00|00\rangle and 11|11\rangle survive.

Notice the probabilities always sum to 1 at every step — each gate is unitary, so it shuffles amplitude around without ever creating or destroying it.

Takeaways

  • Circuit diagrams read left to right; wires are qubits and boxes are gates.
  • CNOT (control dot + target \oplus) is the workhorse two-qubit gate that builds entanglement.
  • Composing gates multiplies their effects; order matters and every step preserves total probability.

References