|q⟩ Bad Qubits

intermediate · Programming · Hamiltonian Simulation & Trotterization

Checkpoint: Trotterize a Hamiltonian

This checkpoint asks you to assemble a complete first-order Trotter circuit for a concrete two-qubit Hamiltonian — combining every skill from this module into a single working program.

The target Hamiltonian

Consider the two-qubit Hamiltonian

H=π8ZZ  +  π8XI.H = \frac{\pi}{8}\, Z \otimes Z \;+\; \frac{\pi}{8}\, X \otimes I.

The first term couples the two spins through a ZZZZ interaction; the second drives single-qubit rotations on qubit 0 alone. Both coefficients equal π/8\pi/8, which keeps the angles tidy.

Applying the first-order Trotter formula

Because ZZZ \otimes Z and XIX \otimes I do not commute — you can verify that (XI)(ZZ)(ZZ)(XI)(X \otimes I)(Z \otimes Z) \neq (Z \otimes Z)(X \otimes I) since XZZXXZ \neq ZX — the exact evolution eiHte^{-iHt} cannot be split naively. The first-order Trotter (Lie–Trotter) product formula gives the approximation

eiHteiH1teiH2t,H1=π8ZZ,H2=π8(XI),e^{-iHt} \approx e^{-i H_1 t}\, e^{-i H_2 t}, \qquad H_1 = \tfrac{\pi}{8} ZZ, \quad H_2 = \tfrac{\pi}{8} (X \otimes I),

with an error of order t2[H1,H2]t^2 [H_1, H_2]. For t=1t = 1 and the given coefficients this is a single Trotter step — enough to demonstrate the structure without needing multiple repetitions.

Compiling each factor to gates

Factor 1 — ei(π/8)ZZe^{-i(\pi/8)\, ZZ}. The ZZZZ eigenvalue of xy|xy\rangle is (1)xy(-1)^{x \oplus y}, so a CNOT from qubit 0 to qubit 1 maps the parity into qubit 1, and a single RzR_z on qubit 1 applies the phase:

eiθZZ=CNOT01(IRz(2θ))CNOT01,θ=π8.e^{-i\theta\, ZZ} = \mathrm{CNOT}_{0 \to 1}\cdot\bigl(I \otimes R_z(2\theta)\bigr)\cdot\mathrm{CNOT}_{0 \to 1}, \qquad \theta = \tfrac{\pi}{8}.

In code: c.cx(0, 1); c.rz(2 * Math.PI/8, 1); c.cx(0, 1);

Factor 2 — ei(π/8)(XI)e^{-i(\pi/8)\, (X \otimes I)}. Only qubit 0 participates. Using eiθX=Rx(2θ)e^{-i\theta X} = R_x(2\theta):

ei(π/8)XI=Rx ⁣(π4)I.e^{-i(\pi/8)\, X \otimes I} = R_x\!\bigl(\tfrac{\pi}{4}\bigr) \otimes I.

In code: c.rx(2 * Math.PI/8, 0);

Try it

Implement both factors in the correct order. The grader checks the full unitary matrix of your two-qubit circuit, so an empty or partial circuit will not pass.

Run your code to see the quantum state.

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