Building Blocks of Quantum Programs
Quantum Circuits
What Is a Quantum Circuit?
A quantum circuit is the quantum equivalent of a classical program. It's a sequence of operations (gates) applied to qubits, followed by measurement.
Unlike classical programs that manipulate bits deterministically, quantum circuits manipulate probability amplitudes to produce probabilistic outputs.
Circuit Anatomy
Wires (Qubits)
Horizontal lines represent qubits. Time flows left to right. Each wire starts in state |0⟩ by default.
Gates
Boxes and symbols on the wires represent operations. Gates are reversible (you can always undo them).
Measurement
The meter symbol at the end collapses the quantum state to classical bits (0 or 1). This is how we extract results.
Try It: Build Your Own Circuit
Drag gates from the palette onto the qubit wires to build a circuit. Watch how the output state changes as you add gates.
Circuit Builder
GATES
Creates superposition - puts qubit in both |0⟩ and |1⟩ simultaneously
|0⟩ → |0⟩+|1⟩ (50/50)Quantum NOT gate - flips the qubit state
|0⟩ → |1⟩, |1⟩ → |0⟩Combines bit flip and phase flip
|0⟩ → i|1⟩, |1⟩ → -i|0⟩Phase flip - adds negative phase to |1⟩ (invisible until measured through H)
|0⟩ → |0⟩, |1⟩ → -|1⟩Quarter turn around Z-axis (90° phase)
|1⟩ → i|1⟩Eighth turn around Z-axis (45° phase) - key for universal quantum computing
|1⟩ → e^(iπ/4)|1⟩Controlled-NOT: flips target qubit only if control qubit is |1⟩
|10⟩ → |11⟩, |00⟩ → |00⟩Exchanges the states of two qubits
|01⟩ → |10⟩Drag gates onto the circuit wires
OUTPUT STATE
Beyond the Basics: More Gates
The Circuit Builder above covers the fundamentals. Real quantum frameworks like Qiskit offer many more gates:
| Gate | Name | What It Does |
|---|---|---|
| Rx(θ) | X-Rotation | Rotates qubit around X-axis by any angle θ. Generalizes the X gate. |
| Ry(θ) | Y-Rotation | Rotates around Y-axis. Creates superposition with controllable amplitudes. |
| Rz(θ) | Z-Rotation | Rotates around Z-axis by any angle. Generalizes Z, S, and T gates. |
| CZ | Controlled-Z | Applies Z to target when control is |1⟩. Symmetric — both qubits act as control. |
| CCX | Toffoli | 3-qubit gate. Flips target only when BOTH controls are |1⟩. Universal for classical computing. |
| S†, T† | Inverse Gates | Reverse the S and T gates. S† = -90° phase, T† = -45° phase. |
| U(θ,φ,λ) | Universal Gate | Any single-qubit operation with 3 parameters. All other single-qubit gates are special cases. |
| iSWAP | iSWAP | Swaps qubits and adds phase. Native to some superconducting hardware. |
The gates in the Circuit Builder (H, X, Y, Z, S, T, CNOT, SWAP) form a universal gate set — you can build any quantum algorithm with them.
Multiple Shots Simulation
Watch how running many shots reveals the true probability distribution!
💡 More shots = more accurate probability estimate. Real quantum computers use 1000+ shots!
The Simulation Workflow
- 1Build , Define qubits and gates using Qiskit
- 2Transpile , Convert to executable form for the backend
- 3Run , Execute on the simulator (many shots)
- 4Analyze , Count outcomes to estimate probabilities
Key Insight: Multiple Shots
Because quantum measurement is probabilistic, we run the same circuit many times (e.g., 1,000 "shots") and count the results. This gives us a histogram of outcomes that approximates the true probability distribution.
"Grover's algorithm... searching unsorted data in √N time. Classical computers can't do this. I'm close to something big."
, Dr. M.
H → CNOT → M = ?
Hint: This famous circuit creates an entangled pair
Reflection Questions
- 1How is designing a quantum circuit different from writing classical code?
- 2Why do we need measurement at the end of a quantum circuit?