|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=π8 Z⊗Z  +  π8 X⊗I.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 Z⊗ZZ \otimes Z and X⊗IX \otimes I do not commute — you can verify that (X⊗I)(Z⊗Z)≠(Z⊗Z)(X⊗I)(X \otimes I)(Z \otimes Z) \neq (Z \otimes Z)(X \otimes I) since XZ≠ZXXZ \neq ZX — the exact evolution e−iHte^{-iHt} cannot be split naively. The first-order Trotter (Lie–Trotter) product formula gives the approximation

e−iHt≈e−iH1t e−iH2t,H1=π8ZZ,H2=π8(X⊗I),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 — e−i(π/8) ZZe^{-i(\pi/8)\, ZZ}. The ZZZZ eigenvalue of ∣xy⟩|xy\rangle is (−1)x⊕y(-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:

e−iθ ZZ=CNOT0→1⋅(I⊗Rz(2θ))⋅CNOT0→1,θ=π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 — e−i(π/8) (X⊗I)e^{-i(\pi/8)\, (X \otimes I)}. Only qubit 0 participates. Using e−iθX=Rx(2θ)e^{-i\theta X} = R_x(2\theta):

e−i(π/8) X⊗I=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.