Curriculum / Real-World Quantum Python / Quantum Phase Estimation
Quantum Phase Estimation
Implement Quantum Phase Estimation (QPE), the engine behind Shor's algorithm and many quantum chemistry calculations.
Quantum Phase Estimation
Quantum Phase Estimation (QPE) is the central subroutine of Shor's factoring algorithm, quantum chemistry solvers, and HHL for linear systems. Given a unitary U and its eigenstate , QPE extracts the phase where .
The Problem
If is an eigenstate of U with eigenvalue , we want to find . Classically, this requires queries to U for -precision. QPE achieves -precision with queries: a quadratic improvement.
Circuit Structure
QPE uses two registers:
- •Phase register: n ancilla qubits (determines precision: φ is estimated to 2⁻ⁿ)
- •Target register: one or more qubits prepared in the eigenstate |u⟩
Steps:
- 1.Apply H to all n ancilla qubits → uniform superposition
- 2.For each ancilla qubit k (k = 0, 1, ..., n−1): apply controlled- where ancilla qubit k is the control and is the target
- 3.Apply the inverse Quantum Fourier Transform (QFT†) to the ancilla register
- 4.Measure the ancilla: the binary outcome encodes φ to n bits
Why Does It Work?
After step 2, the ancilla is in the state:
This is exactly a QFT of |φ⟩ in binary. The inverse QFT undoes this transform, concentrating amplitude at the value of φ. Measuring gives the n-bit binary representation of φ with high probability.
Precision: With n ancilla qubits, φ is estimated to 2⁻ⁿ. For φ = 1/8 = 0.001₂, three ancilla qubits suffice.
Controlled-Phase Operation
For our unitary : (eigenvalue with phase , so ).
The controlled- applies U times when the control is . Since U is a phase rotation: . This is equivalent to a controlled phase gate .
This is the opening of the lesson. The full walkthrough, the interactive circuit, and the graded challenge continue inside myqubit.
How this lesson works
A hands-on coding challenge. You write Qiskit-compatible Python in the browser editor, run it instantly via WebAssembly, watch the circuit and Bloch sphere react, and pass automatic output checks. The AI tutor Qubitus gives Socratic hints if you get stuck.
Part of: Real-World Quantum Python
Write production-quality quantum Python, circuit optimization, hybrid algorithms, cloud backends, noise modeling, and software engineering patterns.
This lesson is part of Pro
Unlock Real-World Quantum Python and all 10 tracks with Pro: $12.99/month, $79/year, or $97 lifetime. Start with the free track first if you are new.