Lesson 9 of 15
Quantum Phase Estimation
Quantum Phase Estimation (QPE)
Quantum Phase Estimation solves a fundamental problem: given a unitary operator and one of its eigenstates , estimate the eigenphase such that:
The algorithm uses ancilla qubits, giving precision .
The QPE State
After the QFT-based interference step, the amplitude for measuring outcome is:
where . This is a geometric series that peaks sharply when .
When is an integer (exact case), the sum equals 1 for and 0 for all other — perfect estimation!
For example, with and bits ():
- , so amplitude is 1 for and 0 for
- Measurement returns 1 with certainty; estimate ✓
Algorithm Summary
- Initialize ancilla qubits in
- Apply Hadamard to each ancilla → uniform superposition
- Apply controlled- for
- Apply inverse QFT to ancilla register
- Measure ancilla → outcome ; estimate
import cmath, math
def qpe_state(phase, n_bits):
N = 2 ** n_bits
amplitudes = []
for m in range(N):
amp = 0
for k in range(N):
amp += cmath.exp(2j * math.pi * (phase * N - m) * k / N)
amp /= N
amplitudes.append(amp)
return amplitudes
def phase_estimation(phase, n_bits):
amps = qpe_state(phase, n_bits)
probs = [abs(a)**2 for a in amps]
best = max(range(len(probs)), key=lambda i: probs[i])
return best / (2**n_bits)
print(phase_estimation(0.25, 2)) # 0.25
Precision Scaling
With ancilla bits, QPE can distinguish phases that differ by at least . Doubling precision requires one extra qubit — an exponential improvement over classical repeated sampling.
Your Task
Implement both functions:
qpe_state(phase, n_bits)— returns the complex amplitudesphase_estimation(phase, n_bits)— returns the estimated phase as a float
Python runtime loading...
Loading...
Click "Run" to execute your code.