State preparation is the first step in almost every quantum algorithm: you must load the data or
the initial conditions before any computation can take place. In module 8 you have built up two
families of single-qubit tools — the RY gate for tuning amplitude magnitudes, and the phase
gate P for adding relative phases. This checkpoint asks you to combine both.
The general single-qubit state
Any normalized single-qubit state can be written as
∣ψ⟩=α∣0⟩+β∣1⟩,∣α∣2+∣β∣2=1.
If α and β are both real and non-negative, a single RY rotation suffices:
RY(θ)∣0⟩=cos2θ∣0⟩+sin2θ∣1⟩.
When β carries a non-trivial complex phase, you need a second gate.
Setting magnitudes and phases independently
A clean two-step recipe exploits the fact that RY leaves all amplitudes real, so any remaining
phase can be added afterward with the phase gateP(λ):
P(λ)=(100eiλ).
P(λ) leaves the ∣0⟩ amplitude unchanged and multiplies the ∣1⟩ amplitude
by eiλ. The recipe is therefore:
Choose θ=2arccos∣α∣ and apply RY(θ) to set the magnitude ratio.
Choose λ=arg(β)−arg(α) and apply P(λ) to install the relative
phase.
For most real applications α is real and positive (so argα=0), which simplifies the
phase choice to λ=arg(β).
A worked example
Suppose the target is
∣ψ⟩=23∣0⟩+2i∣1⟩.
The magnitudes are ∣α∣=3/2 and ∣β∣=1/2.
Step 1 — set the magnitudes. Solve cos(θ/2)=3/2:
2θ=6π⟹θ=3π.
Applying RY(π/3) gives 23∣0⟩+21∣1⟩.
Step 2 — add the phase. The target phase on ∣1⟩ is i=eiπ/2, so λ=π/2.
Applying P(π/2) multiplies the ∣1⟩ amplitude by eiπ/2=i:
P(π/2)(23∣0⟩+21∣1⟩)=23∣0⟩+2i∣1⟩.✓
You can verify normalization: (3/2)2+(1/2)2=3/4+1/4=1.
Try it
Prepare the state 23∣0⟩+2i∣1⟩ using two gates. The grader
checks the full statevector (up to global phase), so both the amplitude magnitudes and the relative
phase must be correct.
Run your code to see the quantum state.
After pressing Run, inspect the statevector readout: the ∣0⟩ amplitude should be
≈0.866 (real) and the ∣1⟩ amplitude should be ≈0.500i (purely imaginary).
Sign in on the full site to ask questions and join the discussion.