Quantum Phase Estimation Tutorial: Build, Simulate, and Measure Precision
quantum phase estimationQPEquantum Fourier transformQiskitPennyLanequantum algorithms

Quantum Phase Estimation Tutorial: Build, Simulate, and Measure Precision

qqbit.vision Editorial Team
2026-11-19
7 min read

Learn how to build quantum phase estimation, interpret eigenphases, and balance precision, qubits, circuit depth, and shots.

This quantum phase estimation tutorial shows how to build the circuit, simulate its measurement distribution, interpret the measured phase as an eigenvalue, and estimate the cost of improving precision. The workflow is designed for Qiskit or PennyLane users, while keeping the algorithmic steps visible enough to debug when a framework API, qubit-order convention, or backend changes.

Overview

Quantum phase estimation (QPE) estimates the phase φ in the eigenvalue equation

U|ψ⟩ = e2πiφ|ψ⟩

Here, U is a unitary operator and |ψ⟩ is one of its eigenstates. The phase is a number between 0 and 1, represented in binary. If the eigenvalue is -1, for example, then e2πiφ = -1 and the phase is φ = 1/2.

QPE uses three components:

  1. An estimation register of m qubits, initialized in superposition.
  2. A controlled-unitary block that applies U2j when estimation qubit j is active.
  3. An inverse quantum Fourier transform (inverse QFT) that converts relative phase into a computational-basis bit string.

After measurement, an integer y from 0 through 2m-1 gives the estimate φ̂ = y/2m. This is a resolution estimate, not a guarantee that every individual shot returns the nearest value. The input state must be an eigenstate, or close enough to one for the desired interpretation. If it is a superposition of eigenstates, the circuit samples from the corresponding eigenphases.

QPE is used as a building block in quantum eigenvalue estimation, Hamiltonian simulation, and some approaches to quantum chemistry. It is also a useful circuit for learning how controlled operations, Fourier transforms, measurement statistics, and resource constraints interact.

How to estimate

1. Choose the precision register

Choose m, the number of estimation qubits. The nominal grid spacing is:

Δφ = 1/2m

For example, three estimation qubits represent eight grid points, so the displayed phase values are separated by 1/8. Increasing m improves the representable resolution but adds qubits and controlled-unitary work.

2. Prepare the eigenstate

Initialize the system register in |ψ⟩. For a first test, choose a unitary with an easy-to-prepare eigenstate. A single-qubit phase gate is useful because computational-basis states remain easy to prepare and the expected phase can be calculated independently.

3. Apply Hadamard gates

Apply a Hadamard gate to every estimation qubit. This creates the uniform superposition required to query several powers of U in one coherent circuit.

4. Build controlled powers of U

For estimation qubit j, apply a controlled version of:

U2j

The powers usually dominate the implementation cost. If U is supplied as a circuit, construct the required power by repeating its gates or by using a native powered operator when the framework supports one. Do not assume that a mathematically compact unitary has a compact hardware decomposition; inspect the transpiled circuit before comparing resources.

5. Apply the inverse QFT

Apply the inverse QFT to the estimation register only. The inverse transform removes the phase relationships created by the controlled powers and concentrates the result near the binary representation of φ.

In a Qiskit-style circuit, the logical structure looks like this:

precision = 3
qc = QuantumCircuit(precision + system_qubits, precision)

# Prepare the eigenstate in the system register.
prepare_eigenstate(qc, system_wires)

# Create the estimation superposition.
for j in range(precision):
    qc.h(j)

# Apply controlled U^(2^j).
for j in range(precision):
    controlled_power = make_controlled_power(U, 2**j)
    qc.append(controlled_power, [j] + system_wires)

# Apply inverse QFT to the estimation register.
qc.append(inverse_qft(precision), range(precision))
qc.measure(range(precision), range(precision))

The helper names in this example are deliberately explicit rather than tied to one release. In a current Qiskit implementation, use the framework's controlled-gate and QFT utilities, then verify qubit order and whether the QFT helper includes swaps. In PennyLane, the same logical sequence can be expressed with Hadamards, controlled powers, an inverse QFT operation or decomposition, and measurement of the estimation wires. Check the installed version's documentation before copying helper names into production code.

6. Convert counts into a phase estimate

For each measured bit string:

  1. Confirm whether the framework reports the most-significant bit first or last.
  2. Reverse the string if required by the circuit's wire convention.
  3. Convert the corrected binary string to an integer y.
  4. Compute φ̂ = y/2m.

Use the most frequent bit string as a simple estimate, but retain the full histogram. A broad or split histogram can indicate finite-shot uncertainty, an imperfect eigenstate, noise, an incorrect controlled power, or an inverse-QFT ordering error.

Inputs and assumptions

Before running QPE, record the following inputs. They make results reproducible and make later recalculation straightforward.

  • Unitary definition: Specify the circuit or matrix for U, its system-qubit order, and the expected eigenvalue or phase when available.
  • Eigenstate preparation: Document how the system state is created and whether it is an exact eigenstate, an approximate eigenstate, or an unknown superposition.
  • Precision: Record m and the nominal spacing 1/2m.
  • Controlled-power construction: Record whether powers are repeated circuits, analytically generated gates, or backend-native operations.
  • Shots: Record the number of repetitions used to form the histogram. More shots improve confidence in the distribution but do not remove systematic circuit errors.
  • Backend model: State whether the result came from an exact statevector simulator, a shot-based simulator, a noisy simulator, or hardware.
  • Compilation settings: Save the transpiled depth, two-qubit-gate count, connectivity assumptions, and basis gates where available.

A useful resource comparison is:

ChoicePhase resolutionEstimation qubitsMain costShot consideration
m bits1/2mmControlled U powers and inverse QFTEnough shots to distinguish nearby peaks
More precisionFiner gridMoreGreater circuit width and depthUsually requires a larger sampling budget
Approximate QPEConfigurablePotentially fewerRequires a chosen approximation strategyInterpret results with its error model

For a broader simulator workflow, compare ideal and noisy backends using quantum simulator benchmarking. For regression checks, pair QPE with the invariants and circuit tests described in How to Test Quantum Programs.

Worked examples

Exact phase on an ideal simulator

Suppose U has an eigenstate with phase φ = 1/8. Choose m = 3. The expected binary representation is 001, so the ideal measurement distribution should concentrate at the integer y = 1. The estimate is:

φ̂ = 1/8 = 0.125

Run this case first with an exact simulator, then with a finite-shot simulator. If the exact result does not map to 001 under your chosen bit convention, inspect the inverse-QFT swaps and measurement mapping before changing the algorithm.

Phase between grid points

Now suppose the true phase is φ = 0.30 and again use m = 3. The grid spacing is 0.125; nearby grid points are 0.25 and 0.375. Since the phase is not exactly representable with three bits, the histogram can spread across neighboring integers. Increasing to m = 5 changes the spacing to 0.03125, giving a closer binary approximation at the cost of additional controlled powers.

Record results in a table like this:

RunUnitaryEigenstatemShotsMost likely bitsφ̂Error
Ideal baselineTest UKnown3Statevector0010.125|φ̂ − φ|
Finite shotsTest UKnown3Record valueRecord valueRecord valueRecord value
Higher precisionTest UKnown5Record valueRecord valueRecord valueRecord value

For a realistic application, substitute the phase-estimation unitary for an operator from a larger workflow, such as a Hamiltonian-related circuit. Keep the QPE test case separate from application logic so that a change in an ansatz, optimizer, or data encoding does not hide a basic phase-readout defect. Related hybrid examples are covered in the VQE implementation and benchmarking workflow.

When to recalculate

Recalculate the estimate whenever an input that affects phase resolution, circuit execution, or measurement interpretation changes. In particular, rerun the workflow when:

  • You increase or decrease the number of estimation qubits.
  • You replace the unitary, eigenstate-preparation circuit, or controlled-power implementation.
  • You change Qiskit, PennyLane, a QFT helper, measurement conventions, or transpilation settings.
  • You move from an ideal simulator to a noisy simulator or hardware backend.
  • The compiled depth, connectivity mapping, or two-qubit-gate count changes materially.
  • You change the shot count and need to compare confidence in the measured peak.
  • The output histogram develops secondary peaks, broadening, or unexpected bit-order patterns.

Use a three-stage validation loop: first verify the known phase on an ideal simulator, then compare shot-based results, and finally evaluate the compiled circuit under the intended noise model or hardware conditions. Save the circuit, software versions, precision, shots, counts, and phase-conversion convention with every run. If noise becomes the limiting factor, consult this practical guide to error mitigation in quantum computing. That record turns QPE from a one-off demonstration into a repeatable quantum programming tutorial workflow that can be revisited as operators, frameworks, and backends evolve.

Related Topics

#quantum phase estimation#QPE#quantum Fourier transform#Qiskit#PennyLane#quantum algorithms
q

qbit.vision Editorial Team

Quantum Computing Editors

Senior editor and content strategist. Writing about technology, design, and the future of digital media. Follow along for deep dives into the industry's moving parts.