Skip to content
Quantum ComputingAN INTERACTIVE OPEN TEXTBOOK
charithj.com.au

Constructing quantum circuits

Turn a sequence of gates into a small, testable computational story.

12 min readDr. Charith Jayasekara↓ Chapter PDF
By the end, you’ll be able to
  • Write a circuit contract with initial state, gates and readout basis.
  • Compare a predicted distribution with a seeded finite-shot sample.

Before adding gates, specify the initial state, qubit ordering, intended transformation and measured output. “Create correlated bits” is incomplete: it does not identify the quantum state or the measurement basis.

For a Bell-state circuit, use this contract:

  • Input: ∣00⟩\lvert00\rangle, q0 leftmost.
  • Gates: H on q0, then CX from q0 to q1.
  • Exact output: (∣00⟩+∣11⟩)/2(\lvert00\rangle+\lvert11\rangle)/\sqrt2.
  • Z readout: 00 and 11 with probability 1/21/2 each.
L02 · INTERACTIVE LABRuns on your device

Quantum gate playground

Gates act on amplitudes. Build a small circuit one operation at a time and compare its exact predictions with repeated measurements.

Make a prediction first

Apply H to q0, then CX from q0 to q1. Which two outcomes should disappear?

Experiment controls

Add a gate · left to right

|00⟩ → I
Maximum 20 gates. CX has q0 as control, q1 as target.
Exact probability
|00⟩
100.0%
|01⟩
0.0%
|10⟩
0.0%
|11⟩
0.0%

Exact ideal-model predictions · run a measurement experiment to compare.

MODEL · Ideal pure-state vector, complex double precisionORDER · q0 is the leftmost bit
Take it further

Create the Bell state, then undo the gates in reverse order. Where did the randomness go?

First calculate the ideal state. Then compare the exact simulator distribution. Finally sample finite shots with a recorded seed. The first two check the model calculation; the third demonstrates sampling fluctuations.

The playground’s Undo removes a gate from the circuit description and recomputes from the initial state. It is an editing operation, not a claim that a measured physical state can be reversed by deleting a line of history.

Move H to q1 but leave CX’s direction unchanged. The control remains 0, so the result is ∣0⟩⊗∣+⟩\lvert0\rangle\otimes\lvert+\rangle, not a Bell state. Its nonzero Z outcomes are 00 and 01.

Repair the circuit and explain the root cause. This is more informative than simply trying gates until the bars look familiar.

Ask whether your test would detect a relative-phase error. A Z gate after Bell preparation leaves the Z counts unchanged but changes the state. Add X-basis evidence using the entanglement lab.

Reference: IBM Quantum — Bits, gates, and circuits.

ONE IDEA FURTHER

Ready for the next step?

Your progress stays in this browser.