|q⟩ Bad Qubits

beginner · Programming · Single-Qubit Gates II: H, S, T & Phase

Checkpoint: Phase Engineering

Throughout this module you have met the three standard phase tools: the Hadamard gate to create superpositions, the S gate to add a π2\frac{\pi}{2} relative phase, and the T gate to add a π4\frac{\pi}{4} relative phase. This checkpoint asks you to combine them to hit a precise target in the complex plane.

The target state

Your goal is the single-qubit state

ψ=12 ⁣(0+ei3π/41).|\psi\rangle = \frac{1}{\sqrt{2}}\!\left(|0\rangle + e^{i3\pi/4}|1\rangle\right).

The factor ei3π/4e^{i3\pi/4} places the 1|1\rangle amplitude at 135°135° in the complex plane, squarely in the second quadrant. Working out the Cartesian form,

ei3π/4=cos ⁣3π4+isin ⁣3π4=12+i2,e^{i3\pi/4} = \cos\!\tfrac{3\pi}{4} + i\sin\!\tfrac{3\pi}{4} = -\tfrac{1}{\sqrt{2}} + \tfrac{i}{\sqrt{2}},

so the two amplitudes are 12\frac{1}{\sqrt{2}} (real, positive) and 12ei3π/4\frac{1}{\sqrt{2}}e^{i3\pi/4} (magnitude 12\frac{1}{\sqrt{2}}, angle 135°135°). Both have the same magnitude, which means a ZZ-basis measurement still gives 50/50 — the phase is hidden unless you use interference to reveal it.

Phase as addition

Phase gates accumulate by addition. A phase gate P(λ)P(\lambda) applied after P(μ)P(\mu) yields a combined relative phase of λ+μ\lambda + \mu. Writing the angles of the standard gates,

Tπ/4  after  Sπ/2ϕ=π2+π4=3π4.\underbrace{T}_{\pi/4} \;\text{after}\; \underbrace{S}_{\pi/2} \quad\Rightarrow\quad \phi = \tfrac{\pi}{2} + \tfrac{\pi}{4} = \tfrac{3\pi}{4}.

So the recipe is: put the qubit in an equal superposition with HH, then rotate its Bloch vector by 90°90° with SS, then by another 45°45° with TT.

Why this is useful

In algorithms such as the quantum Fourier transform, specific relative phases of the form e2πik/2ne^{2\pi i k / 2^n} are required at each step. Many of those fractions decompose into sums of π/4\pi/4 and π/2\pi/2 increments — precisely the contributions of TT and SS. Knowing how to build an exact phase from a small palette of gates is the core skill behind compiling quantum algorithms onto real hardware.

Try it

Engineer the state 12(0+ei3π/41)\tfrac{1}{\sqrt{2}}(|0\rangle + e^{i3\pi/4}|1\rangle) using HH, SS, and TT. The grader checks the full statevector (up to global phase), so both the magnitude and angle of each amplitude must match.

Run your code to see the quantum state.

After running, look at the amplitude panel: the 0|0\rangle entry should read 0.707\approx 0.707 on the positive real axis, and the 1|1\rangle entry should sit at 135°135° in the complex plane — real part 0.5\approx -0.5, imaginary part +0.5\approx +0.5 (each scaled by 12\frac{1}{\sqrt{2}}).

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