The Quantum Circuit Model
Suppose you want to describe, unambiguously, the exact sequence of physical operations a quantum computer must perform. This could be to factor a number or simulate a molecule. You need a notation that is precise enough for an engineer to build hardware from. Yet it must also be abstract enough for a theorist to prove complexity bounds. A theorist should not need to worry about voltages or laser pulses. The quantum circuit model is that notation. It is the shared language of Universal Gate Sets, of algorithm papers, and of the compilers that translate high-level quantum programs into pulses on real devices. The model matters because every quantum algorithm is ultimately specified as a circuit. This includes Shor's factoring algorithm, Grover's search, quantum simulation, and error-correcting codes. A circuit is a finite list of wires carrying qubits and gates carrying unitary operations. These are arranged in a definite time order, ending in measurements. Without a rigorous circuit formalism, it would be impossible to compare algorithms. It would also be impossible to define what "polynomial-time quantum algorithm" even means. Nor could we reason about how many physical operations a given computation will cost. The big picture is that quantum computation is a generalization of the classical Boolean circuit model. Classical circuits chain together AND, OR, and NOT gates on bits. Quantum circuits chain together unitary gates on qubits instead. Measurement serves as the bridge back to classical information. The extra structure includes superposition, entanglement across wires, and the probabilistic collapse of measurement. This structure is what gives quantum circuits their power. It is also what makes their semantics subtler than classical circuits. This article gives the formal definition of a quantum circuit. It covers what a wire is, and what time-ordering means for gates acting on overlapping wires. It also covers the conventions for drawing and reading circuit diagrams. Finally, it explains the precise semantics of measurement, both mid-circuit and terminal. It builds directly on Two-Qubit Gates and the CNOT and Rotation Gates and Arbitrary Single-Qubit Unitaries. It also sets up the language needed for later discussions of Reversibility of Quantum Computation and Quantum vs Classical Parallelism.
- A quantum circuit is a finite sequence of unitary gates acting on a fixed register of qubits, followed by measurement.
- Wires represent qubits through time, not physical wires; gates are boxes drawn left-to-right in temporal order.
- The overall unitary is the product of gate matrices (each tensored with identity on untouched wires), composed in reverse order of the diagram.
- Gates acting on disjoint wires at the "same time slice" commute and can be applied in either order — this is what defines circuit depth.
- Measurement is a non-unitary, irreversible operation governed by the Born rule; it may occur mid-circuit (with classical feedback) or only at the end.
- Circuit size (gate count) and depth (parallel time steps) are the two standard complexity measures, both central to defining quantum polynomial time.
A quantum circuit is a time-ordered composition of unitary gates on qubit wires whose overall action is the matrix product of the gates (read right-to-left against the diagram), with measurement as the sole non-reversible step.
The idea
A quantum circuit on qubits is specified by three ingredients: a register of wires, each initialized to a fixed basis state (conventionally ); a finite ordered list of gates, each a unitary operator acting on one or a few designated wires; and a specification of which wires are measured, and when. The state of the whole register at any moment is a vector in the -dimensional Hilbert space , and a gate acting on a subset of wires is really the operator acting on the full space, where is the identity on the untouched wires. The crucial conceptual point — and the one that most needs care — is time-ordering. A circuit diagram is read left to right as time, not as an algebraic expression. If gate is drawn before gate on overlapping wires, the state after both gates is as a matrix product, i.e. gates compose in reverse textual order, exactly as function composition reads first even though is written first. This convention is a common source of sign and ordering errors and deserves to be stated as a theorem-like fact: if a circuit consists of gates applied in that temporal order, the resulting unitary is
Two gates that act on disjoint sets of wires automatically commute, since . This is why circuit diagrams may legitimately draw gates on different wires "at the same horizontal position" without ambiguity — their relative order genuinely does not matter, and a circuit can be organized into layers (or time steps) of mutually commuting, wire-disjoint gates. The number of layers needed is the circuit's depth, distinguished from its size, the total gate count; depth models parallel execution time on hardware that can apply many gates simultaneously, while size models total physical resource cost.
Measurement breaks unitarity by design. A measurement of a qubit in the computational basis is described by two projectors and ; outcome occurs with probability , and the post-measurement state collapses to . Measurement can be placed at the very end of a circuit (the default, "measure-at-the-end" convention used to define quantum complexity classes), or mid-circuit, in which case the classical outcome bit may be fed forward to control later gates — a classically-controlled gate. The principle of deferred measurement (a foundational fact developed alongside Reversibility of Quantum Computation) states that any mid-circuit measurement followed by classically-controlled unitaries can be replaced by controlled quantum gates and a single measurement at the end, without changing the output distribution; this justifies treating "measure-at-the-end" circuits as the canonical, fully general model.
How it works
Building and simulating a circuit mechanically proceeds by tracking the full state vector (for small ) or, for reasoning about correctness, by symbolic composition of unitaries. The general recipe: 1. Initialize the register: (or another fixed product state). 2. Apply gates in temporal order. For each gate acting on wire subset , update , where the tensor factors are arranged according to which physical wires picks out (not necessarily contiguous). 3. Handle classical controls. If a gate is controlled on a previously measured classical bit , apply iff , else apply identity. 4. Measure the designated wires (possibly all, possibly a subset) at the end (or, under deferred measurement, replace mid-circuit measurements with controlled unitaries and measure everything at the end). 5. Output the classical bit string of measurement outcomes; this is the actual "answer" of the computation, and for probabilistic algorithms the circuit may be run many times to estimate a distribution. The pseudocode below makes explicit how a classical simulator executes an arbitrary circuit — this is exactly the semantics that any physical implementation must reproduce, up to the state being a genuine quantum amplitude vector rather than an explicitly stored classical array (a distinction developed further under Quantum vs Classical Parallelism). ``` function SIMULATE_CIRCUIT(n, ops):
# n: number of qubits
# ops: ordered list of operations, each one of:
# ("gate", U, wires) -- unitary U applied to given wires
# ("measure", wire, classical_reg) -- projective measurement, outcome stored
# ("cgate", U, wires, classical_reg, bit) -- apply U to wires iff classical_reg == bit state = KRON(|0>, |0>, ..., |0>) # length-2^n amplitude vector classical = {} # map: register name -> measured bit for op in ops: if op.type == "gate": state = APPLY_UNITARY(state, op.U, op.wires, n) elif op.type == "cgate": if classical[op.classical_reg] == op.bit: state = APPLY_UNITARY(state, op.U, op.wires, n)
# else: identity, do nothing elif op.type == "measure": p1 = SUM_OF_SQUARED_AMPLITUDES(state, op.wire, outcome=1) outcome = SAMPLE_BERNOULLI(p1) state = PROJECT_AND_RENORMALIZE(state, op.wire, outcome) classical[op.classical_reg] = outcome return classical, state function APPLY_UNITARY(state, U, wires, n):
# Conceptually build U ⊗ I on the full 2^n-dim space, respecting wire order,
# then left-multiply. Efficient implementations act only on the amplitudes
# indexed by the chosen wires, in O(2^n · |U|) time, never forming the full matrix. return FullOperator(U, wires, n) * state ``` Note the deliberate separation: `"gate"` steps are always applied regardless of any classical data (pure unitary evolution), while `"cgate"` steps model the classically-controlled operations that arise from mid-circuit measurement and feedback — precisely the two building blocks the deferred-measurement principle shows are interchangeable with a measure-at-the-end-only circuit. The figure below shows a small but genuinely structural circuit — three qubits, a mix of single- and two-qubit gates arranged in layers, and a terminal measurement — annotated with wire indices and time steps to make the temporal-order convention concrete.
Reading the diagram: at , on and on act on disjoint wires and commute — this is one layer. At , a CNOT entangles (control) and (target). At , an on and a gate on again share a layer since their wires are disjoint. At , a CNOT entangles and . The overall unitary before measurement is
each factor implicitly tensored with identity on the untouched wire — read right to left, matching the left-to-right diagram.
Complexity & correctness
Size and depth as complexity measures. The size of a circuit is the number of gates it contains; the depth is the number of layers of mutually commuting, wire-disjoint gates needed, i.e. the length of the longest chain of gates that must be applied in strict sequence because they share a wire. Formally, build a dependency graph where gates are nodes and an edge () exists if they act on a common wire and no gate between them on that wire separates them; depth is the longest path in this DAG. Depth lower-bounds the circuit's running time on any hardware model that can execute non-overlapping gates in parallel, while size lower-bounds the total number of physical operations (relevant when gates, not time, are the scarce resource, e.g. due to decoherence-limited gate budgets).
Why time-ordering composition is correct. This is not a convention chosen for convenience — it is forced by the axioms of quantum mechanics. Time evolution under a sequence of instantaneous unitary "kicks" then obeys the Schrödinger-equation limit in which each kick multiplies the current state vector on the left: , then . Induction on the number of gates gives the general claim: for a circuit with gates applied in that order,
so the circuit implements the unitary , matrix multiplication composed in reverse diagrammatic order. This is exactly the same logic as composing functions then : you write , not .
Why the layering (commutation) claim is correct. If gates (on wire set ) and (on ) have , then as operators on the full -qubit space, really means and means (with tensor factors reordered to match wire positions). Since acts only on the factors and acts only on the (disjoint) factors, and every operator commutes with the identity on any wire it doesn't touch, as full operators. This is precisely why depth can be smaller than size: independent gates collapse into shared layers, and the DAG longest-path computation runs in time via a topological scan tracking, for each wire, the depth of the last gate seen on it.
Correctness of the deferred-measurement replacement. Suppose a circuit measures wire mid-computation, obtaining outcome with probability , and later applies gate conditioned on . Replace this by: do not measure yet; instead apply a controlled- gate using itself as the control qubit, then measure at the end (after everything else). Because controlled- acts as on the branch and on the branch, and because the reduced statistics of any later measurement on the other wires are computed by summing over the (now-deferred) outcome of exactly as the Born rule would have summed over the earlier measurement outcome, the two circuits induce identical output distributions on all other measured wires. This holds because tracing out (ignoring) a qubit gives the same reduced density matrix whether you measure it early or defer the measurement to the end — a fact usually proved formally via the partial trace and the no-signaling structure of quantum channels. The upshot: circuits with mid-circuit measurement and classical feedback have exactly the same computational power as unitary-only circuits followed by a single terminal measurement, which is why textbooks can define quantum complexity classes using the simpler measure-at-the-end model without loss of generality.
Honest tradeoffs. The circuit model assumes gates are exact, wires are noiseless, and any two-qubit gate can be applied between any pair of wires regardless of physical distance — none of which literally holds on real hardware. Real devices have restricted connectivity (requiring extra SWAP gates that inflate size and depth), noisy gates (requiring Universal Gate Sets with fault-tolerant encodings), and finite coherence time (making depth, not just size, the binding constraint). The abstract circuit model is nonetheless the right level of idealization for algorithm design and asymptotic complexity, in the same way the classical RAM model abstracts away cache hierarchies.
Worked example
Trace the 3-qubit circuit from the diagram on a concrete input, choosing so up to the usual phase convention, i.e. , . Start from (writing kets as ).
| Step | Operation | State (unnormalized where noted) |
|---|---|---|
| 0 | Init | |
| 1 | on , on | |
| 2 | CNOT() | |
| 3 | on , on | |
| 4 | CNOT() | |
| 5 | Measure all | outcomes or , each w.p. |
Working through the middle steps explicitly:
- Step 1: on ; on ; untouched at . Product state: .
- Step 2: CNOT flips whenever : the term () is untouched; the term () becomes . Result .
- Step 3: apply to and to , term by term. For (): leaves the amplitude unchanged, multiplies the amplitude by . For (): multiplies by , multiplies by . Result: .
- Step 4: CNOT flips whenever : () is untouched; () becomes . Result: .
- Step 5: since and are orthonormal basis states with equal magnitude amplitudes (the global phase and the phase on the second term don't affect measurement probabilities), the Born rule gives outcome with probability and outcome with probability .
This traces both the entanglement structure (the two CNOTs correlate all three qubits, so no single-qubit description survives past step 2) and the role of relative phase (the factor from is invisible in the final measurement statistics here, but would matter if a further interfering gate were applied before measurement) — illustrating precisely why circuit semantics must track full complex amplitudes, not just probabilities, until the terminal measurement.
Common pitfalls & traps
| Pitfall | Why it happens | Fix |
|---|---|---|
| Multiplying gates in diagram order instead of reverse | Confusing "reading order" with "composition order" | Always write for gates applied in that temporal order |
| Forgetting the identity on untouched wires | Treating a 2-qubit gate matrix as if it acted on the whole register | Explicitly tensor with on every wire the gate does not touch before multiplying |
| Assuming all gates in a diagram column commute | Only true if their wire sets are disjoint | Check wire overlap; overlapping "simultaneous" gates are a drawing error, not a valid layer |
| Treating mid-circuit measurement as unconditionally equivalent to ignoring the qubit | Confusing "discard/trace out" with "measure and record" | Only discarding (partial trace, no classical record) versus measuring-and-recording differ in whether classical control is available later; both give the same marginal statistics on other wires |
| Ignoring global vs. relative phase | Global phase is unobservable, tempting one to drop all phases | Track relative phases between basis terms carefully — they affect interference at later gates even though a single overall phase never matters |
| Confusing gate count (size) with parallel time (depth) | Both are called "circuit cost" informally | State explicitly which resource is being bounded; they can differ by a factor up to the size itself |
Pioneers & history
The circuit model crystallized the idea that quantum computation could be described with the same clean, composable, resource-counting formalism that made classical circuit complexity tractable, translating decades of circuit-complexity intuition into the quantum setting.
Origins · 1 minDavid Elieser Deutsch and how this was discovered
Deutsch's 1985 paper on the universal quantum computer first formalized quantum Turing machines and quantum networks (an early circuit-like model), asking what it would mean for a physical device to compute according to quantum mechanics rather than classical logic, and laying groundwork for treating gates and wires as first-class computational objects.
Where this matters
Every quantum programming framework in production use — Qiskit, Cirq, Q#, PennyLane, Braket — represents programs internally as quantum circuits: lists of gates on named qubit registers with explicit measurement operations, precisely the object formalized here. Hardware vendors (superconducting-qubit systems, trapped-ion systems, photonic systems) all expose their machines through a circuit-level interface, and their compilers perform exactly the kind of layering, depth-minimization, and wire-routing analysis described above to fit an abstract circuit onto physically constrained connectivity. Quantum error-correcting codes are themselves described as circuits (encoding, syndrome-extraction, and correction gates interleaved with measurement), and estimates of "how many physical qubits and how much time" a fault-tolerant algorithm needs are literally circuit-size and circuit-depth calculations. The formal notion of quantum polynomial time (the class BQP) is defined as the set of problems solvable by a family of circuits, one per input length, whose size grows polynomially — making the circuit model not just an implementation detail but the very object complexity theorists use to define what "efficient quantum computation" means.
Ask the tutor: How does the choice of mid-circuit versus deferred measurement affect qubit-count and depth tradeoffs in real quantum error-correction circuits?
Why does the order of matrix multiplication reverse relative to the circuit diagram?
A circuit diagram encodes time, read left to right, while matrix composition encodes function application, read right to left, exactly like ordinary function composition . If gate happens first and gate happens second, the state evolves as . So the unitary implementing " then " is the product , with the later gate written on the left. This is not a quantum-specific quirk — it is the same convention used whenever any sequence of operators is composed, but it trips up newcomers because circuit diagrams visually suggest reading left to right as if writing an equation.
Can any two gates on the same wire be reordered like disjoint-wire gates?
No. Two gates sharing at least one wire generally do not commute, so their order is physically meaningful and cannot be swapped without potentially changing the computation. For example, applying then to the same qubit gives a different unitary than then , since in general (they anticommute up to sign for Pauli operators, in fact). Only gates acting on completely disjoint wire sets are guaranteed to commute purely from tensor-product structure; any overlap in wires requires explicitly checking whether the specific matrices happen to commute, which is the exception rather than the rule.
Is measuring a qubit mid-circuit fundamentally more powerful than measuring only at the end?
No — this is precisely the content of the deferred-measurement principle. Any circuit that measures a qubit partway through and uses the classical outcome to control later gates can be simulated by a purely unitary circuit that uses controlled versions of those later gates, controlled on the qubit itself (kept quantum), followed by a single measurement of everything at the end. The two circuits produce identical probability distributions over the other measured outcomes. Mid-circuit measurement is often used in practice for efficiency (fewer qubits needed at once, adaptive algorithms, error correction), but it adds no fundamental computational power beyond the measure-at-the-end model.
What exactly is the difference between circuit size and circuit depth, and why do both matter?
Size counts total gates; depth counts the minimum number of sequential time steps needed, given that wire-disjoint gates can run in parallel. A circuit with size 1000 could have depth as low as, say, 10 if the gates decompose into 10 layers of 100 parallel, non-overlapping gates, or as high as 1000 if every gate depends on the previous one. Size matters when gates themselves are the expensive or noisy resource (e.g., each gate has some error probability, so total error scales with gate count). Depth matters when time is the binding constraint, as in systems with limited coherence time, since idle qubits decohere while waiting.
How does the circuit model relate to the definition of the complexity class BQP?
BQP (bounded-error quantum polynomial time) is defined using uniform families of quantum circuits: for each input length , a circuit built from a fixed Universal Gate Sets gate set, with size polynomial in , that outputs the correct answer with probability at least upon measurement. The circuit model is thus not just a convenient picture — it is the literal object complexity theorists quantify over when defining efficient quantum computation, playing the same foundational role that Boolean circuits play in classical circuit complexity and in defining classes like P/poly.
Why must ancilla (helper) qubits initialized to |0⟩ sometimes be added to a circuit?
Some unitary transformations that are natural to implement (for example, simulating an irreversible classical function, or certain multi-controlled gates) are most efficiently built using extra "scratch" qubits initialized to a fixed state, used temporarily, and ideally either measured or returned to before the circuit ends (to avoid unwanted entanglement with the output register). This connects directly to why every reversible quantum circuit computing a classical Boolean function typically needs ancillas — a theme fully developed under Reversibility of Quantum Computation — since classical logic gates like AND are not invertible without extra output bits to record enough information to run backward.
Does the circuit model assume gates can be applied between any pair of qubits, regardless of physical layout?
Yes, the idealized model assumes all-to-all connectivity: any two-qubit gate can act on any pair of wires, with no notion of physical distance. Real hardware (superconducting chips, ion traps with limited interaction ranges, etc.) often only supports gates between physically adjacent qubits, so compilers insert extra SWAP gates to move quantum information into position before applying a distant two-qubit gate. This inflates both circuit size and depth in a hardware-dependent way, but the abstract, fully-connected circuit model remains the right tool for algorithm design and asymptotic complexity analysis, with connectivity treated as a separate compilation concern.