Quantum circuits as programs
A circuit is a program. It is an ordered list of steps. Each step names a gate, the qubits it acts on, and any settings. The diagram is just a drawing of that list. Gate count and depth measure different costs. And the order of the qubits in a step matters: swap one [control, target] pair and the output changes.
Why care? If you think of a circuit as code, you can review it, test it and debug it the way you already work.
Take away the diagram and a quantum circuit is a small program that looks quite ordinary. Here is the Bell circuit in QPU137 Circuit IR. IR stands for intermediate representation: the program text that every tool reads.
{"numQubits": 2, "ops": [{"gate": "H", "qubits": [0]}, {"gate": "CX", "qubits": [0, 1]}]}
Read it like code:
numQubitssays how many qubits the program uses.opsis an ordered list. Its position in the list is the order the steps run.- Each step names a gate and its qubits. For CX, the control comes first and the target second.
- Rotation gates also get a
paramslist of angles, in radians.
The familiar diagram has flat lines for qubits and boxes for gates. It is drawn from this text, the way a colour-coded view is drawn from source code. Think of sheet music and a recording: the sheet is the real instructions. When the diagram and the JSON seem to disagree, the JSON is the program.
- The two-op program, executedINTERACTIVE
- What is the difference between gate count and depth?
- A count-3, depth-3 programINTERACTIVE
- Why does operand order change the program?
- One transposed pair of operandsINTERACTIVE
- Worked exampleINTERACTIVE
- Is the program you wrote the one that runs?
You’ve read the opening of chapter 13. Pro unlocks the other 7 sections — plus every chapter of every course, with circuits you can run right on the page. That’s $11.99 a month, about the price of a coffee, or $99.99 a year (save 30%). The first chapter of every course, and the whole math course, stay free.