Pricing…Open Lab
Chapter 13 of 14 · ~25 min

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:

  • numQubits says how many qubits the program uses.
  • ops is 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 params list 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.

What the rest of this chapter covers
  1. The two-op program, executedINTERACTIVE
  2. What is the difference between gate count and depth?
  3. A count-3, depth-3 programINTERACTIVE
  4. Why does operand order change the program?
  5. One transposed pair of operandsINTERACTIVE
  6. Worked exampleINTERACTIVE
  7. Is the program you wrote the one that runs?
Keep learning with Pro

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.

Start learning with ProSee plansRead chapter 1 free
Quantum circuits as programs · QPU137