Bases & Expectation Values

4 hours ~5 min read first Braket code

Bases & Expectation Values

A measurement is always made in a basis. The computational (ZZ) basis is just one choice; the XX and YY bases ask different questions of the same qubit, and the relative phase that ZZ can't see becomes a definite answer in XX or YY. This lesson makes "measure in a basis" precise, ties the three Pauli bases to the three Bloch axes, and shows the one trick real hardware needs — rotate the basis you care about onto ZZ, then measure — with runnable Braket code on the free local simulator.

Learning Objectives

After this lesson you will be able to:

  1. Write the eigenbases of XX, YY, ZZ and the Born rule for a measurement in any orthonormal basis.
  2. Reduce a measurement in an arbitrary basis to a basis-change unitary followed by a computational-basis readout.
  3. Compute an expectation value A\langle A\rangle from outcome probabilities, and recognize X,Y,Z\langle X\rangle,\langle Y\rangle,\langle Z\rangle as the Bloch coordinates.
  4. Build Braket circuits that measure a qubit in the XX, YY, and ZZ bases and estimate σk\langle\sigma_k\rangle from shot counts.
  5. Relate the finite-shot error of an estimate to the variance of a ±1\pm1 observable.

Intuition

In 1.2.1 we only ever measured in the computational basis — the question "are you 0\lvert0\rangle or 1\lvert1\rangle?" But +\lvert+\rangle and \lvert-\rangle give identical ZZ-statistics (50/5050/50) despite being different states; their distinguishing relative phase is invisible to ZZ. Ask a different question — "are you +\lvert+\rangle or \lvert-\rangle?", the XX-basis measurement — and the two states separate perfectly. Each Pauli observable corresponds to one of the three Bloch axes (1.2.2); measuring it projects the Bloch vector onto that axis. Real devices only ever measure along ZZ, so to ask an XX or YY question we first rotate that axis onto ZZ with a gate, then read out. The averaged answer over many shots is the expectation value, and the three expectation values are exactly the coordinates of the Bloch vector.


Theory

The three Pauli bases

Each Pauli operator is Hermitian with eigenvalues ±1\pm1; its two eigenvectors form an orthonormal basis of C2\mathbb{C}^2 (1.1.2, Appendix E):

Observable Eigenvalue +1+1 Eigenvalue 1-1 Bloch axis
ZZ 0\lvert0\rangle 1\lvert1\rangle ±z\pm z
XX +=12(0+1)\lvert+\rangle = \tfrac1{\sqrt2}(\lvert0\rangle+\lvert1\rangle) =12(01)\lvert-\rangle = \tfrac1{\sqrt2}(\lvert0\rangle-\lvert1\rangle) ±x\pm x
YY +i=12(0+i1)\lvert{+}i\rangle = \tfrac1{\sqrt2}(\lvert0\rangle+i\lvert1\rangle) i=12(0i1)\lvert{-}i\rangle = \tfrac1{\sqrt2}(\lvert0\rangle-i\lvert1\rangle) ±y\pm y

These are the three "natural" bases of a single qubit, mutually unbiased: a state definite in one basis is maximally uncertain in the other two (e.g. 0\lvert0\rangle gives 50/5050/50 in both XX and YY).

The Born rule in an arbitrary basis

Let {b0,b1}\{\lvert b_0\rangle, \lvert b_1\rangle\} be any orthonormal basis. Measuring ψ\lvert\psi\rangle in that basis yields outcome bkb_k with probability (1.1.2)

p(bk)=bkψ2,kp(bk)=1, p(b_k) = |\langle b_k\lvert\psi\rangle|^2, \qquad \sum_k p(b_k) = 1,

and collapses the state to bk\lvert b_k\rangle. For the XX basis, p(+)=+ψ2p(+) = |\langle+\lvert\psi\rangle|^2 and p()=ψ2p(-) = |\langle-\lvert\psi\rangle|^2; for YY, replace ±\lvert\pm\rangle by ±i\lvert\pm i\rangle.

Measurement as a basis change onto ZZ

Hardware measures one fixed basis (the computational ZZ basis). To measure an observable A=kλkbkbkA = \sum_k \lambda_k \lvert b_k\rangle\langle b_k\lvert, collect its eigenvectors as the columns of a unitary U=[b0  b1]U = \big[\,\lvert b_0\rangle\ \ \lvert b_1\rangle\,\big], so that U0=b0U\lvert0\rangle = \lvert b_0\rangle. Then UU^\dagger rotates the eigenbasis onto the computational basis, and

p(bk)=bkψ2=kUψ2: p(b_k) = |\langle b_k\lvert\psi\rangle|^2 = |\langle k\lvert U^\dagger\lvert\psi\rangle|^2 :

measuring AA on ψ\lvert\psi\rangle = applying UU^\dagger, then a computational-basis measurement. For the Pauli bases this needs just one or two gates:

measure Znothing,measure Xapply H,measure Yapply S then H. \underbrace{\text{measure }Z}_{\text{nothing}},\qquad \underbrace{\text{measure }X}_{\text{apply }H},\qquad \underbrace{\text{measure }Y}_{\text{apply }S^\dagger\text{ then }H}.

Indeed H+=0H\lvert+\rangle=\lvert0\rangle, H=1H\lvert-\rangle=\lvert1\rangle (so H=HH = H^\dagger rotates the XX-basis onto ZZ); and HS+i=0HS^\dagger\lvert{+}i\rangle = \lvert0\rangle, HSi=1HS^\dagger\lvert{-}i\rangle=\lvert1\rangle with S=diag(1,i)S^\dagger = \operatorname{diag}(1,-i) (derived in Exercise E3). After the rotation, computational outcome 00 corresponds to eigenvalue +1+1 and outcome 11 to 1-1.

The expectation value of AA is the mean eigenvalue over many measurements (1.1.2):

A=ψAψ=kλkp(bk). \langle A\rangle = \langle\psi\lvert A\lvert\psi\rangle = \sum_k \lambda_k\,p(b_k).

For a ±1\pm1-valued observable (any Pauli) this collapses to a difference of two probabilities,

 σ=p+p=12p  \boxed{\ \langle\sigma\rangle = p_{+} - p_{-} = 1 - 2\,p_{-}\ }

so an estimate is immediate from shot counts: σ(N+N)/N\langle\sigma\rangle \approx (N_{+} - N_{-})/N. Computing all three Pauli expectation values reconstructs the Bloch vector of 1.2.2:

r=(X, Y, Z),Z=cosθ,  X=sinθcosφ,  Y=sinθsinφ. \vec r = \big(\langle X\rangle,\ \langle Y\rangle,\ \langle Z\rangle\big), \qquad \langle Z\rangle = \cos\theta,\ \ \langle X\rangle = \sin\theta\cos\varphi,\ \ \langle Y\rangle = \sin\theta\sin\varphi .

So the abstract "measure three observables" is the concrete "find the point on the sphere."


Worked Examples

Example 1 — +\lvert+\rangle in all three bases

For +\lvert+\rangle: in ZZ, p(0)=p(1)=12p(0)=p(1)=\tfrac12 so Z=0\langle Z\rangle = 0. In XX, +\lvert+\rangle is the +1+1 eigenstate, so p(+)=1p(+)=1 deterministically and X=1\langle X\rangle = 1. In YY, +i+2=12|\langle{+}i\lvert+\rangle|^2 = \tfrac12, so Y=0\langle Y\rangle = 0. The Bloch vector is (X,Y,Z)=(1,0,0)(\langle X\rangle,\langle Y\rangle,\langle Z\rangle) = (1,0,0) — the +x+x axis, exactly as 1.2.2 predicted. Only the XX measurement "sees" the relative phase that distinguishes +\lvert+\rangle from \lvert-\rangle.

Example 2 — Expectation values of a tilted real state

Take ψ=cosπ60+sinπ61\lvert\psi\rangle = \cos\tfrac\pi6\lvert0\rangle + \sin\tfrac\pi6\lvert1\rangle (real amplitudes, φ=0\varphi=0, θ=π3\theta=\tfrac\pi3). Then Z=cos2π6sin2π6=cosπ3=12\langle Z\rangle = \cos^2\tfrac\pi6 - \sin^2\tfrac\pi6 = \cos\tfrac\pi3 = \tfrac12, X=2cosπ6sinπ6=sinπ3=32\langle X\rangle = 2\cos\tfrac\pi6\sin\tfrac\pi6 = \sin\tfrac\pi3 = \tfrac{\sqrt3}2, and Y=0\langle Y\rangle = 0 (real amplitudes never tilt toward ±y\pm y). Bloch vector (32,0,12)\big(\tfrac{\sqrt3}2, 0, \tfrac12\big), with r=1|\vec r| = 1 as required for a pure state.


Hands-on (Python)

Exact, in NumPy

import numpy as np

ket0 = np.array([1, 0], dtype=complex)
ket1 = np.array([0, 1], dtype=complex)
X = np.array([[0, 1], [1, 0]], dtype=complex)
Y = np.array([[0, -1j], [1j, 0]], dtype=complex)
Z = np.array([[1, 0], [0, -1]], dtype=complex)

def expect(A, psi):
    """Exact expectation <psi|A|psi> (real for Hermitian A)."""
    return np.real(psi.conj() @ A @ psi)

plus = (ket0 + ket1) / np.sqrt(2)                       # |+>
print(np.round([expect(A, plus) for A in (X, Y, Z)], 6))  # [1. 0. 0.] -> Bloch +x

# Born probabilities in the X basis come from <+|psi>, <-|psi>:
minus = (ket0 - ket1) / np.sqrt(2)
psi = np.cos(np.pi/6)*ket0 + np.sin(np.pi/6)*ket1       # Worked Example 2
print(round(abs(np.vdot(plus, psi))**2, 6),             # 0.933013  = p(+) in X basis
      round(abs(np.vdot(minus, psi))**2, 6))            # 0.066987  = p(-) in X basis
print(np.round([expect(A, psi) for A in (X, Y, Z)], 6))   # [0.866025 0. 0.5]

Estimating σ\langle\sigma\rangle on Braket (local simulator — free) ⚙️

Braket always measures in the computational (ZZ) basis, so we rotate the axis we want onto ZZ before measuring — H for XX, S† then H (.si(0).h(0)) for YY, nothing for ZZ — then read σ(N0N1)/N\langle\sigma\rangle \approx (N_0 - N_1)/N from the counts. (The deeper Braket result-type API arrives in Term 2.1; here we sample, as in 1.3.1.)

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

device = LocalSimulator()                                # free local state-vector simulator

def estimate_pauli(prep, basis, shots=20000):
    """Estimate <sigma> on the state prepared by `prep` (a function adding gates)."""
    c = Circuit()
    prep(c)                                              # state preparation
    if basis == "X":
        c.h(0)                                           # rotate X-basis onto Z
    elif basis == "Y":
        c.si(0).h(0)                                     # rotate Y-basis onto Z (S† then H)
    # basis == "Z": measure directly
    counts = device.run(c, shots=shots).result().measurement_counts
    n0, n1 = counts.get("0", 0), counts.get("1", 0)
    return (n0 - n1) / (n0 + n1)                          # <sigma> = p(+) - p(-)

prep_plus = lambda c: c.h(0)                              # |+> = H|0>
print("Estimated <X>,<Y>,<Z> on |+>:",
      [round(estimate_pauli(prep_plus, b), 3) for b in ("X", "Y", "Z")])
# ≈ [1.0, 0.0, 0.0]  -> the +x axis, matching the exact NumPy result

Why ±1 estimates are cheap. A Pauli outcome is ±1\pm1 with variance Var(σ)=1σ21\operatorname{Var}(\sigma) = 1 - \langle\sigma\rangle^2 \le 1 (0.2.2), so the standard error of (N0N1)/N(N_0-N_1)/N is 1/N\le 1/\sqrt N. With 20,00020{,}000 shots, X\langle X\rangle on +\lvert+\rangle lands within 0.007\sim0.007 of 11 essentially every run.


Exercises

E1 (easy). For 1\lvert1\rangle, give the XX-basis probabilities and X\langle X\rangle. Which Bloch axis is this?

Solution

+1=12\langle+\lvert1\rangle = \tfrac1{\sqrt2}, 1=12\langle-\lvert1\rangle = -\tfrac1{\sqrt2}, so p(+)=p()=12p(+)=p(-)=\tfrac12 and X=0\langle X\rangle = 0. Likewise Y=0\langle Y\rangle=0, while Z=1\langle Z\rangle=-1: the z-z axis, the south pole. ∎

E2 (easy). Which single Pauli basis perfectly distinguishes +\lvert+\rangle from \lvert-\rangle, and which one cannot tell them apart at all?

Solution

The XX basis distinguishes them with certainty (++1\lvert+\rangle\to+1, 1\lvert-\rangle\to-1). The ZZ basis cannot: both give 50/5050/50. (YY also gives 50/5050/50 for each.) The distinguishing information is the relative phase, visible only along ±x\pm x. ∎

E3 (medium). Show that U=HSU^\dagger = H S^\dagger rotates the YY eigenbasis onto the computational basis, i.e. HS+i=0HS^\dagger\lvert{+}i\rangle = \lvert0\rangle and HSi=1HS^\dagger\lvert{-}i\rangle = \lvert1\rangle.

Solution

S=diag(1,i)S^\dagger = \operatorname{diag}(1,-i). Then $S^\dagger\lvert{+}i\rangle = \tfrac1{\sqrt2}(\lvert0\rangle + (-i)(i)\lvert1\rangle) = \tfrac1{\sqrt2}(\lvert0\rangle+\lvert1\rangle) = \lvert+\rangle,and, and H\lvert+\rangle=\lvert0\rangle$. Similarly Si=12(01)=S^\dagger\lvert{-}i\rangle = \tfrac1{\sqrt2}(\lvert0\rangle-\lvert1\rangle)=\lvert-\rangle and H=1H\lvert-\rangle=\lvert1\rangle. So in a circuit, .si(0).h(0) (apply SS^\dagger, then HH) implements U=HSU^\dagger = HS^\dagger. ∎

E4 (medium). A qubit is measured and reports X=0\langle X\rangle = 0, Y=0\langle Y\rangle = 0, Z=1\langle Z\rangle = 1. What is the state? What if instead (X,Y,Z)=(0,1,0)(\langle X\rangle,\langle Y\rangle,\langle Z\rangle) = (0, -1, 0)?

Solution

The Bloch vector is r=(X,Y,Z)\vec r = (\langle X\rangle,\langle Y\rangle,\langle Z\rangle). First case: (0,0,1)(0,0,1) = north pole = 0\lvert0\rangle. Second case: (0,1,0)(0,-1,0) = y-y axis = i=12(0i1)\lvert{-}i\rangle = \tfrac1{\sqrt2}(\lvert0\rangle-i\lvert1\rangle). For a pure state r=1|\vec r|=1, so the three expectation values fix the state up to global phase. ∎

E5 (hard). You want to estimate Z\langle Z\rangle of a state with true value Z=0.6\langle Z\rangle = 0.6 to within ±0.01\pm0.01 at 95%95\% confidence. About how many shots are needed?

Solution

A ZZ outcome is ±1\pm1 with Var(Z)=1Z2=10.36=0.64\operatorname{Var}(Z) = 1 - \langle Z\rangle^2 = 1-0.36 = 0.64. The estimator (N0N1)/N(N_0-N_1)/N has standard error Var/N=0.64/N\sqrt{\operatorname{Var}/N} = \sqrt{0.64/N}. For a ±0.01\pm0.01 half-width at 95%95\% (z1.96z\approx1.96): 1.960.64/N0.01N1.9620.64/0.0122.46×1041.96\sqrt{0.64/N} \le 0.01 \Rightarrow N \ge 1.96^2\cdot0.64/0.01^2 \approx 2.46\times10^4 shots (from 0.2.2). Note the worst case is Z=0\langle Z\rangle=0 (variance 11), needing 3.84×104\sim3.84\times10^4. ∎


Checkpoint

  1. Write the eigenstates of XX, YY, ZZ and the Bloch axis each basis measures.
  2. State the Born rule for a measurement in an arbitrary orthonormal basis.
  3. How do you measure XX (and YY) on hardware that only measures ZZ?
  4. Give the formula for σ\langle\sigma\rangle in terms of the two outcome probabilities, and connect (X,Y,Z)(\langle X\rangle,\langle Y\rangle,\langle Z\rangle) to the Bloch sphere.
  5. Why is the standard error of a Pauli expectation estimate at most 1/N1/\sqrt N?
Answers
  1. ZZ: 0,1\lvert0\rangle,\lvert1\rangle (±z\pm z); XX: ±\lvert\pm\rangle (±x\pm x); YY: ±i\lvert\pm i\rangle (±y\pm y).
  2. p(bk)=bkψ2p(b_k) = |\langle b_k\lvert\psi\rangle|^2; outcome bkb_k collapses the state to bk\lvert b_k\rangle.
  3. Rotate the target eigenbasis onto ZZ first: apply HH to measure XX, apply SS^\dagger then HH to measure YY, then read out in the computational basis.
  4. σ=p+p\langle\sigma\rangle = p_+ - p_-; the three Pauli expectation values are the Cartesian coordinates of the Bloch vector r\vec r.
  5. A ±1\pm1 observable has variance 1σ211-\langle\sigma\rangle^2\le1, so the mean's standard error is Var/N1/N\sqrt{\operatorname{Var}/N}\le1/\sqrt N.

Further Reading

  • [NC] Nielsen & Chuang, §2.2.3–2.2.5 — measurement, observables, and changing measurement basis.
  • [Pre] Preskill, Ph219, Ch. 2 — qubit observables and mutually unbiased bases.
  • [SDK] amazon-braket-sdk-python — the Circuit gate set (h, s, si) and measurement_counts.

← Prev: The Bloch Sphere · Up: Term 1 · Next: Projective Measurement

Ready to measure your state?

5 exercises · 10 checkpoint questions

Start the quiz