umma.dev

Quantum Computing Basics

Classical computers think in bits. A bit is either 0 or 1 - a switch that is off or on. Everything your laptop does, every photo, video, and spreadsheet, comes down to billions of those switches flipping very fast.

Quantum computers use a different kind of switch called a qubit. And qubits play by strange rules.

Superposition

Here is the first strange rule: a qubit does not have to be 0 or 1 while you are not looking at it. It can be both at the same time. This is called superposition.

Think of it like a coin spinning in the air. While it spins, it is neither heads nor tails - it is kind of both. The moment it lands and you look at it, it picks one. A qubit is the same.

Mathematically, a qubit’s state is written as a linear combination of the two basis states ∣0⟩|0\rangle and ∣1⟩|1\rangle:

∣ψ⟩=α∣0⟩+β∣1⟩|\psi\rangle = \alpha|0\rangle + \beta|1\rangle

Here Ξ±\alpha and Ξ²\beta are complex numbers called amplitudes. They must satisfy:

∣α∣2+∣β∣2=1|\alpha|^2 + |\beta|^2 = 1

This is just the rule that probabilities must add up to 1. When you measure the qubit, you get ∣0⟩|0\rangle with probability ∣α∣2|\alpha|^2 and ∣1⟩|1\rangle with probability ∣β∣2|\beta|^2.

This matters because with nn qubits in superposition you can hold 2n2^n states simultaneously. 10 qubits can hold 1024 states at once. 300 qubits can hold more states than there are atoms in the observable universe.

The trick is learning how to coax the right answer out of all that parallel exploration - which is what quantum algorithms are designed to do.

Entanglement

The second strange rule is entanglement. Two qubits can be linked so that measuring one instantly tells you the state of the other, no matter how far apart they are.

The simplest entangled state is called a Bell state:

∣Φ+⟩=121/2(∣00⟩+∣11⟩)|\Phi^+\rangle = \frac{1}{2^{1/2}}(|00\rangle + |11\rangle)

When you measure, you will always find both qubits in the same state - either both 0, or both 1, with equal probability. There is no way to predict which, but the result is always correlated. This correlation has no classical explanation, and it is a key ingredient in many quantum algorithms.

Einstein famously disliked this, calling it β€œspooky action at a distance.” But experiments have confirmed it is real.

Quantum Gates

To do anything useful you need to manipulate qubits. Quantum computers have quantum gates that transform qubit states. Unlike classical gates, all quantum gates are reversible - each one is represented by a unitary matrix, this means it can always be undone.

Hadamard gate (H) - puts a qubit into equal superposition:

H=121/2(111βˆ’1)H = \frac{1}{2^{1/2}}\begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix}

Applied to ∣0⟩|0\rangle it produces:

H∣0⟩=121/2(∣0⟩+∣1⟩)H|0\rangle = \frac{1}{2^{1/2}}(|0\rangle + |1\rangle)

A perfect 50/50 superposition. This is how most quantum circuits begin.

Pauli-X gate - the quantum NOT gate. It flips ∣0⟩|0\rangle to ∣1⟩|1\rangle and vice versa:

X=(0110)X = \begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix}

CNOT gate - a two-qubit gate. It flips the second qubit (the target) if and only if the first qubit (the control) is ∣1⟩|1\rangle. Written as a 4Γ—44 \times 4 matrix over the basis {∣00⟩,∣01⟩,∣10⟩,∣11⟩}\{|00\rangle, |01\rangle, |10\rangle, |11\rangle\}:

CNOT=(1000010000010010)\text{CNOT} = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0 \end{pmatrix}

Combining H and CNOT is the standard recipe for creating entanglement: apply H to one qubit to put it in superposition, then CNOT to link it with another.

T gate and S gate - rotation gates. The T gate rotates by Ο€/4\pi/4 and the S gate by Ο€/2\pi/2. These are building blocks of more complex algorithms.

Measurement

When you measure a qubit, the superposition collapses and you get a plain 0 or 1. This is both powerful and tricky. You only get one shot - measuring destroys the superposition.

Good quantum algorithms are designed so that the answer you want has the highest probability of appearing when you measure. The wrong answers interfere with each other and cancel out (called destructive interference), while the right answer gets amplified (called constructive interference). This is similar to how noise-cancelling headphones work.

Error Correction

Here is where things get hard in practice. Qubits are extremely fragile. Heat, vibration, stray electromagnetic fields, even cosmic rays can knock a qubit off its state. This is called decoherence, and it is the main reason useful quantum computers are so difficult to build.

Classical computers deal with errors by storing redundant copies. You cannot do that directly with qubits because of a rule called the no-cloning theorem - you cannot make an exact copy of an unknown quantum state.

Quantum error correction gets around this cleverly. Instead of copying a qubit, you spread its information across many physical qubits in a way that lets you detect and fix errors without ever directly measuring the information itself. The most well-known scheme is the surface code, where you arrange qubits in a 2D grid and measure relationships between neighbouring qubits to catch errors without collapsing the computation.

You may need 1000 or more physical qubits to protect a single logical qubit - the error-corrected version that your algorithm actually uses. This is why current machines with hundreds of physical qubits still fall short of running the large-scale algorithms people are excited about.

Getting Started with Qiskit

Qiskit is IBM’s open-source Python SDK for writing and running quantum circuits. It is the most widely used quantum programming framework and a good starting point for moving beyond theory into code.

Install it with:

pip install qiskit qiskit-aer

qiskit-aer is the simulator backend - it lets you run circuits on your laptop without needing access to real quantum hardware.

A Qubit in Superposition

from qiskit import QuantumCircuit
from qiskit.quantum_info import Statevector

qc = QuantumCircuit(1)
qc.h(0)

sv = Statevector(qc)
print(sv)
Statevector([0.70710678+0.j, 0.70710678+0.j], dims=(2,))

The two values are Ξ±\alpha and Ξ²\beta from ∣ψ⟩=α∣0⟩+β∣1⟩|\psi\rangle = \alpha|0\rangle + \beta|1\rangle. Both are 2βˆ’1/2β‰ˆ0.7072^{-1/2} \approx 0.707, so each outcome has a 50% probability on measurement.

Creating a Bell State

from qiskit import QuantumCircuit
from qiskit.quantum_info import Statevector

qc = QuantumCircuit(2)
qc.h(0)
qc.cx(0, 1)

sv = Statevector(qc)
print(sv)
Statevector([0.70710678+0.j, 0.+0.j, 0.+0.j, 0.70710678+0.j], dims=(2, 2))

This is 2βˆ’1/2(∣00⟩+∣11⟩)2^{-1/2}(|00\rangle + |11\rangle) - the Bell state from earlier. The zero amplitudes for ∣01⟩|01\rangle and ∣10⟩|10\rangle confirm the qubits are always correlated: measuring one tells you the other.

Simulating Measurement

from qiskit import QuantumCircuit
from qiskit_aer import AerSimulator

qc = QuantumCircuit(2, 2)
qc.h(0)
qc.cx(0, 1)
qc.measure([0, 1], [0, 1])

sim = AerSimulator()
result = sim.run(qc, shots=1000).result()
print(result.get_counts())
{'00': 503, '11': 497}

You never see 01 or 10. The qubits always agree - exactly as the Bell state predicts.

Drawing a Circuit

Qiskit can render your circuit as a text diagram:

print(qc.draw())
     β”Œβ”€β”€β”€β”      β”Œβ”€β”
q_0: ─ H β”œβ”€β”€β– β”€β”€β”€β”€Mβ”œβ”€β”€β”€
     β””β”€β”€β”€β”˜β”Œβ”€β”΄β”€β” β””β•₯β”˜β”Œβ”€β”
q_1: ────── X β”œβ”€β”€β•«β”€β”€Mβ”œ
          β””β”€β”€β”€β”˜  β•‘ β””β•₯β”˜
c: 2/════════════╩══╩═
                 0  1

Each horizontal line is a qubit. Gates are applied left to right. The H box is the Hadamard, the dot-and-cross symbol is the CNOT (dot = control, X = target), and the meter boxes are measurements that write results into the classical bits at the bottom.

What Quantum Computers Are Actually Good At

Quantum computers are not universally faster. For most everyday tasks a classical computer will beat them. They shine in specific problem types:

Factoring large numbers - Shor’s algorithm can factor an nn-bit number in O(n3)O(n^3) steps. The best known classical algorithm takes exponential time O(en1/3)O(e^{n^{1/3}}). This is why quantum computers are a big deal for cryptography - most modern encryption relies on factoring being hard.

Searching unsorted data - Grover’s algorithm finds a target in an unsorted list of NN items in O(N1/2)O(N^{1/2}) steps instead of the classical O(N)O(N). A quadratic speedup.

Simulating quantum systems - Quantum computers are naturally suited to modelling molecules and materials at the quantum level. This could accelerate drug discovery and materials science.

Optimisation problems - Scheduling, logistics, financial modelling - problems where you are trying to find the best option among a huge number of possibilities.

Where We Are Now

The current era is called NISQ - Noisy Intermediate-Scale Quantum. Machines today have tens to hundreds of qubits but they are noisy and error-prone. Researchers are using them to explore what is possible while working towards fault-tolerant machines large enough to run error-corrected algorithms at scale.