The Qubit

4 hours ~5 min read

The Qubit

The qubit is the hydrogen atom of quantum computing — the simplest nontrivial quantum system, and the one we'll never stop using. Here we make it concrete: what it is physically, how superposition and the Born rule look in C2\mathbb{C}^2, and — for the first time in this program — how to build and run a real quantum circuit on AWS Braket. Everything stays on the free local simulator.

Learning Objectives

After this lesson you will be able to:

  1. Define a qubit as a two-level quantum system and give physical realizations.
  2. Write a general qubit state and compute computational-basis measurement probabilities.
  3. Explain superposition and how a single Hadamard creates it.
  4. Build, run, and read out a circuit on the Braket LocalSimulator (free).
  5. Connect the simulator's amplitudes and shot counts to the Born rule.

Intuition

A bit is a switch: 00 or 11. A qubit is a quantum two-level system whose state can be any superposition of 0\lvert0\rangle and 1\lvert1\rangle — a complex blend that, when measured, yields 00 or 11 with probabilities set by the amplitudes. Physically a qubit can be the spin of an electron (/\uparrow/\downarrow), the polarization of a photon (H/V), two energy levels of an atom or a superconducting circuit (Term 4.4), and more. What makes all of them "qubits" is shared mathematics: the state space is C2\mathbb{C}^2, and the rules are the four postulates of Course 1.1.


Theory

The qubit state

By Postulate 1 (1.1.1), a qubit's state is a unit vector in C2\mathbb{C}^2:

ψ=α0+β1,α,βC,α2+β2=1, \lvert\psi\rangle = \alpha\lvert0\rangle + \beta\lvert1\rangle, \qquad \alpha,\beta\in\mathbb{C}, \qquad |\alpha|^2 + |\beta|^2 = 1,

with the computational basis \lvert0\rangle = \begin{psmallmatrix}1\\0\end{psmallmatrix}, \lvert1\rangle = \begin{psmallmatrix}0\\1\end{psmallmatrix}. The amplitudes α,β\alpha,\beta are complex; their magnitudes give probabilities and their relative phase encodes interference (1.1.1).

Born rule for a qubit

Measuring in the computational basis (ZZ observable, 1.1.2):

p(0)=0ψ2=α2,p(1)=1ψ2=β2,p(0)+p(1)=1. p(0) = |\langle0|\psi\rangle|^2 = |\alpha|^2, \qquad p(1) = |\langle1|\psi\rangle|^2 = |\beta|^2, \qquad p(0)+p(1)=1.

A result of 00 collapses the state to 0\lvert0\rangle; a result of 11 to 1\lvert1\rangle.

Superposition and the Hadamard

The most important single-qubit operation for creating superposition is the Hadamard gate H = \tfrac1{\sqrt2}\begin{psmallmatrix}1&1\\1&-1\end{psmallmatrix} (Appendix E):

H0=12(0+1)=+,H1=12(01)=. H\lvert0\rangle = \tfrac1{\sqrt2}(\lvert0\rangle + \lvert1\rangle) = \lvert+\rangle, \qquad H\lvert1\rangle = \tfrac1{\sqrt2}(\lvert0\rangle - \lvert1\rangle) = \lvert-\rangle.

Starting from the definite state 0\lvert0\rangle, one HH produces an equal superposition: measuring it in the computational basis gives 00 or 11 with probability 12\tfrac12 each. This is the "fair quantum coin," and it's the natural first circuit to run. (Gates get the full treatment in Term 2; here we use HH as our entry point.)


Worked Examples

Example 1 — Probabilities of a general qubit

For ψ=130+23eiπ/41\lvert\psi\rangle = \tfrac1{\sqrt3}\lvert0\rangle + \sqrt{\tfrac23}\,e^{i\pi/4}\lvert1\rangle: p(0)=1/32=1/3p(0) = |1/\sqrt3|^2 = 1/3 and p(1)=2/3eiπ/42=2/3p(1) = |\sqrt{2/3}\,e^{i\pi/4}|^2 = 2/3 (the phase eiπ/4e^{i\pi/4} does not affect the magnitude). Sum =1= 1. ✓ The phase would matter if we measured in the XX or YY basis (1.2.3).

Example 2 — The Hadamard "coin"

Apply HH to 0\lvert0\rangle: +=12(0+1)\lvert+\rangle = \tfrac1{\sqrt2}(\lvert0\rangle+\lvert1\rangle), so a ZZ-measurement gives 00 and 11 each with probability 12\tfrac12. Apply a second HH: since H2=IH^2 = I, HH0=0HH\lvert0\rangle = \lvert0\rangle — measuring now gives 00 with certainty. Two "random" coin flips compose to a deterministic result: interference, not classical randomness. We'll see this directly on the simulator below.


Hands-on (Python)

First, in NumPy

import numpy as np

ket0 = np.array([1, 0], dtype=complex)
ket1 = np.array([0, 1], dtype=complex)
H = np.array([[1, 1], [1, -1]], dtype=complex) / np.sqrt(2)

plus = H @ ket0                                  # |+>
print(np.round(plus, 4))                         # [0.7071 0.7071]
print(np.abs(plus)**2)                           # [0.5 0.5]  Born probabilities

print(np.allclose(H @ (H @ ket0), ket0))         # True: HH = I (interference -> back to |0>)

Now on AWS Braket (local simulator — free) ⚙️

This is your first Braket circuit. It runs entirely on your machine via LocalSimulatorno AWS account, no cost (see Appendix A). Three concepts: a Circuit holds gates; LocalSimulator executes it; shots is how many times we sample the measurement.

# the_qubit.py — free, local, no AWS account needed.
from braket.circuits import Circuit
from braket.devices import LocalSimulator

# Build a one-qubit circuit: H on qubit 0 prepares |+>.
circ = Circuit().h(0)
print(circ)                                      # ASCII circuit diagram

# Run it. Braket measures all qubits in the computational (Z) basis by default.
device = LocalSimulator()                        # default backend: state-vector ("braket_sv")
result = device.run(circ, shots=1000).result()
print(result.measurement_counts)                 # ~ Counter({'0': ~500, '1': ~500})
T  : |0|
q0 : -H-

Counter({'0': 508, '1': 492})

The counts are samples from the Born distribution p(0)=p(1)=12p(0)=p(1)=\tfrac12 — finite-shot estimates with the 1/M1/\sqrt{M} error from 0.2.2. Now confirm the interference of Example 2 — two Hadamards return a definite 00:

circ2 = Circuit().h(0).h(0)                      # H then H = identity on |0>
counts = LocalSimulator().run(circ2, shots=1000).result().measurement_counts
print(counts)                                    # Counter({'0': 1000}) — always 0

If you also want the exact amplitudes (simulator-only superpower; real hardware never gives these), add a state-vector result type:

circ3 = Circuit().h(0)
circ3.state_vector()                             # request the full amplitude vector
sv = LocalSimulator().run(circ3, shots=0).result().values[0]
print(np.round(sv, 4))                           # [0.7071+0.j 0.7071+0.j] = |+>

⚠️ Cost reminder. LocalSimulator is free. The on-demand simulators (SV1/DM1/TN1) and QPUs are billed — we don't touch them until Term 5, and never automatically. Everything in Terms 1–4 runs locally.


Exercises

E1 (easy). For ψ=0.20+0.81\lvert\psi\rangle = \sqrt{0.2}\,\lvert0\rangle + \sqrt{0.8}\,\lvert1\rangle, give the ZZ-measurement probabilities and predict the approximate counts for 1000 shots.

Solution

p(0)=0.2p(0)=0.2, p(1)=0.8p(1)=0.8. Over 1000 shots expect ≈ 200 '0' and ≈ 800 '1', with statistical spread 10000.20.813\sim\sqrt{1000\cdot0.2\cdot0.8}\approx 13 counts.

E2 (easy). Write the Braket circuit that prepares 1\lvert1\rangle from the default 0\lvert0\rangle, and predict its measurement counts.

Solution

Circuit().x(0) (Pauli-XX = NOT flips 01\lvert0\rangle\to\lvert1\rangle). Counts: all '1' (Counter({'1': 1000})), since the state is the definite 1\lvert1\rangle.

E3 (medium). Using only NumPy, verify that applying HH to 1\lvert1\rangle gives \lvert-\rangle and that its ZZ-measurement probabilities are also 12,12\tfrac12,\tfrac12. Why do +\lvert+\rangle and \lvert-\rangle give identical computational-basis statistics despite being different states?

Solution

H1=12(01)=H\lvert1\rangle = \tfrac1{\sqrt2}(\lvert0\rangle-\lvert1\rangle)=\lvert-\rangle; ±1/22=12|{\pm}1/\sqrt2|^2=\tfrac12 each. They share ZZ-statistics because those depend only on amplitude magnitudes; the distinguishing relative phase (++ vs -) only shows up in a different basis (e.g. XX), where +0\lvert+\rangle\to0 and 1\lvert-\rangle\to1 with certainty — see 1.2.3.

E4 (medium). Run (or simulate by hand) Circuit().h(0).h(0).h(0) on 0\lvert0\rangle. What are the output statistics and why?

Solution

Three Hadamards: H3=H2H=IH=HH^3 = H^2\cdot H = I\cdot H = H, so the state is +\lvert+\rangle and the counts are ≈ 50/50. An odd number of HH's acts like a single HH; an even number like the identity.

E5 (hard). A state ψ=cosθ20+sinθ21\lvert\psi\rangle = \cos\tfrac\theta2\lvert0\rangle + \sin\tfrac\theta2\lvert1\rangle (real amplitudes). You run many shots and observe p(1)0.15p(1) \approx 0.15. Estimate θ\theta, and state how many shots you'd need to pin p(1)p(1) to within ±0.01\pm0.01 at 95% confidence.

Solution

p(1)=sin2(θ/2)=0.15sin(θ/2)=0.150.387θ/20.398θ0.80p(1) = \sin^2(\theta/2) = 0.15 \Rightarrow \sin(\theta/2) = \sqrt{0.15}\approx0.387 \Rightarrow \theta/2\approx0.398 \Rightarrow \theta\approx0.80 rad (46°\approx46°). For a ±ε\pm\varepsilon estimate of a probability at 95% confidence, Hoeffding gives M12ε2ln2δM \ge \frac{1}{2\varepsilon^2}\ln\frac{2}{\delta} with ε=0.01\varepsilon=0.01, δ=0.05\delta=0.05: M12(0.01)2ln(40)ln402×1041.84×104M \ge \frac{1}{2(0.01)^2}\ln(40) \approx \frac{\ln 40}{2\times10^{-4}}\approx 1.84\times10^4 shots (from 0.2.2).


Checkpoint

  1. What is a qubit, and what is its state space? Name two physical realizations.
  2. Write a general qubit state and its computational-basis measurement probabilities.
  3. What does a single Hadamard do to 0\lvert0\rangle, and what do two do? Why?
  4. In the Braket code, what are Circuit, LocalSimulator, shots, and measurement_counts?
  5. Why are local-simulator runs free, and which Braket resources are not?
Answers
  1. A two-level quantum system; state space C2\mathbb{C}^2. Realizations: electron spin, photon polarization, atomic/superconducting energy levels (any two).
  2. ψ=α0+β1\lvert\psi\rangle=\alpha\lvert0\rangle+\beta\lvert1\rangle with α2+β2=1|\alpha|^2+|\beta|^2=1; p(0)=α2p(0)=|\alpha|^2, p(1)=β2p(1)=|\beta|^2.
  3. One HH: 0+\lvert0\rangle\to\lvert+\rangle (equal superposition). Two: H2=IH^2=I returns 0\lvert0\rangle — interference, not random.
  4. Circuit is the gate sequence; LocalSimulator runs it on your machine; shots = number of measurement samples; measurement_counts is the histogram of outcome bit-strings.
  5. LocalSimulator runs on your own CPU (no AWS service invoked); on-demand simulators (SV1/DM1/TN1) and QPUs are billed cloud resources (Term 5).

Further Reading

  • [NC] Nielsen & Chuang, §1.2, §2.2 — the qubit and superposition.
  • [Mer] Mermin, Quantum Computer Science, Ch. 1 — qubits for computer scientists.
  • [SDK] amazon-braket-sdk-python README & examples — the Circuit / LocalSimulator API.

← Prev: 1.1.4 Composite Systems Postulate · Up: Term 1 · Next: The Bloch Sphere

Ready to measure your state?

5 exercises · 10 checkpoint questions

Start the quiz