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

Single Qubit
H
Hadam.
X
Pauli-X
Y
Pauli-Y
Z
Pauli-Z
S
S Gate
T
T Gate
Two Qubit
C-NOT
×
SWAP

Drag gates onto the circuit wires

q0|0⟩q1|0⟩t0t1t2t3t4t5t6t7
Step Start /
Speed:
Space Play/Pause← → StepR Reset

OUTPUT STATE

Definite state |00⟩
State
Phase
Probability
%
Angle
Amplitude
|00⟩
Phase: 0°
100.0%
1.00
Normal (0° phase)
Phase shifted
0° = right90° = up180° = left
Drag gates onto wiresClick gate + Delete to removeCNOT/SWAP connect to next qubit

Beyond the Basics: More Gates

The Circuit Builder above covers the fundamentals. Real quantum frameworks like Qiskit offer many more gates:

GateNameWhat It Does
Rx(θ)X-RotationRotates qubit around X-axis by any angle θ. Generalizes the X gate.
Ry(θ)Y-RotationRotates around Y-axis. Creates superposition with controllable amplitudes.
Rz(θ)Z-RotationRotates around Z-axis by any angle. Generalizes Z, S, and T gates.
CZControlled-ZApplies Z to target when control is |1⟩. Symmetric — both qubits act as control.
CCXToffoli3-qubit gate. Flips target only when BOTH controls are |1⟩. Universal for classical computing.
S†, T†Inverse GatesReverse the S and T gates. S† = -90° phase, T† = -45° phase.
U(θ,φ,λ)Universal GateAny single-qubit operation with 3 parameters. All other single-qubit gates are special cases.
iSWAPiSWAPSwaps 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!

|0⟩
H
→ 50/50 expected
?
Shot 0 / 100
0
|0⟩ (0%)
0
|1⟩ (0%)

💡 More shots = more accurate probability estimate. Real quantum computers use 1000+ shots!

The Simulation Workflow

  1. 1
    Build , Define qubits and gates using Qiskit
  2. 2
    Transpile , Convert to executable form for the backend
  3. 3
    Run , Execute on the simulator (many shots)
  4. 4
    Analyze , 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.

Lab Note #004

"Grover's algorithm... searching unsorted data in √N time. Classical computers can't do this. I'm close to something big."

, Dr. M.

N

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?
BackNext