Skip to content

Hamiltonian simulation

Before Shor and Grover, there was a simpler argument for building quantum computers. In the early 1980s Richard Feynman pointed out that quantum systems are extremely hard to simulate on ordinary computers, and suggested using a quantum system that we control to imitate one that we want to understand. This is still widely expected to be the first application of real scientific value.

You know the reason already from the entanglement lesson. A state of nn qubits has 2n2^n amplitudes. The same is true of nn electrons in a molecule or nn spins in a magnet.

Storing 50 qubits’ worth of amplitudes takes about 101510^{15} complex numbers, at the edge of what the largest supercomputers hold. For 300 qubits the number of amplitudes exceeds the number of atoms in the observable universe. Classical methods cope by exploiting special structure, and they work very well for many systems. For others, particularly those where many particles are strongly entangled with one another, every known classical method becomes either inaccurate or exponentially slow.

A quantum computer stores the state of nn qubits in nn qubits.

The behaviour of a quantum system is set by its Hamiltonian HH, a Hermitian matrix that describes its energy. The state changes in time according to the Schrödinger equation, whose solution over a time tt is

∣ψ(t)⟩=e−iHt∣ψ(0)⟩,\ket{\psi(t)} = e^{-iHt}\ket{\psi(0)},

in units where Planck’s constant is 1. The matrix e−iHte^{-iHt} is unitary. Hamiltonian simulation is the task of building a circuit that applies it, to within a chosen error.

The exponential of a matrix is defined by the same power series as for numbers. Two facts make it concrete.

  • For a diagonal matrix, exponentiate each diagonal entry. So e−iZte^{-iZt} has diagonal entries e−ite^{-it} and eite^{it}: it is a rotation about the ZZ axis of the Bloch sphere.
  • For any matrix PP with P2=IP^2 = I, which includes XX, YY, ZZ and their tensor products,
e−iθP=cos⁡θ  I−isin⁡θ  P.e^{-i\theta P} = \cos\theta\; I - i\sin\theta\; P.

The eigenstates of HH are the states of definite energy. If H∣u⟩=E∣u⟩H\ket{u} = E\ket{u} then e−iHt∣u⟩=e−iEt∣u⟩e^{-iHt}\ket{u} = e^{-iEt}\ket{u}: energy shows up as the rate at which a phase turns. Keep that in mind for later.

A general 2n×2n2^n \times 2^n matrix would be hopeless to work with. But the Hamiltonians found in nature are not general. They are sums of terms that each involve only a few particles:

H=H1+H2+⋯+Hm.H = H_1 + H_2 + \dots + H_m.

A standard example is a chain of spins in which neighbours interact and a magnetic field acts on each one:

H=J∑jZjZj+1+g∑jXj.H = J\sum_j Z_jZ_{j+1} + g\sum_j X_j.

Here ZjZj+1Z_jZ_{j+1} means ZZ on qubits jj and j+1j + 1 and the identity elsewhere. The number of terms grows only in proportion to nn.

Each term on its own is easy to simulate. The single-qubit ones are rotations. For a two-qubit term such as Z⊗ZZ \otimes Z, notice that it has the value +1+1 on ∣00⟩\ket{00} and ∣11⟩\ket{11} and −1-1 on ∣01⟩\ket{01} and ∣10⟩\ket{10}: it measures whether the two bits differ. So compute that parity onto one of the qubits with a CNOT, apply a single-qubit phase rotation there, and undo the CNOT.

For θ=π/4\theta = \pi/4 the rotation needed is the SS gate, up to a global phase.

PuzzleEvolve under Z⊗Z

Build e−i(π/4) Z⊗Ze^{-i(\pi/4)\,Z\otimes Z}. Up to a global phase, it leaves ∣00⟩\ket{00} and ∣11⟩\ket{11} alone and multiplies ∣01⟩\ket{01} and ∣10⟩\ket{10} by ii.

This puzzle needs JavaScript.

Hint

CNOT writes the parity of the two bits onto the bottom wire. Apply SS there, then undo the CNOT.

With a rotation by a general angle in place of SS, the same three-gate pattern gives e−iθZ⊗Ze^{-i\theta Z\otimes Z} for any θ\theta.

If each term is easy, why not apply them one after another? Because for matrices,

e−i(A+B)t≠e−iAt e−iBte^{-i(A + B)t} \neq e^{-iAt}\,e^{-iBt}

unless AA and BB commute, meaning AB=BAAB = BA. The terms ZjZj+1Z_jZ_{j+1} all commute with each other, but none of them commutes with the XjX_j on the same qubit. Physically, the system does not evolve under the interactions and then under the field. Both act at once.

Check

H=Z⊗I+I⊗ZH = Z\otimes I + I\otimes Z. How well does applying e−i(Z⊗I)te^{-i(Z\otimes I)t} and then e−i(I⊗Z)te^{-i(I\otimes Z)t} reproduce e−iHte^{-iHt}?

The fix is to take turns quickly. Over a very short time the order in which the terms act hardly matters, so cut the time tt into rr short steps and alternate:

e−i(A+B)t≈(e−iAt/r e−iBt/r)r.e^{-i(A + B)t} \approx \Bigl(e^{-iAt/r}\,e^{-iBt/r}\Bigr)^{r}.

This is the Trotter formula, also called a product formula. Each step makes an error proportional to (t/r)2(t/r)^2 and to the size of the commutator AB−BAAB - BA. There are rr steps, so the total error is proportional to

t2r.\frac{t^2}{r}.

More steps give a better answer, at the cost of more gates.

The simulator uses the smallest possible example: one qubit with H=X+ZH = X + Z, starting in ∣+⟩\ket{+}. The two terms do not commute. The purple curve is the exact evolution, and the orange points are the Trotter approximation after each step.

SimulatorEvolving |+⟩ under H = X + Z

Things to try:

  1. With t=3t = 3 and the first-order formula, start at 1 step and increase. When does the orange path start to follow the purple curve?
  2. Double the number of steps from 20 to 40. By what factor does the error shown fall?
  3. Switch to the second-order formula and repeat. How many steps does it need to match the first-order formula at 40?
  4. Fix the number of steps and increase tt. What happens to the error?

The second-order formula splits one of the terms in half and puts the halves on either side: half a step of ZZ, a full step of XX, half a step of ZZ. The arrangement is symmetric, and that makes the leading error cancel. Its total error falls as 1/r21/r^2 where the first-order one falls as 1/r1/r. When steps are chained together, neighbouring half steps merge into one gate, so the improvement is almost free.

A note on the number in the panel. It shows 1 minus the fidelity between the two final states, which behaves like the square of the error in the state. That is why doubling the steps divides it by about 4 for the first-order formula and about 16 for the second-order one.

Check

With the first-order formula, you want the error in the simulated evolution to be 10 times smaller, for the same total time. How many more steps do you need?

Put the pieces together for a system of nn qubits whose Hamiltonian has mm local terms. One Trotter step uses about mm small gates, and the number of steps grows polynomially with the time and the accuracy wanted. The total is polynomial in the size of the system, where the direct classical approach is exponential. Seth Lloyd made this argument precise in 1996, confirming Feynman’s suggestion.

Product formulas are the simplest method and often perform better in practice than their worst-case bounds suggest. They are not the last word. Later methods, known by names such as linear combination of unitaries, qubitization and quantum signal processing, reach a cost that grows only linearly with the time and logarithmically with the inverse of the error, which is known to be essentially the best possible. They are harder to explain and need more auxiliary qubits, and which method wins depends on the problem.

Simulating evolution is useful directly: you can prepare a state, let it evolve, and measure how a quantity changes. It is also the key to a second kind of question. Chemists and materials scientists mostly want to know energies, above all the lowest one, the ground-state energy, because energy differences govern which reactions happen and how fast.

Recall that an eigenstate with energy EE picks up the phase e−iEte^{-iEt} under e−iHte^{-iHt}. So the energy is an eigenvalue phase of a gate we can now build, and phase estimation reads eigenvalue phases. Run phase estimation with U=e−iHtU = e^{-iHt} and the counting register returns an energy.

There is a condition, which you also met in that lesson. Phase estimation returns the energy of a random eigenstate, weighted by how much of it is present in the starting state. To get the ground-state energy you must start from a state that already overlaps well with the ground state. Preparing such a state is a hard problem in general, and for some Hamiltonians it is believed to be hard even for a quantum computer. In practice people rely on good approximate states from classical chemistry.

  • The promise. Systems with strong correlations among many electrons, such as the active sites of some enzymes and catalysts, and models of high-temperature superconductors, defeat the best classical methods. These are the usual targets.
  • The requirements. Useful accuracy for such problems needs deep circuits, well beyond what today’s noisy devices can run, so it needs error correction. Resource estimates have been improving steadily and are still large.
  • The competition. Classical simulation methods keep improving too, and several claimed quantum advantages in simulation have been matched by better classical algorithms afterwards. Where the practical crossover lies is an open research question.

That completes the track. It is worth setting the algorithms side by side, because between them they cover most of what is known.

Source of the speedup Example Size of the speedup
Hidden periodic structure, found by the Fourier transform Shor’s algorithm, phase estimation Exponential over the best known classical methods
Amplitude amplification Grover’s search Quadratic, and provably no more
The problem is itself quantum Hamiltonian simulation Exponential over the best known classical methods, for suitable systems

In every case the mechanism is the one from the first lesson: arrange the amplitudes so that wrong answers cancel and right ones reinforce. A quantum computer is not a faster computer in general. It is a machine for problems that have the right structure for interference, and finding more of those problems is one of the main open tasks of the field.

Where to go next:

  • Quantum Error Correction explains how the long circuits in this track could ever be run on imperfect hardware.
  • Quantum Machine Learning covers variational algorithms, which try to get value from short circuits, including a different approach to finding ground-state energies.
  • Quantum Cryptography deals with the consequences of Shor’s algorithm and with what quantum states make possible in return.
RecallAnswer from memory, then check
LessonFinish this lesson