Skip to main content
KetQat

Appearance

Lesson 240 min

Qubits and the Bloch sphere

The single-qubit state space, global phase, and its picture as a sphere.

After this lesson you can

  • Count the real parameters of a qubit state and explain why global phase removes one
  • Write any pure qubit state in the Bloch form with angles theta and phi
  • Compute a Bloch vector from amplitudes as the expectation values of X, Y and Z
  • Use the overlap formula (1 + r·s)/2 to show that orthogonal states are antipodal points
  • Recognise that mixtures of states correspond to points inside the sphere, and why they differ from superpositions

Read first: Complex numbers and amplitudes

How many numbers describe a qubit?

A qubit state is a unit vector ∣ψ⟩=α∣0⟩+β∣1⟩\ket\psi = \alpha\ket0 + \beta\ket1 in C2\C^2. Two complex numbers are four real numbers. The previous lesson removed two of them:

  1. Normalisation, ∣α∣2+∣β∣2=1\abs\alpha^2 + \abs\beta^2 = 1, is one real equation.
  2. Global phase is unobservable: ∣ψ⟩\ket\psi and eiγ∣ψ⟩e^{i\gamma}\ket\psi are the same physical state, so one more real parameter is redundant.

Four minus two leaves two real parameters. Two real parameters describe a surface, and for a qubit that surface turns out to be a sphere. Having a picture of every possible single-qubit state is a rare luxury in quantum computing (nothing comparable exists for several qubits), so it is worth building carefully. Our conventions follow the course notation sheet and agree with Nielsen and Chuang, Section 1.2.

The Bloch parametrisation

Use the global-phase freedom to make α\alpha real and non-negative: if α=∣α∣eiγ\alpha = \abs\alpha e^{i\gamma}, multiply the whole state by e−iγe^{-i\gamma}. (If α=0\alpha = 0 the state is ∣1⟩\ket1 up to phase, and we can take β=1\beta = 1.) Now α∈[0,1]\alpha \in [0,1] and ∣β∣=1−α2\abs\beta = \sqrt{1-\alpha^2}, so we can write α=cos⁡(θ/2)\alpha = \cos(\theta/2) and ∣β∣=sin⁡(θ/2)\abs\beta = \sin(\theta/2) for a unique θ∈[0,π]\theta \in [0,\pi], and give β\beta its own phase eiφe^{i\varphi}:

∣ψ⟩=cos⁡θ2 ∣0⟩+eiφsin⁡θ2 ∣1⟩,θ∈[0,π], φ∈[0,2π).\ket\psi = \cos\frac\theta2\,\ket0 + e^{i\varphi}\sin\frac\theta2\,\ket1, \qquad \theta\in[0,\pi],\ \varphi\in[0,2\pi).

The angle θ\theta controls the balance between ∣0⟩\ket0 and ∣1⟩\ket1; the angle φ\varphi is the relative phase between them. At θ=0\theta = 0 the state is ∣0⟩\ket0 whatever φ\varphi is, and at θ=π\theta=\pi it is eiφ∣1⟩e^{i\varphi}\ket1, which is ∣1⟩\ket1 up to global phase. So φ\varphi is meaningless at the two poles, just as longitude is meaningless at the Earth's poles.

Why θ/2\theta/2 and not θ\theta? With half-angles, θ\theta runs over [0,π][0,\pi] while the state runs from ∣0⟩\ket0 to ∣1⟩\ket1. Read θ\theta and φ\varphi as the polar angle (from the north pole) and the azimuth (longitude) of a point on the unit sphere:

r⃗=(sin⁡θcos⁡φ, sin⁡θsin⁡φ, cos⁡θ).\vec r = (\sin\theta\cos\varphi,\ \sin\theta\sin\varphi,\ \cos\theta).

This unit vector is the Bloch vector of the state, and the sphere is the Bloch sphere.

The Bloch sphere A sphere with the z axis pointing up to the state ket 0 at the north pole and down to ket 1 at the south pole. The x axis points towards the viewer to ket plus, and the y axis points right to ket plus i. A state vector from the centre makes the polar angle theta with the z axis; its shadow in the equatorial plane makes the azimuthal angle phi with the x axis. z, |0⟩ |1⟩ y, |+i⟩ x, |+⟩ |ψ⟩ θ φ
The Bloch sphere: polar angle θ measured from |0⟩, azimuth φ measured from the x axis towards the y axis.

Bloch vectors are Pauli expectation values

The geometric definition above has a physical reading that is far more useful in practice. Define the Pauli matrices

X=(0110),Y=(0−ii0),Z=(100−1).X = \begin{pmatrix}0&1\\1&0\end{pmatrix},\quad Y = \begin{pmatrix}0&-i\\ i&0\end{pmatrix},\quad Z = \begin{pmatrix}1&0\\0&-1\end{pmatrix}.

(Physics texts often write σx,σy,σz\sigma_x, \sigma_y, \sigma_z.) Each is Hermitian with eigenvalues ±1\pm1, and for a state ∣ψ⟩\ket\psi its expectation value is ⟨P⟩=⟨ψ∣P∣ψ⟩\expval{P} = \bra\psi P \ket\psi, a real number in [−1,1][-1, 1]. The measurement lesson explains how these numbers are estimated from repeated measurements. The claim is:

r⃗=(⟨X⟩, ⟨Y⟩, ⟨Z⟩).\vec r = \big(\expval X,\ \expval Y,\ \expval Z\big).

Derivation. Write c=cos⁡(θ/2)c = \cos(\theta/2) and s=sin⁡(θ/2)s = \sin(\theta/2), so ∣ψ⟩=(c, eiφs)T\ket\psi = (c,\ e^{i\varphi}s)^T.

  • Z∣ψ⟩=(c, −eiφs)TZ\ket\psi = (c,\ -e^{i\varphi}s)^T, so ⟨Z⟩=c2−s2=cos⁡θ\expval Z = c^2 - s^2 = \cos\theta.
  • X∣ψ⟩=(eiφs, c)TX\ket\psi = (e^{i\varphi}s,\ c)^T, so ⟨X⟩=c eiφs+e−iφs c=2cscos⁡φ=sin⁡θcos⁡φ\expval X = c\,e^{i\varphi}s + e^{-i\varphi}s\,c = 2cs\cos\varphi = \sin\theta\cos\varphi.
  • Y∣ψ⟩=(−ieiφs, ic)TY\ket\psi = (-ie^{i\varphi}s,\ ic)^T, so ⟨Y⟩=−i c eiφs+i e−iφs c=2cssin⁡φ=sin⁡θsin⁡φ\expval Y = -i\,c\,e^{i\varphi}s + i\,e^{-i\varphi}s\,c = 2cs\sin\varphi = \sin\theta\sin\varphi.

We used 2cs=sin⁡θ2cs = \sin\theta and c2−s2=cos⁡θc^2 - s^2 = \cos\theta. Each component agrees with the geometric formula. Two consequences follow immediately. First, the Bloch vector does not depend on the global phase, because ⟨ψ∣P∣ψ⟩\bra\psi P\ket\psi is unchanged by ∣ψ⟩↦eiγ∣ψ⟩\ket\psi\mapsto e^{i\gamma}\ket\psi; so you can compute it from amplitudes without first fixing the phase. Second, Pr⁡[0]=c2=(1+rz)/2\Pr[0] = c^2 = (1+r_z)/2: the height on the sphere gives the computational-basis probabilities.

Landmarks

State θ\theta φ\varphi Bloch vector
∣0⟩\ket0 00 (any) (0,0,1)(0,0,1)
∣1⟩\ket1 π\pi (any) (0,0,−1)(0,0,-1)
∣+⟩\ket+ π/2\pi/2 00 (1,0,0)(1,0,0)
∣−⟩\ket- π/2\pi/2 π\pi (−1,0,0)(-1,0,0)
∣+i⟩\ket{+i} π/2\pi/2 π/2\pi/2 (0,1,0)(0,1,0)
∣−i⟩\ket{-i} π/2\pi/2 3π/23\pi/2 (0,−1,0)(0,-1,0)

Every state on the equator is an equal superposition of ∣0⟩\ket0 and ∣1⟩\ket1; the equator is a circle of relative phases.

Orthogonal states are antipodes

In C2\C^2, ∣0⟩\ket0 and ∣1⟩\ket1 are orthogonal, yet on the sphere they are opposite poles, 180∘180^\circ apart rather than 90∘90^\circ. This is the half-angle at work, and it holds in general. The cleanest route uses the matrix ρ=∣ψ⟩⟨ψ∣\rho = \ketbra{\psi}{\psi} (the density matrix of the state). Multiplying out ∣ψ⟩⟨ψ∣\ket\psi\bra\psi with the Bloch form gives

ρ=(c2cs e−iφcs eiφs2)=12(1+cos⁡θsin⁡θ e−iφsin⁡θ eiφ1−cos⁡θ)=12(I+rxX+ryY+rzZ).\rho = \begin{pmatrix} c^2 & c s\,e^{-i\varphi} \\ c s\,e^{i\varphi} & s^2\end{pmatrix} = \frac12\begin{pmatrix} 1+\cos\theta & \sin\theta\, e^{-i\varphi}\\ \sin\theta\, e^{i\varphi} & 1-\cos\theta\end{pmatrix} = \frac12\big(I + r_x X + r_y Y + r_z Z\big).

For two states with Bloch vectors r⃗\vec r and s⃗\vec s, the squared overlap is ∣⟨χ∣ψ⟩∣2=⟨χ∣ρψ∣χ⟩=Tr⁡(ρχρψ)\abs{\braket{\chi}{\psi}}^2 = \bra\chi\rho_\psi\ket\chi = \tr(\rho_\chi\rho_\psi). The Pauli matrices satisfy Tr⁡(I)=2\tr(I) = 2, Tr⁡(P)=0\tr(P) = 0 and Tr⁡(PQ)=2δPQ\tr(PQ) = 2\delta_{PQ} for P,Q∈{X,Y,Z}P, Q\in\{X,Y,Z\}, so expanding the product gives

∣⟨χ∣ψ⟩∣2=14(2+2 r⃗⋅s⃗)=1+r⃗⋅s⃗2.\abs{\braket{\chi}{\psi}}^2 = \tfrac14\big(2 + 2\,\vec r\cdot\vec s\big) = \frac{1+\vec r\cdot\vec s}{2}.

The overlap is 1 exactly when r⃗=s⃗\vec r = \vec s (same state) and 0 exactly when r⃗=−s⃗\vec r = -\vec s. Orthogonal states are antipodal points, and every orthonormal basis of a qubit corresponds to an axis through the sphere: {∣0⟩,∣1⟩}\{\ket0,\ket1\} to the zz axis, {∣+⟩,∣−⟩}\{\ket+,\ket-\} to the xx axis, and so on.

Worked example

Take θ=π/3\theta = \pi/3 and φ=π/2\varphi = \pi/2.

  1. Amplitudes: cos⁡(π/6)=3/2\cos(\pi/6) = \sqrt3/2 and eiπ/2sin⁡(π/6)=i/2e^{i\pi/2}\sin(\pi/6) = i/2, so ∣ψ⟩=32∣0⟩+i2∣1⟩\ket\psi = \tfrac{\sqrt3}{2}\ket0 + \tfrac{i}{2}\ket1.
  2. Bloch vector: (sin⁡π3cos⁡π2, sin⁡π3sin⁡π2, cos⁡π3)=(0, 32, 12)(\sin\frac\pi3\cos\frac\pi2,\ \sin\frac\pi3\sin\frac\pi2,\ \cos\frac\pi3) = (0,\ \tfrac{\sqrt3}{2},\ \tfrac12).
  3. Pr⁡[0]=(1+rz)/2=3/4\Pr[0] = (1 + r_z)/2 = 3/4, which matches ∣3/2∣2\abs{\sqrt3/2}^2.
  4. Overlap with ∣+⟩\ket+, whose Bloch vector is (1,0,0)(1,0,0): (1+0)/2=1/2(1 + 0)/2 = 1/2. Directly: ⟨+∣ψ⟩=(3/2+i/2)/2\braket{+}{\psi} = (\sqrt3/2 + i/2)/\sqrt2, with squared modulus (3/4+1/4)/2=1/2(3/4 + 1/4)/2 = 1/2. The two methods agree.
  5. Overlap with ∣+i⟩\ket{+i}, Bloch vector (0,1,0)(0,1,0): (1+3/2)/2≈0.933(1 + \sqrt3/2)/2 \approx 0.933. The state leans towards ∣+i⟩\ket{+i}, as its position (between the north pole and the +y+y axis) suggests.

In code:

import numpy as np

X = np.array([[0, 1], [1, 0]]); Y = np.array([[0, -1j], [1j, 0]]); Z = np.diag([1, -1])
theta, phi = np.pi / 3, np.pi / 2
psi = np.array([np.cos(theta / 2), np.exp(1j * phi) * np.sin(theta / 2)])
r = np.array([np.vdot(psi, P @ psi).real for P in (X, Y, Z)])
print(np.round(r, 6))                                  # [0.       0.866025 0.5     ]
s_plus_i = np.array([0, 1, 0])
print(round((1 + r @ s_plus_i) / 2, 6))                # 0.933013

A preview: points inside the sphere

So far every state was a unit vector, which we call a pure state. Suppose instead that a device prepares ∣0⟩\ket0 with probability 1/21/2 and ∣1⟩\ket1 with probability 1/21/2, and does not tell us which. This is a classical lack of knowledge, a mixed state, and it is described by the average of the density matrices, ρ=12∣0⟩⟨0∣+12∣1⟩⟨1∣=I/2\rho = \tfrac12\ketbra00 + \tfrac12\ketbra11 = I/2. Comparing with ρ=12(I+rxX+ryY+rzZ)\rho = \tfrac12(I + r_x X + r_y Y + r_z Z), its Bloch vector is 0⃗\vec 0: the centre of the sphere.

In general a mixture of pure states with probabilities wjw_j has Bloch vector ∑jwjr⃗j\sum_j w_j \vec r_j, a convex combination, which lies inside the ball ∥r⃗∥≤1\norm{\vec r}\le 1; equality holds only for pure states. The length of the vector measures purity: Tr⁡(ρ2)=(1+∥r⃗∥2)/2\tr(\rho^2) = (1+\norm{\vec r}^2)/2, equal to 1 for pure states and 1/21/2 at the centre.

Do not confuse the mixture at the centre with the superposition ∣+⟩\ket+. Both give 50/50 outcomes in the computational basis, but ∣+⟩\ket+ sits on the surface at (1,0,0)(1,0,0), and measuring it in the {∣+⟩,∣−⟩}\{\ket+,\ket-\} basis gives "+" with certainty, whereas the mixture still gives 50/50. A superposition carries a definite relative phase; a mixture does not. This lesson only previews mixed states; the noise lesson uses them in earnest, because noise is exactly what pulls Bloch vectors into the interior.

Limits of the picture

  • The Bloch sphere describes one qubit. An nn-qubit pure state needs 2n+1−22^{n+1}-2 real parameters, and entangled states cannot be drawn as one sphere per qubit.
  • Angles on the sphere are twice angles between state vectors. Points 180∘180^\circ apart are orthogonal states, whereas ∣ψ⟩\ket\psi and −∣ψ⟩-\ket\psi (which are "opposite" vectors in C2\C^2) are the same point.

Common mistakes

  • Dropping the half-angle. The amplitude of ∣0⟩\ket0 is cos⁡(θ/2)\cos(\theta/2), not cos⁡θ\cos\theta. With full angles, θ=π/2\theta=\pi/2 would give ∣1⟩\ket1 instead of an equator state.
  • Assigning meaning to the global phase. ∣ψ⟩\ket\psi and eiγ∣ψ⟩e^{i\gamma}\ket\psi have the same Bloch vector. Before reading off φ\varphi from amplitudes, rotate the global phase so that the ∣0⟩\ket0 amplitude is real and non-negative.
  • Treating orthogonal states as perpendicular Bloch vectors. Perpendicular Bloch vectors (such as ∣0⟩\ket0 and ∣+⟩\ket+) have overlap 1/21/2; orthogonal states are antipodal.
  • Reading φ\varphi at a pole. For ∣0⟩\ket0 and ∣1⟩\ket1 any φ\varphi describes the same state.
  • Calling a mixture a superposition. Both can give equal computational-basis probabilities; only a measurement in another basis tells them apart.

Summary

  • A pure qubit state has two real parameters after normalisation and global phase are removed.
  • Bloch form: cos⁡(θ/2)∣0⟩+eiφsin⁡(θ/2)∣1⟩\cos(\theta/2)\ket0 + e^{i\varphi}\sin(\theta/2)\ket1; Bloch vector r⃗=(sin⁡θcos⁡φ,sin⁡θsin⁡φ,cos⁡θ)=(⟨X⟩,⟨Y⟩,⟨Z⟩)\vec r = (\sin\theta\cos\varphi, \sin\theta\sin\varphi, \cos\theta) = (\expval X, \expval Y, \expval Z).
  • ∣⟨χ∣ψ⟩∣2=(1+r⃗⋅s⃗)/2\abs{\braket{\chi}{\psi}}^2 = (1+\vec r\cdot\vec s)/2, so orthogonal states sit at opposite points.
  • Mixed states are points inside the sphere; ∥r⃗∥\norm{\vec r} measures purity.

The exercise has you convert between amplitudes, angles and Bloch vectors and verify the overlap formula numerically. Next, Quantum gates and unitary transformations shows that single-qubit gates are rotations of this sphere.

Exercises

Run these on your own computer. Each comes with automated checks: python -m pytest test_exercise.py. Nothing you write is sent to KetQat.

From amplitudes to Bloch vectors and back

introductory · about 30 min · needs numpy

You will implement the maps between a qubit's two complex amplitudes, its Bloch angles (θ,φ)(\theta, \varphi) and its Bloch vector r⃗\vec r, and use them to check two facts from the lesson: overlaps depend only on the angle between Bloch vectors, and mixtures land strictly inside the sphere.

Conventions (as in the lesson): ∣ψ⟩=cos⁡(θ/2)∣0⟩+eiφsin⁡(θ/2)∣1⟩\ket\psi = \cos(\theta/2)\ket0 + e^{i\varphi}\sin(\theta/2)\ket1 with θ∈[0,π]\theta\in[0,\pi], φ∈[0,2π)\varphi\in[0,2\pi), and r⃗=(⟨X⟩,⟨Y⟩,⟨Z⟩)\vec r = (\expval{X}, \expval{Y}, \expval{Z}).

Functions to implement (in starter.py)

Function Contract
state_from_angles(theta, phi) Return the length-2 complex array (cos⁡θ2, eiφsin⁡θ2)\big(\cos\frac\theta2,\ e^{i\varphi}\sin\frac\theta2\big).
bloch_vector(psi) Return the NumPy array (⟨X⟩,⟨Y⟩,⟨Z⟩)(\expval X, \expval Y, \expval Z) for a normalised state, computed as ⟨ψ∣P∣ψ⟩\bra\psi P\ket\psi with the Pauli matrices.
angles_from_state(psi) Return (theta, phi) in the ranges above for any normalised psi, whatever its global phase. At the poles (θ=0\theta = 0 or π\pi) return phi = 0.0.
overlap_from_bloch(r, s) Return ∣⟨ψ∣χ⟩∣2\abs{\braket{\psi}{\chi}}^2 computed only from the two Bloch vectors: (1+r⃗⋅s⃗)/2(1 + \vec r\cdot\vec s)/2.
mixture_bloch_vector(states, weights) For pure states prepared with probabilities weights, return the Bloch vector ∑jwjr⃗j\sum_j w_j \vec r_j of the mixture.

What the checks verify

  • The six axis states ∣0⟩,∣1⟩,∣±⟩,∣±i⟩\ket0,\ket1,\ket\pm,\ket{\pm i} land on the expected axes.
  • Bloch vectors of random pure states have length 1 and agree with the closed form (sin⁡θcos⁡φ,sin⁡θsin⁡φ,cos⁡θ)(\sin\theta\cos\varphi, \sin\theta\sin\varphi, \cos\theta).
  • angles_from_state inverts state_from_angles up to a global phase, even when the input carries a random global phase.
  • overlap_from_bloch agrees with ∣⟨ψ∣χ⟩∣2\abs{\braket{\psi}{\chi}}^2 computed directly from amplitudes, and antipodal points are orthogonal states.
  • mixture_bloch_vector agrees with Tr⁡(ρP)\tr(\rho P) for the averaged density matrix ρ=∑jwj∣ψj⟩⟨ψj∣\rho = \sum_j w_j \ketbra{\psi_j}{\psi_j}, which the test builds independently, and the equal mixture of ∣0⟩\ket0 and ∣1⟩\ket1 is the centre.

Run the checks

python -m pip install numpy
python -m pytest test_exercise.py
Terminal
python -m pip install numpy

starter.py

Python
"""From amplitudes to Bloch vectors and back (KetQat Commons, Foundations)."""
import numpy as np

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 state_from_angles(theta, phi):
    """Return (cos(theta/2), exp(i phi) sin(theta/2)) as a complex array."""
    raise NotImplementedError


def bloch_vector(psi):
    """Return np.array([<X>, <Y>, <Z>]) for a normalised state psi (real floats)."""
    raise NotImplementedError


def angles_from_state(psi):
    """Return (theta, phi), theta in [0, pi], phi in [0, 2 pi), for any global phase of psi.

    At the poles return phi = 0.0.
    """
    raise NotImplementedError


def overlap_from_bloch(r, s):
    """Return |<psi|chi>|^2 computed only from the Bloch vectors r and s."""
    raise NotImplementedError


def mixture_bloch_vector(states, weights):
    """Bloch vector of the mixture that prepares states[j] with probability weights[j]."""
    raise NotImplementedError

test_exercise.py

Python
"""Checks for the bloch-vectors exercise. Run: python -m pytest test_exercise.py"""
import importlib.util
import os
from pathlib import Path

def _load_target():
    name = os.environ.get("KETQAT_COMMONS_TARGET", "starter")
    path = Path(__file__).with_name(f"{name}.py")
    spec = importlib.util.spec_from_file_location(f"{Path(__file__).parent.name}_{name}", path)
    module = importlib.util.module_from_spec(spec)
    spec.loader.exec_module(module)
    return module

target = _load_target()

import numpy as np
import pytest

RNG = np.random.default_rng(11)
S2 = np.sqrt(2)


def _random_state():
    v = RNG.normal(size=2) + 1j * RNG.normal(size=2)
    return v / np.linalg.norm(v)


@pytest.mark.parametrize(
    "psi, expected",
    [
        ([1, 0], [0, 0, 1]),
        ([0, 1], [0, 0, -1]),
        ([1 / S2, 1 / S2], [1, 0, 0]),
        ([1 / S2, -1 / S2], [-1, 0, 0]),
        ([1 / S2, 1j / S2], [0, 1, 0]),
        ([1 / S2, -1j / S2], [0, -1, 0]),
    ],
)
def test_axis_states(psi, expected):
    assert np.allclose(target.bloch_vector(np.array(psi, dtype=complex)), expected, atol=1e-12)


def test_state_from_angles_matches_closed_form_bloch_vector():
    for _ in range(50):
        theta, phi = RNG.uniform(0, np.pi), RNG.uniform(0, 2 * np.pi)
        psi = target.state_from_angles(theta, phi)
        assert np.isclose(np.linalg.norm(psi), 1)
        r = target.bloch_vector(psi)
        closed = [np.sin(theta) * np.cos(phi), np.sin(theta) * np.sin(phi), np.cos(theta)]
        assert np.allclose(r, closed)
        assert np.isclose(np.linalg.norm(r), 1)


def test_angles_round_trip_up_to_global_phase():
    for _ in range(50):
        psi = _random_state() * np.exp(1j * RNG.uniform(0, 2 * np.pi))
        theta, phi = target.angles_from_state(psi)
        assert 0 <= theta <= np.pi and 0 <= phi < 2 * np.pi
        rebuilt = target.state_from_angles(theta, phi)
        assert np.isclose(abs(np.vdot(rebuilt, psi)), 1.0)


def test_angles_at_the_poles():
    theta, phi = target.angles_from_state(np.array([0, 1j]))
    assert np.isclose(theta, np.pi) and phi == 0.0
    theta, phi = target.angles_from_state(np.array([np.exp(0.3j), 0]))
    assert np.isclose(theta, 0.0) and phi == 0.0


def test_overlap_from_bloch_matches_amplitudes():
    for _ in range(50):
        a, b = _random_state(), _random_state()
        direct = abs(np.vdot(a, b)) ** 2
        r, s = target.bloch_vector(a), target.bloch_vector(b)
        assert np.isclose(target.overlap_from_bloch(r, s), direct)


def test_antipodal_points_are_orthogonal_states():
    for _ in range(20):
        theta, phi = RNG.uniform(0, np.pi), RNG.uniform(0, 2 * np.pi)
        a = target.state_from_angles(theta, phi)
        b = target.state_from_angles(np.pi - theta, (phi + np.pi) % (2 * np.pi))
        assert np.allclose(target.bloch_vector(a), -target.bloch_vector(b))
        assert abs(np.vdot(a, b)) < 1e-12


def test_mixture_matches_density_matrix_and_lies_inside():
    X = np.array([[0, 1], [1, 0]])
    Y = np.array([[0, -1j], [1j, 0]])
    Z = np.diag([1, -1])
    for k in (2, 3, 5):
        states = [_random_state() for _ in range(k)]
        w = RNG.dirichlet(np.ones(k))
        rho = sum(wj * np.outer(p, p.conj()) for wj, p in zip(w, states))
        expected = [np.trace(rho @ P).real for P in (X, Y, Z)]
        r = target.mixture_bloch_vector(states, w)
        assert np.allclose(r, expected)
        assert np.linalg.norm(r) <= 1 + 1e-12
    centre = target.mixture_bloch_vector([np.array([1, 0]), np.array([0, 1])], [0.5, 0.5])
    assert np.allclose(centre, 0)

Check your understanding

7 questions. Pass with 70% of the points. Answers are checked on the server; retakes are allowed. Explanations appear once you pass or after three complete attempts.

  1. How many real parameters are needed to specify an arbitrary pure single-qubit state as a physical state?

    1 pt
  2. What is the Bloch vector of 12(∣0⟩−i∣1⟩)\tfrac{1}{\sqrt2}(\ket0 - i\ket1)?

    1 pt
  3. Using your functions from the exercise, compute bloch_vector(state_from_angles(1.0, 0.5)) and enter its x component.

    1 pt

    Computed by running exercise “bloch-vectors” on your computer.

  4. A pure state has Bloch vector (0.6,0,0.8)(0.6, 0, 0.8). What is the probability of outcome 0 in a computational-basis measurement?

    1 pt
  5. Which state is orthogonal to cos⁡θ2∣0⟩+eiφsin⁡θ2∣1⟩\cos\frac\theta2\ket0 + e^{i\varphi}\sin\frac\theta2\ket1 (for 0<θ<π0<\theta<\pi)?

    1 pt
  6. Two pure states have Bloch vectors that make an angle of 120∘120^\circ. What is ∣⟨χ∣ψ⟩∣2\abs{\braket{\chi}{\psi}}^2?

    1 pt
  7. Select every true statement.

    1 pt

    Select all that apply.

Sign in with GitHub to check answers and save progress. Reading stays free without an account.

References

  1. Michael A. Nielsen, Isaac L. Chuang (2010). Quantum Computation and Quantum Information (10th Anniversary Edition). Cambridge University Press. doi:10.1017/CBO9780511976667