Constructing quantum circuits
Turn a sequence of gates into a small, testable computational story.
- Write a circuit contract with initial state, gates and readout basis.
- Compare a predicted distribution with a seeded finite-shot sample.
Start with a contract
Section titled “Start with a contract”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: , q0 leftmost.
- Gates: H on q0, then CX from q0 to q1.
- Exact output: .
- Z readout: 00 and 11 with probability each.
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?
Exact ideal-model predictions · run a measurement experiment to compare.
Take it further
Create the Bell state, then undo the gates in reverse order. Where did the randomness go?
Prediction: Apply H to q0, then CX from q0 to q1. Which two outcomes should disappear? Challenge: Create the Bell state, then undo the gates in reverse order. Where did the randomness go?
Verify at more than one level
Section titled “Verify at more than one level”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.
A deliberate defect
Section titled “A deliberate defect”Move H to q1 but leave CX’s direction unchanged. The control remains 0, so the result is , 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.
Extend
Section titled “Extend”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.
Ready for the next step?
Your progress stays in this browser.