PricingOpen Lab
Chapter 13 of 14 · ~25 min

Quantum circuits as programs

A circuit is a program: an ordered list of operations, each naming a gate, its qubit operands, and any parameters — the diagram is just a rendering of that list. Gate count and depth measure different costs, and operand order is semantics: transposing one [control, target] pair changes the output.

Strip away the diagram and a quantum circuit is a small, ordinary-looking program. The Bell circuit in QPU137 Circuit IR — the intermediate representation, the machine-readable program text every tool consumes — is:

{"numQubits": 2, "ops": [{"gate": "H", "qubits": [0]}, {"gate": "CX", "qubits": [0, 1]}]}

Read it like code. numQubits declares the register. ops is an ordered list — position in the list is execution order. Each operation names a gate, its qubit operands (for CX: control first, target second), and, for rotation gates, a params array of angles in radians. The familiar diagram — horizontal wires for qubits, boxes for gates — is a rendering generated from this text, the way a syntax-highlighted view is generated from source. When diagram and JSON seem to disagree, the JSON is the program.

Continue this chapter

You’ve read the opening of chapter 137 more sections follow, with worked examples and circuits you can run on the page. A free account unlocks every chapter of every course (paid plans aren’t live yet — early readers get everything free).

Create a free accountAll chaptersStart with the free chapters
Quantum circuits as programs · QPU137