|q⟩ Bad Qubits

beginner · Programming · The Bloch Sphere

Gates as Rotations

Every single-qubit gate corresponds to a rotation of the Bloch sphere. The three Pauli gates — XX, YY, and ZZ — are the simplest instances: each is a 180° (half-turn) rotation about one of the three coordinate axes.

The Bloch sphere as a rotation target

A qubit state ψ=α0+β1|\psi\rangle = \alpha|0\rangle + \beta|1\rangle (with α2+β2=1|\alpha|^2 + |\beta|^2 = 1) can be written in spherical coordinates as

ψ=cos ⁣θ20+eiϕsin ⁣θ21,|\psi\rangle = \cos\!\tfrac{\theta}{2}\,|0\rangle + e^{i\phi}\sin\!\tfrac{\theta}{2}\,|1\rangle,

where θ[0,π]\theta \in [0,\pi] is the polar angle from the north pole 0|0\rangle and ϕ[0,2π)\phi \in [0, 2\pi) is the azimuthal angle. This maps every (equivalence class of) state to a point on the unit sphere — the Bloch sphere.

Applying a unitary gate moves that point. The general rotation by angle α\alpha about a unit axis n^=(nx,ny,nz)\hat{n} = (n_x, n_y, n_z) is

Rn^(α)=ei(α/2)n^σ=cos ⁣α2Iisin ⁣α2(nxX+nyY+nzZ),R_{\hat{n}}(\alpha) = e^{-i(\alpha/2)\,\hat{n}\cdot\vec{\sigma}} = \cos\!\tfrac{\alpha}{2}\,I - i\sin\!\tfrac{\alpha}{2}\,(n_x X + n_y Y + n_z Z),

where σ=(X,Y,Z)\vec{\sigma} = (X, Y, Z) is the vector of Pauli matrices. At α=π\alpha = \pi (180°) this simplifies: cos(π/2)=0\cos(\pi/2) = 0 and sin(π/2)=1\sin(\pi/2) = 1, so

Rn^(π)=i(nxX+nyY+nzZ).R_{\hat{n}}(\pi) = -i\,(n_x X + n_y Y + n_z Z).

Choosing n^=x^\hat{n} = \hat{x}, y^\hat{y}, or z^\hat{z} in turn gives

Rx(π)=iX,Ry(π)=iY,Rz(π)=iZ.R_x(\pi) = -i\,X, \qquad R_y(\pi) = -i\,Y, \qquad R_z(\pi) = -i\,Z.

The factor i-i is a global phase and has no observable consequence. Up to that phase the Pauli gates are the 180° rotation operators: XRx(π)X \sim R_x(\pi), YRy(π)Y \sim R_y(\pi), ZRz(π)Z \sim R_z(\pi).

What each rotation does on the sphere

Because the rotation axis is fixed by the gate name, the effect on every point is easy to picture:

Continuous rotations from the same formula

The same formula Rn^(α)=ei(α/2)n^σR_{\hat{n}}(\alpha) = e^{-i(\alpha/2)\hat{n}\cdot\vec{\sigma}} works for any angle α\alpha. The circuit API exposes this directly: c.rx(theta, q), c.ry(theta, q), c.rz(theta, q). Setting theta = Math.PI recovers the corresponding Pauli gate up to global phase.

Try it

Apply Rx(π)R_x(\pi) to qubit 0 and verify it matches XX. The grader compares the full unitary matrix, ignoring global phase. An empty circuit (the identity) will fail — you must actually rotate.

Run your code to see the quantum state.

Notice that the unitary of Rx(π)R_x(\pi) equals iX-i\,X. Because global phase is unobservable, the grader accepts this as equivalent to XX. This is the bridge between the abstract rotation picture and the concrete gate operations you use in circuits.

Sign in on the full site to ask questions and join the discussion.