Chapter 4: Hamiltonian Simulation and Time Evolution#
Every algorithm of these notes that uses a Hamiltonian applies its time evolution \(e^{-i\hat{H}t}\), and this chapter is about implementing it. We develop the product formulas of first, second and higher order, the Trotter–Suzuki decompositions, with their error bounds in terms of commutators and their cost at a given accuracy, and we show that a Trotter step is the exact evolution under an effective Hamiltonian, which explains what Trotterization conserves and what a spectral measurement then returns. The formulas are run on the transverse-field Ising chain and the Heisenberg chain, compiled into circuits and counted in gates. Time evolution is then used as a tool: a time series of overlaps measured with one ancilla gives energies, a slowly changing Hamiltonian prepares a correlated ground state adiabatically, and evolution in imaginary time projects onto the ground state at the price of a success probability. The chapter ends with a guide to the simulation methods beyond product formulas.
# 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#
The Hamiltonians of Chapter 3 reached the quantum computer as sums of Pauli strings, and Section From Pauli sums to circuits and measurements turned one such string into a short circuit. This chapter is about the operation that every later algorithm asks of those circuits, the time evolution
with \(\hbar=1\). Phase estimation in Chapter 5 applies \(e^{-i\hat{H}t}\) under the control of an ancilla, the filters of Chapter 7 do the same for random times, the alternating circuit of the quantum approximate optimization algorithm in Chapter 6 is a time evolution with adjustable times, and the real-time dynamics of a many-body system, the application that Chapter 1 singled out as the clearest opportunity for a quantum computer, is Eq. (4.1) itself.
The difficulty is that \(\hat{H}=\sum_j\hat{H}_j\) is a sum of terms that do not commute, while a circuit can only apply the exponential of one simple term at a time. The oldest and still the most widely used answer is the product formula, or Trotterization: replace the exponential of the sum by a product of exponentials of the terms and repeat it over short time steps. Section The Baker–Campbell–Hausdorff expansion and Trotter splitting derived the first- and second-order formulas from the Baker–Campbell–Hausdorff expansion and Section Trotter steps as circuits and a first time evolution compiled a first Trotter step into gates. Here we take the subject up systematically. Section Time evolution as a computational task states the task and its error measures. Section Product formulas develops the product formulas of all orders, their error bounds in terms of commutators, and their cost at a given accuracy. Section The effective Hamiltonian of a Trotter step looks at a Trotter step from the other side, as the exact evolution under a slightly different Hamiltonian, which explains what Trotterization conserves and what phase estimation then measures. Sections Dynamics of two spin chains and From formulas to circuits run the formulas on two spin chains and count the gates. Section Energies from a time series extracts energies from a time series of overlaps measured with one ancilla. Section Time-dependent Hamiltonians and adiabatic preparation treats Hamiltonians that depend on time and prepares a correlated ground state adiabatically, and Section Imaginary time treats evolution in imaginary time, which is not unitary and has to be paid for with a success probability. Section Beyond product formulas is a short guide to the simulation methods that are not product formulas.
We use two models throughout. The first is new, the transverse-field Ising chain of \(n\) spins with open ends,
which is already a sum of Pauli strings and splits into two pieces whose terms commute among themselves; it returns as a target in Chapters 11 and 12. The others are the models of Chapter 3 in the encodings of Section The four models on a qubit register: the Heisenberg chain of Eq. (3.35), the Lipkin model on one qubit per doublet, Eq. (3.73), and the pairing model on one qubit per level, Eq. (3.78). All calculations are dense-matrix simulations on at most eight qubits, checked against exact diagonalization, so that every error quoted below is an error of the method and not of the reference.
Time evolution as a computational task#
The task of Hamiltonian simulation is this: given a description of \(\hat{H}\), a time \(t\) and an accuracy \(\varepsilon\), construct a circuit \(V\) with
in the spectral norm (Section Matrix norms), with a number of gates that grows polynomially with the number of qubits, with \(t\) and with \(1/\varepsilon\). Lloyd’s result [Lloyd1996], quoted in Chapter 1, is that product formulas achieve this for Hamiltonians built from a polynomial number of local terms. Three remarks fix what the norm in Eq. (4.3) does and does not control.
First, it bounds the error of every state and every observable at once. If \(\Vert V-U\Vert\le\varepsilon\) for two unitaries, then \(\Vert V\vert\psi\rangle-U\vert\psi\rangle\Vert\le\varepsilon\) for every normalized state, and for every observable \(\hat{O}\)
which follows by adding and subtracting \(\langle\psi\vert V^\dagger\hat{O}U\vert\psi\rangle\). The converse does not hold: a particular state or a particular observable can be far more accurate than the norm suggests, and Section Dynamics of two spin chains shows a case in which it is, by a symmetry of the initial state. Second, errors of unitary steps add at most linearly,
because \(V^r-U^r=\sum_{k=0}^{r-1}V^{k}(V-U)U^{r-1-k}\) and unitaries have norm one. A bound on one short step is therefore a bound on the whole evolution, and all the bounds below are derived that way. Third, Eq. (4.3) concerns the evolution operator only. The preparation of \(\vert\psi(0)\rangle\) and the estimation of an observable from samples are separate costs, as Chapter 1 stressed, and the statistical error of Eq. (1.4) has to be added to the simulation error before a number can be compared with experiment.
The cost of a circuit is counted here in three ways: the number of exponentials \(e^{-i\tau\hat{H}_j}\) it contains, which is independent of how a term is compiled; the number of CNOT gates, with the gadget of Eq. (3.81) and the improvements of Section From formulas to circuits; and the depth. None of the counts includes routing on a device with limited connectivity or the synthesis of rotations from a fault-tolerant gate set.
Product formulas#
First and second order#
Let \(\hat{H}=\sum_{j=1}^{m}\hat{H}_j\) with Hermitian terms whose exponentials we can apply. The first-order, or Lie–Trotter, formula [Trotter1959] for a step of length \(\Delta t\) is
with \(\hat{H}_1\) acting first, and the second-order, symmetric or Strang, formula is
The evolution over a time \(t\) is approximated by \(r\) steps, \(e^{-i\hat{H}t}\approx S_p(t/r)^r\). These are Eqs. (3.47) and (3.48) for \(m\) terms. One step of \(S_1\) contains \(m\) exponentials and one step of \(S_2\) contains \(2m-1\); in a sequence of steps the last factor of one step of \(S_2\) merges with the first factor of the next, so that the second order costs \(2m-2\) exponentials per step, less than twice the first, and for \(m=2\) exactly the same.
The errors of the two formulas are governed by commutators, as the Baker–Campbell–Hausdorff expansion of Eq. (3.46) suggests, and Childs and coworkers [Childs2021] have turned the suggestion into bounds with explicit constants that do not rest on truncating that series:
With Eq. (4.5) the error of \(r\) steps over a time \(t\) is at most \(r\) times these expressions at \(\Delta t=t/r\), that is proportional to \(t^2/r\) and to \(t^3/r^2\). Two features matter in practice. The bounds vanish when the terms commute, and they involve only the commutators and not the norms of the terms, so that for a lattice Hamiltonian with short-range interactions, in which a term fails to commute with a few neighbors only, the error per step grows with the number of sites and not with its square. And the grouping is ours to choose: terms that commute with each other can be collected into one \(\hat{H}_j\) at no cost in error, which is what the two pieces of Eq. (4.2) do.
Suzuki’s formulas of higher order#
A symmetric formula, one that satisfies \(S(-\Delta t)S(\Delta t)=1\), has an error expansion in odd powers of \(\Delta t\) only. Suzuki [Suzuki1990,Suzuki1991] used this to build formulas of every even order from \(S_2\) recursively,
The five factors advance the time by \(4p_k+(1-4p_k)=1\) steps in all. The leading error of \(S_{2k-2}(x)\) is proportional to \(x^{2k-1}\), and the five errors add to \(4p_k^{2k-1}+(1-4p_k)^{2k-1}\) times it, which the choice of \(p_k\) makes zero; since the product is again symmetric, its error starts two orders higher. For the fourth order \(p_2=0.4144908\) and \(1-4p_2=-0.6579631\): the middle factor runs backward in time, which is harmless for a unitary evolution and will not be for the imaginary time of Section Imaginary time. The price is the number of factors, five times that of the order below. After merging neighbors, one step of \(S_{2k}\) for \(m\) terms has \(2(m-1)5^{k-1}+1\) exponentials: \(3\), \(11\) and \(51\) for \(m=2\) and the orders two, four and six. For the two-term splitting of the Ising chain the fourth-order step is the sequence, in chronological order and in units of \(\Delta t\),
with \(A=\hat{H}_{ZZ}\) and \(B=\hat{H}_X\), where
\((1-3p_2)/2=-0.1217\). The class ProductFormula of
product_formulas.py stores a step in exactly this form, a
chronological list of pairs (term, coefficient), from which both the
matrix of the step and, in Section From formulas to circuits, its circuit
are built:
import numpy as np
from product_formulas import ProductFormula, ising_terms, propagator
terms = ising_terms(4, J=1.0, h=1.0) # [H_ZZ, H_X] on four qubits
exact = propagator(sum(terms), 1.0) # exp(-iHt) at t = 1
for order in (1, 2, 4):
pf = ProductFormula(terms, order)
errors = [pf.error(1.0, r, exact) for r in (4, 8, 16)]
print(order, pf.exponentials(), ["%.2e" % e for e in errors])
1 2 ['3.56e-01', '1.74e-01', '8.65e-02']
2 3 ['7.30e-02', '1.79e-02', '4.45e-03']
4 11 ['5.02e-04', '3.24e-05', '2.04e-06']
For a formula of order \(p\) the error of \(r\) steps and the number of steps needed for an accuracy \(\varepsilon\) are
with \(\alpha_p\) a sum of norms of nested commutators of \(p+1\) terms [Childs2021]. As \(p\) grows the number of steps approaches the linear dependence on \(t\) that no method can improve on, but the number of exponentials per step grows as \(5^{p/2}\), and the order that minimizes the total cost depends on \(t\) and \(\varepsilon\).
The Ising chain as a test#
Table 4.1 and Fig. 4.1 show the four formulas for the Ising chain with \(n=6\) and \(J=h=1\), for which \(\Vert\hat{H}\Vert=7.296\) and \(\Vert[\hat{H}_{ZZ},\hat{H}_X]\Vert=13.976\), at \(t=1\). The errors fall as \(r^{-1}\), \(r^{-2}\), \(r^{-4}\) and \(r^{-6}\); the fitted exponents for \(r\ge4\) are \(-1.01\), \(-2.01\), \(-3.99\) and \(-6.06\). The sixth-order formula reaches the round-off floor of the dense matrices, a few times \(10^{-12}\), at \(r=32\). The bounds of Eqs. (4.8) and (4.9) hold at every \(r\), as the program asserts, and overestimate the error by factors of \(3.1\) and \(3.6\) at \(r=64\): they have the right scaling and the right order of magnitude, which is as much as a bound valid for every Hamiltonian with these commutators can give.
\(r\) |
\(p=1\) |
bound |
\(p=2\) |
bound |
\(p=4\) |
\(p=6\) |
|---|---|---|---|---|---|---|
\(1\) |
\(2.00\) |
\(6.99\) |
\(1.94\) |
\(6.71\) |
\(5.17\times10^{-1}\) |
\(1.65\times10^{-2}\) |
\(2\) |
\(1.22\) |
\(3.49\) |
\(5.20\times10^{-1}\) |
\(1.68\) |
\(1.38\times10^{-2}\) |
\(8.54\times10^{-5}\) |
\(4\) |
\(5.77\times10^{-1}\) |
\(1.75\) |
\(1.20\times10^{-1}\) |
\(4.19\times10^{-1}\) |
\(8.61\times10^{-4}\) |
\(9.50\times10^{-7}\) |
\(8\) |
\(2.84\times10^{-1}\) |
\(8.73\times10^{-1}\) |
\(2.92\times10^{-2}\) |
\(1.05\times10^{-1}\) |
\(5.51\times10^{-5}\) |
\(1.38\times10^{-8}\) |
\(16\) |
\(1.41\times10^{-1}\) |
\(4.37\times10^{-1}\) |
\(7.27\times10^{-3}\) |
\(2.62\times10^{-2}\) |
\(3.47\times10^{-6}\) |
\(2.13\times10^{-10}\) |
\(32\) |
\(7.05\times10^{-2}\) |
\(2.18\times10^{-1}\) |
\(1.81\times10^{-3}\) |
\(6.55\times10^{-3}\) |
\(2.17\times10^{-7}\) |
\(3.5\times10^{-12}\) |
\(64\) |
\(3.52\times10^{-2}\) |
\(1.09\times10^{-1}\) |
\(4.53\times10^{-4}\) |
\(1.64\times10^{-3}\) |
\(1.36\times10^{-8}\) |
\(3.2\times10^{-12}\) |
Table 4.1: Spectral-norm error \(\Vert e^{-i\hat{H}t}-S_p(t/r)^r\Vert\) of
the product formulas of order \(p=1,2,4,6\) for the Ising chain of
Eq. (4.2) with \(n=6\), \(J=h=1\), at \(t=1\), with the bounds of
Eqs. (4.8) and (4.9). Produced by
product_formulas.py.

Figure 4.1: Product formulas for the Ising chain with \(n=6\), \(J=h=1\) at \(t=1\). Left: the error against the number of steps, with the bounds of Eqs. (4.8) and (4.9) as dotted lines. Right: the same errors against the number of exponentials, the measure of cost. Produced by product_formulas.py.
The right panel of the figure plots the same errors against the number of exponentials, and Table 4.2 gives the number of steps and exponentials that each order needs to reach a given accuracy. The conclusion is the one of Eq. (4.11): there is no best order. At \(t=1\) and \(\varepsilon=10^{-2}\) the second-order formula is the cheapest, with \(29\) exponentials against \(31\) and \(101\) for the orders four and six; at \(\varepsilon=10^{-4}\) the fourth order wins by a factor of four over the second; and at \(t=5\) and \(\varepsilon=10^{-6}\) the sixth order, with \(1101\) exponentials, needs \(30\) percent fewer than the fourth and \(24\) times fewer than the second. The first order is never competitive, for a reason that Section The effective Hamiltonian of a Trotter step makes exact: for two terms it costs the same as the second order and is one order less accurate.
\(p=1\) |
\(p=2\) |
\(p=4\) |
\(p=6\) |
||||||
|---|---|---|---|---|---|---|---|---|---|
\(t\) |
\(\varepsilon\) |
\(r\) |
exp. |
\(r\) |
exp. |
\(r\) |
exp. |
\(r\) |
exp. |
\(1\) |
\(10^{-2}\) |
\(226\) |
\(452\) |
\(14\) |
\(29\) |
\(3\) |
\(31\) |
\(2\) |
\(101\) |
\(1\) |
\(10^{-4}\) |
\(22547\) |
\(45094\) |
\(137\) |
\(275\) |
\(7\) |
\(71\) |
\(2\) |
\(101\) |
\(1\) |
\(10^{-6}\) |
\(2.3\times10^{6}\) |
\(4.5\times10^{6}\) |
\(1363\) |
\(2727\) |
\(22\) |
\(221\) |
\(4\) |
\(201\) |
\(5\) |
\(10^{-2}\) |
\(1048\) |
\(2096\) |
\(135\) |
\(271\) |
\(15\) |
\(151\) |
\(7\) |
\(351\) |
\(5\) |
\(10^{-4}\) |
\(104725\) |
\(209450\) |
\(1343\) |
\(2687\) |
\(49\) |
\(491\) |
\(11\) |
\(551\) |
\(5\) |
\(10^{-6}\) |
\(1.0\times10^{7}\) |
\(2.1\times10^{7}\) |
\(13423\) |
\(26847\) |
\(155\) |
\(1551\) |
\(22\) |
\(1101\) |
Table 4.2: Number of steps \(r\) and of exponentials needed for an error
\(\varepsilon\) in the spectral norm, Ising chain with \(n=6\) and
\(J=h=1\). The first-order entries at \(\varepsilon=10^{-6}\) are
extrapolated with the \(1/r\) law. Produced by
product_formulas.py.
The effective Hamiltonian of a Trotter step#
A step of a product formula is a unitary, and every unitary is the exponential of a Hermitian matrix. We can therefore write
with the eigenvalues of \(\hat{H}_{\mathrm{eff}}\Delta t\) in \((-\pi,\pi]\), and read Trotterization differently: \(r\) steps are not an approximate evolution under \(\hat{H}\) but the exact evolution under \(\hat{H}_{\mathrm{eff}}\) for the time \(r\Delta t\). For two terms \(A\) and \(B\), with \(A\) acting first, the Baker–Campbell–Hausdorff expansion gives
both corrections being Hermitian. The program computes \(\hat{H}_{\mathrm{eff}}\) from the logarithm of the step and confirms the two expansions, Table 4.3: the distance \(\Vert\hat{H}_{\mathrm{eff}}-\hat{H}\Vert\) is linear in \(\Delta t\) for the first order and quadratic for the second, and after subtracting the leading corrections the remainders fall by factors of four and sixteen when the step is halved. By Weyl’s inequality, Eq. (B.23), this distance bounds the shift of every eigenvalue.
order |
\(\Delta t\) |
\(\Vert\hat{H}_{\mathrm{eff}}-\hat{H}\Vert\) |
remainder |
\(E_0^{\mathrm{eff}}-E_0\) |
|---|---|---|---|---|
\(1\) |
\(0.2\) |
\(1.42\) |
\(2.46\times10^{-1}\) |
\(5.82\times10^{-2}\) |
\(1\) |
\(0.1\) |
\(7.02\times10^{-1}\) |
\(6.00\times10^{-2}\) |
\(1.43\times10^{-2}\) |
\(1\) |
\(0.05\) |
\(3.50\times10^{-1}\) |
\(1.49\times10^{-2}\) |
\(3.57\times10^{-3}\) |
\(1\) |
\(0.025\) |
\(1.75\times10^{-1}\) |
\(3.72\times10^{-3}\) |
\(8.91\times10^{-4}\) |
\(2\) |
\(0.2\) |
\(2.05\times10^{-1}\) |
\(7.15\times10^{-3}\) |
\(5.82\times10^{-2}\) |
\(2\) |
\(0.1\) |
\(5.02\times10^{-2}\) |
\(4.36\times10^{-4}\) |
\(1.43\times10^{-2}\) |
\(2\) |
\(0.05\) |
\(1.25\times10^{-2}\) |
\(2.71\times10^{-5}\) |
\(3.57\times10^{-3}\) |
\(2\) |
\(0.025\) |
\(3.12\times10^{-3}\) |
\(1.69\times10^{-6}\) |
\(8.91\times10^{-4}\) |
Table 4.3: The effective Hamiltonian of one step for the Ising chain
with \(n=6\), \(J=h=1\): its distance from \(\hat{H}\), the remainder after
subtracting the leading correction of Eqs. (4.13)
and (4.14), and the shift of the ground-state energy,
which is the same for the two orders. Produced by
product_formulas.py.
The last column of the table holds a surprise: the eigenvalues of the two effective Hamiltonians are identical, and both are shifted from those of \(\hat{H}\) in second order of the step, although \(\hat{H}_{\mathrm{eff}}\) of the first-order formula differs from \(\hat{H}\) in first order. The explanation is an identity. For two terms,
because \(S_1=e^{-iB\Delta t}e^{-iA\Delta t}\) and conjugation with \(W\) moves half of the factor \(e^{-iA\Delta t}\) to the other side. The two steps are the same operator in two bases; their effective Hamiltonians have the same spectrum, and \(r\) steps of the first order differ from \(r\) steps of the second only by a half step of \(A\) at the beginning and at the end. Consistently, first-order perturbation theory with the correction of Eq. (4.13) gives no shift, since \(\langle E\vert i[A,B]\vert E\rangle =\langle E\vert i[A,\hat{H}]\vert E\rangle=0\) in an eigenstate of \(\hat{H}\). The identity does not extend to more than two terms.
The effective Hamiltonian explains three things that the error bounds do not.
Conservation. The Trotterized evolution conserves \(\hat{H}_{\mathrm{eff}}\) exactly. The expectation value of \(\hat{H}\) itself therefore oscillates around its initial value with an amplitude set by \(\Vert\hat{H}_{\mathrm{eff}}-\hat{H}\Vert\) and does not drift: for the quench of Section Dynamics of two spin chains, the largest deviation of the energy in four consecutive time windows up to \(t=100\) is \(0.411\), \(0.417\), \(0.404\) and \(0.416\) with second-order steps of \(\Delta t=0.25\), and four times smaller with \(\Delta t=0.125\). This holds as long as the step is small enough for \(\hat{H}_{\mathrm{eff}}\) to be a small deformation of \(\hat{H}\); for large steps the Trotterized dynamics of a many-body system becomes chaotic and heats, with a sharp threshold in the step that also bounds the error of local observables below it [Heyl2019].
Spectroscopy. An algorithm that reads eigenvalues from a Trotterized evolution, the phase estimation of Chapter 5 or the time series of Section Energies from a time series, returns the eigenvalues of \(\hat{H}_{\mathrm{eff}}\). Its Trotter error is a systematic shift, \(5.8\times10^{-2}\) at \(\Delta t=0.2\) in Table 4.3, that no amount of statistics removes and that falls as \(\Delta t^2\) for the formulas of first and second order alike. Section The second error: Trotterization counts what it costs to push it below the resolution of the phase register.
Fixed and variable steps. All of this presupposes a fixed step. If the same total time is reached with steps of different lengths, as in the filters of Chapter 7, whose evolution times are random, there is no single effective Hamiltonian, and the fixed-step picture is a diagnostic rather than a description.
Dynamics of two spin chains#
A quench of the Ising chain#
We prepare the Ising chain with \(n=8\) and \(J=h=1\) in the ferromagnetic product state \(\vert 00\cdots0\rangle\), the ground state at \(h=0\), and let it evolve under the full Hamiltonian: a quench. The state has the energy \(\langle\hat{H}\rangle=-7\). We follow two quantities, the magnetization per site \(m_z(t)=\frac1n\sum_i\langle Z_i\rangle\) and the Loschmidt echo \(\mathcal{L}(t)=\vert\langle\psi(0)\vert\psi(t)\rangle\vert^2\), the probability of finding the system in its initial state. Table 4.4 and the left panel of Fig. 4.2 compare the exact evolution with product formulas at the step \(\Delta t=0.25\) up to \(t=5\).
\(t\) |
\(m_z\) exact |
orders 1 and 2 |
order 4 |
echo |
|---|---|---|---|---|
\(0\) |
\(1.000000\) |
\(1.000000\) |
\(1.000000\) |
\(1.000000\) |
\(1\) |
\(0.239113\) |
\(0.219711\) |
\(0.239121\) |
\(0.093211\) |
\(2\) |
\(0.019500\) |
\(0.020075\) |
\(0.019465\) |
\(0.065996\) |
\(3\) |
\(-0.003369\) |
\(-0.004663\) |
\(-0.003356\) |
\(0.006130\) |
\(4\) |
\(0.002132\) |
\(0.001836\) |
\(0.002137\) |
\(0.130439\) |
\(5\) |
\(-0.001376\) |
\(-0.000976\) |
\(-0.001384\) |
\(0.153072\) |
Table 4.4: Quench of the Ising chain with \(n=8\), \(J=h=1\) from
\(\vert 0\cdots0\rangle\): the magnetization per site from the exact
evolution and from product formulas with \(\Delta t=0.25\), and the
exact Loschmidt echo. The columns of the first and the second order
coincide. Produced by lattice_dynamics.py.

Figure 4.2: Left: quench of the Ising chain (\(n=8\), \(J=h=1\)) from \(\vert 0\cdots0\rangle\); the exact magnetization and Loschmidt echo and the magnetization from product formulas with \(\Delta t=0.25\). Right: the staggered magnetization of the Heisenberg chain (\(n=8\)) from the Néel state, exact and from second-order steps with \(\Delta t=0.4\) in two splittings. Produced by lattice_dynamics.py.
The magnetization decays within a few units of time while the echo revives, as it must in a system of eight spins. The numbers of the first- and second-order formulas agree to every digit shown, with a largest error of \(2.3\times10^{-2}\) in \(m_z\) and \(8.0\times10^{-2}\) in the echo. This is Eq. (4.15) at work, together with two properties of this particular calculation: the initial state is an eigenstate of \(A=\hat{H}_{ZZ}\), so that the half step \(W\) only multiplies it by a phase, and both observables commute with \(A\), so that the half step at the end does nothing to them either. A first-order formula is here a second-order formula in disguise. The energy, which does not commute with \(A\), tells the two apart: its largest error is \(1.61\) in first order and \(0.41\) in second. The fourth-order formula with the same step reduces the errors to \(1.9\times10^{-4}\) and \(5.3\times10^{-4}\) at five times the number of exponentials, \(201\) against \(41\); the second-order formula reaches \(8.5\times10^{-5}\) in \(m_z\) only at \(\Delta t=1/64\), with \(641\) exponentials.
The Heisenberg chain and what a splitting conserves#
The Heisenberg chain of Eq. (3.35) with open ends, \(\hat{H}=\frac{J}{4}\sum_i(X_iX_{i+1}+Y_iY_{i+1}+Z_iZ_{i+1})\), can be split in two natural ways. The even–odd splitting collects the bonds \((0,1),(2,3),\ldots\) into one piece and the bonds \((1,2),(3,4),\ldots\) into the other; the bonds of a piece act on different qubits and commute, and each bond operator is exponentiated as a whole. The Pauli splitting collects all \(XX\) strings into one piece, all \(YY\) strings into a second and all \(ZZ\) strings into a third; the strings of a piece commute as well, and each is a Pauli rotation of Section The exponential of a Pauli string. Both are legitimate product formulas of the same Hamiltonian. They differ in what they conserve. The Hamiltonian commutes with the total spin projection \(\hat{S}^z=\frac12\sum_iZ_i\). So does every bond operator, and hence every factor of the even–odd formula: that formula conserves \(\hat{S}^z\) exactly, for any step. The \(XX\) and \(YY\) pieces do not commute with \(\hat{S}^z\) separately, the program finds \(\Vert[\hat{H}_{XX},\hat{S}^z]\Vert=2.379\), and the Pauli formula conserves \(\hat{S}^z\) only as well as it approximates the evolution.
Table 4.5 follows the chain with \(n=8\) from the Néel state \(\vert 01010101\rangle\), which has \(S^z=0\) and \(\langle\hat{H}\rangle=-1.75\), up to \(t=6\) with second-order steps. The staggered magnetization \(m_s=\frac{1}{2n}\sum_i(-1)^i\langle Z_i\rangle\), shown in the right panel of Fig. 4.2, is reproduced by both splittings with errors that fall as \(\Delta t^2\), the even–odd one being somewhat more accurate. The energy error of the Pauli splitting is seven times larger, and it populates the sectors with \(S^z\ne0\) with a weight \(\langle(\hat{S}^z)^2\rangle\) that falls as \(\Delta t^4\) but is not zero. For the dynamics of a spin chain this is a small error among others. For a calculation that relies on a symmetry sector, a fixed particle number in the Jordan–Wigner encoding of a fermionic model, say, it is a qualitative one, and the remedy is the one used here: split the Hamiltonian into pieces that each respect the symmetry. The same care returns for imaginary time in Section Imaginary time, where a leak out of a sector does not stay small.
splitting |
\(\Delta t\) |
\(\max\vert\delta m_s\vert\) |
\(\max\vert\delta E\vert\) |
\(\max\langle(\hat{S}^z)^2\rangle\) |
|---|---|---|---|---|
even–odd bonds |
\(0.4\) |
\(4.62\times10^{-3}\) |
\(5.76\times10^{-3}\) |
\(0\) |
even–odd bonds |
\(0.2\) |
\(1.16\times10^{-3}\) |
\(1.40\times10^{-3}\) |
\(0\) |
even–odd bonds |
\(0.1\) |
\(2.90\times10^{-4}\) |
\(3.49\times10^{-4}\) |
\(0\) |
\(XX\), \(YY\), \(ZZ\) |
\(0.4\) |
\(6.41\times10^{-3}\) |
\(3.82\times10^{-2}\) |
\(9.46\times10^{-4}\) |
\(XX\), \(YY\), \(ZZ\) |
\(0.2\) |
\(1.59\times10^{-3}\) |
\(9.55\times10^{-3}\) |
\(5.86\times10^{-5}\) |
\(XX\), \(YY\), \(ZZ\) |
\(0.1\) |
\(3.96\times10^{-4}\) |
\(2.39\times10^{-3}\) |
\(3.65\times10^{-6}\) |
Table 4.5: The Heisenberg chain with \(n=8\) and \(J=1\) from the Néel
state, second-order steps up to \(t=6\) in two splittings: the largest
errors of the staggered magnetization and of the energy, and the
largest weight outside the sector \(S^z=0\). Produced by
lattice_dynamics.py.
From formulas to circuits#
Two-qubit exponentials#
The exponentials of the Ising chain are of two kinds. The transverse field is a layer of single-qubit rotations, \(e^{-i\tau\hat{H}_X}=\prod_iR_x(-2h\tau)\), and the coupling is a layer of two-qubit gates, each of them the Pauli rotation of Eq. (3.81) for a string of weight two,
two CNOT gates and one rotation. The bonds \((0,1),(2,3),\ldots\) act on different qubits and can be applied simultaneously, and so can the bonds \((1,2),(3,4),\ldots\), so that the layer has depth six whatever the length of the chain.
The bond of the Heisenberg chain is the exponential of three commuting strings, \(XX\), \(YY\) and \(ZZ\), and three gadgets would cost six CNOT gates. It can be done with three. The reason is that an arbitrary two-qubit gate needs at most three CNOT gates [VatanWilliams2004], and the construction for the gates of this form is the circuit of Fig. 4.3,
read from right to left, with \(\mathrm{CNOT}_{ji}\) controlled by qubit
\(j\). The program bond_circuits.py verifies the identity for
random angles. For the Heisenberg bond, \(a=b=c=\theta\), there is a
second way of seeing what the gate is. The operator \(XX+YY+ZZ\) equals
\(2\,\mathrm{SWAP}-1\), the SWAP gate squares to one, and therefore
a partial SWAP: the exchange interaction exchanges the two spins, a little at a time, and at \(\theta=\pi/4\) the bond is the SWAP gate itself, whose three CNOT gates are familiar.
import numpy as np
import gates as G
from circuit import Circuit
from bond_circuits import xyz_rotation, same_up_to_phase
from pauli_circuits import gate_counts
theta = 0.3
circ = xyz_rotation(Circuit(2), 0, 1, theta, theta, theta)
partial_swap = np.cos(2*theta)*np.eye(4) - 1j*np.sin(2*theta)*G.SWAP
print(same_up_to_phase(circ.unitary(), partial_swap)[0])
print(gate_counts(circ)) # gates, CNOT gates, depth
True
(8, 3, 7)

Figure 4.3: The circuit of Eq. (4.17) for \(e^{-i(aX_iX_j+bY_iY_j+cZ_iZ_j)}\), up to a global phase: three CNOT gates and five single-qubit rotations. With \(a=b=c=\theta\) it is the bond of the Heisenberg chain, the partial SWAP of Eq. (4.18). Verified in bond_circuits.py.
Counting the gates of a simulation#
With these gates a product formula is a circuit, and the program builds it from the same list of terms and coefficients that defined the matrix of the step, compares the two for \(n=6\), and counts. Table 4.6 gives the gates, the CNOT gates and the depth of a second-order step in a long sequence, where the half steps at the ends have merged. The numbers grow linearly with the length of the chain, \(2(n-1)\) CNOT gates per step for the Ising chain and \(3(n-1)\) for the Heisenberg chain, and the depth does not grow at all: a step is a fixed number of layers of gates on disjoint pairs. For the Heisenberg chain the three-CNOT bond halves the entangling gates and more than halves the depth of the version built from Pauli rotations.
chain |
\(n\) |
gates |
CNOT |
depth |
|---|---|---|---|---|
Ising |
\(4\) |
\(13\) |
\(6\) |
\(7\) |
Ising |
\(8\) |
\(29\) |
\(14\) |
\(7\) |
Ising |
\(16\) |
\(61\) |
\(30\) |
\(7\) |
Heisenberg, three-CNOT bonds |
\(4\) |
\(24\) |
\(9\) |
\(12\) |
Heisenberg, three-CNOT bonds |
\(8\) |
\(56\) |
\(21\) |
\(12\) |
Heisenberg, three-CNOT bonds |
\(16\) |
\(120\) |
\(45\) |
\(12\) |
Heisenberg, Pauli rotations |
\(4\) |
\(63\) |
\(18\) |
\(30\) |
Heisenberg, Pauli rotations |
\(8\) |
\(147\) |
\(42\) |
\(30\) |
Heisenberg, Pauli rotations |
\(16\) |
\(315\) |
\(90\) |
\(30\) |
Table 4.6: One second-order step in a long sequence, as a circuit:
gates, CNOT gates and depth for chains of \(n\) sites. Produced by
bond_circuits.py.
The totals for the calculations of Section Dynamics of two spin chains follow. The Ising quench up to \(t=5\) with second-order steps of \(\Delta t=0.25\) is a circuit of \(601\) gates, \(294\) of them CNOT gates, of depth \(146\); the fourth-order formula with the same step has \(1414\) CNOT gates, and the second-order formula with the step \(1/64\) that matches its accuracy has \(4494\). The Heisenberg chain up to \(t=6\) costs \(327\) CNOT gates at \(\Delta t=0.4\) and \(1272\) at \(\Delta t=0.1\). These are the numbers to set against the error rates of Section The hardware. With an error of \(10^{-3}\) per two-qubit gate, the expected number of faults is \(0.3\) in the cheapest of these circuits and \(4.5\) in the most accurate, and the step that minimizes the total error of an uncorrected device is therefore a compromise: a smaller step reduces the Trotter error as a power of \(\Delta t\) and increases the gate error in proportion to \(1/\Delta t\). Experiments on the dynamics of Ising models on more than a hundred qubits [Kim2023] are circuits of exactly this kind, at most a few tens of Trotter steps deep.
Energies from a time series#
Time evolution gives access to the spectrum. Expand the initial state in eigenstates, \(\vert\psi\rangle=\sum_jc_j\vert E_j\rangle\) with weights \(p_j=\vert c_j\vert^2\); then the Loschmidt amplitude is
a sum of oscillations whose frequencies are the eigenvalues and whose amplitudes are the weights. Unlike the echo of Section Dynamics of two spin chains it is a complex number and cannot be read off as a probability, but one ancilla suffices to measure it. In the Hadamard test of Fig. 4.4 the ancilla is put into \((\vert0\rangle+\vert1\rangle)/\sqrt2\), the evolution is applied to the system if the ancilla is \(\vert1\rangle\), and the ancilla is measured after a second Hadamard gate, preceded by \(S^\dagger\) for the imaginary part. The probabilities of the outcome \(0\) are
so that each part is a bias estimated from shots with the statistics of Eq. (1.4). This is the one-ancilla circuit of Section Phase estimation with one control qubit; the difference lies in what is done with its output.

Figure 4.4: The Hadamard test for the Loschmidt amplitude \(g(t)=\langle\psi\vert e^{-i\hat{H}t}\vert\psi\rangle\). Without the dashed gate the ancilla returns \(0\) with probability \((1+\mathrm{Re}\,g)/2\), with it \((1+\mathrm{Im}\,g)/2\), Eq. (4.20).
Given the amplitude at \(K\) equidistant times \(t_k=k\tau\), a windowed Fourier sum
with a smooth window \(w_k\), here \(w_k=\sin^2[\pi(k+\frac12)/K]\), has a peak of height \(p_j\) at every eigenvalue on which the state has weight. The peaks have a width of order \(2\pi/(K\tau)\), the inverse of the longest evolution time, and the sampling interval must satisfy \(\vert E_j\vert\tau<\pi\) for all eigenvalues, or the frequencies are aliased. We take \(\tau=0.9\pi/\Lambda\) with \(\Lambda\) the sum of the absolute values of the Pauli coefficients, which bounds the spectrum; Chapter 5 makes the same choice for the same reason.
The test case is the Lipkin model of Eq. (3.73) on four qubits with the reference state \(\vert0000\rangle\), all particles in the lower level, for which \(\Lambda=6\) and \(\tau=0.4712\). The reference has weight on three eigenstates: \(p=0.9358\) on the ground state at \(E_0=-4.2129\), \(p=0.0640\) at \(E=-0.9191\) and \(p=2.6\times10^{-4}\) at \(E=4.1320\). The Hadamard test on the five-qubit register returns \(P_{\mathrm{Re}}(0)=0.3406\) and \(P_{\mathrm{Im}}(0)=0.9416\) at \(t=\tau\), that is \(g=-0.3189+0.8831\,i\), in agreement with the direct evaluation. Table 4.7 and Fig. 4.5 show the spectra from \(K=64\) samples.
\(E\) |
height |
\(E\) |
height |
|
|---|---|---|---|---|
eigenvalues and weights |
\(-4.2129\) |
\(0.9358\) |
\(-0.9191\) |
\(0.0640\) |
exact evolution |
\(-4.2130\) |
\(0.9358\) |
\(-0.9190\) |
\(0.0640\) |
\(1000\) shots per point |
\(-4.2135\) |
\(0.9358\) |
\(-0.9250\) |
\(0.0662\) |
order 2, \(\Delta t=\tau\) |
\(-4.1550\) |
\(0.9220\) |
\(-0.9290\) |
\(0.0775\) |
order 2, \(\Delta t=\tau/2\) |
\(-4.1990\) |
\(0.9325\) |
\(-0.9225\) |
\(0.0672\) |
Table 4.7: Positions and heights of the two largest peaks of \(\vert F(E)\vert\),
Eq. (4.21), for the Lipkin model on four qubits and
the reference \(\vert0000\rangle\), from \(K=64\) samples at the interval
\(\tau=0.4712\): exact amplitudes, amplitudes from \(1000\) shots per
real and imaginary part, and second-order product formulas with one
and two steps per interval. Produced by time_series.py.

Figure 4.5: The Fourier sum \(\vert F(E)\vert\) of \(K=64\) samples of the Loschmidt amplitude of the Lipkin model on four qubits in the reference state. The gray bars mark the eigenvalues with their weights. Produced by time_series.py.
Three things can be read from the table. With exact amplitudes the peaks sit at the eigenvalues to \(10^{-4}\) and their heights are the weights, although the width of a peak, \(2\pi/(K\tau)=0.21\), is two thousand times larger: the center of an isolated peak is located far better than its width, which is why the method works. With \(1000\) shots per point the ground-state peak moves by \(5\times10^{-4}\) and the small peak by \(6\times10^{-3}\); the noise of the individual amplitudes, of order \(1/\sqrt{1000}=0.03\), is averaged over the \(K\) points to a floor of \(0.009\) in \(\vert F\vert\), below which the third level, of weight \(2.6\times10^{-4}\), is invisible. And with a Trotterized evolution the peaks shift: by \(+0.058\) for one second-order step per sampling interval and by \(+0.014\) for two, the shifts of the ground-state energy of the effective Hamiltonian, \(+0.0577\) and \(+0.0141\), as Section The effective Hamiltonian of a Trotter step said they would be.
The procedure is phase estimation with the Fourier transform done on paper. Its register is one qubit, and its longest coherent evolution is \((K-1)\tau=29.7\), the evolution that one run of a phase register with \(\log_2K=6\) qubits contains; what it pays is repetition, \(K\) separate circuits with a total evolution time of \(\tau K(K-1)/2=950\), each run many times. Refinements of the idea, with better windows and with samples chosen at random times, reach the optimal scaling of the total evolution time with the accuracy [Somma2019,LinTong2022]. Like phase estimation it cannot find a level on which the initial state has little weight: the height of a peak is the overlap \(p_j\) of Eq. (1.3), and a peak below the noise floor is lost. Chapter 7 uses the same controlled evolutions to project onto an eigenstate rather than to read its energy.
Time-dependent Hamiltonians and adiabatic preparation#
The time-ordered exponential#
When the Hamiltonian depends on time, the solution of the Schrödinger equation is the time-ordered exponential, the limit of a product of short evolutions each under the Hamiltonian of its own moment. Taking that Hamiltonian at the midpoint of each interval gives an approximation of second order in the step,
with the earliest factor on the right. Each factor is an ordinary evolution and can be replaced by a product formula; with the second-order formula the whole scheme remains of second order. Nothing else changes: the terms of the Hamiltonian keep their circuits and only the angles depend on the step.
Imaginary time#
A projector that is not unitary#
Replace \(t\) by \(-i\tau\) in Eq. (4.1) and the oscillations of Eq. (4.19) become decays,
every component is damped relative to the one of lowest energy, and the normalized state converges to the lowest eigenstate on which the initial state has weight. With \(\Delta\) the gap to the next such state, the energy and the infidelity fall as
This is the principle of the projection methods of classical many-body theory, diffusion Monte Carlo among them, and of the power method of Section The power method and its quantum relatives, and it is attractive because the convergence is exponential in \(\tau\), where the adiabatic method of the previous section converged as a power of \(T\). Table 4.10 shows it for the pairing model with four levels, two pairs and \(g=1\), starting from \(\vert1100\rangle\). The reference has weights \(0.8676\) on the ground state and \(0.1063\) on the first excited state of the sector at \(E=2.9354\), so that \(\Delta=2.2998\); the energy error falls from \(0.36\) to \(2.9\times10^{-9}\) at \(\tau=4\), with a decay rate of \(4.6006\) between \(\tau=4\) and \(6\) against \(2\Delta=4.5997\).
\(\tau\) |
\(E(\tau)-E_0\) |
infidelity |
\(P\), \(E_{\min}=E_0\) |
\(P\), \(E_{\min}=-3.5\) |
|---|---|---|---|---|
\(0\) |
\(3.6\times10^{-1}\) |
\(1.3\times10^{-1}\) |
\(1.0000\) |
\(1\) |
\(0.5\) |
\(2.9\times10^{-2}\) |
\(1.2\times10^{-2}\) |
\(0.8786\) |
\(1.4\times10^{-2}\) |
\(1\) |
\(2.8\times10^{-3}\) |
\(1.2\times10^{-3}\) |
\(0.8687\) |
\(2.2\times10^{-4}\) |
\(2\) |
\(2.8\times10^{-5}\) |
\(1.2\times10^{-5}\) |
\(0.8676\) |
\(5.7\times10^{-8}\) |
\(3\) |
\(2.9\times10^{-7}\) |
\(1.2\times10^{-7}\) |
\(0.8676\) |
\(1.5\times10^{-11}\) |
\(4\) |
\(2.9\times10^{-9}\) |
\(1.3\times10^{-9}\) |
\(0.8676\) |
\(3.7\times10^{-15}\) |
Table 4.10: Imaginary-time evolution of the pairing model (\(L=4\), two
pairs, \(g=1\)) from \(\vert1100\rangle\): energy error, infidelity, and
the probability that the non-unitary evolution succeeds when it is
applied with one ancilla, Eq. (4.27), for the energy
shift \(E_{\min}=E_0\) and for the bound \(E_{\min}=h_I-\Lambda=-3.5\).
Produced by imaginary_time.py.

Figure 4.7: Imaginary-time evolution of the pairing model with \(L=4\) and two pairs from \(\vert1100\rangle\). Left: energy error and infidelity with the decay \(e^{-2\Delta\tau}\). Right: the success probability of Eq. (4.27) for the two energy shifts. Produced by imaginary_time.py.
The price on a quantum computer#
A quantum computer applies unitaries, and \(e^{-\tau\hat{H}}\) is not one. The standard way around this is to make it part of a unitary on a larger register. Shift the energy by a constant \(E_{\min}\) below the spectrum, so that \(A=e^{-\tau(\hat{H}-E_{\min})}\) is Hermitian with eigenvalues between zero and one. Then
is unitary on the system and one ancilla, and measuring the ancilla in \(\vert0\rangle\) leaves the system in the state of Eq. (4.24). The outcome occurs with the probability
and the same total probability results when the evolution is divided into steps that are each postselected, as the program checks. The last two columns of Table 4.10 and the right panel of Fig. 4.7 show what this means. If the shift equals the ground-state energy, the probability tends to \(p_0=0.8676\), the weight of the ground state in the initial state: imaginary time does not escape the overlap of Eq. (1.3), it only pays for it once instead of at every repetition. But \(E_0\) is what we want to compute. With a shift that can be known beforehand, the bound \(h_I-\Lambda=-3.5\) from the Pauli coefficients, which lies \(4.1\) below \(E_0\), the probability falls as \(e^{-8.3\tau}\), to \(2.2\times10^{-4}\) at \(\tau=1\) and to \(10^{-11}\) at the \(\tau=3\) that the convergence needs. The exponential convergence in \(\tau\) has been exchanged for an exponentially small probability of success, unless the shift is refined as the calculation proceeds. How \(W\) is compiled into gates is a problem of the same kind as Hamiltonian simulation itself, and the methods of Section Beyond product formulas address it.
Two alternatives avoid the postselection at the price of an approximation. Variational imaginary-time evolution [McArdle2019] projects the imaginary-time flow onto the manifold of a parametrized circuit; it is the natural gradient of Section Geometry: the quantum Fisher information, where it is derived. Quantum imaginary-time evolution [Motta2020] replaces each short non-unitary step by a unitary on a neighborhood of the qubits involved, determined from measurements, with a cost that grows with the range of the correlations in the state.
Product formulas and symmetries in imaginary time#
Product formulas apply to \(e^{-\Delta\tau\hat{H}}\) as they do to \(e^{-i\hat{H}\Delta t}\), with one difference in what the error does. A Trotterized imaginary-time evolution converges to the dominant eigenvector of its step, which is not the ground state of \(\hat{H}\), and the energy of that vector lies above \(E_0\) by a bias that no amount of evolution removes. Table 4.11 gives it for the splitting of the previous section: it falls as \(\Delta\tau^2\) for the first-order formula and as \(\Delta\tau^4\) for the second, twice the order of the formula, because the energy is stationary at the ground state and its error is quadratic in the error of the state. The formulas of fourth and higher order of Eq. (4.10) are of less use here: their backward steps are steps of negative imaginary time, which amplify the high-energy components instead of damping them.
\(\Delta\tau\) |
order 1 |
order 2 |
|---|---|---|
\(0.4\) |
\(1.9\times10^{-1}\) |
\(3.4\times10^{-3}\) |
\(0.2\) |
\(4.0\times10^{-2}\) |
\(2.6\times10^{-4}\) |
\(0.1\) |
\(9.0\times10^{-3}\) |
\(1.7\times10^{-5}\) |
\(0.05\) |
\(2.1\times10^{-3}\) |
\(1.1\times10^{-6}\) |
Table 4.11: Bias of the converged energy, \(E-E_0\), of the Trotterized
imaginary-time evolution of the pairing model in the two-pair sector
for the first- and second-order formulas. Produced by
imaginary_time.py.
The second difference concerns symmetries, and the program stumbled on it before we thought of it. The numbers of Table 4.11 are computed within the two-pair sector. The lowest eigenvalue of the Hamiltonian on the whole four-qubit register is \(-0.7792\), in the sector with one pair, \(1.41\) below \(E_0\). The evolution conserves the number of pairs, the initial state has two, and in exact arithmetic nothing connects the two sectors. In floating-point arithmetic the state acquires components at the level of the round-off outside its sector, and imaginary time amplifies them by \(e^{1.41\tau}\) relative to the state we want: run on the whole register, the weight outside the sector is \(10^{-21}\) at \(\tau=10\), \(10^{-9}\) at \(\tau=20\), \(1.6\times10^{-3}\) at \(\tau=25\), and at \(\tau=30\) the state has turned into the one-pair ground state. A unitary evolution leaves such a component at the size it was created with. A non-unitary one makes it grow, and on a noisy device the seed is far larger than the round-off. Whenever imaginary time is used to reach the lowest state of a symmetry sector that is not the absolute ground state, the symmetry has to be enforced, by an encoding that contains only the sector or by projecting after every step.
Beyond product formulas#
Product formulas are not the only way to implement Eq. (4.3), and for the fault-tolerant machines of the future they are not the asymptotically best. Three families of methods deserve to be known by name, and each is characterized by the way its cost depends on \(t\), on \(\varepsilon\) and on the norm \(\Lambda=\sum_\alpha\vert h_\alpha\vert\) of the Pauli coefficients. Randomized compiling [Campbell2019] draws the terms of the product at random with probabilities proportional to \(\vert h_\alpha\vert\); its gate count is of order \(\Lambda^2t^2/\varepsilon\), worse in \(t\) and \(\varepsilon\) than any product formula of second or higher order but independent of the number of terms, which makes it attractive for Hamiltonians with very many small terms. Linear combinations of unitaries implement a truncated Taylor series of the exponential with the help of ancilla qubits and reach a cost of order \(\Lambda t\,\log(\Lambda t/\varepsilon)/\log\log(\Lambda t/\varepsilon)\) [Berry2015]: the dependence on the accuracy is logarithmic, where that of a product formula of order \(p\) is \(\varepsilon^{-1/p}\). Quantum signal processing and qubitization [LowChuang2017,LowChuang2019] improve this to \(\mathcal{O}(\Lambda t+\log(1/\varepsilon))\) up to doubly logarithmic factors, which is optimal in both parameters. All three need a block encoding of the Hamiltonian, a unitary on a register with ancillas that contains \(\hat{H}/\Lambda\) as a block in the way that \(W\) of Eq. (4.26) contains \(A\), and controlled operations that the product formulas do without.
Which method is best for a given problem is not decided by these expressions alone. The cost of a product formula is governed by commutators, Eq. (4.11), and not by \(\Lambda\); for lattice Hamiltonians with local interactions the commutators are far smaller than the norm suggests, and with tight bounds product formulas match or outperform the asymptotically better methods on such systems [Childs2018,Childs2021]. They need no ancillas, they respect the locality and, with a suitable splitting, the symmetries of the Hamiltonian, and their error is a deformation of the Hamiltonian rather than a fault. For these reasons they are the method of the experiments performed so far and of the rest of these notes, and the other families are where to look when a fault-tolerant machine and a demand for many digits meet.
Summary#
A product formula of order \(p\) approximates \(e^{-i\hat{H}t}\) by \(r\) steps with an error of order \(t^{p+1}/r^p\) times a sum of nested commutators of the terms. The first order is never the right choice, the second is the workhorse, and the higher orders of Suzuki pay off for long times and small errors; the best order depends on both. One step is the exact evolution under an effective Hamiltonian that differs from \(\hat{H}\) by terms of order \(\Delta t^p\). The Trotterized dynamics conserves that Hamiltonian, so that its energy error does not grow with time, and spectroscopy with a Trotterized evolution measures its eigenvalues, with a systematic shift of order \(\Delta t^2\) for the formulas of first and second order.
A splitting should be chosen by three criteria: the pieces must have simple circuits, their commutators should be small, and each piece should respect the symmetries one relies on. For spin chains a step is a fixed number of layers, two CNOT gates per Ising bond and three per Heisenberg bond, and the circuits of the small calculations of this chapter have between three hundred and a few thousand CNOT gates.
Time evolution is also a tool. A time series of the Loschmidt amplitude from one ancilla yields the eigenvalues on which the initial state has weight; a slowly changing Hamiltonian prepares a correlated ground state, with an error that a smooth schedule reduces by orders of magnitude and a cost set by the gap along the path; and imaginary time projects onto the ground state exponentially fast, at a probability of success that is bounded by the overlap and decays exponentially when the ground-state energy is not known in advance. In all three the limiting quantities are the ones that Chapter 1 announced: the overlap of a state that can be prepared with the state that is wanted, the precision of a measurement, and the depth of the circuit.
Exercises#
Error measures. (a) Prove Eq. (4.4). (b) Prove Eq. (4.5) and give an example of two unitaries for which it is an equality for \(r=2\). (c) A simulation has the error \(\varepsilon=10^{-2}\) in the spectral norm and the magnetization per site is estimated from \(10^4\) shots. Which of the two errors dominates?
The second-order bound. For two terms \(A\) and \(B\), Eq. (4.9) reads \(\frac{\Delta t^3}{12}\Vert[B,[B,A]]\Vert+\frac{\Delta t^3}{24}\Vert[A,[A,B]]\Vert\). (a) Evaluate it for one qubit with \(A=X\) and \(B=Z\) and compare with the errors of Table 3.10. (b) Which of the two orderings, \(A\) in the middle or \(B\) in the middle, has the smaller bound for the Ising chain at \(h=J\) and at \(h=4J\)? Check with
bound_secondofproduct_formulas.py.Suzuki’s coefficient. (a) Show that a formula with \(S(-\Delta t)S(\Delta t)=1\) has an effective Hamiltonian that is even in \(\Delta t\). (b) Derive \(p_k\) of Eq. (4.10) from the condition that the leading error cancels. (c) A formula with three factors, \(S_2(q\Delta t)S_2((1-2q)\Delta t)S_2(q\Delta t)\), is also of fourth order for a suitable \(q\). Find \(q\), implement the formula with
formula_sequenceas a model, and compare its error constant with that of the five-factor formula for the Ising chain.The effective Hamiltonian. (a) Derive Eqs. (4.13) and (4.14) from Eq. (3.46). (b) Prove Eq. (4.15) and explain why it has no analogue for three terms. (c) For the Heisenberg chain in the Pauli splitting, compute the eigenvalues of the effective Hamiltonians of \(S_1\) and \(S_2\) with
effective_hamiltonianand determine how the shift of the ground-state energy scales with \(\Delta t\) for each.A first-order formula in disguise. (a) Explain why the first- and second-order columns of Table 4.4 coincide. (b) Repeat the quench from the state \(\vert{+}{+}\cdots{+}\rangle\) with the same order of the terms and with the order reversed, and predict before running the program in which case the columns coincide again. (c) Find an observable for which they differ in every case.
The partial SWAP. (a) Show that \(X_iX_j+Y_iY_j+Z_iZ_j=2\,\mathrm{SWAP}_{ij}-1\) and derive Eq. (4.18). (b) Verify Eq. (4.17) by hand for \(a=b=0\), where it must reduce to Eq. (4.16) up to single-qubit gates. (c) Count the CNOT gates of one second-order step of the four-site Heisenberg ring and compare with Table 3.19.
Resolution and noise of the time series. With
time_series.py: (a) halve and double \(K\) and determine how the width of the peaks and the accuracy of the ground-state peak change; (b) reduce the shots per point until the second peak is lost and compare with an estimate of the noise floor; (c) replace the reference by a state with weight \(0.5\) on each of two eigenstates separated by less than \(2\pi/(K\tau)\) and describe what the Fourier sum shows.Schedules. (a) Show with first-order time-dependent perturbation theory that the transition amplitude of a linear ramp is of order \(1/T\), with contributions from the two ends of the ramp, and that these contributions vanish when \(\dot{s}(0)=\dot{s}(T)=0\). (b) Add the schedule \(s=\sin^2[\frac{\pi}{2}\sin^2(\pi t/2T)]\) to
adiabatic.pyand compare. (c) Increase the coupling to \(g=3\) and determine how the time needed for an infidelity of \(10^{-4}\) changes.Imaginary time. (a) Derive Eq. (4.25) and show that the energy error and the infidelity decay at the same rate. (b) Show that \(W\) of Eq. (4.26) is unitary and derive Eq. (4.27). (c) Suppose the shift is updated to the current energy estimate \(E(\tau)\) after every short step. Compute the total success probability for the pairing model with
imaginary_time.pyand compare with the two columns of Table 4.10.The optimal step on a noisy device. Model the total error of a second-order simulation of the Ising quench as \(c\,\Delta t^2+\epsilon_2N_{\mathrm{CNOT}}\) with the CNOT count of Table 4.6 and an error \(\epsilon_2\) per gate. Determine \(c\) from Table 4.4, find the step that minimizes the total error for \(\epsilon_2=10^{-3}\) and \(10^{-4}\), and state the smallest total error that can be reached in each case.
Programs for this chapter#
Every number and figure in this chapter comes from the programs in
LectureMaterial/BookPrograms/chapter4/, which build on the shared
modules of Chapters 2 and 3
(gates, statevector, circuit,
pauli, models) and on mapped_models.py and
pauli_circuits.py of Chapter 3. All of
them are imported by the notebook
LectureMaterial/Notebooks/chapter4/chapter4.ipynb, and
all run on numpy and matplotlib alone.
product_formulas.pyThe classProductFormulafor the formulas of Eqs. (4.6), (4.7) and (4.10), the bounds of Eqs. (4.8) and (4.9), the effective Hamiltonian of Eq. (4.12), and the Ising and Heisenberg chains as lists of terms; Tables 4.1, 4.2 and 4.3 and Fig. 4.1. A few seconds.lattice_dynamics.pyThe quench of the Ising chain and the Heisenberg chain from the Néel state in two splittings, with the long-time energy error; Tables 4.4 and 4.5 and Fig. 4.2. A few seconds.bond_circuits.pyThe two-qubit gates of Eqs. (4.16), (4.17) and (4.18), the steps of the two chains as circuits checked against their matrices, and the gate counts of Table 4.6. One second.time_series.pyThe Hadamard test of Eq. (4.20), the Fourier sum of Eq. (4.21) with exact, sampled and Trotterized amplitudes; Table 4.7 and Fig. 4.5. Two seconds.adiabatic.pyThe pairing model as \(\hat{H}_0+s\hat{V}\), the midpoint rule of Eq. (4.22), the two schedules and the Trotterized circuit; Tables 4.8 and 4.9 and Fig. 4.6. About six seconds.imaginary_time.pyImaginary-time evolution, the dilation of Eq. (4.26) and its success probability, product formulas in imaginary time and the amplification of components outside a symmetry sector; Tables 4.10 and 4.11 and Fig. 4.7. One second.
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' / 'chapter4/product_formulas.py'), run_name='__main__')
for png in sorted((root / 'BookFigures' / 'chapter4').glob('*.png')):
if png.stat().st_mtime >= t0:
display(Image(str(png)))
=== Transverse-field Ising chain, n = 6, J = 1.0, h = 1.0: ||H|| = 7.296230, ||[H_ZZ, H_X]|| = 13.975837
=== One step of each formula (two terms A = H_ZZ, B = H_X)
order 1: 2 exponentials in one step, 20 in ten steps
order 2: 3 exponentials in one step, 21 in ten steps
order 4: 11 exponentials in one step, 101 in ten steps p_k = 0.4144907718, 1 - 4 p_k = -0.6579630872
order 6: 51 exponentials in one step, 501 in ten steps p_k = 0.3730658277, 1 - 4 p_k = -0.4922633109
order 4, coefficients of A and B in chronological order:
A:+0.207245 B:+0.414491 A:+0.414491 B:+0.414491 A:-0.121736 B:-0.657963 A:-0.121736 B:+0.414491 A:+0.414491 B:+0.414491 A:+0.207245
=== Spectral-norm error of S_p(t/r)^r at t = 1.0 (Table 4.errors)
r order 1 bound order 2 bound order 4 order 6
1 2.000e+00 6.988e+00 1.944e+00 6.711e+00 5.166e-01 1.648e-02
2 1.219e+00 3.494e+00 5.203e-01 1.678e+00 1.380e-02 8.538e-05
4 5.774e-01 1.747e+00 1.195e-01 4.194e-01 8.613e-04 9.502e-07
8 2.836e-01 8.735e-01 2.923e-02 1.049e-01 5.509e-05 1.385e-08
16 1.411e-01 4.367e-01 7.266e-03 2.621e-02 3.467e-06 2.128e-10
32 7.049e-02 2.184e-01 1.814e-03 6.554e-03 2.170e-07 3.517e-12
64 3.523e-02 1.092e-01 4.533e-04 1.638e-03 1.357e-08 3.231e-12
fitted slopes for r >= 4: order 1: -1.01, order 2: -2.01, order 4: -3.99, order 6: -6.06
bound / error at r = 64: first order 3.10, second order 3.61
=== Steps r and exponentials needed for an error eps (Table 4.cost)
t = 1.0
eps r(1) exp r(2) exp r(4) exp r(6) exp
1e-02 226 452 14 29 3 31 2 101
1e-04 22547 45094 137 275 7 71 2 101
1e-06 2254701 4509402 1363 2727 22 221 4 201
t = 5.0
eps r(1) exp r(2) exp r(4) exp r(6) exp
1e-02 1048 2096 135 271 15 151 7 351
1e-04 104725 209450 1343 2687 49 491 11 551
1e-06 10472500 20945000 13423 26847 155 1551 22 1101
=== Effective Hamiltonian of one step, H_eff = i log S(dt)/dt (Table 4.heff)
order dt ||H_eff - H|| ||H_eff - H - corr|| max |E_eff - E| E0_eff - E0
1 0.200 1.421e+00 2.461e-01 5.815e-02 5.815e-02
1 0.100 7.016e-01 5.998e-02 1.432e-02 1.432e-02
1 0.050 3.497e-01 1.490e-02 3.567e-03 3.567e-03
1 0.025 1.747e-01 3.719e-03 8.910e-04 8.910e-04
2 0.200 2.046e-01 7.146e-03 5.815e-02 5.815e-02
2 0.100 5.018e-02 4.364e-04 1.432e-02 1.432e-02
2 0.050 1.249e-02 2.712e-05 3.567e-03 3.567e-03
2 0.025 3.118e-03 1.693e-06 8.910e-04 8.910e-04
two-term splitting: S_2 = W S_1 W^dagger with W = exp(-iA dt/2); largest difference of eigenphases 3.2e-15
figure written to BookFigures/chapter4/formulas.pdf
import runpy, time
from IPython.display import Image, display
t0 = time.time()
runpy.run_path(str(root / 'BookPrograms' / 'chapter4/lattice_dynamics.py'), run_name='__main__')
for png in sorted((root / 'BookFigures' / 'chapter4').glob('*.png')):
if png.stat().st_mtime >= t0:
display(Image(str(png)))
=== Ising quench, n = 8, J = h = 1, from |0...0>; <H> = -7.000000, dt = 0.25, T = 5.0 (Table 4.quench)
t m_z exact order 1 order 2 order 4 echo
0.00 1.000000 1.000000 1.000000 1.000000 1.000000
1.00 0.239113 0.219711 0.219711 0.239121 0.093211
2.00 0.019500 0.020075 0.020075 0.019465 0.065996
3.00 -0.003369 -0.004663 -0.004663 -0.003356 0.006130
4.00 0.002132 0.001836 0.001836 0.002137 0.130439
5.00 -0.001376 -0.000976 -0.000976 -0.001384 0.153072
order 1: largest error in m_z 2.28e-02, in the echo 8.00e-02, in the energy 1.61e+00; 40 exponentials
order 2: largest error in m_z 2.28e-02, in the echo 8.00e-02, in the energy 4.11e-01; 41 exponentials
order 4: largest error in m_z 1.92e-04, in the echo 5.28e-04, in the energy 4.20e-03; 201 exponentials
the same accuracy in m_z from the second-order formula needs
dt = 0.125 error 5.50e-03, 81 exponentials
dt = 0.0625 error 1.36e-03, 161 exponentials
dt = 0.03125 error 3.41e-04, 321 exponentials
dt = 0.015625 error 8.51e-05, 641 exponentials
=== Heisenberg chain, n = 8, J = 1, from the Neel state (Table 4.conservation)
<H> = -1.750000, <S^z> = 0.0
splitting dt max |dm_s| max |dE| max <(S^z)^2>
evenodd 0.40 4.623e-03 5.762e-03 1.541e-28
evenodd 0.20 1.160e-03 1.399e-03 5.618e-28
evenodd 0.10 2.902e-04 3.490e-04 2.288e-27
pauli 0.40 6.409e-03 3.821e-02 9.462e-04
pauli 0.20 1.587e-03 9.554e-03 5.861e-05
pauli 0.10 3.959e-04 2.388e-03 3.649e-06
evenodd: ||[H_j, S^z]|| = 0.000, 0.000
pauli: ||[H_j, S^z]|| = 2.379, 2.379, 0.000
=== Energy error over a long time, Ising quench, second order
dt = 0.25 max |dE| for t in [0,25], [25,50], [50,75], [75,100]: 4.111e-01, 4.169e-01, 4.036e-01, 4.160e-01
dt = 0.125 max |dE| for t in [0,25], [25,50], [50,75], [75,100]: 9.561e-02, 1.045e-01, 9.592e-02, 1.044e-01
figure written to BookFigures/chapter4/dynamics.pdf
import runpy, time
from IPython.display import Image, display
t0 = time.time()
runpy.run_path(str(root / 'BookPrograms' / 'chapter4/bond_circuits.py'), run_name='__main__')
for png in sorted((root / 'BookFigures' / 'chapter4').glob('*.png')):
if png.stat().st_mtime >= t0:
display(Image(str(png)))
=== Two-qubit exponentials
exp(-i theta ZZ) with 2 CNOTs: True, phase 1.000000+0.000000j
exp(-i(a XX + b YY + c ZZ)) with 3 CNOTs: 21 angle triples verified, circuit = exp(-i pi/4) x exponential; gates, CNOTs, depth = (8, 3, 7)
the same from three Pauli rotations: gates, CNOTs, depth = (21, 6, 15)
XX + YY + ZZ = 2 SWAP - 1 and exp(-i theta(XX+YY+ZZ)) = e^{i theta}(cos 2theta - i sin 2theta SWAP): True
at theta = pi/4 the bond is the SWAP gate up to a phase: True
=== One second-order step as a circuit against the matrix of ProductFormula (n = 6)
Ising chain: equal up to a phase True
Heisenberg chain, three-CNOT bonds: equal up to a phase True
Heisenberg chain, Pauli rotations: equal up to a phase True
=== Gates of second-order steps (Table 4.gates): gates, CNOTs, depth
chain n one step per step in a long run
Ising 4 (22, 12, 13) (13, 6, 7)
Ising 8 (50, 28, 13) (29, 14, 7)
Ising 16 (106, 60, 13) (61, 30, 7)
Heisenberg, three-CNOT bonds 4 (40, 15, 21) (24, 9, 12)
Heisenberg, three-CNOT bonds 8 (88, 33, 21) (56, 21, 12)
Heisenberg, three-CNOT bonds 16 (184, 69, 21) (120, 45, 12)
Heisenberg, Pauli rotations 4 (105, 30, 45) (63, 18, 30)
Heisenberg, Pauli rotations 8 (231, 66, 45) (147, 42, 30)
Heisenberg, Pauli rotations 16 (483, 138, 45) (315, 90, 30)
=== CNOT gates of the quenches of lattice_dynamics.py (n = 8)
Ising, order 2, dt = 0.25 : 601 gates, 294 CNOTs, depth 146
Ising, order 4, dt = 0.25 : 2921 gates, 1414 CNOTs, depth 706
Ising, order 2, dt = 0.015625: 9301 gates, 4494 CNOTs, depth 2246
Heisenberg, order 2, dt = 0.4 : 872 gates, 327 CNOTs, depth 193
Heisenberg, order 2, dt = 0.1 : 3392 gates, 1272 CNOTs, depth 733
import runpy, time
from IPython.display import Image, display
t0 = time.time()
runpy.run_path(str(root / 'BookPrograms' / 'chapter4/time_series.py'), run_name='__main__')
for png in sorted((root / 'BookFigures' / 'chapter4').glob('*.png')):
if png.stat().st_mtime >= t0:
display(Image(str(png)))
=== Lipkin model on four qubits, reference |0000>: eigenvalues with weight in the reference
E = -4.212877 p = 0.935763
E = -0.919136 p = 0.063980
E = 4.132012 p = 0.000257
Pauli 1-norm of the traceless part Lambda = 6.000000, sampling interval tau = 0.9 pi/Lambda = 0.471239, |E|_max tau = 1.9853 < pi
=== Hadamard test at t = tau: g = -0.318863+0.883145j; P(0) = 0.340568 and 0.941572, 2P(0) - 1 = -0.318863 and 0.883145
=== Peaks of |F(E)| from K = 64 samples, total time (K-1) tau = 29.688, resolution 2 pi/(K tau) = 0.2083 (Table 4.spectrum)
case E height E height
eigenvalues, weights -4.2129 0.9358 -0.9191 0.0640
exact -4.2130 0.9358 -0.9190 0.0640
1000 shots -4.2135 0.9358 -0.9250 0.0662
order 2, dt = tau/1 -4.1550 0.9220 -0.9290 0.0775
order 2, dt = tau/2 -4.1990 0.9325 -0.9225 0.0672
largest |F| of the shot noise alone: 0.0086; the third level, of weight 0.0003, is below it
shifts of the lowest peak under the product formula against the effective Hamiltonian:
dt = tau/1 = 0.4712: peak shift +0.0580, E0(H_eff) - E0 = +0.0577
dt = tau/2 = 0.2356: peak shift +0.0140, E0(H_eff) - E0 = +0.0141
figure written to BookFigures/chapter4/spectrum.pdf
import runpy, time
from IPython.display import Image, display
t0 = time.time()
runpy.run_path(str(root / 'BookPrograms' / 'chapter4/adiabatic.py'), run_name='__main__')
for png in sorted((root / 'BookFigures' / 'chapter4').glob('*.png')):
if png.stat().st_mtime >= t0:
display(Image(str(png)))
=== Pairing model, L = 4, two pairs: E_0(g = 0) = 2.000000, E_0(g = 1) = 0.63554847, overlap of |1100> with the target 0.867638
gap of the two-pair sector along the path: 2.0000 at s = 0, 2.2998 at s = 1, minimum 2.0000 at s = 0.00
=== Infidelity 1 - |<target|psi(T)>|^2 (Table 4.adiabatic)
T linear smooth
1 7.225e-02 9.251e-02
2 1.939e-02 4.140e-02
5 2.488e-03 3.998e-05
10 5.644e-04 8.218e-06
20 1.485e-04 8.048e-07
40 2.823e-05 1.973e-08
80 1.173e-05 5.096e-09
midpoint rule at T = 20, smooth schedule, 100/200/400/800 steps: 7.906475e-07, 8.012964e-07, 8.040551e-07, 8.047510e-07
=== The smooth schedule as a circuit of second-order steps (Table 4.adiabaticcircuit)
T steps dt infidelity CNOTs continuous
5 10 0.5000 3.481e-03 300 3.998e-05
5 20 0.2500 2.111e-04 600 3.998e-05
5 40 0.1250 5.611e-05 1200 3.998e-05
5 80 0.0625 4.252e-05 2400 3.998e-05
20 40 0.5000 3.210e-03 1200 8.048e-07
20 80 0.2500 1.414e-04 2400 8.048e-07
20 160 0.1250 9.767e-06 4800 8.048e-07
20 320 0.0625 1.556e-06 9600 8.048e-07
number of pairs in the final state: 2.0000000000
figure written to BookFigures/chapter4/adiabatic.pdf
import runpy, time
from IPython.display import Image, display
t0 = time.time()
runpy.run_path(str(root / 'BookPrograms' / 'chapter4/imaginary_time.py'), run_name='__main__')
for png in sorted((root / 'BookFigures' / 'chapter4').glob('*.png')):
if png.stat().st_mtime >= t0:
display(Image(str(png)))
=== Pairing model, L = 4, two pairs, g = 1: eigenvalues of the sector and weights of |1100>
E = 0.635548 p = 0.867638
E = 2.935381 p = 0.106325
E = 5.000000 p = 0.014507
E = 5.000000 p = 0.009303
E = 7.208940 p = 0.001550
E = 9.220130 p = 0.000678
lowest excited state with weight in the reference: 2.935381, gap 2.299833; h_I = 5.0000, Lambda = 8.5000, lower bound h_I - Lambda = -3.5000 (E_0 = 0.635548)
=== Imaginary-time evolution from |1100> (Table 4.ite)
tau E(tau) - E0 infidelity P, E_min = E0 P, E_min = bound
0.0 3.645e-01 1.324e-01 1.000000 1.000e+00
0.5 2.943e-02 1.248e-02 0.878605 1.405e-02
1.0 2.850e-03 1.235e-03 0.868711 2.222e-04
2.0 2.850e-05 1.239e-05 0.867648 5.678e-08
3.0 2.865e-07 1.246e-07 0.867638 1.452e-11
4.0 2.881e-09 1.253e-09 0.867638 3.715e-15
6.0 2.908e-13 1.261e-13 0.867638 2.431e-22
8.0 -6.661e-16 0.000e+00 0.867638 1.591e-29
decay rate of E(tau) - E0 between tau = 4 and 6: 4.6006; twice the gap: 4.5997
success probability for E_min = E0 tends to the weight of the ground state, 0.867638
=== Dilation at tau = 1.0: P(ancilla = 0) = 2.222201e-04, ||A psi||^2 = 2.222201e-04; overlap of the postselected state with A psi/||A psi||: 1.000000000000
8 postselected steps of tau/8: total probability 2.222201e-04
=== Product formulas for exp(-tau H): converged energy minus E0 (Table 4.itetrotter)
dtau order 1 order 2
0.40 1.887e-01 3.379e-03
0.20 4.026e-02 2.570e-04
0.10 9.016e-03 1.695e-05
0.05 2.120e-03 1.074e-06
=== Lowest eigenvalue of the whole register: -0.779164 with 1 pair(s); E_0 of the two-pair sector lies 1.414712 above it
tau E(tau) - E0 weight outside the sector
10 -4.441e-16 5.847e-22
20 -1.606e-09 1.135e-09
25 -2.234e-03 1.579e-03
30 -1.414e+00 9.995e-01
40 -1.415e+00 1.000e+00
figure written to BookFigures/chapter4/imaginary.pdf
