qsengine 1.1.1

The Bloch sphere

Every state of a single qubit can be drawn as a point on the surface of a sphere. It turns gates from matrices into something you can picture: each one is a rotation.

Two angles describe any qubit

An overall phase on the whole state cannot be measured, so it can be dropped. What is left of α∣0⟩+β∣1⟩\alpha\ket{0} + \beta\ket{1} fits in two angles:

∣ψ⟩=cos⁡θ2∣0⟩+eiφsin⁡θ2∣1⟩,0≤θ≤π,  0≤φ<2π\ket{\psi} = \cos\tfrac{\theta}{2}\ket{0} + e^{i\varphi}\sin\tfrac{\theta}{2}\ket{1}, \qquad 0 \le \theta \le \pi,\ \ 0 \le \varphi < 2\pi

θ\theta is the latitude, measured down from the north pole, and φ\varphi is the longitude around the equator. θ\theta alone sets the measurement odds; φ\varphi is the relative phase.

Landmarks

StateAnglesWhere it sits
∣0⟩\ket{0}θ=0\theta = 0North pole
∣1⟩\ket{1}θ=π\theta = \piSouth pole
∣+⟩=12(∣0⟩+∣1⟩)\ket{+} = \tfrac{1}{\sqrt2}(\ket0 + \ket1)θ=π2, φ=0\theta = \tfrac{\pi}{2},\ \varphi = 0On the equator, facing +X
∣−⟩=12(∣0⟩−∣1⟩)\ket{-} = \tfrac{1}{\sqrt2}(\ket0 - \ket1)θ=π2, φ=π\theta = \tfrac{\pi}{2},\ \varphi = \piOn the equator, facing −X
12(∣0⟩+i∣1⟩)\tfrac{1}{\sqrt2}(\ket0 + i\ket1)θ=π2, φ=π2\theta = \tfrac{\pi}{2},\ \varphi = \tfrac{\pi}{2}On the equator, facing +Y

The poles are the basis states. Every point on the equator is an equal superposition, differing only in phase.

Gates are rotations

GateRotationMethod
XXπ about X\pi \text{ about } Xqc.x(q)
YYπ about Y\pi \text{ about } Yqc.y(q)
ZZπ about Z\pi \text{ about } Zqc.z(q)
SSπ2 about Z\tfrac{\pi}{2} \text{ about } Zqc.s(q)
TTπ4 about Z\tfrac{\pi}{4} \text{ about } Zqc.t(q)
HHπ about X+Z2\pi \text{ about } \tfrac{X+Z}{\sqrt2}qc.h(q)
RX(θ), RY(θ), RZ(θ)R_X(\theta),\ R_Y(\theta),\ R_Z(\theta)θ about X, Y or Z\theta \text{ about } X,\ Y \text{ or } Zqc.rx(q, theta)
P(λ)P(\lambda)λ about Z\lambda \text{ about } Zqc.p(q, lam)

A quarter turn about X takes the north pole to the equator, at the point facing −Y:

RX(π2)∣0⟩=12(∣0⟩−i∣1⟩)R_X(\tfrac{\pi}{2})\ket{0} = \tfrac{1}{\sqrt2}\left(\ket{0} - i\ket{1}\right)
import math
import qsengine

qc = qsengine.QuantumCircuit(1)
qc.rx(0, math.pi / 2)

print(qc.statevector())
print(qc.probabilities())

Output

[0.70710678+0.j         0.        -0.70710678j]
[0.5 0.5]

The second amplitude is −i/√2, exactly as the formula says, and the odds are 50/50.

Where the picture stops

The sphere describes one qubit on its own. Two or more qubits that are entangled have no point on any sphere, which is exactly what makes them interesting. That is the subject of the next pages.