Qubits and Superposition — The Foundation of Quantum Computing
In this tutorial, you'll learn about Qubits and Superposition. We cover key concepts, practical examples, and best practices to help you understand and apply this topic effectively.
Qubits are the fundamental building blocks of quantum information, and Superposition is the property that allows them to exist in multiple states simultaneously until measured.
What You'll Learn
By the end of this tutorial, you will understand qubit state representation using Dirac notation and the Bloch sphere, how to create Superposition using the Hadamard gate, and how measurement probabilities work in practice.
Why It Matters
Superposition is what gives quantum computers their massive parallelism. Without Superposition, a quantum computer would be no more powerful than a classical one. Understanding qubits and Superposition is the first step toward programming quantum algorithms.
Real-World Use
When IBM researchers calibrate their quantum processors, they repeatedly prepare qubits in Superposition, measure them, and analyze the statistics to characterize gate fidelity. This same concept appears in every quantum algorithm from Grover search to Quantum Machine Learning.
Learning Path
flowchart LR
A[Quantum Overview] --> B[Qubits and Superposition]
B --> C[Quantum Gates]
C --> D[Quantum Circuits]
B --> E{You Are Here}
style E fill:#f90,color:#fff
Prerequisites: Review the quantum computing overview for background on qubits and superposition concepts.
Dirac Notation
Quantum states are written using Dirac notation, also called bra-ket notation. A ket |ψ⟩ represents a quantum state. The basis states for a qubit are |0⟩ and |1⟩.
The Qubit State Vector
A qubit state is a unit vector in a two-dimensional complex vector space:
|ψ⟩ = α|0⟩ + β|1⟩
The normalization condition |α|² + |β|² = 1 ensures the total probability equals 1. The values α and β are complex numbers called probability amplitudes.
Column Vector Representation
In computational basis, we can write:
|0⟩ = [1] |1⟩ = [0]
[0] [1]
And a general state:
|ψ⟩ = [α ]
[β ]
Python Representation
# qubit_state.py
import numpy as np
import cmath
class QubitState:
def __init__(self, alpha=1+0j, beta=0+0j):
self.amplitudes = np.array([alpha, beta], dtype=complex)
self._normalize()
def _normalize(self):
norm = np.sqrt(np.sum(np.abs(self.amplitudes)**2))
self.amplitudes /= norm
def as_vector(self):
return self.amplitudes
def prob_0(self):
return np.abs(self.amplitudes[0])**2
def prob_1(self):
return np.abs(self.amplitudes[1])**2
def __str__(self):
a, b = self.amplitudes
return f"|psi⟩ = ({a.real:.3f}+{a.imag:.3f}j)|0⟩ + ({b.real:.3f}+{b.imag:.3f}j)|1⟩"
# Create basis states
ket0 = QubitState(1, 0)
ket1 = QubitState(0, 1)
print(f"|0⟩: {ket0}")
print(f"|1⟩: {ket1}")
# Create a superposition state
phi = QubitState(1+0j, 1+0j) # Equal superposition
print(f"\nSuperposition: {phi}")
print(f"P(0) = {phi.prob_0():.1%}")
print(f"P(1) = {phi.prob_1():.1%}")
Expected output:
|0⟩: |psi⟩ = (1.000+0.000j)|0⟩ + (0.000+0.000j)|1⟩
|1⟩: |psi⟩ = (0.000+0.000j)|0⟩ + (1.000+0.000j)|1⟩
Superposition: |psi⟩ = (0.707+0.000j)|0⟩ + (0.707+0.000j)|1⟩
P(0) = 50.0%
P(1) = 50.0%
Notice the amplitudes were automatically normalized to 1/√2 each, giving equal 50% probabilities.
The Bloch Sphere
The Bloch sphere is a geometric representation of a single qubit's state space. Every pure qubit state maps to a point on the sphere's surface.
Coordinates
|ψ⟩ = cos(θ/2)|0⟩ + e^(iφ) sin(θ/2)|1⟩
- θ (theta): polar angle, 0 to π
- φ (phi): azimuthal angle, 0 to 2π
Key Points on the Bloch Sphere
| State | θ | φ | Meaning | |-------|---|---|---------| | |0⟩ | 0 | 0 | North pole | | |1⟩ | π | 0 | South pole | | |+⟩ | π/2 | 0 | Equal Superposition (X axis) | | |−⟩ | π/2 | π | Equal Superposition (-X axis) | | |+i⟩ | π/2 | π/2 | Equal Superposition (Y axis) |
Visualizing the Bloch Sphere
graph TD
subgraph "Bloch Sphere"
center((" "))
north("|0⟩ (North Pole)")
south("|1⟩ (South Pole)")
east("|+⟩")
west("|-⟩")
center --> north
center --> south
center --> east
center --> west
end
style north fill:#4af,color:#fff
style south fill:#f44,color:#fff
The Hadamard Gate: Creating Superposition
The Hadamard gate (H) is the most important single-qubit gate. It creates Superposition by transforming basis states:
H|0⟩ = (|0⟩ + |1⟩)/√2 = |+⟩
H|1⟩ = (|0⟩ - |1⟩)/√2 = |−⟩
Matrix Form
H = 1/√2 [1 1]
[1 -1]
Applying the Hadamard Gate in Python
# hadamard_gate.py
import numpy as np
def hadamard(state_vector):
"""Apply Hadamard gate to a qubit state vector."""
H = (1/np.sqrt(2)) * np.array([[1, 1], [1, -1]], dtype=complex)
return H @ state_vector
def measure(state_vector, samples=1000):
"""Simulate measurement statistics."""
prob_0 = np.abs(state_vector[0])**2
prob_1 = np.abs(state_vector[1])**2
results = np.random.choice([0, 1], size=samples, p=[prob_0, prob_1])
zeros = np.sum(results == 0)
ones = np.sum(results == 1)
return zeros, ones
# Start with |0⟩
ket0 = np.array([1, 0], dtype=complex)
print(f"Starting state: |0⟩ = {ket0}")
# Apply Hadamard
superposed = hadamard(ket0)
print(f"After H: {superposed}")
# Measure statistics
zeros, ones = measure(superposed, 10000)
print(f"\nMeasurement statistics (10000 samples):")
print(f"|0⟩: {zeros} ({zeros/100:.1f}%)")
print(f"|1⟩: {ones} ({ones/100:.1f}%)")
# Apply Hadamard again to verify H² = I
back_to_zero = hadamard(superposed)
print(f"\nAfter second H: {back_to_zero}")
Expected output:
Starting state: |0⟩ = [1 0]
After H: [0.70710678 0.70710678]
Measurement statistics (10000 samples):
|0⟩: 4987 (49.9%)
|1⟩: 5013 (50.1%)
After second H: [1. 0.]
The Hadamard gate is its own inverse: applying it twice returns the original state. This is true of all quantum gates (they are unitary).
Multi-Qubit States
When you have multiple qubits, the state space grows exponentially. For n qubits, you need 2ⁿ amplitudes.
Tensor Product
The combined state of two independent qubits is the tensor product:
|ψ⟩ ⊗ |φ⟩ = [α₀α₁, α₀β₁, β₀α₁, β₀β₁]ᵀ
Example: Two Qubits
# two_qubits.py
import numpy as np
def tensor_product(state_a, state_b):
"""Compute the tensor product of two qubit states."""
return np.kron(state_a, state_b)
# Create two qubits in |0⟩ and |1⟩
qubit_0 = np.array([1, 0], dtype=complex)
qubit_1 = np.array([0, 1], dtype=complex)
# Combined state |01⟩
combined = tensor_product(qubit_0, qubit_1)
print(f"|0⟩ ⊗ |1⟩ = |01⟩ = {combined}")
# Create |+⟩|+⟩ (two qubits both in superposition)
plus = np.array([1, 1], dtype=complex) / np.sqrt(2)
both_superposed = tensor_product(plus, plus)
print(f"\n|+⟩ ⊗ |+⟩ = {both_superposed}")
# Probabilities for all 4 basis states
basis_labels = ['|00⟩', '|01⟩', '|10⟩', '|11⟩']
probs = np.abs(both_superposed)**2
print("\nProbabilities:")
for label, prob in zip(basis_labels, probs):
print(f" {label}: {prob:.1%}")
Expected output:
|0⟩ ⊗ |1⟩ = |01⟩ = [0 1 0 0]
|+⟩ ⊗ |+⟩ = [0.5 0.5 0.5 0.5]
Probabilities:
|00⟩: 25.0%
|01⟩: 25.0%
|10⟩: 25.0%
|11⟩: 25.0%
With two qubits in Superposition, all four basis states are equally likely.
Measurement in Practice
Quantum measurement is probabilistic and destructive. The measurement outcome is random, and the qubit collapses to the measured state.
Measurement Operators
The measurement is described by projection operators:
M₀ = |0⟩⟨0| = [[1, 0], [0, 0]]
M₁ = |1⟩⟨1| = [[0, 0], [0, 1]]
The probability of measuring outcome m is ⟨ψ|M_m† M_m|ψ⟩.
Repeated Measurement Sequence
# repeated_measurement.py
import numpy as np
def single_shot_measurement(state_vector):
"""Perform a single measurement and return the collapsed state."""
prob_0 = np.abs(state_vector[0])**2
if np.random.random() < prob_0:
return 0, np.array([1, 0], dtype=complex)
else:
return 1, np.array([0, 1], dtype=complex)
# Create a qubit with bias toward |1⟩
alpha = np.sqrt(0.3)
beta = np.sqrt(0.7)
state = np.array([alpha, beta], dtype=complex)
print(f"Initial state: P(0)={alpha**2:.1%}, P(1)={beta**2:.1%}")
# Perform measurements
print("\nSingle shot measurements (10 runs):")
for i in range(10):
result, collapsed = single_shot_measurement(state)
print(f" Run {i+1}: measured {result} → collapsed to {'|0⟩' if result == 0 else '|1⟩'}")
# Verify collapse
result_1, collapsed_1 = single_shot_measurement(state)
result_2, collapsed_2 = single_shot_measurement(collapsed_1)
print(f"\nFirst measurement: {result_1}")
print(f"Second measurement (same qubit): {result_2}")
print(f"Same result: {result_1 == result_2}")
Expected output:
Initial state: P(0)=30.0%, P(1)=70.0%
Single shot measurements (10 runs):
Run 1: measured 1 → collapsed to |1⟩
Run 2: measured 0 → collapsed to |0⟩
Run 3: measured 1 → collapsed to |1⟩
...
First measurement: 1
Second measurement (same qubit): 1
Same result: True
After the first measurement collapses the qubit, subsequent measurements always give the same result. The Superposition is destroyed.
Common Mistakes
1. Confusing Probability Amplitudes with Probabilities
The amplitudes α and β are complex numbers. Their squared magnitudes |α|² and |β|² are probabilities. People often mistake α for the probability directly.
2. Forgetting Normalization
A valid qubit state must satisfy |α|² + |β|² = 1. If you create a state like |ψ⟩ = 0.5|0⟩ + 0.5|1⟩, the probabilities sum to 0.5, not 1.
3. Thinking the Bloch Sphere Shows All States
The Bloch sphere only shows pure states. Mixed states (statistical ensembles) exist inside the sphere. Additionally, multi-qubit states cannot be represented on a single Bloch sphere.
4. Assuming Phase Does Not Matter
The relative phase between |0⟩ and |1⟩ matters. The state (|0⟩ + |1⟩)/√2 is different from (|0⟩ - |1⟩)/√2. Phase enables interference effects in quantum algorithms.
5. Misunderstanding Measurement Collapse
Some believe the qubit was always in a definite state but we just did not know it (hidden variables). Bell's theorem proves this wrong: the measurement outcome is genuinely random until the moment of measurement.
Practice Questions
1. Write the state |+⟩ in Dirac notation and explain its measurement probabilities.
|+⟩ = (|0⟩ + |1⟩)/√2. Measuring gives |0⟩ with 50% probability and |1⟩ with 50% probability.
2. What is the Hadamard gate and what does it do?
The Hadamard gate creates Superposition. It maps |0⟩ to (|0⟩ + |1⟩)/√2 and |1⟩ to (|0⟩ - |1⟩)/√2. It is its own inverse.
3. Why does a second Hadamard gate undo the first?
Because the Hadamard gate is unitary and Hermitian: H² = I. The two applications interfere destructively for the |1⟩ component and constructively for the |0⟩ component.
4. How many amplitudes are needed to represent an n-qubit state?
2ⁿ amplitudes. For n=1, you need 2. For n=2, you need 4. For n=50, you need 2⁵⁰ amplitudes, which exceeds classical memory capacity.
5. What is the difference between a pure state and a mixed state?
A pure state can be described by a single state vector (point on Bloch sphere surface). A mixed state is a statistical ensemble of pure states (point inside Bloch sphere). Mixed states arise from noise or entanglement with the environment.
Challenge: Phase Estimation
Write a Python function that takes an unknown qubit state and determines its relative phase φ by applying Hadamard gates and measuring:
def estimate_phase(unknown_state, num_measurements=1000):
"""
Estimate the relative phase φ of a state |ψ⟩ = (|0⟩ + e^(iφ)|1⟩)/√2.
Apply H, measure, and use interference to determine φ.
"""
# Hint: Applying H to (|0⟩ + e^(iφ)|1⟩)/√2 gives
# cos(φ/2)|0⟩ - i*sin(φ/2)|1⟩ (up to global phase)
# Count measurement outcomes to estimate φ
pass
Hints: Use the fact that H changes the measurement probabilities based on φ. The ratio of |0⟩ to |1⟩ measurements reveals the phase.
Real-World Task: Qubit Calibration Simulation
Quantum hardware teams calibrate qubits by repeatedly preparing, applying gates, and measuring. Write a script that:
- Creates a qubit in |0⟩
- Applies a Hadamard gate
- Measures 1000 times
- Reports the ratio of |0⟩ to |1⟩ outcomes
- Adjusts calibration parameters until the ratio is 50/50 within 1% tolerance
This simulates the actual calibration Process used in IBM and Google quantum processors.
FAQ
Try It Yourself
Use the Python code in this tutorial to create different Superposition states. Try varying the probability amplitudes and observe how the measurement statistics change. Experiment with the phase by creating states like (|0⟩ + i|1⟩)/√2 and see how applying a second Hadamard gate produces different results.
What's Next
Now you understand qubits and Superposition. Next, you will learn how to manipulate qubits using quantum gates to build quantum algorithms.
Built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro. Last updated: 2026-06-21.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro