|q⟩ Bad Qubits

intermediate · Programming · Amplitude Amplification

Amplitude Estimation (Intro)

Amplitude amplification can boost a success probability, but it does not tell us what that probability is. Quantum amplitude estimation answers the "how much?" question: it extracts the value a=sin2 ⁣θa = \sin^2\!\theta directly, with precision that improves quadratically faster than classical sampling.

From Phase to Amplitude

Recall the amplitude-amplification operator

Q=AS0ASχ,Q = -\mathcal{A}\,S_0\,\mathcal{A}^\dagger\,S_\chi,

where A0=cosθbad+sinθgood\mathcal{A}|0\rangle = \cos\theta\,|\text{bad}\rangle + \sin\theta\,|\text{good}\rangle. This operator is a rotation by 2θ2\theta in the two-dimensional good/bad plane, so its eigenvalues are e±2iθe^{\pm 2i\theta}. Writing these as e2πiϕe^{2\pi i\phi}, the phases are

ϕ=θπandϕ=1θπ.\phi = \frac{\theta}{\pi} \quad \text{and} \quad \phi = 1 - \frac{\theta}{\pi}.

Quantum Phase Estimation (QPE) can estimate ϕ\phi to mm bits of precision using mm counting qubits and O(2m)O(2^m) controlled applications of QQ. Once ϕ^\hat{\phi} is in hand, the amplitude follows:

a^=sin2(πϕ^).\hat{a} = \sin^2(\pi\hat{\phi}).

This is amplitude estimation: the circuit reads the phase of QQ, and arithmetic converts it to the desired probability.

A Minimal Example

To keep the circuit small enough to run in a browser, we replace QQ with the simpler phase gate SS on a single state qubit. SS has the same eigenvalue structure as QQ:

S1=eiπ/21=e2πi(1/4)1,ϕ=14.S|1\rangle = e^{i\pi/2}|1\rangle = e^{2\pi i \cdot (1/4)}|1\rangle, \quad \phi = \tfrac{1}{4}.

With ϕ=1/4\phi = 1/4 the estimated amplitude is

a^=sin2 ⁣(π14)=sin2 ⁣π4=12.\hat{a} = \sin^2\!\bigl(\pi \cdot \tfrac{1}{4}\bigr) = \sin^2\!\tfrac{\pi}{4} = \tfrac{1}{2}.

Circuit Layout

We use 3 qubits: qubits 0 and 1 form the 2-bit counting register (qubit 0 = most significant bit), and qubit 2 is the state qubit.

  1. Prepare qubit 2 in 1|1\rangle (the eigenstate of SS): apply XX to qubit 2.
  2. Superpose the counting qubits: HH on qubits 0 and 1.
  3. Phase kickback — the core of QPE. Each counting qubit jj controls U2jU^{2^j} acting on the state qubit:
    • Qubit 1 (LSB, weight 20=12^0 = 1) controls S1S^1: a controlled phase of π/2\pi/2.
    • Qubit 0 (MSB, weight 21=22^1 = 2) controls S2=ZS^2 = Z: a controlled phase of π\pi.
  4. Inverse QFT on qubits 0 and 1 decodes the phase into the computational basis.
  5. Measure all qubits.

Tracing the Arithmetic

After the phase kickbacks and before the inverse QFT, the counting-register state is

12(00+i0110i11)=QFT01.\frac{1}{2}\bigl(|00\rangle + i|01\rangle - |10\rangle - i|11\rangle\bigr) = \mathrm{QFT}|01\rangle.

The inverse QFT collapses this exactly to 01|01\rangle. Combined with the state qubit remaining in 1|1\rangle, the full output is

011(q0=0,  q1=1,  q2=1).|011\rangle \quad (q_0 = 0,\; q_1 = 1,\; q_2 = 1).

Reading the counting register as a binary fraction: 021+122=14=ϕ^0 \cdot 2^{-1} + 1 \cdot 2^{-2} = \tfrac{1}{4} = \hat{\phi}. Applying the formula a^=sin2(πϕ^)=sin2(π/4)=12\hat{a} = \sin^2(\pi\hat{\phi}) = \sin^2(\pi/4) = \tfrac{1}{2} recovers the amplitude exactly.

Try it

The starter code has the state preparation, Hadamards, and the inverse QFT already in place. Add the two controlled-phase gates that implement the phase kickback. The grader checks the distribution and expects probability 1 on the outcome 011|011\rangle.

Run your code to see the quantum state.

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