Chapter 5: Quantum Fourier Transform and Phase Estimation#

This chapter derives the quantum Fourier transform and quantum phase estimation, with explicit bit ordering, finite-register probabilities and controlled-evolution resource counts. Iterative and Bayesian variants are discussed, followed by energy estimation for the model Hamiltonians of the preceding chapters. We distinguish rounding error, Hamiltonian-simulation error, overlap and conditional-state fidelity. The Harrow–Hassidim–Lloyd linear-system algorithm illustrates coherent use of eigenvalue information, including finite-clock postselection, conditioning and readout costs. Examples cover a discrete Poisson problem and a real-frequency resolvent; complex frequencies require a Hermitian embedding. NumPy programs and an executable notebook provide reproducible checks of the derivations and numerical examples.

\[ \newcommand{\bm}[1]{\boldsymbol{#1}} \newcommand{\wick}[1]{\overline{#1}} \newcommand{\matr}[1]{\boldsymbol{#1}} \newcommand{\bfv}[1]{\boldsymbol{#1}} \renewcommand{\vec}[1]{\boldsymbol{#1}} \newcommand{\uvec}[1]{\boldsymbol{\hat{#1}}} \newcommand{\op}[1]{\widehat{#1}} \newcommand{\Op}[1]{\boldsymbol{\widehat{#1}}} \newcommand{\OP}[1]{\boldsymbol{\widehat{#1}}} \newcommand{\Det}[1]{|\boldsymbol{#1}|} \newcommand{\bigO}{\mathcal{O}} \newcommand{\var}{\mathrm{Var}} \newcommand{\cov}{\mathrm{Cov}} \newcommand{\real}[1]{\mathrm{Re}\left\{#1\right\}} \newcommand{\ud}[1]{d#1} \newcommand{\udd}[1]{d^2#1} \newcommand{\mean}[1]{\langle #1 \rangle} \newcommand{\overlap}[2]{\langle #1 | #2 \rangle} \newcommand{\bracket}[3]{\langle #1 | #2 | #3 \rangle} \newcommand{\projection}[2]{| #1 \rangle \langle #2 |} \newcommand{\brab}[1]{\big\langle #1 \big|} \newcommand{\ketb}[1]{\big| #1 \big\rangle} \newcommand{\bket}[1]{\vert #1\rangle} \newcommand{\bbra}[1]{\langle #1\vert} \newcommand{\ketbra}[2]{\vert #1\rangle\langle #2\vert} \newcommand{\braket}[2]{\langle #1\vert #2\rangle} \]
# Put every BookPrograms/chapter*/ and BookPrograms/common/ on sys.path
import sys, pathlib
root = pathlib.Path.cwd().resolve()
while not (root / 'BookPrograms').is_dir() and root.parent != root:
    root = root.parent
sys.path[:0] = sorted(str(p) for p in (root / 'BookPrograms').iterdir() if p.is_dir())
import numpy as np

Introduction#

Every method of Chapter 3 was classical, and several of them ran into the exponential wall of Section The exponential wall: the number of Slater determinants that can be built from \(M\) single-particle states is \(\binom{M}{N}\), exponential in \(M\) at fixed filling. This is the cost of storing a general state in that basis, not a proof that every physical instance requires exponential classical work. Section From fermions to qubits moved the wall rather than removing it, by storing a state of \(M\) modes in \(M\) qubits instead of in \(2^M\) complex numbers, and it left every model of the book as a Pauli sum \(\hat{H}=\sum_\alpha h_\alpha P_\alpha\) together with the circuits that exponentiate it term by term. The question is then what can actually be computed with such a register, and this chapter answers it for the one quantity we have wanted throughout: an eigenvalue of a Hamiltonian.

The algorithm is quantum phase estimation. Its input is a unitary and one of its eigenstates; its output is the eigenphase, written out in binary in a register of qubits, to a precision that improves exponentially with the size of that register, while the total controlled evolution time grows exponentially as well. Its engine is the quantum Fourier transform, which is the subject of the first part of the chapter and which is worth the space: the QFT is the transformation that converts phase information into computational-basis information, and it underlies phase estimation and important period-finding algorithms. Nothing new is needed from the formalism. Chapter 2 set out the gate model, with states \(\vert x_1x_2\cdots x_n\rangle\) in the computational basis, unitaries acting on one or two qubits at a time and measurements given by projections, and observed that quantum computing is a restricted form of linear algebra: matrix-vector multiplications with special unitary matrices on exponentially large vectors. This chapter is that observation carried through to an algorithm.

The chapter runs in four parts. The first, Sections From the discrete Fourier transform to the quantum one–Cost, approximation and conventions, is the quantum Fourier transform: the definition, the product form derived twice, the circuit, the gate count, the approximate transform and the bit-ordering convention that causes more confusion than any other detail of the subject. The second, Sections Quantum phase estimation and From phases to energies, is phase estimation: the algorithm, why the inverse QFT is the right final step, the exact and the inexact case, the precision, the one-control-qubit variants, and the bridge from the eigenphases of \(e^{-i\hat{H}t}\) to energies. The third, Sections Two small Hamiltonians, worked through and The model Hamiltonians on a quantum computer, runs the algorithm on the Hamiltonians of Section The four models on a qubit register, from the one-qubit pairing Hamiltonian of Eq. (3.80) to the eight-qubit Hubbard ring, and confronts the two errors that a real calculation must balance, the finite register and the Trotterization of the evolution operator, as well as the question of what happens when the input is not an eigenstate. The fourth, Section An application: the linear-system algorithm of Harrow, Hassidim and Lloyd, is an application of phase estimation to something other than an energy: the algorithm of Harrow, Hassidim and Lloyd for linear systems of equations, which uses the phase register to invert a matrix spectrally, and which we apply to a discretized differential equation and to the resolvent \((z-\hat{H})^{-1}\) of a many-body Hamiltonian, the object behind every Green’s function. The programs are in LectureMaterial/BookPrograms/chapter5/: a QFT built gate by gate on the simulator of Chapter 2 and checked against the Fourier matrix, a PhaseEstimation class, the model calculations, and an HHL class. Every number quoted below comes from them.

From the discrete Fourier transform to the quantum one#

The classical discrete Fourier transform of a vector \(x=(x_0,\dots,x_{N-1})\) is

\[ y_k = \frac{1}{\sqrt{N}}\sum_{j=0}^{N-1}x_j\,e^{2\pi i jk/N}, \qquad k=0,\dots,N-1 ,\tag{5.1} \]

that is, multiplication by the unitary matrix

\[\begin{equation*} \matr{F}_N = \frac{1}{\sqrt{N}} \begin{pmatrix} 1 & 1 & 1 & \cdots & 1\\ 1 & \omega & \omega^2 & \cdots & \omega^{N-1}\\ 1 & \omega^2 & \omega^4 & \cdots & \omega^{2(N-1)}\\ \vdots & \vdots & \vdots & \ddots & \vdots\\ 1 & \omega^{N-1} & \omega^{2(N-1)} & \cdots & \omega^{(N-1)^2} \end{pmatrix}, \qquad \omega = e^{2\pi i/N} .\tag{5.2} \end{equation*}\]

The matrix is unitary, \(\matr{F}_N^{\dagger}\matr{F}_N=\matr{I}\), by the orthogonality relation \(\sum_{j}\omega^{j(k-k')}=N\delta_{kk'}\); it therefore preserves inner products and norms, which is exactly the condition for a matrix to be an admissible quantum gate. Its columns are an orthonormal basis, and \(\matr{F}_N\) is the change of basis between them and the computational basis.

The quantum Fourier transform is the same matrix, applied to the amplitudes of a quantum state. For \(N=2^{n}\) it is the unitary defined on the computational basis \(\vert x\rangle\) of \(n\) qubits by

\[ \mathrm{QFT}_N\vert x\rangle = \frac{1}{\sqrt{N}} \sum_{k=0}^{N-1}e^{2\pi i xk/N}\vert k\rangle, \qquad x=0,\dots,N-1 ,\tag{5.3} \]

and extended to a general state \(\vert\psi\rangle=\sum_x c_x\vert x\rangle\) by linearity, \(\mathrm{QFT}_N\vert\psi\rangle=\sum_x c_x\,\mathrm{QFT}_N\vert x\rangle\). Here and throughout the chapter the integer \(x\) and the bit string \(x_1x_2\cdots x_n\) of the register are the same object, with qubit \(0\) of Chapters 2 and 3 holding the most significant bit \(x_1\),

\[ x = \sum_{j=1}^{n}x_j 2^{n-j}, \qquad x_j\in\{0,1\} .\tag{5.4} \]

The QFT acts on \(N=2^n\) amplitudes using \(\bigO(n^2)\) ideal gates, whereas the classical FFT computes an explicit length-\(N\) vector in \(\bigO(N\log N)\) operations. These are different input and output tasks. A computational-basis measurement samples \(\vert y_k\vert^2\); it does not reveal the complex vector \(y\). Preparing arbitrary input amplitudes and recovering the complete output can remove the apparent speedup. The QFT is useful when an efficiently prepared input and subsequent interference make a small amount of desired information accessible, as in phase estimation. It is not a general replacement for the classical FFT.

The product form#

Everything about the QFT circuit follows from rewriting Eq. (5.3) as a product of one-qubit states. We do it twice: once in general, and once explicitly for two qubits, where every step can be followed by eye. Besides the binary expansion (5.4) we need the binary fraction

\[ 0.x_jx_{j+1}\dots x_n = \frac{x_j}{2}+\frac{x_{j+1}}{2^2} + \dots + \frac{x_n}{2^{n-j+1}} .\tag{5.5} \]

This notation is not a convenience: the phases of the QFT factor into exactly such fractions, and the same fractions reappear as the output of phase estimation in Section Quantum phase estimation.

The general derivation. Start from Eq. (5.3) with \(N=2^n\) and write the output label in binary, \(k=\sum_{m=1}^{n}k_m2^{n-m}\). Then

\[ \frac{xk}{2^n} = x\sum_{m=1}^{n}\frac{k_m}{2^{m}}, \qquad\text{so}\qquad e^{2\pi i xk/2^n} = \prod_{m=1}^{n}e^{2\pi i x k_m/2^{m}} .\tag{5.6} \]

The exponential has factorized into one term per output qubit, and each term depends on \(k\) only through the single bit \(k_m\). A sum over all \(k\) is a sum over all the bits independently, so it factorizes too:

\[ \mathrm{QFT}_N\vert x\rangle = \frac{1}{2^{n/2}} \bigotimes_{m=1}^{n}\left(\vert 0\rangle+e^{2\pi i x/2^{m}}\vert 1\rangle\right) .\tag{5.7} \]

Finally, \(e^{2\pi i x/2^m}\) depends only on the fractional part of \(x/2^m\), and that fractional part is precisely the binary fraction \(0.x_{n-m+1}x_{n-m+2}\dots x_n\). Hence

\[\begin{equation*} \begin{aligned} \mathrm{QFT}_N\vert x_1x_2\dots x_n\rangle = \frac{1}{2^{n/2}} &\left(\vert 0\rangle+e^{2\pi i\,0.x_n}\vert 1\rangle\right) \otimes\left(\vert 0\rangle+e^{2\pi i\,0.x_{n-1}x_n}\vert 1\rangle\right)\\ &\otimes\cdots\otimes \left(\vert 0\rangle+e^{2\pi i\,0.x_1x_2\dots x_n}\vert 1\rangle\right) . \end{aligned}\tag{5.8} \end{equation*}\]

Three consequences, all of them important. First, the output is a product state: the QFT of a computational basis state is completely unentangled, and each qubit carries a phase and nothing else. It is worth pausing on that, because the \(\bigotimes\) in Eq. (5.8) is doing real work. A general state of \(n\) qubits needs \(2^n\) amplitudes; a product state needs \(2n\). The QFT of a basis state is therefore compactly describable. The particular binary-phase structure, rather than separability alone, gives a single efficient circuit that works coherently on every input. Second, the first output qubit depends only on the last input bit, the second on the last two, and so on. This is already the mathematical output order of \(F_N\); the circuit below first produces these factors in the opposite wire order and then reverses the wires. Third, each factor can be produced by a Hadamard followed by a few controlled phase rotations, which is the circuit.

Two qubits, explicitly. For \(n=2\), write \(\vert x\rangle=\vert x_1x_2\rangle\) with \(x=2x_1+x_2\), and \(k=2k_1+k_2\). Then

\[ \mathrm{QFT}_4\vert x_1x_2\rangle = \frac{1}{2} \sum_{k_1,k_2\in\{0,1\}} e^{2\pi i(2x_1+x_2)(2k_1+k_2)/4}\vert k_1k_2\rangle ,\tag{5.9} \]

and the exponent expands as

\[ \frac{(2x_1+x_2)(2k_1+k_2)}{4} = x_1k_1 + \frac{x_1k_2}{2} + \frac{x_2k_1}{2} + \frac{x_2k_2}{4} .\tag{5.10} \]

The first term is an integer, so \(e^{2\pi i x_1k_1}=1\) and it drops out. This is the essential simplification, and it is what makes the QFT efficient: the high-order products of input and output bits contribute nothing at all. Collecting what remains by output bit,

\[ e^{2\pi i xk/4} = e^{2\pi i k_1\left(\frac{x_2}{2}\right)}\, e^{2\pi i k_2\left(\frac{x_1}{2}+\frac{x_2}{4}\right)} = e^{2\pi i k_1(0.x_2)}\,e^{2\pi i k_2(0.x_1x_2)} ,\tag{5.11} \]

so the sum factorizes into

\[ \mathrm{QFT}_4\vert x_1x_2\rangle = \frac{1}{\sqrt2}\left(\vert 0\rangle+e^{2\pi i\,0.x_2}\vert 1\rangle\right) \otimes \frac{1}{\sqrt2}\left(\vert 0\rangle+e^{2\pi i\,0.x_1x_2}\vert 1\rangle\right) ,\tag{5.12} \]

which is Eq. (5.8) for \(n=2\). The first factor depends only on \(x_2\) and the second on both bits: the least significant phase appears first, which is the reversal again, now visible in three lines of algebra.

The circuit#

Two gates suffice, and both are in Chapter 2. The Hadamard \(\mathrm{H}=(X+Z)/\sqrt2\) creates an equal superposition, and the phase rotation

\[\begin{equation*} R_k = \begin{pmatrix}1 & 0\\ 0 & e^{2\pi i/2^{k}}\end{pmatrix}\tag{5.13} \end{equation*}\]

adds one binary digit to the phase. \(R_k\) is a rotation about the \(z\) axis up to a global phase, \(R_k = e^{i\pi/2^{k}}R_z(2\pi/2^{k})\), and \(R_1=Z\), \(R_2=S\), \(R_3=T\) are the standard names. A controlled \(R_k\) applies the rotation only on the subspace where the control qubit is \(\vert 1\rangle\); it is symmetric in its two qubits, since it multiplies the single amplitude of \(\vert 11\rangle\) by \(e^{2\pi i/2^k}\) and leaves the other three alone.

Read Eq. (5.8) backwards to see the construction. The last output factor carries the phase \(e^{2\pi i\,0.x_1x_2\dots x_n}\). A Hadamard on qubit \(1\) produces \(\vert 0\rangle+e^{2\pi i\,0.x_1}\vert 1\rangle\), since \(\mathrm{H}\vert x_1\rangle=(\vert 0\rangle+(-1)^{x_1}\vert 1\rangle)/\sqrt2\) and \((-1)^{x_1}=e^{2\pi i\,0.x_1}\), and controlled rotations from qubits \(2,3,\dots,n\) append the digits \(x_2,x_3,\dots,x_n\) one at a time: a controlled \(R_2\) from qubit \(2\) multiplies the \(\vert 1\rangle\) component by \(e^{2\pi i x_2/4}\), a controlled \(R_3\) from qubit \(3\) by \(e^{2\pi i x_3/8}\), and so on. The same pattern then repeats on qubit \(2\), which needs the digits \(x_3,\dots,x_n\), and so on down the register. At the end the qubit that was processed first holds the last factor of Eq. (5.8), so the register is reversed with \(\lfloor n/2\rfloor\) SWAP gates. Figures 5.1 and 5.2 show the result for two and three qubits, and for \(n=3\) the product form reads

\[ \mathrm{QFT}_8\vert x_1x_2x_3\rangle = \frac{1}{\sqrt8} \left(\vert 0\rangle+e^{2\pi i\,0.x_3}\vert 1\rangle\right) \otimes\left(\vert 0\rangle+e^{2\pi i\,0.x_2x_3}\vert 1\rangle\right) \otimes\left(\vert 0\rangle+e^{2\pi i\,0.x_1x_2x_3}\vert 1\rangle\right),\tag{5.14} \]

so the first qubit needs the phase contributions \(x_2/4+x_3/8\), which is exactly what the controlled \(R_2\) and \(R_3\) of Fig. 5.2 supply.

The two-qubit QFT a Hadamard on qubit , a controlled  with , a Hadamar

Figure 5.1: The two-qubit QFT: a Hadamard on qubit \(1\), a controlled \(R_2\) with \(R_2=\mathrm{diag}(1,e^{i\pi/2})\), a Hadamard on qubit \(2\), and a SWAP that undoes the reversal of Eq. (5.12).

The three-qubit QFT. Hadamard on , then controlled  and  from  and  Ha

Figure 5.2: The three-qubit QFT. Hadamard on \(x_1\), then controlled \(R_2\) and \(R_3\) from \(x_2\) and \(x_3\); Hadamard on \(x_2\), then a controlled \(R_2\) from \(x_3\); Hadamard on \(x_3\); then the reversal, which for three qubits is a single SWAP of the outer pair. The nested triangular structure is the general pattern.

The general \(n\)-qubit circuit is therefore: for \(j=1,\dots,n\), apply a Hadamard to qubit \(j\) and then, for each later qubit \(k>j\), a controlled \(R_{k-j+1}\) with control \(k\) and target \(j\); finally reverse the register. The function qft_circuit in qft.py builds it as a Circuit of Chapter 2, in the same dozen lines,

from qft import qft_circuit, qft_matrix
from statevector import StateVector
import numpy as np

circ = qft_circuit(3)                       # H, controlled R_k, SWAP, Fig. 6.3
print(circ.draw())
print(np.abs(circ.unitary() - qft_matrix(3)).max())      # the Fourier matrix, to 1e-15
out = circ.run(StateVector.from_bits("101"))
print(np.round(out.psi, 4))                 # the eight amplitudes of QFT_8 |101>
q0: |0>--[H]-[R2]-[R3]---------------x---
q1: |0>-------*----|---[H]-[R2]------|---
q2: |0>------------*--------*---[H]--x---
1.415262216750919e-15
[ 0.3536+0.j     -0.25  -0.25j    0.    +0.3536j  0.25  -0.25j
 -0.3536+0.j      0.25  +0.25j   -0.    -0.3536j -0.25  +0.25j  ]

and the script checks, for \(n\) up to five, that the unitary of the circuit is the matrix of Eq. (5.2), that its action on every basis state is the product state of Eq. (5.8) built with no circuit at all, that its action on a random state is numpy.fft.ifft with orthonormal scaling, and that the inverse circuit undoes it, all to \(3.5\times10^{-15}\). The second check is the one that matters, since the product form is built directly from the binary-fraction factorization and therefore tests the derivation rather than the implementation’s self-consistency.

A worked example#

Take \(\vert x\rangle=\vert 101\rangle\), so \(x_1=1\), \(x_2=0\), \(x_3=1\) and \(x=5\). The product form gives

\[ \mathrm{QFT}_8\vert 101\rangle = \frac{1}{\sqrt8} \left(\vert 0\rangle+e^{2\pi i\,0.1}\vert 1\rangle\right) \otimes\left(\vert 0\rangle+e^{2\pi i\,0.01}\vert 1\rangle\right) \otimes\left(\vert 0\rangle+e^{2\pi i\,0.101}\vert 1\rangle\right) .\tag{5.15} \]

Evaluating the binary fractions, \(0.1=\tfrac12\), \(0.01=\tfrac14\) and \(0.101=\tfrac12+\tfrac18=\tfrac58\), so \(e^{2\pi i\,0.1}=-1\), \(e^{2\pi i\,0.01}=i\), \(e^{2\pi i\,0.101}=e^{5\pi i/4}\), and

\[ \mathrm{QFT}_8\vert 101\rangle = \frac{1}{\sqrt8} \left(\vert 0\rangle-\vert 1\rangle\right)\otimes\left(\vert 0\rangle+i\vert 1\rangle\right) \otimes\left(\vert 0\rangle+e^{5\pi i/4}\vert 1\rangle\right) .\tag{5.16} \]

Expanding the product gives eight amplitudes, all of modulus \(1/\sqrt8=0.353553\), with the phase of \(\vert k\rangle\) equal to \(2\pi\times(5k/8 \bmod 1)\), which is Eq. (5.3) with \(x=5\), as it must be. qft.py prints the eight amplitudes and confirms both statements, and Fig. 5.3 draws them.

The eight amplitudes of mathrmQFT8vert 101rangle, drawn as vectors in

Figure 5.3: The eight amplitudes of \(\mathrm{QFT}_8\vert 101\rangle\), drawn as vectors in the complex plane and labeled by the output basis state \(\vert k\rangle\) they belong to. Every one of them has the same modulus \(1/\sqrt8=0.3536\), marked by the dashed circle, and the phase of \(\vert k\rangle\) is \(2\pi\times(5k/8\bmod1)\). Since \(5\) and \(8\) have no common factor the eight vectors occupy the eight eighth-roots of unity exactly once each, reached in the order \(0,5,2,7,4,1,6,3\) as \(k\) runs from \(0\) to \(7\). Produced by qft.py.

Two things in Fig. 5.3 are worth dwelling on, and both are properties of the transform rather than of this particular input. The first is that all eight vectors have the same length. A measurement of the transformed register in the computational basis would return each of the eight outcomes with probability \(1/8\), that is, it would return no information about the input label \(x\): the entire content of \(\mathrm{QFT}_8\vert 101\rangle\) sits in the angles, and angles are exactly what a single measurement cannot see. This is the disappointment of Section From the discrete Fourier transform to the quantum one made visual. For a suitable superposition input, however, a QFT or inverse QFT immediately followed by measurement can reveal useful information. The second is the arrangement of the angles. Reading the labels anticlockwise from \(\vert 000\rangle\) gives \(0,5,2,7,4,1,6,3\), which is the sequence \(5k\bmod 8\): the input integer has been turned into a rotation rate, one eighth of a turn per unit of \(x\) per unit of \(k\). Because \(5\) is coprime to \(8\) the rate is primitive and the eight vectors are all distinct, whereas for \(x=4\) the phase \(4k/8\) takes only the two values \(0\) and \(\tfrac12\), and the eight vectors would pile up four deep on two positions. This is a periodic pattern of amplitudes, not a peaked measurement distribution. Shor’s period-finding procedure instead Fourier transforms a superposition over periodic input values; interference then produces peaks in the measurement probabilities. The product form can be traced directly in the picture: expanding Eq. (5.16), the amplitude of \(\vert k_1k_2k_3\rangle\) is \((-1)^{k_1}\,i^{k_2}\,e^{5\pi ik_3/4}/\sqrt8\), so the first output bit contributes a half-turn, the second a quarter-turn and the third five-eighths of a turn, independently of one another. Three angles, one per qubit, generate all eight, and that is the reason the circuit needs three Hadamards and three controlled rotations rather than an \(8\times8\) matrix multiplication.

Cost, approximation and conventions#

The inverse. The inverse QFT is obtained by reversing the order of the gates and replacing each \(R_k\) by \(R_k^{\dagger}\); the SWAP network is its own inverse. It is therefore no more expensive than the forward transform, and in practice it is the one algorithms use, phase estimation among them.

The gate count. Counting the circuit of Section The circuit: \(n\) Hadamards, \(\sum_{j=1}^{n}(n-j)=n(n-1)/2\) controlled rotations, and \(\lfloor n/2\rfloor\) swaps, so

\[ \text{gates} = \bigO(n^2) .\tag{5.17} \]

Compare the classical cost of applying \(\matr{F}_N\) directly to a \(2^n\)-dimensional vector, which is \(\bigO(N^2)=\bigO(4^{n})\) operations, or \(\bigO(N\log N)\) with the fast Fourier transform; Table 5.1 gives the numbers. These ideal gate counts exclude routing and the precision-dependent synthesis of rotations into a discrete gate set.

\(n\)

\(\mathrm{H}\)

controlled \(R_k\)

swaps

direct classical DFT

\(3\)

\(3\)

\(3\)

\(1\)

\(6.4\times10^{1}\)

\(6\)

\(6\)

\(15\)

\(3\)

\(4.1\times10^{3}\)

\(10\)

\(10\)

\(45\)

\(5\)

\(1.0\times10^{6}\)

\(100\)

\(100\)

\(4950\)

\(50\)

\(1.6\times10^{60}\)

Table 5.1: Ideal QFT gate counts and the leading \(N^2=4^n\) operation count for direct classical matrix multiplication. The classical FFT reduces the latter to \(\bigO(n2^n)\); it returns an explicit vector, whereas the QFT returns a quantum state. Produced by qft.py.

The approximate QFT. Omitting controlled \(R_k\) with \(k>d\) retains \((d-1)n-d(d-1)/2\) controlled rotations for \(1\le d\le n\). A telescoping comparison of the two circuits and \(\Vert R_k-I\Vert\le2\pi/2^k\) give

\[ \Vert F_N-F_N^{(d)}\Vert \le \sum_{k=d+1}^{n}(n-k+1)\frac{2\pi}{2^k} \le 2\pi n2^{-d} .\tag{5.18} \]

This is an operator-norm bound valid for every normalized input. For error at most \(\epsilon\), a sufficient choice is \(d=\min\{n,\lceil\log_2(2\pi n/\epsilon)\rceil\}\), giving \(\bigO(n\log(n/\epsilon))\) gates until the full circuit is reached [Coppersmith1994]. The familiar \(\bigO(n\log n)\) statement holds at fixed target error.

Table 5.2 instead measures the largest component error for one particular input, \(\vert37\rangle\) on six qubits. It is not a worst-case circuit error. Its last gate removes the last approximation, so the error then reaches roundoff; this does not show that small-angle gates generally matter more than large-angle ones. Truncation should be chosen from the required accuracy and an appropriate norm or task-specific criterion. For example, \(n=100,d=7\) retains \(579\) rotations, but the loose bound \(2\pi n/128\) gives no small-error guarantee.

\(d\)

controlled rotations

largest amplitude error

\(1\)

\(0\)

\(2.50\times10^{-1}\)

\(2\)

\(5\)

\(2.43\times10^{-1}\)

\(3\)

\(9\)

\(1.29\times10^{-1}\)

\(4\)

\(12\)

\(3.67\times10^{-2}\)

\(5\)

\(14\)

\(1.23\times10^{-2}\)

\(6\)

\(15\)

\(1.4\times10^{-16}\) (exact)

Table 5.2: The approximate QFT on \(n=6\) qubits, applied to \(\vert x\rangle\) with \(x=37\): the number of controlled rotations kept when only \(R_k\) with \(k\le d\) are retained, and the largest error in any output amplitude. Produced by qft.py.

Largest component error of the approximate mathrmQFT64 on vert37rangle

Figure 5.4: Largest component error of the approximate \(\mathrm{QFT}_{64}\) on \(\vert37\rangle\), against the number of retained controlled rotations. The \(d=6\) point is the exact circuit up to floating-point roundoff. This input-specific curve should not be interpreted as an operator-norm error bound. Produced by qft.py.

Bit reversal: the commonest confusion. The circuit before its final swaps produces the factors of Eq. (5.8) in reverse wire order. The swaps restore the mathematical Fourier convention. Many software libraries omit the swaps and document the reversed convention instead, since a relabelling costs nothing classically. The consequence is that a circuit copied from one library into another can be silently wrong. qft.py makes the statement precise: without the swaps the amplitude that should sit on \(\vert k\rangle\) sits on the basis state whose bits are those of \(k\) in reverse order, so that for \(\mathrm{QFT}_8\vert 001\rangle\) the phase \(1/8\) appears on \(\vert 100\rangle\), \(2/8\) on \(\vert 010\rangle\) and \(4/8\) on \(\vert 001\rangle\). When in doubt, transform \(\vert 0\cdots01\rangle\) and look at where the phase \(e^{2\pi i/N}\) ends up.

Quantum phase estimation#

Let \(U\) be unitary with an eigenstate \(\vert\psi\rangle\),

\[ U\vert\psi\rangle = e^{2\pi i\phi}\vert\psi\rangle, \qquad 0\le\phi<1 .\tag{5.19} \]

The spectral theorem guarantees that such eigenstates exist and form a complete orthonormal set, and that

\[ U = \sum_j e^{2\pi i\phi_j}\vert\psi_j\rangle\langle\psi_j\vert, \qquad U^{k} = \sum_j e^{2\pi i k\phi_j}\vert\psi_j\rangle\langle\psi_j\vert ,\tag{5.20} \]

so that powers of \(U\) are obtained by raising the eigenvalues to that power and nothing else, the fact on which the whole algorithm turns. Because \(U\) is unitary its eigenvalues have unit modulus, so a single real number \(\phi_j\) per eigenstate carries all the information. Quantum phase estimation determines it [Kitaev1995,Cleve1998,NielsenChuang].

The algorithm uses two registers: a control register of \(m\) qubits prepared in \(\vert 0\rangle^{\otimes m}\), which will hold the answer, and a system register holding \(\vert\psi\rangle\).

Step 1: superposition. Hadamards on every control qubit give

\[ \vert 0\rangle^{\otimes m}\vert\psi\rangle \;\longmapsto\; \frac{1}{2^{m/2}}\sum_{k=0}^{2^m-1}\vert k\rangle\vert\psi\rangle .\tag{5.21} \]

Step 2: controlled powers. Apply \(U^{2^{j}}\) controlled on the control qubit that holds the bit of weight \(2^j\), for \(j=0,1,\dots,m-1\). Since \(\vert\psi\rangle\) is an eigenstate, \(U^{2^{j}}\vert\psi\rangle=e^{2\pi i2^{j}\phi}\vert\psi\rangle\), so if the control register is in \(\vert k\rangle\) the total operation applied is \(U^{k}\) and

\[ U^{k}\vert\psi\rangle = e^{2\pi i k\phi}\vert\psi\rangle .\tag{5.22} \]

The system register is therefore unchanged, factors out, and the control register is left in the Fourier state

\[ \frac{1}{2^{m/2}}\sum_{k=0}^{2^m-1}e^{2\pi i k\phi}\vert k\rangle .\tag{5.23} \]

The eigenstate has acted as a catalyst: it is returned untouched, having written its phase into the control register. Nothing about the system register was measured, and nothing about it needs to be known beyond the fact that it is an eigenstate.

Step 3: the inverse QFT. Compare Eq. (5.23) with Eq. (5.3). If \(\phi=k'/2^{m}\) for an integer \(k'\), the control register is exactly \(\mathrm{QFT}\vert k'\rangle\). Applying the inverse QFT therefore returns \(\vert k'\rangle\), and measuring gives the binary digits of \(\phi\) with certainty:

\[ \mathrm{QFT}^{-1}\left(\frac{1}{2^{m/2}} \sum_{k}e^{2\pi ik\phi}\vert k\rangle\right) = \vert\phi_1\phi_2\dots\phi_m\rangle, \qquad \phi = 0.\phi_1\phi_2\dots\phi_m .\tag{5.24} \]

This is why the inverse QFT is the right final step, and it is the whole of the algorithm: step 2 writes the phase into a Fourier state, step 3 inverts the Fourier transform. Figure 5.5 draws the circuit.

Quantum phase estimation with a three-qubit control register. Hadamard

Figure 5.5: Quantum phase estimation with a three-qubit control register. Hadamards, then the controlled powers \(U^{4}\), \(U^{2}\), \(U\) from the control qubits of weight \(4\), \(2\), \(1\), then the inverse QFT, then measurement of the control register. For an input eigenstate with an exact three-bit phase \(\phi=0.\phi_1\phi_2\phi_3\), the bits are returned with certainty and the system eigenstate is unchanged.

The bits, one at a time#

It is worth seeing the same thing in the product form, because it shows the bits emerging individually. Writing \(\phi=0.\phi_1\phi_2\dots\), the state (5.23) factorizes exactly as Eq. (5.7) did,

\[ \frac{1}{2^{m/2}} \left(\vert 0\rangle+e^{2\pi i\,2^{m-1}\phi}\vert 1\rangle\right) \otimes\left(\vert 0\rangle+e^{2\pi i\,2^{m-2}\phi}\vert 1\rangle\right) \otimes\cdots\otimes \left(\vert 0\rangle+e^{2\pi i\,\phi}\vert 1\rangle\right) .\tag{5.25} \]

Now \(2^{m-1}\phi = \phi_1\phi_2\cdots\phi_{m-1}.\phi_m\phi_{m+1}\dots\), and only the fractional part survives in the exponential, so the first factor is \(\vert 0\rangle+e^{2\pi i\,0.\phi_m\phi_{m+1}\dots}\vert 1\rangle\) and so on down the register. If the expansion terminates after \(m\) bits this is

\[ \frac{1}{2^{m/2}} \left(\vert 0\rangle+e^{2\pi i\,0.\phi_m}\vert 1\rangle\right) \otimes\cdots\otimes \left(\vert 0\rangle+e^{2\pi i\,0.\phi_1\phi_2\dots\phi_m}\vert 1\rangle\right),\tag{5.26} \]

which is precisely the QFT state (5.8) of the bit string \(\phi_1\phi_2\dots\phi_m\) when the expansion of \(\phi\) terminates after \(m\) bits. Each control qubit carries one successive binary suffix of the phase; the inverse QFT decodes them all at once. The control qubit that was given \(U^{2^{m-1}}\) carries the least significant bit, since multiplying \(\phi\) by \(2^{m-1}\) pushes all but the last digit into the integer part: the highest power of \(U\) resolves the finest digit, which is the reason the resolution improves exponentially with the number of controlled powers.

The exact and the inexact case#

Exact. Let \(\phi=5/8=0.101\) and \(m=3\), with \(U=\mathrm{diag}(1,e^{2\pi i\phi})\) on one qubit and the eigenstate \(\vert 1\rangle\). Then the output is \(\vert 101\rangle\) with probability one. phase_estimation.py runs the circuit of Fig. 5.5 on the simulator and confirms it: probability \(1.000000\), estimate \(0.625000\).

Inexact. If \(\phi\) is not of the form \(k'/2^{m}\), as is typical but not inevitable for a Hamiltonian eigenphase, the control register is not a computational basis state and the measurement returns a distribution. Its shape is a short calculation. The amplitude of the outcome \(\vert k'\rangle\) after the inverse QFT is the geometric sum

\[ a_{k'} = \frac{1}{2^m}\sum_{k=0}^{2^m-1} e^{2\pi i k\left(\phi-k'/2^m\right)} = \frac{1}{2^m}\, \frac{1-e^{2\pi i 2^m\delta}}{1-e^{2\pi i\delta}}, \qquad \delta = \phi-\frac{k'}{2^m},\tag{5.27} \]

and with \(\vert 1-e^{i\theta}\vert=2\vert\sin(\theta/2)\vert\) the probability is the squared, normalized Dirichlet-kernel amplitude

\[ P(k') = \vert a_{k'}\vert^2 = \frac{\sin^2(\pi2^m\delta)}{2^{2m}\sin^2(\pi\delta)} .\tag{5.28} \]

At removable singularities the limit is taken, so an exactly represented phase has probability one at its matching outcome. For the nearest grid point, \(\vert\delta\vert\le1/(2T)\) with \(T=2^m\). The inequalities \(\sin(\pi T\vert\delta\vert)\ge2T\vert\delta\vert\) and \(\vert\sin(\pi\delta)\vert\le\pi\vert\delta\vert\) give

\[ P\ge\frac{(2T\vert\delta\vert)^2} {T^2(\pi\vert\delta\vert)^2} =\frac{4}{\pi^2}\approx0.405 ,\tag{5.29} \]

whatever \(\phi\) may be, and the two nearest outcomes together carry at least \(8/\pi^2\approx0.81\). phase_estimation.py scans \(\phi\) across a grid interval and finds the minimum \(0.4054\) at the midpoint and the minimum for the two nearest outcomes \(0.8107\), both within a tenth of a per cent of the bounds. Table 5.3 takes \(\phi=0.3\), which has the non-terminating expansion \(0.0100110011\dots\), and increases the register.

\(m\)

outcome

probability

estimate

error

two best

\(3\)

\(\vert 010\rangle\)

\(0.5775\)

\(0.250000\)

\(5.0\times10^{-2}\)

\(0.837\)

\(4\)

\(\vert 0101\rangle\)

\(0.8756\)

\(0.312500\)

\(1.3\times10^{-2}\)

\(0.931\)

\(6\)

\(\vert 010011\rangle\)

\(0.8752\)

\(0.296875\)

\(3.1\times10^{-3}\)

\(0.930\)

\(8\)

\(\vert 01001101\rangle\)

\(0.8751\)

\(0.300781\)

\(7.8\times10^{-4}\)

\(0.930\)

Table 5.3: Phase estimation of \(\phi=0.3\) with the eigenstate as input. The estimate is the modal outcome read as a binary fraction; its error is at most half a grid spacing. The grid spacing halves per control qubit, but the actual rounding error need not halve. The last column is the combined probability of the two most likely outcomes. Produced by phase_estimation.py.

The full output distribution of phase estimation applied to phi0.3, wi

Figure 5.6: The full output distribution of phase estimation applied to \(\phi=0.3\), with a control register of \(m=4\) qubits (left) and \(m=8\) qubits (right). The bars give the probability of each of the \(2^m\) representable values \(k/2^m\), plotted at that value; the dashed line marks the true phase. The peak carries probability \(0.876\) at \(m=4\) and \(0.875\) at \(m=8\): enlarging the register narrows the distribution by a factor of sixteen without making the modal outcome any more likely, since the height is governed mainly by the offset in grid units, with a finite-\(m\) correction in Eq. (5.28). Produced by phase_estimation.py.

Figure 5.6 shows the two extreme rows of Table 5.3 as distributions rather than as modal outcomes, and the comparison makes a point that the table cannot. Going from four control qubits to eight divides the grid spacing by sixteen and the error with it, from \(1.3\times10^{-2}\) to \(7.8\times10^{-4}\), yet the peak barely moves in height: \(0.8756\) against \(0.8751\). The two numbers are close for a reason that is arithmetic rather than accidental. The binary expansion of \(0.3\) has period four, so multiplying by \(2^4\) shifts it by a whole period and leaves the fractional part unchanged; the distance from \(\phi\) to the nearest grid point, measured in units of the grid, is therefore \(\vert u\vert=2^m\vert\delta\vert=0.2\) for \(m=4\) and for \(m=8\) alike, and the large-register limit \(\sin^2(\pi u)/(\pi u)^2\approx0.875\) is the same both times. It is the offset \(u\), not the size of the register, that decides how likely the best answer is, which is exactly what the \(4/\pi^2\) bound says, since \(u=\tfrac12\) is its worst case.

The tails also matter. At \(m=4\), the bins immediately below and above the peak have probabilities approximately \(0.055\) and \(0.025\). The peak and the lower neighbor give the two-best-bin probability \(0.931\) in Table 5.3; all three bins give about \(0.956\). Away from the peak and before periodic wraparound, the envelope falls as the inverse square of the distance in grid units. A finite register therefore gives outliers. As \(m\) grows the probability distribution nevertheless concentrates in any fixed neighborhood of the true phase.

The probability of being within one grid step, at least \(8/\pi^2>1/2\), allows independent repetitions to be combined by a median after phases have been unwrapped in a known interval. Ordinary linear medians near phase \(0=1\) require this care. A median does not turn the weaker \(4/\pi^2<1/2\) nearest-bin guarantee into a majority guarantee. For a superposition of eigenstates, repeated runs sample different energies; a median then need not select the desired eigenvalue. Coherent uses of QPE, such as HHL, must instead control the tails within the circuit.

Precision. With \(m\) control qubits the resolution is

\[ \Delta\phi \sim \frac{1}{2^{m}} ,\tag{5.30} \]

exponential in the register size, and to obtain \(\phi\) to within \(2^{-b}\) with probability at least \(1-\epsilon\) a sufficient register size is \(m=b+\lceil\log_2(2+1/(2\epsilon))\rceil\) control qubits (Exercise 5.3). One extra control qubit doubles the evolution resources: implementing the powers by repetitions uses \(2^m-1\) applications of \(U\), with longest evolution \(2^{m-1}t\). At fixed confidence, phase error thus scales as the inverse total coherent evolution time. Independent measurements with fixed interrogation time generally give the inverse square-root scaling in shot count. These are different resource assumptions; the comparison is not an unconditional exponential advantage over variational energy estimation.

Phase estimation with one control qubit#

First assume an exact \(m\)-bit eigenphase. The \(m\) control qubits of Fig. 5.5 interact only through the inverse QFT, and the inverse QFT can be dispensed with. Read Eq. (5.26) from the top: the control qubit that was given \(U^{2^{m-1}}\) is in the state \(\left(\vert 0\rangle+e^{2\pi i\,0.\phi_m}\vert 1\rangle\right)/\sqrt2\), and \(0.\phi_m\) is either \(0\) or \(\tfrac12\), so a Hadamard turns it into \(\vert\phi_m\rangle\) outright: the least significant bit can be measured with a single control qubit and no Fourier transform at all. The next qubit is in the state with phase \(0.\phi_{m-1}\phi_m\); now that \(\phi_m\) is known, a rotation \(R_z\) by \(-2\pi\,0.0\phi_m\) removes it, and a Hadamard returns \(\phi_{m-1}\). Continuing upwards, the bit \(\phi_j\) is obtained from one control qubit, one controlled \(U^{2^{j-1}}\), one rotation by the phase \(-2\pi\,0.0\phi_{j+1}\cdots\phi_m\) built from the bits already measured, and one Hadamard. This is the semiclassical inverse-QFT form of iterative phase estimation [GriffithsNiu1996,Dobsicek2007], related to but distinct from Kitaev’s original phase-estimation construction [Kitaev1995], and it is what the inverse QFT does anyway, since the controlled \(R_k^\dagger\) of the inverse transform are exactly these corrections, applied coherently instead of classically. The saving is that a single control qubit is recycled \(m\) times, so the register of Fig. 5.5 shrinks to one ancilla plus the system, using \(m\) rounds with classical feedback. For a superposition input, the system register must retain its conditional state between rounds. When \(\phi\) is not exactly representable each bit is obtained only with a probability, and the code optionally repeats each bit measurement and takes a majority. That option assumes that the same eigenstate can be supplied for every shot; it is not valid for independently re-prepared superpositions. With one shot per bit the code instead retains the collapsed system state, reproducing the standard QPE distribution. phase_estimation.py implements the procedure and recovers the bits \(101\) of \(\phi=5/8\) with three rounds and the estimate \(0.300781\) of \(\phi=0.3\) with eight rounds of eleven shots each, the same eight bits as the last row of Table 5.3.

The one-control-qubit form invites a more statistical reading. Each round with the controlled power \(U^{2^{j}}\) and a rotation by \(\theta\) returns \(0\) with probability \(\cos^2(\pi2^{j}\phi+\theta/2)\), a sinusoidal signal in \(\phi\) whose frequency is set by the power. Choosing the powers and rotation angles adaptively, and updating a probability distribution for \(\phi\) after every shot with Bayes’ rule, is Bayesian phase estimation [Wiebe2016]. It replaces explicit bit decisions by inference and can incorporate a noise model. Reducing the ancilla count does not remove the need for long controlled evolutions; Heisenberg scaling requires suitable coherent interrogations and does not follow under arbitrary noise.

The rodeo algorithm of Chapter 7 takes the same one-ancilla circuit in yet another direction, using the measurement outcome to filter the system register rather than to read a bit.

Using the class. The class PhaseEstimation in phase_estimation.py runs the circuit of Fig. 5.5 on the simulator of Chapter 2, with the control register in qubits \(0\) to \(m-1\), the most significant bit first, and the system register after it. It is built either from a unitary matrix, whose powers it obtains by repeated squaring, or from a Hermitian matrix and a time \(t\), in which case \(U=e^{-i\hat{H}t}\) and the powers come from the spectral theorem:

from phase_estimation import PhaseEstimation, dirichlet_probability
import numpy as np

phi = 0.3
U = np.diag([1, np.exp(2j * np.pi * phi)])            # eigenstate |1>, eigenphase phi
qpe = PhaseEstimation.from_unitary(U, m=4)
qpe.run([0, 1])                                       # the system state |1>
k, estimate, prob = qpe.estimate()
print(format(k, "04b"), estimate, round(prob, 4))     # 0101 0.3125 0.8756
p = qpe.distribution()                                # all sixteen outcomes
print(np.allclose(p, dirichlet_probability(phi, 4, np.arange(16))))
0101 0.3125 0.8756
True

For a system of \(n\) qubits the controlled power is a \(2^{n+1}\times2^{n+1}\) matrix applied to the control qubit and the system register together. This is a dense classical simulation of the logical operation, not a hardware gate decomposition; for the eight-qubit Hubbard Hamiltonian of Section The model Hamiltonians on a quantum computer this is slow, and the class offers a second method that rotates the system register into the eigenbasis of \(U\) once, where every controlled power is diagonal, and rotates back at the end. The two are the same unitary, by the spectral decomposition, and the script checks that they agree to machine precision on a random two-qubit Hamiltonian.

From phases to energies#

Everything so far concerned a unitary. Physics gives us a Hamiltonian, and the bridge is time evolution. If \(\hat{H}\vert E\rangle=E\vert E\rangle\) then

\[ U(t) = e^{-i\hat{H}t} \qquad\Longrightarrow\qquad U(t)\vert E\rangle = e^{-iEt}\vert E\rangle ,\tag{5.31} \]

so comparing with Eq. (5.19),

\[ \phi = -\frac{Et}{2\pi} \bmod 1 .\tag{5.32} \]

An eigenstate of the Hamiltonian is an eigenstate of \(U(t)\), and QPE measures its energy [AbramsLloyd1999,AspuruGuzik2005]. Hamiltonian simulation becomes a subroutine of a measurement. Chapter 4 developed the product formulas and their errors; the controlled product-formula construction needed here is given below, using the circuits already developed in Section From Pauli sums to circuits and measurements.

The time step and the reading of the phase#

The modulus in Eq. (5.32) is not a formality. Phases are defined only modulo one, so two energies differing by \(2\pi/t\) are indistinguishable: aliasing, exactly as in classical signal processing. A shifted Hamiltonian may have eigenvalues of both signs; a useful convention is to read the register as a signed fraction, the two’s complement of the computer scientists,

\[\begin{equation*} \tilde\phi = \begin{cases} k/2^m, & k<2^{m-1},\\ k/2^m-1, & k\ge2^{m-1},\end{cases} \qquad E = -\frac{2\pi\tilde\phi}{t} ,\tag{5.33} \end{equation*}\]

so that the outcomes with the leading bit \(0\) are the negative energies and those with the leading bit \(1\) the positive ones, and the time step must satisfy \(\vert E\vert t<\pi\) for every eigenvalue that can appear. This requires a bound on the spectrum. On real hardware the spectrum is precisely what one does not know, and the bound available from the Hamiltonian as written is the \(1\)-norm of the Pauli coefficients of Section Pauli strings and Pauli sums,

\[ \Lambda = \sum_{\alpha}\vert h_{\alpha}\vert \;\ge\; \left\Vert\hat{H}\right\Vert , \qquad t = \frac{\pi s}{\Lambda},\quad s<1 ,\tag{5.34} \]

with a safety margin \(s\), which we take as \(0.9\) throughout. The register then resolves energies on the grid

\[ \Delta E = \frac{2\pi}{t\,2^m} = \frac{2\Lambda}{s\,2^m} ,\tag{5.35} \]

For an eigenstate, the nearest grid point is within \(\Delta E/2\) provided rounding does not cross the signed branch boundary. It occurs with probability at least \(4/\pi^2\); other outcomes can be much farther away. A safety margin of at least half a grid step prevents boundary rounding, in addition to preventing aliasing of the exact phase.

A known identity term can be removed to improve the spectral bound: write \(\hat H=h_I I+\hat H'\), evolve \(\hat H'\) and add \(h_I\) to the reported energy. The reason is not that this phase is invisible to QPE. Although \(e^{-ih_It}\) is a global phase on an uncontrolled system, it becomes a measurable relative phase under control:

\[\begin{equation*} \operatorname{ctrl}(e^{-i\hat Ht})= \left(\begin{pmatrix}1&0\\0&e^{-ih_It}\end{pmatrix}_{c}\otimes I\right) \operatorname{ctrl}(e^{-i\hat H't}) .\tag{5.36} \end{equation*}\]

Ignoring it without adding the shift back gives the wrong energy.

A tighter certified bound on the occupied spectral interval permits a larger \(t\). If that interval is \([E_{\min},E_{\max}]\), its midpoint is the optimal centring shift for the signed convention. An approximate ground-state energy alone is not a bound on all eigenvalues present in the trial state. Restricting the bound to a symmetry sector is safe only when both preparation and evolution preserve that sector.

Building the controlled evolution#

QPE needs the controlled powers \(U^{2^{j}}=e^{-i\hat{H}t2^{j}}\), so it needs Hamiltonian simulation. For a Pauli sum \(\hat{H}=\sum_\alpha h_\alpha P_\alpha\) the ingredients are those of Section From Pauli sums to circuits and measurements: each factor \(e^{-ih_\alpha P_\alpha\tau}\) is the rotation gadget of Eq. (3.81), a basis change into the \(Z\) eigenbasis of \(P_\alpha\), a ladder of CNOT gates collecting the parity, one \(R_z(2h_\alpha\tau)\) and the ladder undone, and the strings are assembled by the Trotter formula of Eq. (3.49),

\[ e^{-i\hat{H}t} \approx U_r = \left(\prod_{\alpha}e^{-ih_{\alpha}P_{\alpha}t/r}\right)^{r} ,\tag{5.37} \]

with the first-order error \(\bigO(t^2/r)\) governed by the commutators \([P_\alpha,P_\beta]\), or the symmetric splitting of Eq. (3.48) with error \(\bigO(t^3/r^2)\). Strings that commute with one another can be exponentiated together with no splitting error at all, but the error between groups depends on the norms of their commutators and higher nested commutators, their coefficients and their order. The number of groups alone does not determine it.

What is new is the control. A controlled \(e^{-i\theta P}\) is \(e^{-i\theta\,\vert 1\rangle\langle 1\vert\otimes P}\), and since \(\vert 1\rangle\langle 1\vert=(I-Z_c)/2\) on the control qubit \(c\) it is the product of two commuting rotations, \(e^{-i\theta P/2}\) and \(e^{+i\theta Z_cP/2}\). In the gadget of Eq. (3.81) only the central \(R_z(2\theta)\) depends on \(\theta\), so the control can be attached there alone: replace \(R_z(2\theta)\) on the last qubit of the support by a controlled \(R_z(2\theta)\), which is \(R_z(\theta)\), \(\mathrm{CNOT}\), \(R_z(-\theta)\), \(\mathrm{CNOT}\) with the control qubit as the control of both CNOTs, Fig. 5.7. The basis change and the parity ladder are applied unconditionally, which is harmless because they cancel when the control is \(\vert 0\rangle\). A controlled Pauli rotation therefore costs two CNOT gates and one rotation more than the uncontrolled one, whatever the weight of the string, and a controlled Trotter step costs \(2K\) CNOT gates more than an ordinary one for a Hamiltonian of \(K\) strings. The powers \(U^{2^j}\) are obtained by repeating the step \(2^jr\) times, so that the total number of controlled Pauli rotations in the circuit of Fig. 5.5 is \(K r(2^m-1)\): the price of the exponential precision is an exponential number of gates, and it is the number of applications of \(U\), not of qubits, that limits phase estimation on real hardware.

The controlled rotation  with control qubit  the gadget of Fig. 3.5, w

Figure 5.7: The controlled rotation \(e^{-i\theta X_0X_1}\) with control qubit \(c\): the gadget of Fig. 3.5, with the central \(R_z(2\theta)\) replaced by the controlled rotation \(R_z(\theta)\), CNOT, \(R_z(-\theta)\), CNOT. When \(c=\vert 0\rangle\) the two rotations cancel and the rest of the circuit is the identity; when \(c=\vert 1\rangle\) the CNOTs flip the sign of the second rotation and the two add up to \(R_z(2\theta)\).

What the algorithm is, physically. QPE measures the dynamical phase \(e^{-iEt}\) accumulated by an energy eigenstate, using the control register as an interferometer: each control qubit is a which-path degree of freedom, the controlled evolution puts a relative phase between the paths, and the inverse QFT is the recombining beam splitter. It is an interferometric measurement of an energy, with resolution set by the total coherent evolution time. If an isolated eigenvalue is sufficiently well resolved, the conditional system state approximates its eigenstate, as Section The state you start from will show, which is why the same circuit is the starting point of the state-preparation methods of Chapter 7.

Two small Hamiltonians, worked through#

Before the many-body models it is worth running the algorithm on two Hamiltonians small enough to hold in the head, both of which Section From fermions to qubits left ready to use. Using the same operators again is the point: it is the only way to compare two algorithms without also comparing two problems, and both return in Chapter 6, where the variational quantum eigensolver is applied to exactly the same Pauli sums.

One qubit: the tapered pairing Hamiltonian#

Section Tapering a discrete symmetry reduced the two-level pairing model with one pair to the single-qubit Hamiltonian of Eq. (3.80),

\[ \hat{H} = \frac12\,I + Z - \frac12\,X , \qquad E_\pm = \frac12\pm\frac{\sqrt5}{2} = -0.618034,\ 1.618034 ,\tag{5.38} \]

whose ground state is \(R_y(\theta)\vert 0\rangle\) with \(\theta=\pi-\arctan(1/2)\); the quadrant is essential for selecting the ground state rather than the excited state. The identity carries \(h_I=\tfrac12\); the traceless part \(Z-\tfrac12X\) has \(\Lambda=1.5\) against the exact norm \(\sqrt5/2=1.118\), and Eq. (5.34) gives \(t=0.9\pi/1.5=1.8850\). The evolution operator \(e^{-i(Z-X/2)t}\) is a single rotation of the qubit about the axis \((-\tfrac12,0,1)\) by the angle \(2\cdot1.118\,t\), and its controlled version is a controlled rotation about the same axis, which costs two CNOT gates and a few single-qubit gates. Table 5.4 shows the result of feeding the exact ground state to PhaseEstimation with increasing registers.

\(m\)

outcome

\(E_{\mathrm{QPE}}\)

\(\vert E_{\mathrm{QPE}}-E_-\vert\)

probability

\(3\)

\(011\)

\(-0.750000\)

\(1.3\times10^{-1}\)

\(0.714\)

\(4\)

\(0101\)

\(-0.541667\)

\(7.6\times10^{-2}\)

\(0.630\)

\(5\)

\(01011\)

\(-0.645833\)

\(2.8\times10^{-2}\)

\(0.787\)

\(6\)

\(010101\)

\(-0.593750\)

\(2.4\times10^{-2}\)

\(0.461\)

\(7\)

\(0101011\)

\(-0.619792\)

\(1.8\times10^{-3}\)

\(0.985\)

\(8\)

\(01010110\)

\(-0.619792\)

\(1.8\times10^{-3}\)

\(0.941\)

\(10\)

\(0101010111\)

\(-0.616536\)

\(1.5\times10^{-3}\)

\(0.471\)

Table 5.4: Phase estimation on the one-qubit pairing Hamiltonian of Eq. (5.38), prepared in the exact ground state, with the identity removed and added back and \(t=1.8850\). The exact answer is \(E_-=-0.618034\); the grid spacing \(\Delta E=2\pi/(t2^m)\) halves with each control qubit. Produced by qpe_models.py.

Three features of the table recur in every application and are worth naming at once. The leading bit is \(0\) in every row: the energy is negative, and Eq. (5.33) reads the register accordingly. The nearest-grid error is nonincreasing on these nested grids, but it decreases in steps rather than by a fixed factor, because the estimate is always the nearest point of a grid of spacing \(\Delta E\), and a phase that happens to sit near a grid point is resolved well early, as at \(m=7\), and then not improved until the grid refines past it. And the success probability wanders between \(0.46\) and \(0.99\) without trend, as the \(4/\pi^2\) bound allows. A single shot returns one bin, not its probability; the displayed modal probabilities are available from the simulator. Confidence requires a specified sampling procedure, and a uniform constant number of shots cannot reliably distinguish nearly tied neighboring bins. The script also runs the case one should not: keeping the identity in the Hamiltonian and choosing \(t\) from the full \(1\)-norm \(2\) gives \(t=1.4137\) and a grid \(0.0174\) instead of \(0.0130\) at \(m=8\), a grid one third wider because of an avoidable known energy offset. Finally, the two-qubit form of the same model, Eq. (3.79) in the one-pair sector, returns identical outcomes and probabilities row for row, which the script checks: tapering changes the number of qubits and the depth of the circuit, and nothing about what is measured.

Two qubits: the two-mode Hamiltonian#

The next case up is the two-mode Hamiltonian of Eq. (3.71) with \(\varepsilon_0=1\), \(\varepsilon_1=2\), \(t_{01}=0.3\) and \(U=0.5\),

\[ \hat{H} = 1.625\,II - 0.625\,ZI - 1.125\,IZ + 0.125\,ZZ + 0.15\,(XX+YY) ,\tag{5.39} \]

six strings, with the spectrum \(0\), \(0.916905\), \(2.083095\), \(3.5\) of which the middle two form the one-particle block of Section A worked example: two modes. After the identity is removed \(\Lambda=2.175\) and \(t=1.3000\), and the five remaining strings fall into two commuting groups, \(\{ZI,IZ\}\) and \(\{ZZ,XX,YY\}\), so that a single Trotter step of \(U\) is two exponentials with one splitting error between them; the step costs \(6\) CNOT gates, and its controlled version \(2\cdot5=10\) more, two per string. Table 5.5 gives the runs from the exact one-particle ground state.

\(m\)

outcome

\(E_{\mathrm{QPE}}\)

\(\vert E_{\mathrm{QPE}}-E_0\vert\)

probability

\(3\)

\(001\)

\(1.020833\)

\(1.0\times10^{-1}\)

\(0.908\)

\(4\)

\(0010\)

\(1.020833\)

\(1.0\times10^{-1}\)

\(0.667\)

\(5\)

\(00101\)

\(0.869792\)

\(4.7\times10^{-2}\)

\(0.718\)

\(6\)

\(001001\)

\(0.945313\)

\(2.8\times10^{-2}\)

\(0.613\)

\(7\)

\(0010011\)

\(0.907552\)

\(9.4\times10^{-3}\)

\(0.814\)

\(8\)

\(00100110\)

\(0.907552\)

\(9.4\times10^{-3}\)

\(0.413\)

\(10\)

\(0010010110\)

\(0.916992\)

\(8.7\times10^{-5}\)

\(0.999\)

Table 5.5: Phase estimation on the two-qubit Hamiltonian of Eq. (5.39), prepared in the exact one-particle ground state, with \(t=1.3000\). The exact energy is \(0.916905\). Produced by qpe_models.py.

At \(m=10\) the phase happens to be very nearly representable, the distribution collapses onto a single outcome with probability \(0.999\), and the error drops by two orders of magnitude at once. This is the behavior the \(4/\pi^2\) bound describes: when \(\phi\) is exactly a dyadic rational the algorithm is deterministic, and near-exactness is nearly deterministic. It is also a warning. Nothing about the \(m=8\) run announces that its answer is no better than the \(m=7\) one; only knowing the exact answer reveals it. A hardware shot returns one outcome, whereas the simulator also provides its exact probability. Neither alone is a confidence interval, and turning the one into the other requires the analysis of Section The exact and the inexact case rather than inspection of the output. The leading bit is now \(1\) in no row, because after the shift by \(h_I=1.625\) the targeted lower one-particle energy is negative; the upper one-particle energy is positive. The state \(\vert 11\rangle\) with energy \(3.5-1.625=1.875\) would give the leading bit \(1\), and \(1.875\,t=2.44<\pi\) confirms that no eigenvalue wraps.

The script ends this example by feeding the algorithm the reference determinant \(\vert 10\rangle\) of Section Reference states and fermionic rotations, the particle in the lower mode, instead of the exact eigenstate. Its overlaps with the two one-particle eigenstates are \(\vert c_j\vert^2=0.9287\) and \(0.0713\), and the histogram of the \(m=8\) register shows two peaks, at \(0.9169\) and at \(2.0831\), carrying \(0.7529\) and \(0.0637\) within one grid step of each eigenvalue: the weights are the contributions of both eigencomponents to the chosen windows, governed by the Dirichlet factors of Section The exact and the inexact case. There is no spectral peak at the expectation value \(\langle 10\vert\hat{H}\vert 10\rangle=1\). This is the first sight of a behavior that Section The state you start from examines in detail: QPE resolves spectral components rather than returning their expectation value; at finite precision this is an approximate projection.

The model Hamiltonians on a quantum computer#

Table 3.18 collected the four models of Chapter 3 in the qubit encodings that use their symmetries: the Lipkin model with \(N=\Omega=4\), \(\varepsilon=2\), \(V=-1/3\), \(W=-1/4\) on one qubit per doublet, Eq. (3.73); the pairing model with \(L=4\) levels, \(\xi=g=1\) and two pairs on one qubit per level, Eq. (3.78); the half-filled Hubbard ring with \(U=4t\) on eight qubits in the spin-major ordering of Section The four models on a qubit register; and the four-site Heisenberg ring with \(J=1\), Eq. (3.35). We now feed them to phase estimation. The cost of the calculation is set by the numbers in Table 5.6: how many Pauli strings the Hamiltonian has and what their weight is, which fix the gate count of one Trotter step; into how many mutually commuting groups they fall, which suggests possible splittings but does not fix their error; and the norm bound \(\Lambda\), which fixes the time step and hence the energy resolution of a given register.

model

qubits

strings

weight

groups

\(\Lambda\)

\(\Vert\hat{H}-h_I I\Vert\)

\(t\)

\(E_0\)

Lipkin, \(N=4\)

\(4\)

\(16\)

\(2\)

\(3\)

\(6.000\)

\(4.213\)

\(0.4712\)

\(-4.212877\)

pairing, \(L=4\)

\(4\)

\(17\)

\(2\)

\(4\)

\(8.500\)

\(5.779\)

\(0.3326\)

\(0.635548\)

Hubbard ring

\(8\)

\(29\)

\(4\)

\(3\)

\(20.000\)

\(12.000\)

\(0.1414\)

\(-2.102748\)

Heisenberg ring

\(4\)

\(12\)

\(2\)

\(2\)

\(3.000\)

\(2.000\)

\(0.9425\)

\(-2.000000\)

Table 5.6: The four models of Table 3.18 as inputs to phase estimation: qubits, Pauli strings, largest weight, number of groups of mutually commuting strings (identity excluded), the \(1\)-norm \(\Lambda\) of the traceless part, its exact spectral norm, the time step \(t=0.9\pi/\Lambda\), and the exact ground-state energy of Chapter 3 in the relevant sector. Produced by qpe_models.py.

The table repays reading. The Lipkin and Heisenberg models have weight-two Hamiltonians with no Jordan–Wigner strings at all, for the reasons of Section The four models on a qubit register: in the Lipkin model the quasispin operators of one doublet act on one qubit, and in the Heisenberg model the degrees of freedom are spins to begin with. The Hubbard ring pays the fermionic price, weight four for the bond that closes the ring, and its \(1\)-norm \(\Lambda=20\) overestimates the norm by nearly a factor of two, which will cost it a control qubit. The Heisenberg ring has the fewest commuting groups, two, because the six strings of the bonds \((0,1)\) and \((2,3)\) act on disjoint pairs of qubits and the three strings \(XX\), \(YY\), \(ZZ\) of one bond commute among themselves, and the same for the bonds \((1,2)\) and \((3,0)\): the even bonds form one group and the odd bonds the other, the familiar even-odd splitting of a spin chain. The Lipkin model splits into its \(XX\), \(YY\) and \(Z\) parts, and the pairing model into three sets of disjoint \(XX+YY\) pairs and the \(Z\) part. The Heisenberg ring is the model on which the Trotter error is studied below.

Phase estimation on the models#

Table 5.7 runs the algorithm. The system register is prepared in the exact ground state, the time step is that of Table 5.6, the evolution operator is exact, and the control register is varied. For the four-qubit models the controlled powers are applied to the register as dense \(32\times32\) matrices in the classical simulator; for the eight-qubit Hubbard ring, where \(m=10\) control qubits make an \(18\)-qubit register, the spectral method of PhaseEstimation is used, and the script checks on the Lipkin model that the two give the same distribution. All exact eigenvectors and dense powers here are verification tools, not efficient state-preparation or Hamiltonian-simulation algorithms.

model

\(m\)

outcome

\(E_{\mathrm{QPE}}\)

error

probability

Lipkin, \(N=4\)

\(4\)

\(0101\)

\(-4.166667\)

\(4.6\times10^{-2}\)

\(0.990\)

\(6\)

\(010100\)

\(-4.166667\)

\(4.6\times10^{-2}\)

\(0.848\)

\(8\)

\(01010001\)

\(-4.218750\)

\(5.9\times10^{-3}\)

\(0.959\)

\(10\)

\(0101000100\)

\(-4.218750\)

\(5.9\times10^{-3}\)

\(0.486\)

pairing, \(L=4\)

\(4\)

\(0100\)

\(0.277778\)

\(3.6\times10^{-1}\)

\(0.733\)

\(6\)

\(001111\)

\(0.572917\)

\(6.3\times10^{-2}\)

\(0.860\)

\(8\)

\(00111011\)

\(0.646701\)

\(1.1\times10^{-2}\)

\(0.927\)

\(10\)

\(0011101101\)

\(0.628255\)

\(7.3\times10^{-3}\)

\(0.581\)

Hubbard ring

\(4\)

\(0010\)

\(-1.555556\)

\(5.5\times10^{-1}\)

\(0.879\)

\(6\)

\(001001\)

\(-2.250000\)

\(1.5\times10^{-1}\)

\(0.861\)

\(8\)

\(00100011\)

\(-2.076389\)

\(2.6\times10^{-2}\)

\(0.926\)

\(10\)

\(0010001101\)

\(-2.119792\)

\(1.7\times10^{-2}\)

\(0.585\)

Heisenberg ring

\(4\)

\(0101\)

\(-2.083333\)

\(8.3\times10^{-2}\)

\(0.876\)

\(6\)

\(010011\)

\(-1.979167\)

\(2.1\times10^{-2}\)

\(0.875\)

\(8\)

\(01001101\)

\(-2.005208\)

\(5.2\times10^{-3}\)

\(0.875\)

\(10\)

\(0100110011\)

\(-1.998698\)

\(1.3\times10^{-3}\)

\(0.875\)

Table 5.7: Phase estimation of the ground-state energies of Table 5.6, with the exact ground state as input and the exact \(e^{-i\hat{H}t}\). The error falls by roughly a factor of two per control qubit, plateauing when the modal outcome does not change, and is never larger than half the grid spacing \(\Delta E\) of Eq. (5.35). Produced by qpe_models.py.

The error of the phase-estimated ground-state energy against the numbe

Figure 5.8: The error of the phase-estimated ground-state energy against the number of control qubits for the four models of Table 5.6, with the exact ground state and the exact evolution operator; the dashed line is half the grid spacing of Eq. (5.35) for the Heisenberg ring. Every curve halves per qubit on average and none crosses its own half-grid line. Produced by qpe_models.py.

The pattern is the expected one and it is worth stating plainly: the accuracy is controlled entirely by the size of the control register and the time step, not by the size or difficulty of the physical system. Figure 5.8 extends the table to \(m=12\) and shows all four curves falling by a factor of two per qubit on average, each below its own half-grid line. What the difficulty of the Hamiltonian controls is the cost of each application of \(U\), through the strings and their weights, and, as Section The second error: Trotterization shows, the number of Trotter steps. The Heisenberg curve is the lowest not because the model is simplest but because its \(\Lambda\) is smallest, and the Hubbard curve the highest because its \(\Lambda=20\) is the loosest bound in the table: for the four-particle, \(S_z=0\) ground state one is estimating an eigenvalue of magnitude \(2.1\) on a grid designed for shifted eigenvalues up to \(20\); its shifted ground-state energy has magnitude about \(6.1\). The script quantifies what a better bound buys at \(m=10\). With \(t\) from the \(1\)-norm the grid is \(0.0434\) and the error \(1.7\times10^{-2}\); with \(t\) from the exact norm \(12\) the grid is \(0.0260\) and the error \(9.0\times10^{-3}\); with \(t\) from the width of the four-particle sector alone, \(\max\vert E-h_I\vert=6.1\), the grid is \(0.0132\) and the error \(2.6\times10^{-3}\), with the modal probability up from \(0.585\) to \(0.875\). The sector bound in this comparison is obtained by exact diagonalization, so it is a benchmark rather than a scalable prescription. On hardware, a certified interval for the occupied sector could provide the same benefit. A variational energy estimate alone supplies no such interval; shifting by it does not automatically prevent aliasing of excited components. Exercise 5.5 derives the optimal shift when both endpoints are known.

The second error: Trotterization#

On hardware \(e^{-i\hat{H}t}\) is itself built from gates by Eq. (5.37), and this introduces an error with nothing to do with the control register. Table 5.8 and Fig. 5.9 separate the two on the Heisenberg ring, whose twelve strings admit an even–odd grouping. The numerical test uses the Pauli-string insertion order in the circuits of trotter_step from Section Trotter steps as circuits and a first time evolution, \(84\) gates and \(24\) CNOTs per first-order step at \(t=0.9425\), with \(m=8\) control qubits and the exact ground state as input. The Trotterized unitary \(U_r\) is built as a matrix from the circuit and handed to PhaseEstimation.from_unitary, which raises it to the powers \(2^j\) by repeated squaring, exactly as the controlled powers of Fig. 5.5 would repeat the step circuit.

order

\(r\)

\(E_{\mathrm{QPE}}\)

error

probability

\(\Vert U_r-U\Vert\)

CNOTs

\(1\)

\(1\)

\(-1.927083\)

\(7.3\times10^{-2}\)

\(0.721\)

\(4.76\times10^{-1}\)

\(24\)

\(1\)

\(2\)

\(-1.979167\)

\(2.1\times10^{-2}\)

\(0.851\)

\(2.48\times10^{-1}\)

\(48\)

\(1\)

\(4\)

\(-2.005208\)

\(5.2\times10^{-3}\)

\(0.667\)

\(1.25\times10^{-1}\)

\(96\)

\(1\)

\(8\)

\(-2.005208\)

\(5.2\times10^{-3}\)

\(0.830\)

\(6.25\times10^{-2}\)

\(192\)

\(1\)

\(16\)

\(-2.005208\)

\(5.2\times10^{-3}\)

\(0.864\)

\(3.13\times10^{-2}\)

\(384\)

\(1\)

\(32\)

\(-2.005208\)

\(5.2\times10^{-3}\)

\(0.872\)

\(1.56\times10^{-2}\)

\(768\)

\(2\)

\(1\)

\(-1.979167\)

\(2.1\times10^{-2}\)

\(0.936\)

\(8.73\times10^{-2}\)

\(46\)

\(2\)

\(2\)

\(-2.005208\)

\(5.2\times10^{-3}\)

\(0.530\)

\(2.29\times10^{-2}\)

\(92\)

\(2\)

\(4\)

\(-2.005208\)

\(5.2\times10^{-3}\)

\(0.803\)

\(5.79\times10^{-3}\)

\(184\)

\(2\)

\(8\)

\(-2.005208\)

\(5.2\times10^{-3}\)

\(0.858\)

\(1.45\times10^{-3}\)

\(368\)

\(2\)

\(16\)

\(-2.005208\)

\(5.2\times10^{-3}\)

\(0.871\)

\(3.63\times10^{-4}\)

\(736\)

\(2\)

\(32\)

\(-2.005208\)

\(5.2\times10^{-3}\)

\(0.874\)

\(9.08\times10^{-5}\)

\(1472\)

Table 5.8: Trotterized evolution inside phase estimation on the four-site Heisenberg ring, \(m=8\) control qubits, exact \(E_0=-2\): the energy the algorithm reports, its error, the probability of the modal outcome, the spectral norm of \(U_r-e^{-i\hat{H}t}\), and the number of CNOT gates in \(U_r\). A controlled first-order version needs \(24r\) extra CNOTs; the unfused second-order sequence has \(23\) rotation gadgets and needs \(46r\) extra CNOTs. The first-order error falls as \(1/r\) and the second-order error as \(1/r^2\); the energy error stops at the resolution of the register. Produced by qpe_models.py.

The two error sources of a phase-estimation run on the four-site Heise

Figure 5.9: The two error sources of a phase-estimation run on the four-site Heisenberg ring with \(t=0.9425\) and \(m=8\) control qubits, against the number of Trotter steps \(r\) on logarithmic axes: the spectral norm of \(U_r-U\) (circles) and the error of the reported energy (squares), for the first-order splitting (full lines) and the symmetric one (dashed); the dotted line is half the grid spacing of the register. The operator error falls as \(1/r\) and \(1/r^2\); the energy error follows it down and then stops at the grid. Produced by qpe_models.py.

The operator errors approach the expected \(1/r\) and \(1/r^2\) rates. The modal energy reaches the same grid point as exact evolution at \(r=4\) and \(r=2\), respectively. Further refinement can still improve outcome probabilities and the conditional state: an unchanged rounded energy is not evidence that every additional step is wasted.

For a quantitative budget, let \(\delta=\Vert U_r-U\Vert\). Reusing the same approximation gives \(\Vert U_r^p-U^p\Vert\le p\delta\), so the whole QPE circuit differs by at most \((2^m-1)\delta\) before measurement. This conservative bound controls the distribution, not just its mode. For an isolated, consistently matched eigenphase, the induced energy bias is of order \(\delta/t\), away from the phase branch cut. Eigenstate perturbations also depend on spectral gaps.

At fixed \(t\), fixed Hamiltonian and fixed failure tolerance, a simple worst-case balance for energy accuracy \(\epsilon\) is \(2^m=\bigO(1/\epsilon)\) and \(r=\bigO(1/\epsilon)\) for a first-order product formula. Since all controlled powers cost \(Kr(2^m-1)\) rotations, the total is \(\bigO(\epsilon^{-2})\), not \(\bigO(\epsilon^{-1})\). Second order instead gives \(r=\bigO(\epsilon^{-1/2})\) and total cost \(\bigO(\epsilon^{-3/2})\), up to constants and confidence overhead. These are sufficient bounds for this construction, not optimal Hamiltonian-simulation complexities.

The eigenphase bias can converge faster than the operator error. For a two-group product \(e^{-iA\tau}e^{-iB\tau}\), conjugation by \(e^{iA\tau/2}\) produces the symmetric product \(e^{-iA\tau/2}e^{-iB\tau}e^{-iA\tau/2}\), with exactly the same spectrum. Thus first-order operator error need not imply first-order spectral error. Real Hamiltonians can also have vanishing diagonal expectation of the leading commutator correction. Such cancellations must be checked for the actual splitting; a count of commuting groups or the symmetry of the exact Hamiltonian alone does not establish them.

Comparison with variational ansatz errors.

In a variational calculation, changing the product formula changes the family of states accessible to the optimizer. Re-optimization can partly or, in a special small example, completely compensate. There is no general theorem that it removes product-formula or hardware errors. QPE instead measures eigenphases of the unitary actually implemented; changing that unitary changes the measured observable. Approximation errors therefore need an explicit budget even when the phase register itself is arbitrarily precise.

The state you start from#

One assumption has been carried silently through the whole chapter: that the system register contains an eigenstate. It need not. The eigenstates are complete, so any state may be expanded in them,

\[ \vert\psi_{\mathrm{trial}}\rangle = \sum_j c_j\vert E_j\rangle, \qquad c_j = \langle E_j\vert\psi_{\mathrm{trial}}\rangle ,\tag{5.40} \]

and Eq. (5.20) then carries every term through the algorithm independently: the controlled powers act on each \(\vert E_j\rangle\) with its own phase, and the control register ends entangled with the system register,

\[ \sum_j c_j \vert\widetilde{\phi_j}\rangle\vert E_j\rangle ,\tag{5.41} \]

with \(\vert\widetilde{\phi_j}\rangle\) the peaked control state of Section The exact and the inexact case. For a finite clock, the exact outcome law and conditional state are

\[\begin{equation*} \begin{aligned} P(k)&=\sum_j\vert c_j\vert^2\vert a_k(\phi_j)\vert^2,\\ \vert\psi_k\rangle&= \frac{\sum_j c_j a_k(\phi_j)\vert E_j\rangle}{\sqrt{P(k)}} \quad\text{when }P(k)>0 . \end{aligned}\tag{5.42} \end{equation*}\]

Thus QPE measures a broadened spectral distribution, not the expectation value of \(\hat H\). Exact projection occurs for resolved, exactly representable phases. Otherwise the conditional state contains tails from other eigencomponents. Degenerate eigenvalues select an eigenspace, not a unique vector. Resolving a particular eigenstate requires a clock fine enough relative to its spectral gaps as well as nonzero overlap. For an accepted energy window with probability \(p\), the mean number of independent preparations is \(1/p\); achieving at least one success with failure probability at most \(\eta\) requires \(R\ge\log\eta/\log(1-p)\). Only when the window isolates the target does \(p\) approach its overlap weight.

model

trial state

\(\vert c_0\vert^2\)

\(1/\vert c_0\vert^2\)

\(P(E_0\ \text{bits})\)

Lipkin, \(N=4\)

reference \(\vert 0000\rangle\)

\(0.9358\)

\(1.1\)

\(0.8973\)

pairing, \(L=4\)

reference \(\vert 1100\rangle\)

\(0.8676\)

\(1.2\)

\(0.8044\)

Hubbard ring

Néel determinant \(\vert 10100101\rangle\)

\(0.2410\)

\(4.1\)

\(0.2368\)

Heisenberg ring

Néel state \(\vert 0101\rangle\)

\(0.3333\)

\(3.0\)

\(0.2917\)

Table 5.9: Simple trial states for the four models: the overlap \(\vert c_0\vert^2\) with the exact ground state, the expected number of repetitions, and the probability of the nearest ground-energy bin from an \(m=8\) register. The repetition column is \(1/\vert c_0\vert^2\), an ideal isolated-eigenvalue benchmark, not \(1/P(E_0\ \text{bits})\). Produced by qpe_models.py.

Table 5.9 gives the numbers for the cheapest trial states available, the computational basis states of Section Reference states and fermionic rotations. For the Lipkin and pairing models at these couplings the reference determinant has an overlap above \(0.85\) and a single run succeeds most of the time; for the Hubbard ring at \(U=4t\) the Néel determinant carries a quarter of the ground state, and the Heisenberg Néel state exactly one third, so that four and three runs respectively are needed on average. For each model the target bin also contains contributions from other eigenstates through Eq. (5.42). For example, the Hubbard reference has overlap \(0.2410\), whereas its target-bin probability is \(0.2368\): this is not simply \(0.2410\) times the ground-state Dirichlet probability. Good trial states reduce repetition costs, but a product-state overlap need not decrease exponentially for every model. Such decay can occur at fixed interaction strength as system size grows; it should not be identified without qualification with Anderson’s orthogonality catastrophe, which concerns a different thermodynamic limit. Chapters 6 and 7 discuss ways to improve preparation and filtering.

Output histograms of phase estimation on the Lipkin model with N4, var

Figure 5.10: Output histograms of phase estimation on the Lipkin model with \(N=4\), \(\varepsilon=1\), \(V=-2/3\), \(W=0\) (coupling \(\chi=2\)) and \(m=8\) control qubits, for three input states: the reference \(\vert 0000\rangle\), the symmetry-broken mean-field product state of Table 3.20 with \(\alpha=\pi/3\), and the exact ground state. The horizontal axis is the energy of Eq. (5.33); the dotted lines mark the five eigenvalues of the \(J=2\) quasispin block, \(-3.0551\), \(-2.2361\), \(0\), \(2.2361\), \(3.0551\). The spectral peak locations are unchanged, while their weights and Dirichlet tails depend on the input. Finite-clock probability also appears between the peaks. Produced by qpe_models.py.

Figure 5.10 makes the projection visible, on the Lipkin model at the coupling \(\chi=2\) where the mean field of Section Reference states and fermionic rotations breaks the symmetry. Compare the three panels by their spectral weights. The exact ground state has overlap one at \(E_0=-3.0551\); the reference has ground-state weight \(0.6845\), weight \(0.2857\) at zero, and \(0.0298\) at the highest \(J=2\) level. The mean-field product state instead has ground-state weight \(0.5208\) and first-excited-state weight \(0.4440\), with smaller weights at the other levels. These are eigenstate overlaps, not the heights or integrated areas of arbitrary histogram bins. The script also reports probabilities within one grid step of each eigenvalue; for \(E_0\) they are \(0.8503\), \(0.5820\) and \(0.4428\) for the exact, reference and mean-field inputs, respectively.

Although the mean-field expectation value \(-2.5\) is below the reference value \(-2\), its overlap with the true ground state is smaller. Breaking parity mixes in the nearby odd-parity eigenstate. A lower variational energy therefore does not by itself order two trial states by target overlap. The histogram reveals this distinction and also shows excited levels to which the chosen source couples. No peak is associated with the expectation value itself, although finite-clock tails can occur near that value.

Phase estimation as state preparation. The collapse that accompanies the measurement is not a nuisance but a resource. After the control register has been read as the bits of \(E_0\), the system register is left in the state \(\vert E_0\rangle\), up to the small admixture of other eigenstates that the Dirichlet tails allow; the script computes the fidelity of the collapsed register with the exact ground state for all three inputs of Fig. 5.10 and finds \(1.0000\) in each case. Phase estimation therefore does two things at once: it measures an eigenvalue and it prepares the corresponding eigenstate, from any input that overlaps with it, ready to be used for the measurement of other observables. This is the projective view of the algorithm, and Chapter 7 builds a cheaper version of it, the rodeo algorithm, that keeps the projection and drops the digits.

Where this leads. That last observation is the reason the two great algorithms of quantum many-body computing fit together rather than compete. The variational quantum eigensolver of Chapter 6 prepares a state by minimizing \(\langle\psi(\vec{\theta})\vert\hat{H}\vert\psi(\vec{\theta})\rangle\) over the parameters of a shallow circuit; it uses expectation-value measurements without controlled evolution, and its exact expectation value gives a variational upper bound. Finite-shot estimates and noisy implementations need separate error analysis, but its accuracy is limited by the ansatz and by the difficulty of the classical optimization. QPE needs deep coherent circuits and controlled \(e^{-i\hat{H}t}\), which makes useful high-precision many-body applications demanding of fault-tolerant resources. Small demonstrations do not establish that these resources are available at scale. Table 5.10 sets the two side by side. One possible workflow is: use VQE, or any other method in this book, to prepare a state with substantial overlap with the target eigenstate; then use QPE to refine the energy and project onto the eigenstate. Whether this plan delivers an exponential advantage for ground-state energies is a question of the overlaps of Table 5.9 for systems far larger than the ones here, and the evidence is examined critically in [Lee2023].

VQE

QPE

Output

an energy expectation

an energy bin and a conditional state

Circuit depth

ansatz dependent

grows with target precision

Needs controlled \(e^{-i\hat{H}t}\)

no

yes

Precision cost

typically \(\bigO(\epsilon^{-2})\) shots at fixed variance

\(\bigO(\epsilon^{-1})\) coherent evolution at fixed confidence

Limited by

ansatz, optimization and measurement

preparation, simulation and coherence

Trotter error

may be reduced by re-optimization

changes the measured unitary

Era

near-term

fault-tolerant

Table 5.10: The two algorithms. The natural workflow uses both: VQE as a state-preparation front end, QPE as the readout.

An application: the linear-system algorithm of Harrow, Hassidim and Lloyd#

Phase estimation writes an eigenvalue into a register. Everything so far has read that register out; the algorithm of this section leaves it unread and uses it, coherently, to control a further operation whose strength depends on the eigenvalue. The operation is a division, and the result is the solution of a linear system of equations. The construction is due to Harrow, Hassidim and Lloyd [HHL2009], it is the template of a whole class of quantum algorithms that apply a function of a matrix to a state, and it has a direct many-body reading: the inverse of \(z-\hat{H}\) is a Green’s function.

The problem and the spectral idea#

Let \(A\) be a Hermitian and invertible \(N\times N\) matrix and \(\vec{b}\) a vector, and consider \(A\vec{x}=\vec{b}\). Many problems of physics and numerical analysis have this form, finite-difference discretizations of differential equations, implicit time steps, and linear-response equations among them, and the classical cost of solving it is \(\bigO(N^3)\) for a dense matrix or \(\bigO(N)\) times the number of iterations for a sparse one. The quantum version of the problem [HHL2009] encodes \(\vec{b}\) in the amplitudes of an \(n\)-qubit register, \(N=2^n\),

\[ \vert b\rangle = \frac{1}{\Vert\vec{b}\Vert}\sum_{i=0}^{N-1}b_i\vert i\rangle ,\tag{5.43} \]

and asks for the state

\[ \vert x\rangle = \frac{A^{-1}\vert b\rangle}{\Vert A^{-1}\vert b\rangle\Vert} .\tag{5.44} \]

The output is a quantum state, not a classical vector. Reconstructing all \(2^n\) complex amplitudes requires additional measurements and removes an exponential saving in output size. What can be extracted is an expectation value \(\langle x\vert O\vert x\rangle\), an overlap with another state, or samples from the basis probabilities \(\vert x_i\vert^2\). This is the first entry of the fine print of Section The fine print, and it should be kept in mind from the start.

The idea is spectral. Write \(A=\sum_j\lambda_j\vert u_j\rangle\langle u_j\vert\) and expand \(\vert b\rangle=\sum_j\beta_j\vert u_j\rangle\) with \(\beta_j=\langle u_j\vert b\rangle\). Then

\[ A^{-1}\vert b\rangle = \sum_j\frac{\beta_j}{\lambda_j}\vert u_j\rangle ,\tag{5.45} \]

so the algorithm has to multiply every eigencomponent of \(\vert b\rangle\) by \(1/\lambda_j\). The map \(\lambda\mapsto1/\lambda\) is not unitary, and no circuit implements it directly; but a circuit can implement it conditionally, on a branch of an ancilla whose amplitude is proportional to \(1/\lambda_j\), provided the eigenvalue is available in a register to condition on. Phase estimation puts it there.

The circuit#

The register has three parts: the system register in \(\vert b\rangle\), a clock register of \(m\) qubits in \(\vert 0\rangle^{\otimes m}\), and one ancilla in \(\vert 0\rangle\). Figure 5.11 shows the four steps. We first derive the ideal case of exact eigenvalue labels, then treat finite clock precision. The implementation below is a dense classical demonstration: it diagonalizes \(A\) to construct controlled evolution and choose \(t,C\). Those operations are benchmarks, not the efficient input-access procedures assumed in complexity claims.

The HHL circuit. Phase estimation of  labels every eigencomponent of

Figure 5.11: The HHL circuit. Phase estimation of \(e^{iAt}\) labels every eigencomponent of \(\vert b\rangle\) with its eigenvalue in the clock register; a rotation of the ancilla controlled by the clock puts the amplitude \(C/\lambda\) on its \(\vert 1\rangle\) branch; the inverse of the phase estimation returns the clock to \(\vert 0\rangle^{\otimes m}\); and post-selecting the ancilla on \(\vert 1\rangle\) leaves the system register in \(\vert x\rangle\propto A^{-1}\vert b\rangle\) in the ideal exact-label limit. A finite clock generally retains entanglement.

Step 1: phase estimation. Apply the circuit of Fig. 5.5 with \(U=e^{iAt}\), whose eigenphases are \(\phi_j=\lambda_jt/2\pi\), read with the signed convention of Eq. (5.33) so that negative eigenvalues are allowed. By the linearity of Section The state you start from every eigencomponent is labeled with its own eigenvalue,

\[ \vert 0\rangle_a\vert 0\rangle^{\otimes m}\sum_j\beta_j\vert u_j\rangle \;\longmapsto\; \vert 0\rangle_a\sum_j\beta_j\vert\tilde\lambda_j\rangle\vert u_j\rangle ,\tag{5.46} \]

where the ideal \(\vert\tilde\lambda_j\rangle\) is a single exact binary label. At finite precision it is instead a superposition over clock values, and the following factorization becomes approximate. This is the moment at which the hidden spectral decomposition of \(\vert b\rangle\) becomes explicit, and its inverse in step 3 uses the same controlled evolution. Nothing is measured at this stage.

Step 2: the controlled rotation. Choose a constant \(C\) no larger than the smallest \(\vert\lambda_j\vert\) that occurs, and rotate the ancilla for each retained label with \(\vert\lambda\vert\ge C\), by the angle \(\theta_\lambda=2\arcsin(C/\lambda)\),

\[ \vert\tilde\lambda\rangle\vert 0\rangle_a \;\longmapsto\; \vert\tilde\lambda\rangle \left(\sqrt{1-\frac{C^2}{\lambda^2}}\,\vert 0\rangle_a + \frac{C}{\lambda}\,\vert 1\rangle_a\right) ,\tag{5.47} \]

since \(R_y(\theta)\vert 0\rangle=\cos(\theta/2)\vert 0\rangle+\sin(\theta/2)\vert 1\rangle\). On the superposition (5.46) the rotation acts on every branch with its own eigenvalue, and regrouping by the ancilla,

\[ \vert 0\rangle_a\sum_j\beta_j\sqrt{1-\frac{C^2}{\lambda_j^2}} \vert\tilde\lambda_j\rangle\vert u_j\rangle +\vert 1\rangle_a\sum_j\frac{C\beta_j}{\lambda_j} \vert\tilde\lambda_j\rangle\vert u_j\rangle .\tag{5.48} \]

In the exact-label limit, the \(\vert1\rangle_a\) branch carries the inverse weights in Eq. (5.45). For finite clocks the code uses a specified bounded filter: \(f(\lambda)=C/\lambda\) for \(\vert\lambda\vert\ge C\), and \(f(\lambda)=0\) otherwise, including \(\lambda=0\). A choice \(C=0.9\min_j\vert\lambda_j\vert\) does not prevent clock tails below the cutoff; those tails are part of the approximation error. The original algorithm uses a smoother treatment of the ill-conditioned region [HHL2009].

A lookup table of \(2^m\) unrelated angles is generally exponential in \(m\). Efficient implementations compute a reciprocal and rotation angle by reversible arithmetic to a specified precision, followed by rotation synthesis and arithmetic uncomputation. There is no general exact \(\bigO(m)\) construction for \(\arcsin(C/\lambda)\). The demonstration applies the multiplexed rotation directly to state-vector blocks; it does not claim an efficient gate decomposition.

Step 3: uncomputation. In the exact-label limit, apply the inverse of step 1. On every branch it maps \(\vert\tilde\lambda_j\rangle\vert u_j\rangle\) back to \(\vert 0\rangle^{\otimes m}\vert u_j\rangle\), so the clock register is disentangled from the system,

\[ \vert 0\rangle^{\otimes m}\left[ \vert 0\rangle_a\sum_j\beta_j\sqrt{1-\frac{C^2}{\lambda_j^2}}\vert u_j\rangle +\vert 1\rangle_a\sum_j\frac{C\beta_j}{\lambda_j}\vert u_j\rangle\right] .\tag{5.49} \]

This is why the uncomputation matters: without it the eigenvalue labels would remain entangled with the system register, and tracing out distinguishable eigenvalue labels would remove the coherences needed for the solution state.

Step 4: post-selection. Measure the ancilla. With probability

\[ p_{\mathrm{succ}} = C^2\sum_j\frac{\vert\beta_j\vert^2}{\lambda_j^2} = C^2\,\big\Vert A^{-1}\vert b\rangle\big\Vert^2\tag{5.50} \]

the outcome is \(1\), and the system register is then in \(C\sum_j(\beta_j/\lambda_j)\vert u_j\rangle\) up to normalization, which is \(\vert x\rangle\) of Eq. (5.44). Otherwise the run is discarded and repeated. Given coherent access to preparation, its inverse and a success reflection, amplitude amplification reduces the number of coherent uses from order \(1/p_{\mathrm{succ}}\) to order \(1/\sqrt{p_{\mathrm{succ}}}\). This is not simply a reduction in independent experimental repetitions. The success probability also carries information: since \(C\) is known, \(p_{\mathrm{succ}}\) gives the norm of the solution, and the classical vector with its scale is \(\vec{x}=\Vert\vec{b}\Vert\sqrt{p_{\mathrm{succ}}}\,\vert x\rangle/C\).

What finite-clock postselection actually returns. Write the final state as \(\sum_{a,k}\vert a,k\rangle\vert v_{ak}\rangle\), where \(\vert v_{ak}\rangle\) are unnormalized system vectors. Then

\[\begin{equation*} \begin{aligned} p_a&=\sum_k\Vert v_{1k}\Vert^2, & \rho_a&=\frac{\sum_k\vert v_{1k}\rangle\langle v_{1k}\vert}{p_a},\\ p_{a0}&=\Vert v_{10}\Vert^2, & \vert x_0\rangle&=\frac{\vert v_{10}\rangle}{\sqrt{p_{a0}}}, \qquad q_0=\frac{p_{a0}}{p_a}. \end{aligned}\tag{5.51} \end{equation*}\]

Ancilla-only postselection gives \(\rho_a\), generally mixed. Additional clock-zero postselection gives \(\vert x_0\rangle\) with joint probability \(p_{a0}\), not \(p_a\). The simulator reconstructs the approximate vector \(\Vert\vec b\Vert\,\vert v_{10}\rangle/C\) and reports both fidelities, \(\langle x_{\rm exact}\vert\rho_a\vert x_{\rm exact}\rangle\) and \(\vert\langle x_{\rm exact}\vert x_0\rangle\vert^2\), as well as a relative residual. It would be inconsistent to scale \(\vert x_0\rangle\) by \(\sqrt{p_a}\) unless \(q_0=1\).

Checking the conditioning in code. For a coarse clock the two fidelities can differ substantially:

from hhl import HHL
import numpy as np

A = np.array([[1.5, 0.5], [0.5, 1.5]])
h = HHL(A, m=4, window="uniform").run([1, 0])
print("ancilla, joint:", h.success, h.joint_success)
print("fidelity, ancilla/joint:", h.ancilla_fidelity, h.fidelity)
print("relative residual:", h.residual)
assert np.isclose(h.joint_success, h.success * h.clock_reset)
assert np.allclose(h.solution(), h.x_unnormalised / h.C)
ancilla, joint: 0.31337287356607946 0.2010206431396312
fidelity, ancilla/joint: 0.7254835618680384 0.9586100638462999
relative residual: 0.32860994547711136

The condition number. The condition number \(\kappa\) of Section The condition number measures how strongly a linear system amplifies errors of its data. With absolute eigenvalues in \([1/\kappa,1]\) and \(C=1/\kappa\), the ideal success probability satisfies \(p_{\rm succ}\ge1/\kappa^2\), with equality for an input at the largest absolute eigenvalue. This is a worst-case lower bound, not the success probability of every input. A relative inverse error of order \(\epsilon\) requires eigenvalue resolution of order \(\epsilon/\kappa\), since \(\vert\delta(1/\lambda)\vert/\vert1/\lambda\vert\approx \vert\delta\lambda\vert/\vert\lambda\vert\). Thus the longest evolution, not the base alias-free time step, is of order \(\kappa/\epsilon\) in these units.

For an \(s_A\)-sparse matrix with efficient row-entry access and efficient preparation of \(\vert b\rangle\), the original HHL state-preparation bound is commonly written \(\widetilde{\bigO}(s_A^2\kappa^2\log N/\epsilon)\), suppressing logarithmic factors [HHL2009]. Subsequent algorithms obtain nearly linear dependence on \(\kappa\) and polylogarithmic dependence on inverse state error in the corresponding oracle model [Childs2017]. These bounds exclude general data loading and full-vector readout; estimating a classical observable to prescribed accuracy has its own measurement cost. None is a runtime bound for the dense simulator used in this chapter.

A two-by-two example#

Take

\[\begin{equation*} A = \begin{pmatrix}1.5 & 0.5\\ 0.5 & 1.5\end{pmatrix}, \qquad \vec{b} = \begin{pmatrix}1\\0\end{pmatrix}, \qquad \lambda_{1,2} = 1,\ 2, \qquad \vert u_{1,2}\rangle = \frac{1}{\sqrt2}\begin{pmatrix}1\\ \mp1\end{pmatrix} ,\tag{5.52} \end{equation*}\]

so that \(\beta_1=\beta_2=1/\sqrt2\), \(\kappa=2\), and the exact solution is \(\vec{x}=(0.75,-0.25)\). Choose \(t=\pi/4\), so that the eigenphases are \(\phi_1=1/8\) and \(\phi_2=1/4\), exactly representable with \(m=3\) clock qubits, and \(C=1\). hhl.py runs the circuit of Fig. 5.11 on the simulator, with the ancilla as qubit \(0\), the clock as qubits \(1\) to \(3\) and the system as qubit \(4\). After step 1 the clock distribution is \(0.5\) on \(\vert 001\rangle\) and \(0.5\) on \(\vert 010\rangle\), the two eigenvalues with the weights \(\vert\beta_j\vert^2\) and nothing else. After steps 2 and 3 the ancilla reads \(1\) with probability \(0.625=C^2(\tfrac12/1+\tfrac12/4)\), the clock has returned to \(\vert 000\rangle\) with probability \(1.000000\), and the system register is \((0.948683,-0.316228)=(3,-1)/\sqrt{10}\), the exact \(\vert x\rangle\); with the scale from the success probability the classical vector \((0.75,-0.25)\) is recovered to machine precision. The logical steps of Section The circuit have been simulated, and the whole calculation is

from hhl import HHL
import numpy as np

A = np.array([[1.5, 0.5], [0.5, 1.5]])
hhl = HHL(A, m=3, t=np.pi / 4, C=1.0, window="uniform").run([1.0, 0.0])
print(np.round(hhl.clock_distribution, 6))          # [0. 0.5 0.5 0. 0. 0. 0. 0.]
print(round(hhl.success, 6), round(hhl.clock_reset, 6))   # 0.625 1.0
print(np.round(hhl.x.real, 4), np.round(hhl.solution().real, 4))   # [0.9487 -0.3162] [0.75 -0.25]
[0.  0.5 0.5 0.  0.  0.  0.  0. ]
0.625 1.0
[ 0.9487 -0.3162] [ 0.75 -0.25]

When the clock is inexact. For the generic choice \(t=0.9\pi/2\), the labels are no longer exact. Clock-dependent inversion changes the shape of each label distribution, so inverse QPE cannot reset the clock exactly. The cutoff described above must also be included in the error analysis; choosing \(C\) below the true spectral gap does not eliminate all below-cutoff clock probability.

A useful way to reduce distant Fourier tails is to prepare the clock in

\[ \vert w\rangle=\sqrt{\frac{2}{2^m}}\sum_{k=0}^{2^m-1} \sin\frac{\pi(k+\tfrac12)}{2^m}\,\vert k\rangle .\tag{5.53} \]

For distances large compared with one bin and small compared with the period, this sine window has amplitude tails of order \(1/d^2\), rather than the uniform clock’s \(1/d\); probability tails are correspondingly of order \(1/d^4\) and \(1/d^2\). Uncomputation includes the inverse window preparation. The code applies a Householder reflection without storing its dense matrix, but does not synthesize an efficient hardware circuit for that reflection.

Table 5.11 shows the benefit and the limitation. At \(m=10\) the sine-window state conditioned on both outcomes has infidelity about \(2\times10^{-12}\), while \(1-q_0\approx4\times10^{-6}\) remains. These are different error measures. Windowing suppresses tails but does not make a finite clock exact or remove the need for enough resolution at the smallest eigenvalues.

clock

\(m\)

\(p_a\)

\(q_0\)

\(1-\vert\langle x_{\mathrm{exact}}\vert x_0\rangle\vert^2\)

\(\vec{x}_0\)

uniform

\(3\)

\(0.408\)

\(0.6367\)

\(3.3\times10^{-1}\)

\((0.3372,-0.4551)\)

uniform

\(4\)

\(0.313\)

\(0.6415\)

\(4.1\times10^{-2}\)

\((0.4948,-0.0581)\)

uniform

\(6\)

\(0.487\)

\(0.9371\)

\(1.4\times10^{-4}\)

\((0.7145,-0.2289)\)

uniform

\(8\)

\(0.498\)

\(0.9821\)

\(4.8\times10^{-5}\)

\((0.7386,-0.2405)\)

uniform

\(10\)

\(0.505\)

\(0.9953\)

\(1.6\times10^{-6}\)

\((0.7473,-0.2480)\)

sine

\(3\)

\(0.360\)

\(0.5466\)

\(2.4\times10^{-1}\)

\((0.3324,-0.3642)\)

sine

\(4\)

\(0.299\)

\(0.5179\)

\(2.3\times10^{-3}\)

\((0.4212,-0.1182)\)

sine

\(6\)

\(0.508\)

\(0.9984\)

\(4.0\times10^{-7}\)

\((0.7503,-0.2506)\)

sine

\(8\)

\(0.506\)

\(0.9999\)

\(5.6\times10^{-10}\)

\((0.7500,-0.2500)\)

sine

\(10\)

\(0.506\)

\(1.0000\)

\(2.0\times10^{-12}\)

\((0.7500,-0.2500)\)

Table 5.11: HHL on the system of Eq. (5.52) with the generic time step \(t=0.9\pi/2\) and \(C=0.9\lambda_{\min}\), against the number of clock qubits, for the uniform clock state and for the sine window of Eq. (5.53): the success probability, the probability that the clock is zero conditional on ancilla success, \(q_0\), the infidelity conditional on both outcomes, and the simulator vector \(\vec{x}_0=\Vert\vec b\Vert\vert v_{10}\rangle/C\) (exact \((0.75,-0.25)\)). Produced by hhl.py.

A differential equation#

The advertised applications of the algorithm are the large sparse systems that come from discretized differential equations, and the smallest such system is instructive. The Poisson equation

\[ -u''(x) = \sin(\pi x), \qquad x\in(0,1),\qquad u(0)=u(1)=0, \qquad u(x)=\frac{\sin(\pi x)}{\pi^2} ,\tag{5.54} \]

discretized on \(N\) interior points \(x_i=ih\), \(h=1/(N+1)\), with the centered second difference, becomes \(A\vec{u}=\vec{b}\) with

\[\begin{equation*} A = \frac{1}{h^2} \begin{pmatrix} 2 & -1 & & \\ -1 & 2 & \ddots & \\ & \ddots & \ddots & -1\\ & & -1 & 2 \end{pmatrix}, \qquad b_i = \sin(\pi x_i) , \qquad \lambda_k = \frac{4}{h^2}\sin^2\frac{k\pi}{2(N+1)} ,\tag{5.55} \end{equation*}\]

a symmetric positive-definite tridiagonal matrix with known spectrum and condition number \(\kappa\approx4(N+1)^2/\pi^2\), growing with the resolution of the grid. A classical computer solves this system by elimination in \(\bigO(N)\) operations (Section Direct methods), so the example is a test with a known answer. For \(N=4\) the system register is two qubits, the eigenvalues are \(9.549\), \(34.549\), \(65.451\), \(90.451\) and \(\kappa=9.47\); the finite-difference solution differs from \(\sin(\pi x)/\pi^2\) by \(3.2\times10^{-3}\), the discretization error of a four-point grid. Table 5.12 and Fig. 5.12 show HHL with the sine window and \(t=0.9\pi/\lambda_{\max}\) against the number of clock qubits. The normalized solution fidelity is one for every row because the sampled vector \(b_i=\sin(\pi i/(N+1))\) is exactly the lowest eigenvector of this discrete Laplacian. Inverting it changes only its norm. This is a useful scale check but a weak test of a general linear solver; validation.py also checks a complex superposition of multiple eigenvectors. The joint-branch reconstruction improves from an error \(4.40\times10^{-2}\) against the discrete solution at \(m=4\) to \(7.62\times10^{-6}\) at \(m=10\). The continuum discrepancy then approaches the \(3.23\times10^{-3}\) discretization error. At coarse resolution the two errors can partially cancel; they obey a triangle bound rather than adding as positive scalar errors.

\(m\)

\(p_{\mathrm{succ}}\)

\(\max\vert u_{\mathrm{HHL}}-u_{\mathrm{FD}}\vert\)

\(\max\vert u_{\mathrm{HHL}}-u\vert\)

\(4\)

\(0.345\)

\(4.4\times10^{-2}\)

\(4.1\times10^{-2}\)

\(5\)

\(0.244\)

\(6.0\times10^{-2}\)

\(5.7\times10^{-2}\)

\(6\)

\(0.726\)

\(9.4\times10^{-3}\)

\(6.1\times10^{-3}\)

\(7\)

\(0.751\)

\(6.8\times10^{-3}\)

\(3.6\times10^{-3}\)

\(8\)

\(0.810\)

\(1.8\times10^{-4}\)

\(3.1\times10^{-3}\)

\(9\)

\(0.811\)

\(1.7\times10^{-5}\)

\(3.3\times10^{-3}\)

\(10\)

\(0.810\)

\(7.6\times10^{-6}\)

\(3.2\times10^{-3}\)

Table 5.12: HHL for the discretized Poisson equation of Eq. (5.55) with \(N=4\), two system qubits, the sine window and \(t=0.9\pi/\lambda_{\max}\): the success probability, the largest deviation of the recovered solution from the finite-difference solution \(\vec{u}_{\mathrm{FD}}\), and from the exact \(u(x)\), against the number of clock qubits. The discretization error alone is \(3.2\times10^{-3}\). Produced by hhl.py.

Left the exact solution sinpi xpi2 of Eq. 5.54, the finite-difference

Figure 5.12: Left: the exact solution \(\sin(\pi x)/\pi^2\) of Eq. (5.54), the finite-difference solution on four interior points, and the HHL solution with \(m=5\), \(7\) and \(10\) clock qubits, reconstructed from the joint ancilla-one, clock-zero branch. Right: the deviation of the HHL solution from the finite-difference vector and from the exact function against \(m\); the dotted line is the discretization error. Produced by hhl.py.

Resolvents, Green’s functions and linear response#

For a many-body physicist the matrix to invert is not a discretized Laplacian but \(z-\hat{H}\). The resolvent

\[ G(z) = (z-\hat{H})^{-1} = \sum_j\frac{\vert E_j\rangle\langle E_j\vert}{z-E_j}\tag{5.56} \]

is the object behind every Green’s function, and the quantity most often wanted is a diagonal matrix element in a source proportional to \(\hat{O}\vert\Psi_0\rangle\) made by acting with an excitation operator on the ground state,

\[ G_b(z) = \langle b\vert(z-\hat{H})^{-1}\vert b\rangle = \sum_j\frac{\vert\langle E_j\vert b\rangle\vert^2}{z-E_j} ,\tag{5.57} \]

whose poles are the absolute energies \(E_j\) and whose residues are the source weights. For excitation energies relative to \(E_0\), replace \(\hat H\) by \(\hat H-E_0 I\) (equivalently use \(z=E_0+\omega+i\eta\)). For a normalized source \(\vert b\rangle=\hat O\vert\Psi_0\rangle/ \Vert\hat O\vert\Psi_0\rangle\Vert\), restore the squared source norm to obtain physical transition strengths. With this energy-origin convention, its imaginary part at \(z=\omega+i\eta\) gives the spectral or strength function \(S(\omega)=-\frac1\pi\mathrm{Im}\,G_b(\omega+i\eta)\) that response experiments measure. The linear response of a system to a weak external field, the random-phase approximation and the time-dependent Hartree–Fock equations all reduce, in the frequency domain, to a linear system \((\omega-\mathcal{L})\,\delta\rho=s\) with a source \(s\) and a linearized Hamiltonian or Liouvillian \(\mathcal{L}\), that is, to the application of a resolvent to a source state. Solving \((z-\hat{H})\vert x\rangle=\vert b\rangle\) is therefore not an application of HHL borrowed from numerical analysis; it is the many-body problem in its own frequency-domain form, and the algorithm implements the spectral map \(E_j\mapsto1/(z-E_j)\) exactly as Eq. (5.45) implements \(\lambda_j\mapsto1/\lambda_j\). The matrix element itself comes out of the run: since the post-selected branch of Eq. (5.49) is \(\vert\tilde x\rangle=C\sum_j(\beta_j/\lambda_j)\vert u_j\rangle\) before normalization,

\[ G_b(z) = \frac{\langle b\vert\tilde x\rangle}{C} = \frac{\sqrt{p_{\mathrm{succ}}}\,\langle b\vert x\rangle}{C} ,\tag{5.58} \]

in the ideal limit for a normalized source. At finite clock precision, use \(\vert\tilde x\rangle=\vert v_{10}\rangle\) and \(p_{a0}\). A hardware overlap measurement requires a coherent reference, controlled preparation and uncomputation of the success construction; a success rate and a stand-alone postselected state do not determine a signed or complex amplitude. The simulator reads this amplitude directly.

For real \(z\) outside the spectrum, \(A=zI-\hat H\) is Hermitian and the present HHL implementation applies. For \(z=\omega+i\eta\) with \(\eta>0\), it is not Hermitian; passing it to a Hermitian eigensolver is incorrect. One possible extension uses

\[\begin{equation*} \mathcal A=\begin{pmatrix}0&A\\A^\dagger&0\end{pmatrix}, \qquad \mathcal A\begin{pmatrix}0\\x\end{pmatrix} =\begin{pmatrix}b\\0\end{pmatrix} .\tag{5.59} \end{equation*}\]

This adds one qubit and replaces eigenvalue conditioning by singular-value conditioning. For a Hermitian \(\hat H\), the singular values of \(A\) are \(\sqrt{(\omega-E_j)^2+\eta^2}\) (with the chosen energy shift), so \(\eta\) controls the distance to singularity. General linear-response Liouvillians likewise require an appropriate Hermitian embedding or a solver for non-Hermitian matrices. The figure below uses real \(z\) only; finite phase resolution is not equivalent to physical broadening by \(i\eta\).

The resolvent matrix element Gbzlangle bvertz-hatH-1vert brangle of th

Figure 5.13: The resolvent matrix element \(G_b(z)=\langle b\vert(z-\hat{H})^{-1}\vert b\rangle\) of the two-level pairing Hamiltonian of Eq. (3.79) in the reference state \(\vert b\rangle=\vert 10\rangle\), exact and from HHL runs with \(m=6\) and \(m=9\) clock qubits at \(110\) values of \(z\); the dotted lines are the four eigenvalues, of which the two in the one-pair sector, \(-0.618\) and \(1.618\), are the poles. Produced by hhl.py.

Figure 5.13 does this for the two-level pairing Hamiltonian of Eq. (3.79) and the reference state \(\vert b\rangle=\vert 10\rangle\), one pair in the lower level, whose overlaps with the one-pair eigenstates are \(0.9472\) and \(0.0528\). For each of \(110\) real values of \(z\), the matrix \(A=zI-\hat H\) is positive definite, negative definite or indefinite depending on \(z\); the signed clock handles all three cases. Each run uses its own \(t,C\) from the full four-dimensional spectrum. On the sampled points at least \(0.3\) from every full-space eigenvalue, the largest relative errors are \(5.51\times10^{-1}\) at \(m=6\) and \(2.70\times10^{-4}\) at \(m=9\). Thus the coarse-clock error is not uniformly a few per cent. At \(z=-1.5\) the \(m=9\) result is \(-1.0909\); at \(z=2.5\) it is \(0.3636\).

As a relevant pole is approached, \(\kappa\) diverges and a fixed clock cannot resolve the small eigenvalue. The ideal success probability need not vanish: with \(C=0.9\min_j\vert z-E_j\vert\), it tends to \(0.81\vert\langle E_j\vert b\rangle\vert^2\) near an isolated pole with nonzero source weight. Conversely, a small eigenvalue with zero source weight can unnecessarily reduce \(C\) when a full-space bound is used. Here the eigenvalues \(0\) and \(1\) have zero source weight and are not poles of \(G_b\). Projecting to the known one-pair sector can avoid that cost. These distinctions separate spectral conditioning, source overlap and finite-clock error. Exercise 5.9 extends the example to a larger pairing model.

The fine print#

A speedup depends on the input-access model, conditioning, state preparation and requested output [Aaronson2015]. Preparing a general length-\(N\) vector requires order \(N\) resources; smoothness alone does not prove an efficient preparation circuit. A polynomial-size Pauli sum with controlled coefficient norms can be simulated efficiently at fixed accuracy, but an arbitrary dense Hamiltonian cannot. Large condition numbers, long evolution times and stringent output accuracy can dominate the cost. Full-vector readout has at least linear output size and also requires statistical precision; even one expectation value has a measurement cost.

The classical comparison must solve the same restricted task with the same data access. When the whole solution vector is wanted, the baseline for a sparse positive-definite matrix is the conjugate gradient method, whose cost grows with \(N\sqrt{\kappa}\), Eq. (B.17). For example, classical algorithms with length-square sampling access can imitate low-rank linear-system sampling under additional rank and conditioning assumptions [Gilyen2018]. This is not a general dequantization of every sparse-Hamiltonian problem. Matrix-function methods based on block encodings and singular-value transformation generalize the spectral idea of HHL; Section Beyond product formulas places them among the simulation methods. Many-body response problems provide promising structured inputs and compact outputs, but this alone does not establish an advantage over their best classical methods.

Summary#

The quantum Fourier transform is the map \(\vert x\rangle\mapsto N^{-1/2}\sum_k e^{2\pi ixk/N}\vert k\rangle\). Its whole theory follows from one rewriting: the phase factors into binary fractions, Eq. (5.8), so that the output for a computational-basis input is an unentangled product of one-qubit phase states. General inputs need not stay separable. That factorization gives the circuit, Hadamards, controlled \(R_k\) and a final reversal, a gate count of \(\bigO(n^2)\) against \(\bigO(4^n)\) for the matrix it represents, and an approximate version at \(\bigO(n\log n)\). What it does not give is a way to read the transform out: the answer is in the amplitudes.

Quantum phase estimation is what makes that acceptable, because it needs only one number. Controlled powers of \(U\) write the eigenphase into a control register as a Fourier state, Eq. (5.23); the inverse QFT decodes it into binary, exactly when the phase is a dyadic rational and with the Dirichlet-kernel probabilities of Eq. (5.28) otherwise. With \(m\) control qubits the resolution is \(2^{-m}\), one more digit per qubit, at the price of doubling the number of applications of \(U\); a single recycled control qubit, with classical feedback, does the same job. For physics the unitary is \(e^{-i\hat{H}t}\) and the phase is \(-Et/2\pi\) read as a signed fraction. Two consequences follow. The period forces a choice of \(t\) from a bound on the spectrum, and a loose bound can waste register space. A known identity term may be removed provided its energy shift is restored explicitly. And \(e^{-i\hat{H}t}\) must be implemented accurately, for example by Trotterization, whose error is independent of the register and must be balanced against it, as Table 5.8 shows; variational re-optimization of a state-preparation circuit does not correct the unitary being measured. Applied to the models of Section The four models on a qubit register, the algorithm recovers the exact ground-state energies with the grid-dependent errors in Table 5.7, and the difficulty of the Hamiltonian shows up in the cost of each \(U\), not in the achievable accuracy.

Phase estimation does not require the exact eigenstate, only overlap with it, and what the overlap buys is repetitions rather than precision: the histogram of outcomes is the spectrum weighted by the overlaps, and the register left behind after a successful readout is an approximate eigenstate when the energy is isolated and well resolved. That is the hinge between this chapter and the two that follow, the variational preparation of states with large overlap in Chapter 6 and the filtering of states by measurement in Chapter 7. Finally, the eigenvalue register need not be read at all. Used coherently to control a rotation, it applies \(1/\lambda\) to every eigencomponent of a state, which is the HHL algorithm for linear systems and, with \(A=z-\hat{H}\) for real \(z\) off the spectrum, a quantum resolvent calculation. Complex frequencies require a Hermitian embedding or a more general solver. Its cost is dominated by the condition number, its output is a state rather than a vector, and it inherits from phase estimation a sensitivity to the tails of the Dirichlet kernel that a shaped clock register suppresses. At finite precision one must distinguish ancilla-only and joint postselection.

Exercises#

  1. The quantum Fourier transform. (a) Show that \(\matr{F}_N\) of Eq. (5.2) is unitary, using \(\sum_{j}\omega^{j(k-k')}=N\delta_{kk'}\). (b) Carry out the derivation of Eq. (5.8) in full, justifying the interchange of sum and product and the step in which only the fractional part of \(x/2^m\) survives. (c) Repeat the two-qubit calculation of Section The product form for three qubits, and identify explicitly which products \(x_jk_m\) are integers and therefore drop out. (d) Show that the QFT of a computational basis state is always a product state, and that the QFT of a general state need not be. What does that say about where the entanglement in phase estimation comes from? (e) Show that \(\mathrm{QFT}_N\) has order four, \(\mathrm{QFT}_N^4=\mathbb{1}\), and find its eigenvalues.

  2. Circuits, cost and conventions. (a) Verify that the circuit of Fig. 5.1 implements Eq. (5.12), by following \(\vert x_1x_2\rangle\) through gate by gate for all four inputs. (b) Show that a controlled \(R_k\) is symmetric in its two qubits, and distinguish \(R_1=Z\) from the Hadamard. Verify \(H=(X+Z)/\sqrt2\) and compare their eigenbases. (c) Count the gates in the general circuit and derive Eq. (5.17). (d) Show that reversing the gate order and conjugating each \(R_k\) gives the inverse transform. (e) Estimate the error of the approximate QFT when all rotations with \(k-j+1>d\) are dropped, and show that it is bounded by \(2\pi n2^{-d}\); hence justify the choice \(d\sim\log n\) and the \(\bigO(n\log n)\) gate count. (f) Using qft.py, write the forward circuit without swaps as \(BF_N\), with \(B\) the bit-reversal permutation. Its inverse is \(F_N^\dagger B\), not \(BF_N^\dagger\). Test why omitting the initial swaps of the inverse circuit cannot generally be corrected by reversing the measured bits.

  3. Phase estimation. (a) Derive Eq. (5.23), being explicit about why the system register factors out. (b) Show that Eq. (5.23) is exactly \(\mathrm{QFT}\vert k'\rangle\) when \(\phi=k'/2^m\). (c) Derive the Dirichlet kernel of Eq. (5.28) and the bound \(4/\pi^2\) of Eq. (5.29), and show that the two nearest outcomes together carry at least \(8/\pi^2\). (d) Show that to obtain \(\phi\) to within \(2^{-b}\) with probability at least \(1-\epsilon\) the sufficient choice is \(m=b+\lceil\log_2(2+1/(2\epsilon))\rceil\) control qubits. (e) Show that the iterative scheme of Section Phase estimation with one control qubit produces the same bits as the inverse QFT, by identifying the classical phase corrections with the controlled \(R_k^\dagger\) of the inverse transform. (f) For a fixed eigenstate and phases unwrapped in a known interval, use the \(8/\pi^2>1/2\) one-grid-step guarantee to bound the failure probability of a median over independent runs. Why is the nearest-bin \(4/\pi^2\) bound insufficient? Explain the difficulty with a simple mean and with superpositions of eigenstates.

  4. Controlled evolution. (a) Show that a controlled \(e^{-i\theta P}\) equals \(e^{-i\theta P/2}e^{i\theta Z_cP/2}\) and hence that Fig. 5.7 is correct. (b) Count the gates of a controlled first-order Trotter step of the two-level pairing Hamiltonian of Eq. (3.79) and of the Heisenberg ring, starting from Table 3.19. (c) The controlled powers \(U^{2^j}\) can be built by repeating the step circuit or by Trotterizing \(e^{-i\hat{H}2^jt}\) afresh with \(2^jr\) steps; are the two the same circuit? (d) For the one-qubit Hamiltonian of Eq. (5.38), write \(e^{-i(Z-X/2)t}\) as a rotation about an axis of the Bloch sphere and give its controlled version as a circuit of two CNOT gates and single-qubit rotations. Check with the Circuit class.

  5. Energies, aliasing and the time step. (a) Derive Eq. (5.32) and explain the modulus. (b) Two eigenvalues \(E\) and \(E+2\pi/t\) give the same phase. Show that choosing \(t<\pi/\Vert\hat{H}\Vert\) with the signed reading of Eq. (5.33) removes the ambiguity, and that shifting \(\hat{H}\rightarrow\hat{H}-\lambda\mathbb{1}\) lets one use the range more efficiently. What is the optimal \(\lambda\) if the spectrum lies in \([E_{\min},E_{\max}]\), and how many control qubits does it save for the Hubbard ring of Table 5.6? (c) Show that \(\Lambda=\sum_\alpha\vert h_\alpha\vert\ge\Vert\hat{H}\Vert\), and give an example in which the bound is loose by a factor growing with the system size. (d) Reproduce Table 5.4 with the identity kept in the Hamiltonian and \(t\) chosen from the full \(1\)-norm, and explain row by row what was lost.

  6. Two errors, one budget. (a) Starting from Eq. (3.46), show that the first-order Trotter error over a time \(t\) with \(r\) steps is bounded by \(\frac{t^2}{2r}\sum_{\alpha<\beta}\Vert[H_\alpha,H_\beta]\Vert\), and identify the contributions that vanish for commuting terms. Explain why the number of groups alone does not specify the bound. Evaluate the bound for the Heisenberg ring from Table 3.17 and compare with Table 5.8. (b) Given a target energy error \(\epsilon\), use the eigenphase bias \(\bigO(\Vert U_r-U\Vert/t)\) and fixed confidence to choose sufficient \((m,r)\). Include all \(2^m-1\) powers: show the worst-case rotation counts \(\bigO(\epsilon^{-2})\) and \(\bigO(\epsilon^{-3/2})\) for first and second order at fixed \(t\). (c) Show that \(e^{-iA\tau}e^{-iB\tau}\) is unitarily similar to its symmetric splitting, and discuss why eigenphase and operator errors can have different leading orders. Check the actual Pauli ordering used in the table before invoking a two-group argument. (d) Explain why variational re-optimization may compensate some ansatz errors but does not guarantee their removal, and why inserting a variational change into the QPE evolution changes the observable being measured.

  7. The models. (a) Reproduce Table 5.7, then apply QPE to the first excited state of the Lipkin model and confirm that the algorithm is indifferent to which eigenstate it is given. (b) The pairing Hamiltonian of Eq. (3.78) on four qubits contains all pair numbers at once. Feed QPE the reference \(\vert 1100\rangle\) and explain why the system remains in the two-pair sector. Distinguish this exact conservation law from tails in the measured energy bins. (c) For the Hubbard ring, replace the Néel determinant of Table 5.9 by the Hartree–Fock determinant of Section When the mean field does nothing: pairing and Hubbard and compare the overlaps. (d) Estimate the resources for a calculation one would actually want: the pairing model with ten levels and five pairs, to an accuracy of \(10^{-3}\) in units of \(\xi\). How many qubits, how many Trotter steps, how many controlled Pauli rotations? Compare with the size of the seniority-zero matrix of Section The pairing model.

  8. Spectroscopy and state preparation. (a) Reproduce Fig. 5.10 and compare the visible peaks with all five \(J=2\) eigenvalues and their source weights. Distinguish overlap weights, modal heights and probabilities integrated over specified bins. (b) Show that the reference \(\vert 0000\rangle\) is an eigenstate of \(Z_0Z_1Z_2Z_3\), the parity of the number of raised doublets, that the Lipkin Hamiltonian commutes with it, and hence that only every other level of the \(J=2\) block appears in the left panel. (c) Compute the overlap of the mean-field product state with the ground state as a function of \(\chi\) and locate the coupling above which it falls below that of the reference. (d) After reading the bits of \(E_0\), the collapsed system register has a fidelity with \(\vert E_0\rangle\) that the script reports as \(1.0000\). Show that the admixture of \(\vert E_j\rangle\) is controlled by the Dirichlet tail at the distance \(\vert E_j-E_0\vert/\Delta E\), and find the smallest \(m\) for which the fidelity exceeds \(0.99\) when the input is the mean-field state.

  9. HHL. (a) Verify the algebra of Section The circuit on the example of Eq. (5.52) by hand: the eigenvector expansion of \(\vert b\rangle\), the two rotation angles, the post-selected state and the success probability. (b) Show that \(p_{\mathrm{succ}}\ge1/\kappa^2\) when \(C=\lambda_{\min}\) and the eigenvalues lie in \([\lambda_{\min},\kappa\lambda_{\min}]\), with equality when \(\vert b\rangle=\vert u_{\max}\rangle\). (c) Show that the Fourier transform of the sine window of Eq. (5.53) has amplitude tails falling as \(1/d^2\) away from the central bins and before periodic wraparound, and explain with Eq. (5.48) why the uniform clock leaves a residual error that decreases only slowly with \(m\). (d) Run the Poisson example with \(N=8\) and \(N=16\) interior points; how do \(\kappa\), the required \(m\) and the success probability change? (e) Repeat the resolvent calculation of Fig. 5.13 for the four-qubit pairing Hamiltonian of Table 5.6 with the source state \(\hat{P}^+_3\hat{P}^-_1\vert\Psi_0\rangle\), the pair excitation of Chapter 3 acting on the exact ground state, and identify the poles.

  10. Numerical explorations. (a) Reproduce Table 5.2 and extend it to \(n=8\) and \(n=10\); compare the component error for a fixed basis input with the operator norm at sizes where the full matrix is affordable. How does the sufficient cutoff from Eq. (5.18) depend on \(n\) and the target error? (b) Verify the \(4/\pi^2\) bound numerically by scanning \(\phi\) across a whole grid interval and recording the worst case. (c) Reproduce Table 5.8 with a deliberately grouped even–odd splitting. Confirm that exponentiating commuting strings separately or as their group gives the same unitary when their order is unchanged; explain why reordering noncommuting groups can change the result. (d) Implement Bayesian phase estimation for the one-qubit Hamiltonian of Eq. (5.38): a grid of prior probabilities for \(E\), single-shot measurements with random powers and angles, Bayes’ updates, and the posterior width against the number of shots.

Programs for this chapter#

Every number and figure in this chapter comes from the programs in LectureMaterial/BookPrograms/chapter5/, which build on the shared modules of Chapters 2 and 3 (statevector, circuit, gates, pauli, models) and on mapped_models.py and pauli_circuits.py of Chapter 3. All of them are imported by the notebook LectureMaterial/Notebooks/chapter5/chapter5.ipynb, and all run on numpy and matplotlib alone.

  • qft.py The Fourier matrix of Eq. (5.2), the circuit of Section The circuit as a Circuit, with and without the swaps and with the rotation ladder truncated, the product form of Eq. (5.8) built without a circuit, the four verifications, the worked example of Fig. 5.3, Tables 5.1 and 5.2, Fig. 5.4 and the bit-reversal check.

  • phase_estimation.py The class PhaseEstimation running the circuit of Fig. 5.5 on the state-vector simulator, by controlled matrices or in the eigenbasis of \(U\), the Dirichlet kernel of Eq. (5.28), the signed phase-to-energy conversion and the time step of Eqs. (5.33) and (5.34), iterative phase estimation with one control qubit with retained conditional states, the exact example \(\phi=5/8\), Table 5.3, Fig. 5.6 and the numerical check of the \(4/\pi^2\) and \(8/\pi^2\) bounds.

  • qpe_models.py Phase estimation on the one- and two-qubit Hamiltonians of Section Two small Hamiltonians, worked through, Tables 5.4 and 5.5; the four models of Table 5.6, Table 5.7 and Fig. 5.8, with the comparison of time steps for the Hubbard ring; the Trotter budget of Table 5.8 and Fig. 5.9; the trial states of Table 5.9, the Lipkin histograms of Fig. 5.10 and the fidelity of the collapsed register. Every energy is checked against Chapter 3.

  • hhl.py The class HHL implementing the circuit of Fig. 5.11 with a uniform or a sine-window clock, the example of Eq. (5.52) and Table 5.11, the \(1/\kappa^2\) check, the Poisson equation of Table 5.12 and Fig. 5.12, and the resolvent of Fig. 5.13. The class distinguishes ancilla-only and joint postselection and reports a residual.

  • validation.py Independent checks of Fourier conventions, phase wraparound, controlled identity phases, finite-clock conditioning, iterative measurements and HHL with complex indefinite systems. Run this after changing the chapter programs.

Running the programs of this chapter#

Each cell below runs one of the programs listed above as a script and shows the figures it writes to BookFigures/.

import runpy, time
from IPython.display import Image, display
t0 = time.time()
runpy.run_path(str(root / 'BookPrograms' / 'chapter5/qft.py'), run_name='__main__')
for png in sorted((root / 'BookFigures' / 'chapter5').glob('*.png')):
    if png.stat().st_mtime >= t0:
        display(Image(str(png)))
=== The QFT circuit against the Fourier matrix, the product form, numpy.fft and its inverse
  worst discrepancy over n = 1..5: 3.5e-15

=== QFT_8 |101>: the eight amplitudes (Eq. 5.example101result)
  |000>  +0.353553+0.000000i   modulus 0.353553   phase/2pi 0.0000   5k/8 mod 1 = 0.0000
  |001>  -0.250000-0.250000i   modulus 0.353553   phase/2pi 0.6250   5k/8 mod 1 = 0.6250
  |010>  +0.000000+0.353553i   modulus 0.353553   phase/2pi 0.2500   5k/8 mod 1 = 0.2500
  |011>  +0.250000-0.250000i   modulus 0.353553   phase/2pi 0.8750   5k/8 mod 1 = 0.8750
  |100>  -0.353553+0.000000i   modulus 0.353553   phase/2pi 0.5000   5k/8 mod 1 = 0.5000
  |101>  +0.250000+0.250000i   modulus 0.353553   phase/2pi 0.1250   5k/8 mod 1 = 0.1250
  |110>  -0.000000-0.353553i   modulus 0.353553   phase/2pi 0.7500   5k/8 mod 1 = 0.7500
  |111>  -0.250000+0.250000i   modulus 0.353553   phase/2pi 0.3750   5k/8 mod 1 = 0.3750
=== Gate counts (Table 5.qftcost)
   n     H   cR_k  swaps   direct DFT ops
   3     3      3      1          6.4e+01
   6     6     15      3          4.1e+03
  10    10     45      5          1.0e+06
 100   100   4950     50          1.6e+60

=== The approximate QFT on n = 6 qubits, |x> with x = 37 (Table 5.aqft)
  d  rotations  largest amplitude error
  1          0                 2.50e-01
  2          5                 2.43e-01
  3          9                 1.29e-01
  4         12                 3.67e-02
  5         14                 1.23e-02
  6         15                 1.37e-16
=== Bit reversal: the circuit without swaps produces the output register in reversed order
  QFT_8 |001> without the swaps: |000>:0.000 |001>:0.500 |010>:0.250 |011>:0.750 |100>:0.125 |101>:0.625 |110>:0.375 |111>:0.875
  the phase k/8 of output |k> sits at |reverse(k)>: 1/8 at |100>, 2/8 at |010>, 4/8 at |001>

QFT checks passed
../_images/f90291fad8d50af090733dff6cfb92b62ba1749329b11040dbebc956d528efd6.png ../_images/94ad960ea3251d39fc23ce24e19961238819144dfc681e9cfc3f358f0c8b03b0.png
import runpy, time
from IPython.display import Image, display
t0 = time.time()
runpy.run_path(str(root / 'BookPrograms' / 'chapter5/phase_estimation.py'), run_name='__main__')
for png in sorted((root / 'BookFigures' / 'chapter5').glob('*.png')):
    if png.stat().st_mtime >= t0:
        display(Image(str(png)))
=== Exact case: U = diag(1, e^{2 pi i phi}) with phi = 5/8 = 0.101, eigenstate |1>, m = 3
  outcome |101> with probability 1.000000, estimate 0.625000
  circuit and spectral implementations agree on a random two-qubit Hamiltonian

=== Inexact case: phi = 0.3 = 0.0100110011..., increasing the register (Table 5.inexact)
  m      outcome  probability   estimate     error  two best
  3        |010>       0.5775   0.250000   5.0e-02     0.837
  4       |0101>       0.8756   0.312500   1.3e-02     0.931
  6     |010011>       0.8752   0.296875   3.1e-03     0.930
  8   |01001101>       0.8751   0.300781   7.8e-04     0.930
  every distribution equals the Dirichlet kernel of Eq. (5.dirichlet)
=== The worst case over a whole grid interval, m = 6
  smallest modal probability 0.4054 at phi = 0.16406 (midpoint 10.5/64 = 0.16406); bound 4/pi^2 = 0.4053
  smallest probability of landing within one grid step: 0.8107 >= 8/pi^2 = 0.8106

=== Iterative phase estimation with one control qubit
  phi = 0.6250, m = 3: bits 101, estimate 0.625000, error 0.0e+00
  phi = 0.3000, m = 8: bits 01001101, estimate 0.300781, error 7.8e-04

phase-estimation checks passed
../_images/dad17e0c7a04b495208ec21037efa05e8f6c3061f52af34284ea602a929cb812.png
import runpy, time
from IPython.display import Image, display
t0 = time.time()
runpy.run_path(str(root / 'BookPrograms' / 'chapter5/qpe_models.py'), run_name='__main__')
for png in sorted((root / 'BookFigures' / 'chapter5').glob('*.png')):
    if png.stat().st_mtime >= t0:
        display(Image(str(png)))
=== One qubit: the tapered two-level pairing Hamiltonian H = I/2 + Z - X/2 (Eq. 3.tapered)
  spectrum [-0.618034  1.618034], Lambda = 1.5 after removing the identity, t = 1.8850
  m      outcome          E    |E-E0|    prob
  3          011  -0.750000   1.3e-01   0.714
  4         0101  -0.541667   7.6e-02   0.630
  5        01011  -0.645833   2.8e-02   0.787
  6       010101  -0.593750   2.4e-02   0.461
  7      0101011  -0.619792   1.8e-03   0.985
  8     01010110  -0.619792   1.8e-03   0.941
 10   0101010111  -0.616536   1.5e-03   0.471
  keeping the identity: t = 1.4137, E_QPE = -0.625000 (exact -0.618034); without the shift the resolution is 0.0174 instead of 0.0130
  the two-qubit form of Eq. (3.jwpairingtwolevels) in the one-pair sector returns the same outcomes and probabilities

=== Two qubits: the two-mode Hamiltonian of Eq. (3.twoqubitH), eps = (1, 2), t = 0.3, U = 0.5
  spectrum [0.       0.916905 2.083095 3.5     ]; the one-particle block holds 0.916905 and 2.083095
  Lambda = 2.175, t = 1.3000, groups of commuting strings: [['ZZ', 'XX', 'YY'], ['ZI', 'IZ']]
  m      outcome          E    |E-E0|    prob
  3          001   1.020833   1.0e-01   0.908
  4         0010   1.020833   1.0e-01   0.667
  5        00101   0.869792   4.7e-02   0.718
  6       001001   0.945313   2.8e-02   0.613
  7      0010011   0.907552   9.4e-03   0.814
  8     00100110   0.907552   9.4e-03   0.413
 10   0010010110   0.916992   8.7e-05   0.999
  trial state |10>: |c_j|^2 = [0.9287 0.0713] on the one-particle eigenvalues [0.916905 2.083095]; histogram weight within one grid step of each: [0.7529 0.0637] (m = 8)

=== The models of Table 3.summary as inputs to phase estimation (Table 5.models)
           model qubits strings weight groups  Lambda   ||H||       t          E0
   Lipkin, $N=4$      4      16      2      3   6.000   4.213  0.4712 -4.21287670
  pairing, $L=4$      4      17      2      4   8.500   5.779  0.3326  0.63554847
    Hubbard ring      8      29      4      3  20.000  12.000  0.1414 -2.10274848
 Heisenberg ring      4      12      2      2   3.000   2.000  0.9425 -2.00000000

=== Phase estimation of the ground-state energies, exact eigenstate and exact U (Table 5.qpemodels)
           model   m       outcome       E_QPE    error   prob
   Lipkin, $N=4$   4          0101   -4.166667  4.6e-02  0.990
   Lipkin, $N=4$   6        010100   -4.166667  4.6e-02  0.848
   Lipkin, $N=4$   8      01010001   -4.218750  5.9e-03  0.959
   Lipkin, $N=4$  10    0101000100   -4.218750  5.9e-03  0.486
  pairing, $L=4$   4          0100    0.277778  3.6e-01  0.733
  pairing, $L=4$   6        001111    0.572917  6.3e-02  0.860
  pairing, $L=4$   8      00111011    0.646701  1.1e-02  0.927
  pairing, $L=4$  10    0011101101    0.628255  7.3e-03  0.581
    Hubbard ring   4          0010   -1.555556  5.5e-01  0.879
    Hubbard ring   6        001001   -2.250000  1.5e-01  0.861
    Hubbard ring   8      00100011   -2.076389  2.6e-02  0.926
    Hubbard ring  10    0010001101   -2.119792  1.7e-02  0.585
 Heisenberg ring   4          0101   -2.083333  8.3e-02  0.876
 Heisenberg ring   6        010011   -1.979167  2.1e-02  0.875
 Heisenberg ring   8      01001101   -2.005208  5.2e-03  0.875
 Heisenberg ring  10    0100110011   -1.998698  1.3e-03  0.875

=== What a tighter bound on the spectrum buys: the Hubbard ring with m = 10
                 Pauli 1-norm, t = 0.9 pi / Lambda: t = 0.1414, grid step 0.0434, E_QPE = -2.119792, error 1.7e-02, prob 0.585
                 spectral norm, t = 0.9 pi / ||H||: t = 0.2356, grid step 0.0260, E_QPE = -2.093750, error 9.0e-03, prob 0.664
   four-particle sector, t = 0.9 pi / max|E - h_I|: t = 0.4633, grid step 0.0132, E_QPE = -2.105397, error 2.6e-03, prob 0.875
=== Trotterised evolution inside phase estimation: the Heisenberg ring, m = 8 (Table 5.trotter)
  t = 0.9425; one first-order step: (84, 24, 55) (gates, CNOTs, depth)
order   r      E_QPE    error   prob  ||U_r - U||  CNOTs in U_r
    1   1  -1.927083  7.3e-02  0.721     4.76e-01            24
    1   2  -1.979167  2.1e-02  0.851     2.48e-01            48
    1   4  -2.005208  5.2e-03  0.667     1.25e-01            96
    1   8  -2.005208  5.2e-03  0.830     6.25e-02           192
    1  16  -2.005208  5.2e-03  0.864     3.13e-02           384
    1  32  -2.005208  5.2e-03  0.872     1.56e-02           768
    2   1  -1.979167  2.1e-02  0.936     8.73e-02            46
    2   2  -2.005208  5.2e-03  0.530     2.29e-02            92
    2   4  -2.005208  5.2e-03  0.803     5.79e-03           184
    2   8  -2.005208  5.2e-03  0.858     1.45e-03           368
    2  16  -2.005208  5.2e-03  0.871     3.63e-04           736
    2  32  -2.005208  5.2e-03  0.874     9.08e-05          1472
=== Overlaps of simple trial states with the exact ground states (Table 5.overlaps)
           model  trial state  |c_0|^2 1/|c_0|^2  P(E_0 bits), m=8
   Lipkin, $N=4$         0000   0.9358       1.1            0.8973
  pairing, $L=4$         1100   0.8676       1.2            0.8044
    Hubbard ring     10100101   0.2410       4.1            0.2368
 Heisenberg ring         0101   0.3333       3.0            0.2917

=== The Lipkin model at chi = 2 (eps = 1, V = -2/3, W = 0): reference, mean field and exact (Fig. 5.spectroscopy)
  mean-field energy -2.500000 (Table 3.lipkinmf: -2.500000), exact -3.055050, J = 2 eigenvalues [-3.05505  -2.236068  0.        2.236068  3.05505 ]
      reference $|0000\rangle$: |c_j|^2 over the J=2 levels [0.6845 0.     0.2857 0.     0.0298]; histogram weights [0.582  0.0004 0.2858 0.     0.0254]; fidelity of the collapsed register with the ground state after reading the E_0 bits: 1.0000
    mean field, $\alpha=\pi/3$: |c_j|^2 over the J=2 levels [0.5208 0.444  0.0011 0.0247 0.0093]; histogram weights [0.4428 0.44   0.0011 0.0245 0.008 ]; fidelity of the collapsed register with the ground state after reading the E_0 bits: 1.0000
            exact ground state: |c_j|^2 over the J=2 levels [1. 0. 0. 0. 0.]; histogram weights [0.8503 0.0006 0.0001 0.     0.    ]; fidelity of the collapsed register with the ground state after reading the E_0 bits: 1.0000
model phase-estimation checks passed
../_images/c7f82ad6b57b3fd6d57ef7edb3342c5e396781fc600e554d9ddd5780e752590b.png ../_images/00802beb5ac636c0218bb28196ec0b5d33e6fefa58ca16e5343d50de141776bc.png ../_images/b6024b1d8ad256a192039de9e214e6ef1834a8c46685555286fb95dcbadef117.png
import runpy, time
from IPython.display import Image, display
t0 = time.time()
runpy.run_path(str(root / 'BookPrograms' / 'chapter5/hhl.py'), run_name='__main__')
for png in sorted((root / 'BookFigures' / 'chapter5').glob('*.png')):
    if png.stat().st_mtime >= t0:
        display(Image(str(png)))
=== A = [[1.5, 0.5], [0.5, 1.5]], b = (1, 0): eigenvalues 1 and 2, t = pi/4, m = 3 (Eq. 5.hhlexample)
  clock distribution after phase estimation: [0.  0.5 0.5 0.  0.  0.  0.  0. ]
    (lambda = 1 -> phi = 1/8 -> |001>, lambda = 2 -> phi = 2/8 -> |010>, each with weight |beta_j|^2 = 1/2)
  success probability 0.625000 (C^2 sum beta_j^2 / lambda_j^2 = 0.625000)
  clock returned to |000>: 1.000000; output state [ 0.948683+0.j -0.316228+0.j]; exact [ 0.948683+0.j -0.316228+0.j]; fidelity 1.0000000000
  classical solution recovered with its scale: [ 0.75 -0.25], exact [ 0.75 -0.25]
  b = |u_max>: success probability 1/kappa^2 for kappa = 2, 5, 10

=== The same system with a generic t = 0.9 pi / 2: the clock no longer represents the eigenvalues exactly (Table 5.hhlclock)
Fidelity below is conditional on BOTH ancilla=1 and clock=0; rho gives ancilla-only output.
  m       C   window  success  clock reset  1 - fidelity           x (scaled)
  3  0.9000  uniform   0.4081     0.636700      3.30e-01    [ 0.3372 -0.4551]
  4  0.9000  uniform   0.3134     0.641474      4.14e-02    [ 0.4948 -0.0581]
  6  0.9000  uniform   0.4866     0.937113      1.37e-04    [ 0.7145 -0.2289]
  8  0.9000  uniform   0.4976     0.982137      4.80e-05    [ 0.7386 -0.2405]
 10  0.9000  uniform   0.5045     0.995347      1.55e-06    [ 0.7473 -0.248 ]
  3  0.9000     sine   0.3603     0.546603      2.38e-01    [ 0.3324 -0.3642]
  4  0.9000     sine   0.2993     0.517898      2.32e-03    [ 0.4212 -0.1182]
  6  0.9000     sine   0.5076     0.998438      4.01e-07    [ 0.7503 -0.2506]
  8  0.9000     sine   0.5063     0.999926      5.55e-10        [ 0.75 -0.25]
 10  0.9000     sine   0.5063     0.999996      1.98e-12        [ 0.75 -0.25]

=== -u'' = sin(pi x), four interior points, two system qubits (Table 5.poisson)
  eigenvalues [ 9.54915 34.54915 65.45085 90.45085], condition number 9.472
  finite-difference solution [0.061554 0.099596 0.099596 0.061554], exact [0.059555 0.096362 0.096362 0.059555], discretisation error 3.23e-03
  m   success   fidelity   max |u_HHL - u_FD|   max |u_HHL - u|
  4    0.3447   1.000000             4.40e-02          4.08e-02
  5    0.2435   1.000000             6.02e-02          5.70e-02
  6    0.7257   1.000000             9.35e-03          6.12e-03
  7    0.7505   1.000000             6.79e-03          3.55e-03
  8    0.8104   1.000000             1.75e-04          3.06e-03
  9    0.8108   1.000000             1.69e-05          3.25e-03
 10    0.8102   1.000000             7.62e-06          3.24e-03
=== The resolvent (z - H)^{-1} of the two-level pairing Hamiltonian, b = |10> (Fig. 5.hhlresolvent)
  eigenvalues [-0.618034  0.        1.        1.618034], |beta_j|^2 = [0.947214 0.       0.       0.052786]
  m = 6: largest relative error at least 0.3 away from every pole 5.51e-01; success probability at z = 2: 0.0585, at z = -1: 0.7572
  m = 9: largest relative error at least 0.3 away from every pole 2.70e-04; success probability at z = 2: 0.0591, at z = -1: 0.7686
     z   exact G   HHL m=6   HHL m=9  success m=9
 -1.50   -1.0909   -1.0454   -1.0909       0.7708
 -0.25    2.5455    2.5642    2.5458       0.3549
  0.50    0.8000    0.7994    0.8000       0.1620
  2.50    0.3636    0.3609    0.3636       0.1041
HHL checks passed
../_images/8cc194a596f6075d8701e25312a0ef5e9cb15b057db651d4603a48bdcd6bc07e.png ../_images/77f958bd133dcc7d657b513f9a947977d04cc3a60f8ed2a76951ff9e1aaddba2.png
import runpy, time
from IPython.display import Image, display
t0 = time.time()
runpy.run_path(str(root / 'BookPrograms' / 'chapter5/validation.py'), run_name='__main__')
for png in sorted((root / 'BookFigures' / 'chapter5').glob('*.png')):
    if png.stat().st_mtime >= t0:
        display(Image(str(png)))
PASS: full QFT, inverse swaps and input-independent truncation bound
PASS: complex-basis QPE, analytical mixture, conditional state and phase boundaries
PASS: controlled identity phase changes the energy readout
PASS: iterative QPE on a superposition (1024 seeded shots), eigenstate-only majority guard
PASS: signed complex HHL and distinct ancilla-only/joint output normalization
PASS: mixed-source Poisson residual and complex-frequency Hermitian embedding
PASS: invalid physical inputs and impossible conditioning rejected
All Chapter 5 independent validation checks passed.