Pricing…Open Lab
Chapter 02 of 13 · ~10 min

Circuit State Step by Step

Keep track of the full list of amplitudes after every gate. Each gate takes the current list and makes the next one. Most circuit bugs jump out as soon as you compare the list you expected at a step with the list you actually got.

Why step through the state at all?

Why bother? When a circuit gives the wrong answer, the final counts rarely say where it went wrong. Checking the state after each gate does.

The state of a group of qubits is the full list of amplitudes. There is one amplitude for each possible readout. An amplitude is a number. Square it, and you get the chance of seeing that readout when you measure.

Two qubits have four possible readouts. So the state is a list of four numbers. We write each readout as a bitstring, a short row of 0s and 1s. q0 is the rightmost digit:

  • 00: both qubits are 0.
  • 01: q0 is 1.
  • 10: q1 is 1.
  • 11: both are 1.

Each gate is a small, exact rule. It turns the current list into the next list. So fixing a circuit works like fixing any program. Look at the state after each step. Find the first step where what you see is not what you expected.

It is like checking a long bank statement. If the final balance is wrong, you go line by line. The first line that doesn't add up is where the mistake is. The example breaks in one way: bank amounts are always zero or more, but amplitudes can be negative and cancel.

What the rest of this chapter covers
  1. Worked example: what does the Bell circuit do, one gate at a time?
  2. Run it and check the predictionINTERACTIVE
  3. Worked example: what if the same gates run in the opposite order?
  4. Compare: CX before HINTERACTIVE
  5. Is measurement just another step?
  6. Try this: append a second CXINTERACTIVE
  7. What should I remember?
Keep learning with Pro

You’ve read the opening of chapter 2. 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
Circuit State Step by Step · QPU137