|q⟩ Bad Qubits

beginner · Programming · The Qubit State Vector & Dirac Notation

Superposition with Arbitrary Weights

Not every useful qubit state has equal amplitudes. A superposition with arbitrary weights lets you control exactly how much probability mass sits on 0|0\rangle versus 1|1\rangle — and that control is at the heart of preparing initial states for quantum algorithms.

The general single-qubit state

Any normalized single-qubit state can be written as

ψ=α0+β1,|\psi\rangle = \alpha|0\rangle + \beta|1\rangle,

where α,βC\alpha, \beta \in \mathbb{C} and the normalization condition

α2+β2=1|\alpha|^2 + |\beta|^2 = 1

must hold so that the Born-rule probabilities sum to one. When the amplitudes are real and non-negative, this is equivalent to writing α=cos(θ/2)\alpha = \cos(\theta/2) and β=sin(θ/2)\beta = \sin(\theta/2) for some angle θ[0,π]\theta \in [0, \pi], since cos2(θ/2)+sin2(θ/2)=1\cos^2(\theta/2) + \sin^2(\theta/2) = 1 by the Pythagorean identity.

The Ry rotation

The Ry(θ)R_y(\theta) gate rotates the Bloch-sphere state vector about the yy-axis by angle θ\theta. Its matrix is

Ry(θ)=(cos(θ/2)sin(θ/2)sin(θ/2)cos(θ/2)).R_y(\theta) = \begin{pmatrix} \cos(\theta/2) & -\sin(\theta/2) \\ \sin(\theta/2) & \cos(\theta/2) \end{pmatrix}.

Applying it to 0=(10)|0\rangle = \binom{1}{0} gives

Ry(θ)0=(cos(θ/2)sin(θ/2))=cos ⁣(θ2)0+sin ⁣(θ2)1.R_y(\theta)|0\rangle = \begin{pmatrix} \cos(\theta/2) \\ \sin(\theta/2) \end{pmatrix} = \cos\!\left(\tfrac{\theta}{2}\right)|0\rangle + \sin\!\left(\tfrac{\theta}{2}\right)|1\rangle.

So choosing θ\theta determines the split. When θ=π/2\theta = \pi/2, we get cos(π/4)=sin(π/4)=1/2\cos(\pi/4) = \sin(\pi/4) = 1/\sqrt{2} — the familiar 50/50 superposition from 0|0\rangle. Note that Ry(π/2)R_y(\pi/2) and the Hadamard gate HH agree on 0|0\rangle but are different unitaries (HH maps 1(01)/2|1\rangle \to (|0\rangle - |1\rangle)/\sqrt{2}, whereas Ry(π/2)R_y(\pi/2) maps 1(0+1)/2|1\rangle \to (-|0\rangle + |1\rangle)/\sqrt{2}).

Confirming normalization

Suppose you want the state ψ=320+121|\psi\rangle = \tfrac{\sqrt{3}}{2}|0\rangle + \tfrac{1}{2}|1\rangle. Check that it is normalized:

322+122=34+14=1.\left|\tfrac{\sqrt{3}}{2}\right|^2 + \left|\tfrac{1}{2}\right|^2 = \tfrac{3}{4} + \tfrac{1}{4} = 1. \checkmark

To prepare it with RyR_y, set cos(θ/2)=3/2\cos(\theta/2) = \sqrt{3}/2. Because cos(π/6)=3/2\cos(\pi/6) = \sqrt{3}/2, we have θ/2=π/6\theta/2 = \pi/6, so θ=π/3\theta = \pi/3. The measurement probabilities are P(0)=3/4P(0) = 3/4 and P(1)=1/4P(1) = 1/4.

Try it

Prepare the state ψ=320+121|\psi\rangle = \tfrac{\sqrt{3}}{2}|0\rangle + \tfrac{1}{2}|1\rangle by choosing the right angle for an RyR_y rotation. The grader checks the full statevector, so the amplitudes must match the target exactly (up to global phase).

Run your code to see the quantum state.

After running, inspect the statevector panel: you should see amplitudes close to 0.8663/20.866 \approx \sqrt{3}/2 on 0|0\rangle and 0.50.5 on 1|1\rangle, with probabilities 0.750.75 and 0.250.25 respectively.

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