A square lattice gives a simple description of a quantum magnet. Each interior spin interacts with its four nearest neighbors. That description becomes a more interesting computational problem when the simulation must run on a quantum processor whose physical qubits have a different pattern of connections.
The mathematical structure of the simulation gives a compiler some freedom. Understanding that freedom also gives us a useful way to design a benchmark for quantum compilation.
Start with the Hamiltonian
Consider an open rectangular lattice with a transverse-field Ising Hamiltonian
H = J ∑(u,v)∈ E Zu Zv + h ∑u∈ V Xu.
Here E contains the horizontal and vertical nearest-neighbor bonds. A first-order product formula approximates the evolution for a small time interval δ by applying the bond rotations and the field rotations in sequence. The bond terms commute with one another, even when they share a spin. We can reorder those rotations within their block without changing that block's unitary. The field rotations also commute with one another, but generally do not commute with the bond terms.
That distinction matters. Reordering commuting terms is an exact transformation; changing the product formula may change the approximation to the intended physical dynamics. A comparison of compiled circuits should preserve the chosen formula and time interval, or explicitly account for the different approximation.
Four groups of bonds
On a rectangular lattice, horizontal bonds can be divided by the parity of the left endpoint's column. Vertical bonds can be divided by the parity of the upper endpoint's row. Each group is a matching: no spin belongs to two bonds in the same group. This means that, with suitable physical connections, all its interactions can be scheduled together.
The following example constructs those groups for an open square lattice. It verifies that each bond appears once and that each group consists of disjoint pairs. It also checks the count for a straightforward decomposition of each ZZ rotation into two entangling gates and a single-qubit rotation, assuming native connectivity and no cross-block simplification.
Disjoint bond endpoints permit parallel application in the logical model; physical scheduling also depends on target timing and simultaneous-operation restrictions.
Illustration: standalone Python calculation.
from itertools import chain
rows = cols = 8
layers = [[] for _ in range(4)]
for r in range(rows):
for c in range(cols):
u = r * cols + c
if c + 1 < cols:
layers[c % 2].append((u, u + 1))
if r + 1 < rows:
layers[2 + r % 2].append((u, u + cols))
edges = list(chain.from_iterable(layers))
assert len(edges) == len(set(edges)) == rows*(cols-1)+cols*(rows-1)
for layer in layers:
endpoints = list(chain.from_iterable(layer))
assert len(set(endpoints)) == len(endpoints)
assert [len(g) for g in layers] == [32, 24, 32, 24]
print('Bonds by group:', [len(g) for g in layers])
print('Entangling gates in the stated decomposition:', 2*len(edges)) The example is a logical scheduling reference. A standard decomposition is a useful starting cost; it is not a lower bound on every possible native implementation. Native gate sets, special angles, cancellation and joint synthesis can change the count.
From lattice to processor
A sparse quantum processor may have too few connections to represent all the lattice bonds under one fixed placement. An interior spin with four distinct neighbors cannot retain all those neighbors on a physical qubit of degree three. Logical-to-physical placement can change during the computation, and the order of commuting rotations gives the compiler choices about when to change it.
A hand-designed reference should exploit this structure. For example, it might process groups of interactions in a repeating order, carry the resulting placement into the next product-formula step and restore the original placement only if the surrounding computation requires it. It is worth testing more than one such arrangement, since a single reference can miss a useful property of the problem.
How to compare implementations
Choose one target with a fixed set of usable connections and native gates. Give each method the same Hamiltonian, angles, number of steps and output mapping requirements. Measure native two-qubit gates, their scheduled depth and the compilation resources. Verify the resulting operation for selected small cases and use a suitable independent check for larger ones. If the target changes, repeat the comparison under the new conditions.
For a simulation experiment, also compare relevant observables against a reference calculated with the same product formula. Routing cost, product-formula error and hardware noise are different sources of error. The best choice of circuit for a particular scientific measurement depends on their combined effect.
The 4colors Quantum Compiler gives you a way to investigate circuit implementations for the hardware you intend to use.