UQC

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 are qubits. Time flows left to right. Each wire starts in state |0⟩.

Gates

Boxes on the wires are operations. Every gate is reversible, you can always undo it.

Measurement

The meter at the end collapses the quantum state to classical bits. This is how we extract a result.

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

Real quantum frameworks like Qiskit offer many more.

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!

|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

Build

Define qubits and gates using Qiskit.

Transpile

Convert the circuit to executable form for the backend.

Run

Execute on the simulator. Many shots, not one.

Analyze

Count outcomes to estimate the probability distribution.

Key Insight

Because quantum measurement is probabilistic, we run the same circuit many times (e.g., 1,000 shots) and count the results. The histogram approximates the true probability distribution.

Hands-on exercise

15 minutes

Open in Google Colab

Reflection

  1. 01How is designing a quantum circuit different from writing classical code?
  2. 02Why do we need measurement at the end of a quantum circuit?