|q⟩ Bad Qubits

intermediate · Programming · Quantum Phase Estimation

Single-Qubit Phase Estimation

The full Quantum Phase Estimation (QPE) circuit can use many ancilla qubits to achieve high precision, but the essential ideas are already present when the counting register contains just one qubit. In that simplest case the entire algorithm fits in two qubits and four gates, yet it already demonstrates phase kickback and the inverse QFT working together to extract an eigenphase.

The two-qubit QPE circuit

Let UU be a unitary with eigenvector u|u\rangle satisfying

Uu=e2πiφu,φ[0,1).U|u\rangle = e^{2\pi i \varphi}|u\rangle, \qquad \varphi \in [0,1).

We allocate two qubits:

The circuit has three stages.

Stage 1 — Superpose the counting qubit.

H0=12(0+1).H|0\rangle = \tfrac{1}{\sqrt{2}}\bigl(|0\rangle + |1\rangle\bigr).

The full state is now 12(0+1)u\tfrac{1}{\sqrt{2}}\bigl(|0\rangle + |1\rangle\bigr) \otimes |u\rangle.

Stage 2 — Controlled-UU (phase kickback).

Apply UU to the eigenstate register only when the counting qubit is 1|1\rangle. Because u|u\rangle is an eigenstate, this does not entangle the two registers in amplitude — it merely multiplies the 1|1\rangle amplitude of the counting qubit by the eigenvalue e2πiφe^{2\pi i\varphi}:

12(0u+1e2πiφu)=12(0+e2πiφ1)u.\tfrac{1}{\sqrt{2}}\bigl(|0\rangle \cdot |u\rangle + |1\rangle \cdot e^{2\pi i\varphi}|u\rangle\bigr) = \tfrac{1}{\sqrt{2}}\bigl(|0\rangle + e^{2\pi i\varphi}|1\rangle\bigr) \otimes |u\rangle.

The eigenstate register is unchanged; the phase has been kicked back into the counting qubit.

Stage 3 — Inverse QFT on 1 qubit.

The 1-qubit QFT is just HH, so the inverse QFT is also HH. Applying HH to the counting qubit:

H(0+e2πiφ12)=(1+e2πiφ)0+(1e2πiφ)12.H\Bigl(\tfrac{|0\rangle + e^{2\pi i\varphi}|1\rangle}{\sqrt{2}}\Bigr) = \frac{(1+e^{2\pi i\varphi})|0\rangle + (1-e^{2\pi i\varphi})|1\rangle}{2}.

Measuring the counting qubit now yields:

P(0)=1+e2πiφ22=cos2(πφ),P(1)=sin2(πφ).P(0) = \left|\frac{1+e^{2\pi i\varphi}}{2}\right|^2 = \cos^2(\pi\varphi), \qquad P(1) = \sin^2(\pi\varphi).

A worked example: the ZZ gate

The ZZ gate acts on its eigenstate 1|1\rangle as

Z1=1=eiπ1=e2πi1/21,Z|1\rangle = -|1\rangle = e^{i\pi}|1\rangle = e^{2\pi i \cdot 1/2}|1\rangle,

so φ=1/2\varphi = 1/2. Plugging into the formula above:

P(0)=cos2 ⁣(π12)=cos2 ⁣(π2)=0,P(1)=sin2 ⁣(π2)=1.P(0) = \cos^2\!\left(\pi \cdot \tfrac{1}{2}\right) = \cos^2\!\left(\tfrac{\pi}{2}\right) = 0, \qquad P(1) = \sin^2\!\left(\tfrac{\pi}{2}\right) = 1.

The counting qubit is measured as 1 with certainty, encoding the 1-bit binary fraction 0.12=1/2=φ0.1_2 = 1/2 = \varphi exactly. Because φ=1/2\varphi = 1/2 is representable in one bit there is no approximation error.

In the circuit this means:

  1. c.x(1) — prepare the eigenstate 1|1\rangle on qubit 1.
  2. c.h(0) — put the counting qubit into superposition.
  3. c.cz(0, 1) — controlled-ZZ performs the phase kickback (CZ multiplies 11|11\rangle by 1-1, which is exactly controlled-ZZ acting on the 1|1\rangle eigenstate of ZZ).
  4. c.h(0) — inverse QFT undoes the superposition and converts the phase to a basis state.
  5. c.measure(0) — read out the estimated phase bit.

Try it

Complete the circuit below. The eigenstate 1|1\rangle is already prepared and the first Hadamard is in place. Your task is to add the controlled-Z (the controlled-UU step) and the second Hadamard (the inverse QFT), then measure the counting qubit. The grader checks the output distribution: all probability should land on bitstring 11 (counting qubit = 1, eigenstate qubit = 1, with qubit 0 most significant).

Run your code to see the quantum state.

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