|q⟩ Bad Qubits

beginner · Programming · Rotation Gates & Universal Single-Qubit Ops

Preparing an Arbitrary State

Every pure single-qubit state corresponds to exactly one point on the Bloch sphere. The north pole is 0|0\rangle, the south pole is 1|1\rangle, and every other point encodes a superposition. Two angles fully specify a point: the polar angle θ\theta (latitude from the north pole) and the azimuthal angle ϕ\phi (longitude). Parametrically,

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

The factor of 1/21/2 on the angles is a convention: it ensures the antipodal points θ=0\theta = 0 and θ=π\theta = \pi give the orthogonal pair 0|0\rangle and 1|1\rangle.

Reaching any state with two rotations

To prepare ψ(θ,ϕ)|\psi(\theta, \phi)\rangle starting from 0|0\rangle, apply two gates in sequence:

  1. RY(θ)R_Y(\theta) rotates around the yy-axis and sets the amplitude ratio:
RY(θ)0=cos ⁣θ20+sin ⁣θ21.R_Y(\theta)|0\rangle = \cos\!\tfrac{\theta}{2}\,|0\rangle + \sin\!\tfrac{\theta}{2}\,|1\rangle.

Both amplitudes are real after this step — the state lives on the meridian ϕ=0\phi = 0.

  1. RZ(ϕ)R_Z(\phi) rotates around the zz-axis and dials in the relative phase:
RZ(ϕ)(α0+β1)=eiϕ/2α0+eiϕ/2β1.R_Z(\phi)\bigl(\alpha|0\rangle + \beta|1\rangle\bigr) = e^{-i\phi/2}\alpha\,|0\rangle + e^{i\phi/2}\beta\,|1\rangle.

Up to a global phase eiϕ/2e^{-i\phi/2} (which is unobservable), this multiplies the 1|1\rangle component by eiϕe^{i\phi}, placing the state at longitude ϕ\phi on the Bloch sphere.

The combined action is

RZ(ϕ)RY(θ)0=eiϕ/2(cos ⁣θ20+eiϕsin ⁣θ21),R_Z(\phi)\,R_Y(\theta)|0\rangle = e^{-i\phi/2}\bigl(\cos\!\tfrac{\theta}{2}\,|0\rangle + e^{i\phi}\sin\!\tfrac{\theta}{2}\,|1\rangle\bigr),

which equals the target state up to the global phase eiϕ/2e^{-i\phi/2}. Global phases are physically equivalent because they cancel in every Born-rule probability and every expectation value.

A worked example

Suppose the target is θ=π/3\theta = \pi/3 (polar angle) and ϕ=π/3\phi = \pi/3 (azimuthal angle):

ψ=cos ⁣π60+eiπ/3sin ⁣π61=320+12eiπ/31.|\psi\rangle = \cos\!\tfrac{\pi}{6}\,|0\rangle + e^{i\pi/3}\sin\!\tfrac{\pi}{6}\,|1\rangle = \tfrac{\sqrt{3}}{2}\,|0\rangle + \tfrac{1}{2}e^{i\pi/3}|1\rangle.

The probabilities are P(0)=cos2(π/6)=3/4P(0) = \cos^2(\pi/6) = 3/4 and P(1)=sin2(π/6)=1/4P(1) = \sin^2(\pi/6) = 1/4, which come from the amplitude magnitudes 320.866\tfrac{\sqrt{3}}{2} \approx 0.866 and 12=0.5\tfrac{1}{2} = 0.5.

To realise this state, first apply RY(π/3)R_Y(\pi/3) to set the amplitude ratio, then RZ(π/3)R_Z(\pi/3) to attach the phase eiπ/3e^{i\pi/3} to the 1|1\rangle component.

Try it

Prepare the state with polar angle θ=π/3\theta = \pi/3 and azimuthal angle ϕ=π/3\phi = \pi/3:

ψ=cos ⁣π60+eiπ/3sin ⁣π61.|\psi\rangle = \cos\!\tfrac{\pi}{6}\,|0\rangle + e^{i\pi/3}\sin\!\tfrac{\pi}{6}\,|1\rangle.

Use RYR_Y to fix the amplitudes, then RZR_Z to set the phase. The grader checks the full statevector.

Run your code to see the quantum state.

After pressing Run, the statevector panel should show the 0|0\rangle amplitude as a complex number near 0.750.433i0.75 - 0.433i (magnitude 0.866\approx 0.866) and the 1|1\rangle amplitude near 0.433+0.25i0.433 + 0.25i (magnitude 0.50.5, argument π/60.524\pi/6 \approx 0.524 rad). The relative phase between the two amplitudes is π/3\pi/3, which is the azimuthal angle ϕ\phi of the target state. The probabilities tab should show P(0)=0.75P(0) = 0.75 and P(1)=0.25P(1) = 0.25.

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