Part III. Circuit Model · Chapter 22
Circuit Cost: Depth, Width, Gate Set, Connectivity
A circuit diagram is a claim about a device, and the claim can die in compilation. This chapter replaces the diagram with a cost table — width, depth, gate set, connectivity, measurement — that survives contact with real hardware.
In this chapter 8 sections
Reader question. Which resource quantities determine whether an abstract quantum circuit can run on a target machine?
Width, logical gate counts, dependency depth, native gate set, connectivity, measurement/reset, and error/time budgets jointly determine feasibility; routing and decomposition can make a shallow abstract circuit deeper and less reliable than a larger-looking alternative.
- This chapter does not compress all resource quality into one score or compare current vendor devices.
- It does not treat asymptotic gate count as a substitute for compiled and timed execution.
The seven-column circuit ledger
Define width, counts, depth, gate set, topology, measurement, and timing.
An abstract circuit states the intended computation. A runnable circuit has to fit a device or a simulator, and the distance between those two objects is where most overclaims live. Five quantities measure the distance:
- Width. How many qubits the circuit occupies.
- Depth. How many layers of gates must run sequentially.
- Gate set. Whether the operations are native to the hardware or must be decomposed.
- Connectivity. Whether qubits that need to interact are physically or logically adjacent.
- Measurement structure. When quantum state becomes classical evidence, and how often that readout is wrong.
Judging a circuit means pricing all five. Optimizing one in isolation usually just moves the cost to another.
Evidence boundary. Circuit width, depth, and gate counts are distinct computational resources. [Michael A. Nielsen] [John Preskill]
Dependency depth differs from line count
Schedule independent operations explicitly.
First, routing. When a circuit demands an interaction between qubits that are not adjacent, the compiler inserts swap chains or reroutes the logic, and the depth you drew is not the depth you get:
Second, errors accumulate per gate. A rough teaching model:
This is deliberately crude; real noise models are richer; but it makes the operative point: two circuits computing the same function can carry wildly different risk. Two-qubit gates, readout error, idle time, and crosstalk usually dominate the budget, so the cheaper circuit is the one with fewer expensive operations, not fewer boxes on the page.
Evidence boundary. Native gate sets and connectivity require compilation and routing that can increase depth and error exposure. [openqasm3] [Lieven M. K. Vandersypen et al.]
Routing prices a missing edge
Map a nonlocal CNOT onto a line and count swaps.
The classic failure is algorithm-name-as-evidence. "We ran Grover" or "the demo uses QFT" says nothing about qubits, depth, native gates, connectivity, shots, noise, or the classical baseline. The name is the one part of the claim that carries no cost information.
The subtler failure is treating transpilation as formatting; a reprint of the same circuit in a new notation. Transpilation changes depth, gate counts, scheduling, and measurement layout. It preserves meaning, but it can flip the practical verdict on a specific device, which is why resource claims should always quote the compiled circuit, not the source.
Evidence boundary. End-to-end hardware feasibility depends on timed operations and system-level constraints beyond abstract gate count. [Lieven M. K. Vandersypen et al.] [National Academies of Sciences]
Notation contract: Width W, dependency depth D, gate counts G1/G2, topology graph E, duration τ, first-order success model assumptions stated.
Decomposition changes the error mix
Translate a logical gate into a native basis.
This is systems work. A high-level description lowers through an intermediate representation to target-specific instructions; each target produces a different compiled form; each optimization trades one cost against another. Anyone who has read a compiler's output assembly will find the situation familiar.
The deliverable that turns a drawing into an engineering artifact is a cost table:
- abstract qubits, and physical or logical qubits after mapping;
- abstract depth and transpiled depth;
- one-qubit and two-qubit gate counts;
- measurement count;
- connectivity assumption;
- error or fidelity assumption;
- classical baseline.
If a claim cannot fill in most of those rows, it is not yet a circuit claim; it is a schedule of intentions.
Two circuits change rank after compilation
Compare abstract and mapped resource tables.
When a startup, research group, or internal team claims a circuit-level advantage, request the table before engaging with the narrative. Then stress it: does the advantage survive routing? Finite precision? The error budget? The classical baseline?
If the advantage evaporates under any of those, the honest recommendation is monitor or wait, whatever the demo looked like. If the table is transparent and survives sensitivity checks, the claim has earned deeper review; and the team has demonstrated they know what they are selling.
Topology-aware circuit cost calculator
| Field | Reader-visible record |
|---|---|
| Format | Compiler fixture plus before/after resource ledger |
| Verification | Tests legal connectivity, dependency depth, swap insertion, native decomposition counts, and a first-order success estimate with declared assumptions. |
| Availability | Published companion and deterministic command |
Nearest-neighbor CNOT router is the executable companion used by this page.
cd labs && python -m unittest tests.test_companion_models.CompanionModelTests.test_line_router_exposes_swap_cost_and_layout -vExecutable reference fixture
Run with Python 3.11 or later. The final assertion is the chapter-level pass condition for this small instance.
def validate_circuit(qubits, circuit):
if qubits < 2:
raise ValueError("routing needs at least two physical qubits")
for control, target in circuit:
if control == target or not 0 <= control < qubits or not 0 <= target < qubits:
raise ValueError("CNOT endpoints must be distinct valid logical wires")
def dependency_depth(circuit, qubits):
ready = [0] * qubits
depth = 0
for left, right in circuit:
layer = max(ready[left], ready[right]) + 1
ready[left] = ready[right] = layer
depth = max(depth, layer)
return depth
def route_line(qubits, circuit):
validate_circuit(qubits, circuit)
placement = list(range(qubits))
routed = []
for logical_control, logical_target in circuit:
control = placement.index(logical_control)
target = placement.index(logical_target)
while abs(control - target) > 1:
step = 1 if target > control else -1
neighbor = control + step
routed.append(("SWAP", control, neighbor))
placement[control], placement[neighbor] = placement[neighbor], placement[control]
control = neighbor
routed.append(("CX", control, target))
return routed, tuple(placement)
def expand_native(routed):
primitives = []
for gate, left, right in routed:
if gate == "SWAP":
primitives.extend(((left, right), (right, left), (left, right)))
else:
primitives.append((left, right))
return primitives
def report(qubits, circuit, two_qubit_error):
if not 0 <= two_qubit_error < 1:
raise ValueError("error probability must lie in [0,1)")
routed, final_layout = route_line(qubits, circuit)
assert all(abs(left - right) == 1 for _, left, right in routed)
primitives = expand_native(routed)
swaps = sum(gate == "SWAP" for gate, _, _ in routed)
exact_success = (1 - two_qubit_error) ** len(primitives)
first_order_success = 1 - len(primitives) * two_qubit_error
return {
"logical_depth": dependency_depth(circuit, qubits),
"routed_depth": dependency_depth(primitives, qubits),
"swaps": swaps,
"native_two_qubit_gates": len(primitives),
"final_layout": final_layout,
"exact_success": exact_success,
"first_order_success": first_order_success,
}
scenarios = (
(5, ((0, 4),), 0.002),
(5, ((0, 3), (1, 4), (0, 2)), 0.005),
(4, ((0, 1), (2, 3)), 0.01),
)
reports = [report(*scenario) for scenario in scenarios]
assert reports[0]["swaps"] == 3 and reports[0]["native_two_qubit_gates"] == 10
assert reports[2]["logical_depth"] == 1 and reports[2]["swaps"] == 0
for result in reports:
assert result["native_two_qubit_gates"] == 3 * result["swaps"] + len(scenarios[reports.index(result)][1])
assert 0 < result["exact_success"] <= 1
assert abs(result["exact_success"] - result["first_order_success"]) < 0.02
naive_nonlocal = ((0, 4),)
assert any(abs(left - right) != 1 for left, right in naive_nonlocal)
assert reports[0]["native_two_qubit_gates"] > len(naive_nonlocal)
invalid_rejected = False
try:
report(5, ((2, 2),), 0.001)
except ValueError:
invalid_rejected = True
assert invalid_rejected
bad_rate_rejected = False
try:
report(5, ((0, 1),), 1.0)
except ValueError:
bad_rate_rejected = True
assert bad_rate_rejected
total_swaps = sum(result["swaps"] for result in reports)
print(f"PASS: 22 topology calculator routes {len(scenarios)} circuits with total SWAPs={total_swaps}, native two-qubit counts={[result['native_two_qubit_gates'] for result in reports]}, depths={[(result['logical_depth'], result['routed_depth']) for result in reports]}, success={[round(result['exact_success'], 4) for result in reports]}")
Scope boundary
- This chapter does not compress all resource quality into one score or compare current vendor devices.
- It does not treat asymptotic gate count as a substitute for compiled and timed execution.
Depth commitment. One seven-field ledger, two compiled circuits, and one sensitivity analysis.
Practice problem
Compile two logically equivalent four-qubit circuits to a line topology and decide which is preferable under supplied one- and two-qubit error rates.
Line topology: 0--1--2--3. Native 1q error=0.001; native 2q error=0.01.
Circuit A logical layers: CX(0,3); CX(1,2).
Circuit B logical layers: CX(0,1); CX(2,3); CX(1,2).
Restore initial layout and report logical gates, inserted SWAPs, native 2q count, and depth separately.
- Deliverable
- Mapped circuits, seven-column ledgers, success estimates, and a conditional choice.
- Pass condition
- The reference mapper and cost script reproduce counts/depth and recalculate the choice under a sensitivity sweep.
Verification record
Expected solution form. Before/after tables plus generated routing diff and sensitivity plot.
Model answer. On the declared line, Circuit B uses only legal adjacent edges. Circuit A's CX(0,3) requires routing and restoration, adding four SWAPs or twelve native CNOTs in the simple move-and-return schedule. Under the supplied error rates, Circuit B has the smaller two-qubit exposure and is preferred unless a different final layout is allowed.
Model result and check. CI rejects illegal edges and compares submitted ledger fields with compiler output.
Acceptance test. The reference mapper and cost script reproduce counts/depth and recalculate the choice under a sensitivity sweep.
Companion work
Artifacts for this chapter
These entries resolve to checked-in local source. Commands are reproduced exactly from the chapter manifest, and source-embedded fixtures are exported as direct downloads.
Reproduce or test
cd labs && python -m unittest tests.test_companion_models.CompanionModelTests.test_line_router_exposes_swap_cost_and_layout -v
Provenance
Sources and review
- Michael A. Nielsen and Isaac L. Chuang. Quantum Computation and Quantum Information. Cambridge University Press. 2010textbook
- John Preskill. Lecture Notes for Physics 219: Quantum Computation. California Institute of Technology. 2018graduate lecture notes
- OpenQASM Technical Steering Committee. OpenQASM 3 specification. Linux Foundation Joint Development Foundation. 2026official technical specification
- Lieven M. K. Vandersypen et al.. A look at the full stack. Nature Reviews Physics. 2021peer-reviewed perspective
- National Academies of Sciences, Engineering, and Medicine. Quantum Computing: Progress and Prospects. National Academies Press. 2019consensus study report
The load-bearing claims in the chapter are mapped inline to this registered source set. A citation supports only the bounded claim beside it.