|q⟩ Bad Qubits

intermediate · Programming · Hamiltonian Simulation & Trotterization

The Trotter Product Formula

The time-evolution operator eiHte^{-iHt} for a sum of Hamiltonians H=H1+H2H = H_1 + H_2 cannot generally be split into eiH1teiH2te^{-iH_1 t} e^{-iH_2 t}, because matrices that do not commute satisfy eA+BeAeBe^{A+B} \ne e^A e^B in general. The Lie–Trotter product formula makes this splitting an approximation that becomes exact in a controlled limit.

The first-order Trotter formula

For any two operators AA and BB,

eA+B=limr(eA/reB/r)r.e^{A+B} = \lim_{r \to \infty} \left(e^{A/r} e^{B/r}\right)^r.

Truncating to a single step (r=1r = 1) gives the first-order Trotter approximation:

ei(H1+H2)teiH1teiH2t.e^{-i(H_1 + H_2)t} \approx e^{-iH_1 t}\, e^{-iH_2 t}.

The error in the unitary can be bounded using the Baker–Campbell–Hausdorff expansion. To leading order,

eiH1teiH2t=ei(H1+H2)te12[H1,H2]t2+O(t3),e^{-iH_1 t} e^{-iH_2 t} = e^{-i(H_1+H_2)t}\, e^{-\tfrac{1}{2}[H_1,H_2]t^2 + O(t^3)},

so the operator error is O(t2[H1,H2])O(t^2 \|[H_1, H_2]\|). When H1H_1 and H2H_2 commute the commutator [H1,H2]=0[H_1, H_2] = 0 and the approximation is exact for any tt.

Mapping a Trotter step to gates

Consider the Hamiltonian

H=Z0Z1+X0,H = Z_0 Z_1 + X_0,

where Z0Z1Z_0 Z_1 is the two-qubit Pauli interaction from the previous lesson and X0X_0 acts only on qubit 0. The two terms do not commute — [ZZ,XI]=2iYZ[ZZ, X \otimes I] = 2i\, Y \otimes Z — so Trotterization introduces an approximation error proportional to t2t^2.

A single first-order Trotter step at time tt decomposes as:

eit(Z0Z1+X0)eitX0  eitZ0Z1.e^{-it(Z_0 Z_1 + X_0)} \approx e^{-it X_0}\; e^{-it Z_0 Z_1}.

Reading the product right-to-left (standard operator convention), this means the ZZZZ factor is applied to the state first, followed by the X0X_0 factor — matching the left-to-right gate order in the circuit diagram below.

Each factor maps directly to known gate patterns:

Factor 1 (applied first to the state): eitZ0Z1e^{-it Z_0 Z_1}

As derived in the previous lesson, the ZZZZ rotation is implemented with a CNOT sandwich:

eitZ0Z1=CNOT01(IRz(2t))CNOT01.e^{-it Z_0 Z_1} = \mathrm{CNOT}_{0 \to 1} \cdot \bigl(I \otimes R_z(2t)\bigr) \cdot \mathrm{CNOT}_{0 \to 1}.

Factor 2 (applied second to the state): eitX0e^{-it X_0}

Using the general Pauli rotation identity eiθP=RP(2θ)e^{-i\theta P} = R_P(2\theta),

eitX0=Rx(2t).e^{-it X_0} = R_x(2t).

Chaining these two factors gives the full Trotter step as a four-gate circuit:

cx(0, 1)       // parity encode
rz(2t, 1)      // ZZ rotation
cx(0, 1)       // parity decode
rx(2t, 0)      // X_0 rotation

Generalising to many terms

The same recipe extends to any Hamiltonian written as a sum of Pauli strings:

H=jcjPj.H = \sum_{j} c_j P_j.

Each eicjtPje^{-i c_j t P_j} can be implemented with at most O(n)O(n) CNOT gates (one CNOT ladder of length nn), so a single Trotter step over an nn-qubit system with kk terms requires O(kn)O(kn) two-qubit gates in total. Larger rr (more repetitions) trades circuit depth for accuracy.

Try it

Implement one first-order Trotter step for H=Z0Z1+X0H = Z_0 Z_1 + X_0 at time t=π/4t = \pi/4. The grader checks the full unitary matrix, so an empty circuit will not pass.

Run your code to see the quantum state.

After grading, try changing tt to a different value (such as π/8\pi/8 or π/2\pi/2) and observe how the unitary changes — but make sure your referenceSolution matches whatever tt you choose.

Sign in on the full site to ask questions and join the discussion.