Quantum Measurement Basis Explained with Python

A quantum measurement basis is the set of directions you choose when you measure a qubit. Previous post showed that a qubit’s state is a point on the Bloch sphere. This post shows what a measurement does to that point, and why the direction you measure in changes the answer. This idea is the heart of BB84. No quantum background is needed, and every new term is defined the first time it appears.

Measurement: asking a question with a chosen direction

A measurement is a physical test with a fixed set of possible answers. The setup of the test defines the question. A polarizer asks “is the photon horizontal or vertical?” Turning the polarizer asks a different question.

The set of answers for one setup is called a basis. A basis is a pair of states that sit opposite each other on the Bloch sphere. Three bases matter here:

  • Z basis (also called rectilinear): $|0\rangle$ and $|1\rangle$, the north and south poles.
  • X basis (also called diagonal): $|+\rangle$ and $|-\rangle$, the $+x$ and $-x$ points.
  • Y basis (also called circular): $|+i\rangle$ and $|-i\rangle$, the $+y$ and $-y$ points.

A measurement in one basis always returns one of its two states. Which one is random, with odds set by the state being measured.

Overlap: how close is the state to each answer?

To find the odds, compare the state with each answer. The comparison is called the inner product, or overlap. In bra-ket notation it is written $\langle e|\psi\rangle$. The symbol $\langle e|$ is a bra: the conjugate of the ket $|e\rangle$, meaning every imaginary part has its sign flipped, written as a row. The overlap is a complex number, and its squared size gives the probability:

$$P(e) = \left|\langle e|\psi\rangle\right|^2$$

This is the Born rule from posts 1 and 2. Think of the overlap as a shadow: how much of the state arrow lies along the answer arrow. Malus law in post 1 is this same shadow calculation with real numbers.

Two examples:

  • $|0\rangle$ measured in the Z basis: $P(0) = |\langle 0|0\rangle|^2 = 1$. The answer is certain.
  • $|0\rangle$ measured in the X basis: $\langle +|0\rangle = 1/\sqrt{2}$, so $P(+) = 1/2$. The answer is a coin toss.

On the Bloch sphere the rule has a simple form. For a measurement along a unit direction $\hat{n}$, with the state’s Bloch vector $\vec{r}$:

$$P(\text{outcome along } \hat{n}) = \frac{1 + \vec{r}\cdot\hat{n}}{2}$$

Here $\vec{r}\cdot\hat{n}$ is the cosine of the angle between the state and the measurement direction. The formula takes that cosine from $-1$ to $1$ and rescales it to a probability from $0$ to $1$.

Measuring along an axis: the state's projections onto z and x give the probabilities
Figure 1: For the state at 60 degrees from the north pole, the Z measurement gives $P(0) = 0.75$ and the X measurement gives $P(+) = 0.93$. Each probability is a projection onto the measurement axis.

Collapse: the measurement changes the state

After a measurement, the qubit is in the basis state it was found in. This is called collapse, or projection. The standard textbook picture is:

  1. Start with $|+\rangle$. Measure in the Z basis. The result is 0 or 1, each with probability 1/2.
  2. The qubit is now $|0\rangle$ (if the result was 0) or $|1\rangle$ (if the result was 1).
  3. Measure again in the Z basis. The answer is the same as before, every time.
  4. Measure in the X basis instead. The odds are back to 50/50, and the earlier Z result is gone.

Post 1 used the same idea: a photon that passes a polarizer points along its slats afterward. The first measurement set the state, and that state is what the next measurement sees.

Same state, three bases: the probability of the first outcome in each basis

Figure 2: For each state, the chance of the first outcome in each basis. The same state gives 1.00, 0.50, or 0.00 depending on the basis.

A wrong basis gives random answers, not wrong ones

The state $|0\rangle$ is perfectly definite in the Z basis. In the X basis it is a coin toss. Measuring in the “wrong” basis does not reveal a wrong value; it gives a random value. This is what BB84 relies on: when the sender and receiver pick different bases, the receiver’s results are random and they discard them. When they pick the same basis, the results agree.

Malus law is a measurement basis

A polarizer at angle $\beta$ is a measurement in a basis with states

$$\cos\beta\,|H\rangle + \sin\beta\,|V\rangle \quad \text{and} \quad -\sin\beta\,|H\rangle + \cos\beta\,|V\rangle$$

Here $|H\rangle$ and $|V\rangle$ are horizontal and vertical. A photon polarized at angle $\alpha$ passes the first answer with probability $\cos^2(\alpha – \beta)$. That is Malus law from post 1, now written as a measurement.

Python: bases, collapse, and the Bloch rule

This code builds the three bases, computes the odds, simulates collapse, checks the Bloch rule, and reproduces Malus law as a measurement.

import numpy as np

KET_0 = np.array([1, 0], dtype=complex)                    # |0>, horizontal
KET_1 = np.array([0, 1], dtype=complex)                    # |1>, vertical
KET_PLUS = (KET_0 + KET_1) / np.sqrt(2)                    # |+>, 45 degrees
KET_MINUS = (KET_0 - KET_1) / np.sqrt(2)                   # |->, -45 degrees
KET_PLUS_I = (KET_0 + 1j * KET_1) / np.sqrt(2)             # |+i>
KET_MINUS_I = (KET_0 - 1j * KET_1) / np.sqrt(2)            # |-i>

BASIS_Z = (KET_0, KET_1)                                   # rectilinear basis
BASIS_X = (KET_PLUS, KET_MINUS)                            # diagonal basis
BASIS_Y = (KET_PLUS_I, KET_MINUS_I)                        # circular basis

def measure_probabilities(state, basis):
    """Probability of each basis outcome: the squared overlap |<e|psi>|^2."""
    return np.array([np.abs(np.vdot(e, state)) ** 2 for e in basis])

def measure(state, basis, rng):
    """Simulate one measurement. Returns the outcome index and the collapsed state."""
    p = measure_probabilities(state, basis)
    outcome = rng.choice(len(basis), p=p / p.sum())
    return outcome, basis[outcome]

rng = np.random.default_rng(5)

# Same state, two different measurement bases
print("|0> in Z basis:", measure_probabilities(KET_0, BASIS_Z).round(3))
print("|0> in X basis:", measure_probabilities(KET_0, BASIS_X).round(3))

# Collapse: measure |+> in Z, then measure again in Z
repeat_same = 0
trials = 1000
for _ in range(trials):
    first, after = measure(KET_PLUS, BASIS_Z, rng)
    second, _ = measure(after, BASIS_Z, rng)
    repeat_same += (first == second)
print("Z measured twice on |+>, same answer:", repeat_same / trials)

# Frequencies: 10,000 measurements of |0> in the X basis
outcomes = [measure(KET_0, BASIS_X, rng)[0] for _ in range(10_000)]
print("fraction of |+> outcomes for |0> in X:", round(1 - np.mean(outcomes), 3))

# Bloch rule: probability of the +n outcome = (1 + r . n) / 2
def bloch_vector(state):
    a, b = state
    return np.array([2 * np.real(np.conj(a) * b),
                     2 * np.imag(np.conj(a) * b),
                     np.abs(a) ** 2 - np.abs(b) ** 2])

r = bloch_vector(KET_PLUS)                 # |+> points along +x
n_x = np.array([1.0, 0.0, 0.0])
print("Bloch rule for |+> along x:", ((1 + r @ n_x) / 2).round(3))

# Polarizer = measurement basis: photon at alpha, analyzer at beta
alpha, beta = np.deg2rad(20), np.deg2rad(50)
photon = np.cos(alpha) * KET_0 + np.sin(alpha) * KET_1
analyzer_pass = np.cos(beta) * KET_0 + np.sin(beta) * KET_1
print("photon at 20, analyzer at 50, P(pass):",
      np.round(np.abs(np.vdot(analyzer_pass, photon)) ** 2, 3))
print("cos^2(30 deg):", round(np.cos(np.deg2rad(30)) ** 2, 3))

Running it prints:

|0> in Z basis: [1. 0.]
|0> in X basis: [0.5 0.5]
Z measured twice on |+>, same answer: 1.0
fraction of |+> outcomes for |0> in X: 0.498
Bloch rule for |+> along x: 1.0
photon at 20, analyzer at 50, P(pass): 0.75
cos^2(30 deg): 0.75

The Z results match the theory: $|0\rangle$ is certain in the Z basis and 50/50 in the X basis. The repeated Z measurement agrees every time, which is collapse. The polarizer result matches Malus law.

Three common misunderstandings

  • “Measuring does nothing to the state.” It does. After a measurement the state is the basis state you found.
  • “A wrong basis gives a wrong answer.” It gives a random answer. Nothing is wrong, the question is just different.
  • “One measurement tells you the full state.” One measurement gives one bit in one direction. Learning the full state takes many copies measured in several bases.

What comes next

Post 4 adds noise. A real channel flips some bits, and the rate of those flips is the quantum bit error rate (QBER). Post 5 then puts the pieces together: random bases, random bits, and QBER, which is the BB84 protocol.

Summary

  • A measurement is a question with two answers, called a basis. The Z, X and Y bases are the standard examples.
  • The probability of an answer is the squared overlap between the state and that answer.
  • On the Bloch sphere, the probability along a direction is $(1 + \vec{r}\cdot\hat{n})/2$.
  • Measuring collapses the state onto the answer you got, and later measurements in the same basis agree.
  • A polarizer is a measurement basis, and its odds are Malus law.

Learning path: Quantum basics for engineers

  1. Malus law and polarization
  2. Qubits and the Bloch sphere
  3. Measurement and basis choice
  4. Quantum bit error rate
  5. The BB84 protocol
  6. BB84 simulation with an eavesdropper

References


Classical communication math behind this series. Projections, inner products and error probabilities are the same tools used in digital communications and signal detection. The GaussianWaves eBooks cover that classical side with runnable Python and Matlab code.

Browse all GaussianWaves eBooks and products

Leave a Comment