Quantum computing refresher: superposition, entanglement, and interference

Overview

Why this post

Personal curiosity. A break from Kubernetes and AI fatigue.


Why quantum computing?

Classical computers represent everything as bits: 0 or 1. Quantum computers use qubits, which can be in a superposition of 0 and 1 simultaneously. This gives certain algorithms a significant speedup over classical equivalents.

Problem Classical Quantum
Search (unsorted) O(n) O(sqrt(n)) - Grover
Factoring large numbers Exponential O((log N)^3) - Shor
Simulating molecules O(2^n) O(n^2) or O(n^3)
Machine learning O(n^2) O(log n) - quantum PCA

Factoring is relevant for cryptography: Shor's algorithm can break RSA. Simulation is relevant for drug discovery and materials science.


Three core principles

Superposition

A qubit can be in a combination of 0 and 1 at the same time. This is written as:

$$|\psi\rangle = \alpha|0\rangle + \beta|1\rangle$$
  • $\alpha$ and $\beta$ are complex amplitudes (think of them as waves).
  • The total probability must equal 1: $|\alpha|^2 + |\beta|^2 = 1$
  • Before measurement, the qubit is in both states at once.
  • After measurement, it collapses to either 0 or 1.

Schrodinger's cat illustrates this: in an isolated system, the cat is both alive and dead until you open the box and observe it.

$$|cat\rangle = \frac{1}{\sqrt{2}}|alive\rangle + \frac{1}{\sqrt{2}}|dead\rangle$$

To put a qubit into superposition in code (Qiskit):

1circuit.h(0)  # Hadamard gate on qubit 0

The Hadamard gate (H) is a laser pulse that puts the qubit into an equal superposition of 0 and 1.

Entanglement

Two qubits can be entangled so that measuring one instantly determines the state of the other, regardless of distance. Einstein called this "spooky action at a distance."

$$|qubits\rangle = \frac{1}{\sqrt{2}}|00\rangle + \frac{1}{\sqrt{2}}|11\rangle$$

This means:

  • Both qubits are in superposition.
  • If you measure qubit A and get 0, qubit B is also 0.
  • If you measure qubit A and get 1, qubit B is also 1.

To entangle two qubits in code:

1circuit.cx(0, 1)  # CNOT gate entangles qubits 0 and 1

The CNOT gate flips qubit 1 if qubit 0 is 1. You cannot entangle a single qubit - entanglement requires at least two.

Interference

Quantum interference is what makes quantum algorithms useful. Amplitudes can add (constructive interference) or cancel (destructive interference).

A quantum algorithm is designed so that:

  • Wrong answers interfere destructively and cancel out.
  • The correct answer interferes constructively and becomes more probable.

This is the wave-like behavior of quantum mechanics applied to computation.


Grover's search algorithm

Grover's algorithm searches an unsorted database of n items in O(sqrt(n)) steps instead of O(n).

How it works:

  1. Put all qubits into superposition. All database items are now represented simultaneously.
  2. Apply an oracle: a function that marks the target item by flipping its amplitude.
  3. Apply a diffusion step: amplify the marked item using interference, while canceling the unmarked items.
  4. Repeat steps 2 and 3 approximately sqrt(n) times.
  5. Measure: the result is the target item with high probability.
1# Example oracle pseudocode
2oracle = {
3    "search_function": "if name == 'target' then flip_amplitude",
4    "quantum_interface": "processes all |address> states simultaneously"
5}

The oracle explores all possibilities at once because the qubits are entangled in a superposition representing the entire database.


Running on real hardware

Quantum computers use ions (atoms missing an electron) as qubits. A Hadamard gate is implemented as a laser pulse.

To run a circuit on Quantinuum hardware:

1backend = provider.get_backend("quantinuum.sim.h1-1e")
2job = backend.run(circuit, shots=100)
3print("Job id:", job.id())

From the command line:

1az quantum execute \
2  --target-id quantinuum.qpu.h1 \
3  -- --n-qubits=3 --idx-marked=6

Summary

Concept What it means
Qubit Quantum bit, can be 0, 1, or both at once
Superposition Qubit is in multiple states before measurement
Entanglement Measuring one qubit determines another
Interference Amplitudes add or cancel like waves
Hadamard gate Puts a qubit into superposition
CNOT gate Entangles two qubits
Oracle Marks the target in a quantum search
Grover Search in O(sqrt(n)) instead of O(n)
Shor Factoring in O((log N)^3) instead of O(2^n)