Quantum Walks with Spins
On this page
caroli-walk evolves a quantum walker on a graph whose edges each carry a spin ½: at every step the walker chooses a direction with a coin, moves along an edge, and interacts with the spin of that edge through an exchange coupling. This is the model of K. Sellapillay and A. D. Verga (Phys. Rev. E 103, 032123 (2021)), in which the walker flips the spins it passes, so that the spins magnetise and become entangled with it. The crate computes the exact evolution of the whole state, walker and spins, for any graph whose Hilbert space fits in memory (\(1.7 \cdot 10^9\) amplitudes on a ring of 25 nodes), and the observables of the paper: the walker's distribution, the edge spins, the entanglement entropies, the concurrence of two spins and the time-averaged distributions of a scan of parameters.
A step is applied without a matrix, as two sweeps over the state, on all the cores of the CPU in f64 or f32, or on the GPU (Metal) in f32 or double-single, checked against the CPU. The time evolution of electrons under a Hamiltonian is on another page, Time evolution.
The model
The walker lives on the half-edges of the graph: node \(x\) of degree \(d_x\) has one half-edge per incident edge, and the position of a half-edge among those of its node is its colour \(c = 0, \dots, d_x - 1\). Edge \(e\) carries spin \(e\). The basis of the Hilbert space is
$$ \lvert x, c \rangle \otimes \lvert s \rangle, \qquad s = (s_0, s_1, \dots, s_{\lvert E \rvert - 1}), \quad s_e \in \{ \uparrow, \downarrow \}, $$
so that its dimension is \(2 \lvert E \rvert \cdot 2^{\lvert E \rvert}\): the \(\sum_x d_x = 2\lvert E \rvert\) half-edges times the spin configurations.
| Symbol | Meaning |
|---|---|
| \(N\), \(\lvert E \rvert\) | Numbers of nodes and of edges; \(\lvert E \rvert\) is also the number of spins |
| \(d_x\) | Degree of node \(x\), its number of colours |
| \(h = (x, c)\) | A half-edge: node \(x\), colour \(c\) |
| \(s\) | A spin configuration, read as an integer: bit \(e\) is the spin of edge \(e\), 0 for up |
| \(C_x\) | Coin of node \(x\), a \(d_x \times d_x\) unitary matrix |
| \(\theta\) | Angle of the rotation coin |
| \(J\) | Coupling between the walker and the spins (dimensionless) |
| \(\boldsymbol\tau\), \(\boldsymbol\sigma\) | Pauli matrices on the walker's side of an edge and on the spin of that edge |
| \(t\) | Time, in steps |
The paper's lattice is a ring of \(n\) nodes (Graph::cycle): edge \(x\) joins nodes \(x\) and \(x + 1\) (modulo \(n\)), colour 0 of node \(x\) points to \(x + 1\) and colour 1 to \(x - 1\). Its dimension is \(n \cdot 2^{n+1}\). Graph::path gives a chain, whose end nodes have one colour. Any other graph is given by its edges: Graph::from_edges numbers the colours of each node in the order in which its edges appear, and Graph::new takes the colours of every node explicitly. An edge must join two distinct nodes; two distinct edges may join the same pair (a ring of two nodes).
The state in memory
The state is one vector of complex amplitudes,
$$ \psi(h, s) = \psi\big[\, h \cdot 2^{\lvert E \rvert} + s \,\big], $$
with the half-edges numbered node by node and, within a node, in colour order. A half-edge's spin configurations form a contiguous row of \(L = 2^{\lvert E \rvert}\) amplitudes, and the rows of a node are consecutive. This layout makes each part of a step a sweep over memory:
- the coin of node \(x\) mixes the \(d_x\) rows of a contiguous block, entry by entry;
- the motion and the interaction on edge \(e\) pair the two rows of the edge's half-edges and, within them, the configurations \(s\) and \(s + 2^e\) that differ by the spin of edge \(e\), as a one-qubit gate on qubit \(e\) does in a state-vector simulator.
| Ring of \(n\) nodes | 13 | 15 | 17 | 19 | 21 | 23 | 25 |
|---|---|---|---|---|---|---|---|
| Dimension | \(2.1 \cdot 10^5\) | \(9.8 \cdot 10^5\) | \(4.5 \cdot 10^6\) | \(2.0 \cdot 10^7\) | \(8.8 \cdot 10^7\) | \(3.9 \cdot 10^8\) | \(1.7 \cdot 10^9\) |
| State in f64 | 3.4 MB | 16 MB | 71 MB | 319 MB | 1.4 GB | 6.2 GB | 27 GB |
| State in f32 | 1.7 MB | 7.9 MB | 36 MB | 159 MB | 0.7 GB | 3.1 GB | 13 GB |
The largest system of the paper is the ring of 19 nodes.
One step
One step of the walk is
$$ U = V(J)\, M\, C, \qquad \lvert \psi(t + 1) \rangle = U \lvert \psi(t) \rangle . $$
The coin
\(C\) applies the coin \(C_x\) of each node to the colours of that node and leaves the spins alone:
$$ \psi'(x, c, s) = \sum_{k \lt d_x} (C_x)_{ck}\, \psi(x, k, s). $$
Each node has its own coin (SpinWalk::new takes one per node and checks its size). Three are provided, with \(j, k = 0, \dots, d - 1\):
$$ R(\theta) = \begin{pmatrix} \cos\theta & -\sin\theta \\ \sin\theta & \cos\theta \end{pmatrix}, \qquad (G_d)_{jk} = \frac{2}{d} - \delta_{jk}, \qquad (F_d)_{jk} = \frac{e^{2\pi i jk/d}}{\sqrt d}, $$
the rotation of the paper (rotation), Grover's coin (grover) and the discrete Fourier transform (fourier). SpinWalk::ring(n, θ, J) is the ring with \(R(\theta)\) at every node.
On the ring, the motion below leaves the walker on the colour that points back along the edge it came by. The coin then decides what it does next: it turns back with amplitude \(\cos\theta\) and goes on with amplitude \(\sin\theta\). At \(\theta = 0\) the walker bounces on one edge forever; at \(\theta = \pi/2\) it runs around the ring.
The motion
\(M\) swaps the two half-edges of every edge and leaves the spins alone. If edge \(e\) joins colour \(c_y\) of node \(x\) (pointing to \(y\)) and colour \(c_x\) of node \(y\) (pointing to \(x\)),
$$ M \lvert x, c_y, s \rangle = \lvert y, c_x, s \rangle, \qquad M \lvert y, c_x, s \rangle = \lvert x, c_y, s \rangle . $$
\(M\) is a permutation and \(M^2 = 1\). Every half-edge belongs to exactly one edge, so the edges act on disjoint pairs of rows.
The interaction with the spins
On each edge, the walker's side of the edge is a two-level system: half-edge \(a\), at the edge's first node (Graph::halves(e).0), or half-edge \(b\), at its second node. Call \(\boldsymbol\tau\) the Pauli matrices of this two-level system, with \(\tau_z = +1\) on \(a\), and \(\boldsymbol\sigma\) those of the edge's spin, with \(\sigma_z = +1\) for up. The interaction is the exchange
$$ V(J) = \sum_e P_e \otimes \exp\Big(\frac{iJ}{4}\, \boldsymbol\tau \cdot \boldsymbol\sigma_e\Big), $$
where \(P_e\) projects the walker on the two half-edges of edge \(e\) (the \(P_e\) add up to the identity) and the other spins are left alone.
For two spins ½, \(\boldsymbol\tau \cdot \boldsymbol\sigma = 2P - 1\), with \(P\) the operator that exchanges their states (\(+1\) on the three triplet states, \(-1\) on the singlet). Since \(P^2 = 1\),
$$ \exp\Big(\frac{iJ}{4}\, \boldsymbol\tau \cdot \boldsymbol\sigma\Big) = e^{-iJ/4} \exp\Big(\frac{iJ}{2} P\Big) = e^{-iJ/4} \Big(\cos\frac{J}{2} + i \sin\frac{J}{2}\, P\Big). $$
\(P\) leaves \(\lvert a \uparrow \rangle\) and \(\lvert b \downarrow \rangle\) unchanged and exchanges \(\lvert a \downarrow \rangle\) and \(\lvert b \uparrow \rangle\). In the basis \((\lvert a \uparrow \rangle, \lvert a \downarrow \rangle, \lvert b \uparrow \rangle, \lvert b \downarrow \rangle)\), the exchange on one edge is therefore
$$ V_e = \begin{pmatrix} p & 0 & 0 & 0 \\ 0 & \alpha & \beta & 0 \\ 0 & \beta & \alpha & 0 \\ 0 & 0 & 0 & p \end{pmatrix}, \qquad p = e^{iJ/4}, \quad \alpha = e^{-iJ/4} \cos\frac{J}{2}, \quad \beta = i\, e^{-iJ/4} \sin\frac{J}{2}, $$
which is what SpinWalk::exchange returns, as \((p, \alpha, \beta)\). Its eigenvalues are \(e^{iJ/4}\) on the triplet and \(\alpha - \beta = e^{-3iJ/4}\) on the singlet \((\lvert a \downarrow \rangle - \lvert b \uparrow \rangle)/\sqrt 2\). Three properties follow from the formula:
- \(V_e\) commutes with \(\tau_z + \sigma_z\): the walker changes its side of the edge only by flipping the spin;
- \(\lvert p \rvert = 1\), \(\lvert \alpha \rvert^2 + \lvert \beta \rvert^2 = 1\) and \(\alpha \bar\beta + \beta \bar\alpha = 0\): \(V_e\) is unitary;
- \(V(J + 2\pi) = i\, V(J)\): \(J\) and \(J + 2\pi\) give the same probabilities, and at \(J = 0\) the walk is free (\(p = \alpha = 1\), \(\beta = 0\)).
Motion and exchange together
\(V M\) acts edge by edge on four amplitudes. For edge \(e\) and each configuration \(s\) with the spin of \(e\) up, write \(a_0 = \psi(a, s)\), \(a_1 = \psi(a, s + 2^e)\), \(b_0 = \psi(b, s)\), \(b_1 = \psi(b, s + 2^e)\). Then
$$ a_0' = p\, b_0, \qquad a_1' = \alpha\, b_1 + \beta\, a_0, \qquad b_0' = \beta\, b_1 + \alpha\, a_0, \qquad b_1' = p\, a_1 . $$
Read column by column: a walker leaving \(a\) with the spin down crosses to \(b\) with the phase \(p\); a walker leaving \(a\) with the spin up crosses with amplitude \(\alpha\), or stays on \(a\) and flips the spin down with amplitude \(\beta\). The same holds from \(b\) with the spins reversed.
Initial states
SpinWalk::product_state(walker, spins) builds a product of the walker and of every spin,
$$ \psi(h, s) = w_h \prod_{e} \chi_e(s_e), $$
from the amplitude \(w_h\) of the walker on each half-edge and the (up, down) amplitudes \(\chi_e\) of each spin. localized(x, c) puts the walker on one half-edge; UP is \(\lvert \uparrow \rangle\) and PLUS is \((\lvert \uparrow \rangle + \lvert \downarrow \rangle)/\sqrt 2\), the spin along \(+x\). The paper's initial states "z" and "x" have every spin up or every spin along \(+x\).
Observables
The functions of observables follow section 2.2 of the paper. Sums run over all half-edges \(h\) and configurations \(s\) unless stated otherwise.
Distributions. The probability of each half-edge and of each node:
$$ p(h) = \sum_s \lvert \psi(h, s) \rvert^2, \qquad p(x) = \sum_{c \lt d_x} p(x, c). $$
Edge spins. For each edge, from the pairs of configurations that differ by its spin:
$$ \langle X_e \rangle + i \langle Y_e \rangle = 2 \sum_h \sum_{s:\, s_e = \uparrow} \overline{\psi(h, s)}\, \psi(h, s + 2^e), \qquad \langle Z_e \rangle = \sum_h \sum_{s:\, s_e = \uparrow} \Big( \lvert \psi(h, s) \rvert^2 - \lvert \psi(h, s + 2^e) \rvert^2 \Big). $$
Reduced density matrices of the walker. The walker's density matrix (position and colour) is the Gram matrix of the rows,
$$ \rho_W(h, h') = \sum_s \psi(h, s)\, \overline{\psi(h', s)}, $$
one matrix product of the \(2\lvert E \rvert \times L\) state with its adjoint. The position and the colour are traced from it, the colours being padded to the largest degree (on a regular graph, such as the ring, these are the exact partial traces):
$$ \rho_x(x, y) = \sum_{c \lt \min(d_x, d_y)} \rho_W\big((x, c), (y, c)\big), \qquad \rho_c(c, k) = \sum_{x:\, \max(c, k) \lt d_x} \rho_W\big((x, c), (x, k)\big). $$
Entanglement entropies. The von Neumann entropy, in bits, from the eigenvalues of a density matrix (Hermitian eigensolver of Dense linear algebra; eigenvalues below \(10^{-300}\), rounding errors included, are left out):
$$ S(\rho) = -\sum_{\lambda \gt 10^{-300}} \lambda \log_2 \lambda . $$
entropies returns \((S_x, S_c, S_s)\): the entropies of \(\rho_x\), of \(\rho_c\) and of \(\rho_W\). The whole state being pure, the entropy of the walker equals that of all the spins together (Schmidt decomposition): \(S_s\) measures the entanglement between the walker and the spins.
Spins of a subset. For edges \(A = (e_0, \dots, e_{k-1})\), the reduced density matrix of their spins is
$$ \rho_A(i, j) = \sum_h \sum_r \psi(h, a_i + r)\, \overline{\psi(h, a_j + r)}, \qquad a_i = \sum_{m \lt k} i_m\, 2^{e_m}, $$
where \(i_m\) is bit \(m\) of \(i\) and \(r\) runs over the configurations of the other spins. Its basis index is \(\sum_m s_{e_m} 2^m\), in the order of the edges given. spin_entropy is the entanglement entropy \(S(\rho_A)\) of these spins with the rest of the system.
Concurrence. For two spins, Wootters's concurrence,
$$ C = \max\big(0,\, \sqrt{\lambda_1} - \sqrt{\lambda_2} - \sqrt{\lambda_3} - \sqrt{\lambda_4}\big), \qquad \tilde\rho = (\sigma_y \otimes \sigma_y)\, \rho^{\ast}\, (\sigma_y \otimes \sigma_y), $$
with \(\lambda_1 \ge \dots \ge \lambda_4\) the eigenvalues of \(\rho \tilde\rho\). They are computed as those of the Hermitian matrix \(\sqrt\rho\, \tilde\rho\, \sqrt\rho\), which has the same spectrum, with \(\sqrt\rho\) from the eigendecomposition of \(\rho\) (negative rounding eigenvalues set to zero). \(C = 0\) for a product state and 1 for a Bell pair.
Cost. \(\rho_W\) costs \((2\lvert E \rvert)^2 L\) multiply-adds and \(\rho_A\) costs \(2 \lvert E \rvert\, L\, 2^k\); their eigenproblems are tiny.
Scans of parameters
The paper maps the walk's behaviour over the \((\theta, J)\) plane by the time-averaged distribution
$$ \bar p(h) = \frac{1}{T} \sum_{t=1}^{T} p_t(h) $$
and its Kolmogorov–Smirnov distance to the uniform distribution over the \(N\) nodes (Eq. 31 of the paper),
$$ D = \max_x \Big\lvert \sum_{y \le x} \frac{p(y)}{\sum_z p(z)} - \frac{x + 1}{N} \Big\rvert, $$
0 for a walker spread evenly, up to \(1 - 1/N\) for one localised on a node (ks_distance). The cumulative sum follows the numbering of the nodes, the natural order on a ring or a chain.
step_serial_accumulate adds the \(p_t(h)\) during the step itself: the edge pass writes every amplitude exactly once, so the squared moduli of the entries it writes add up to the probabilities after the step, with no extra sweep over memory.
scan runs many walks of one graph (their coins and couplings may differ) and returns the summed \(p_t(h)\) of each:
- One walk per CPU thread, on that thread only (
step_serial), so that each state stays in its core's cache: at \(n = 13\), 3.4 MB in f64. The threads take the next walk from one queue. - Optionally, one more thread feeds the GPU: it takes batches of walks (about 8 MB of f32 states, 1 to 64 walks), which the GPU steps together. If the GPU fails, that thread finishes its batch on the CPU in f64 and stops.
- The walks run in reduced precision are checked kind by kind (f32 on the CPU, f32 on the GPU). One in fifty, at least one, is recomputed in f64 on the CPU, and the deviation is \(\max_h \lvert \bar p(h) - \bar p_{64}(h) \rvert / \sum_h \bar p_{64}(h)\). Above the tolerance (\(10^{-3}\) by default), or for a NaN, every walk of that kind is recomputed in f64.
ScanReport says how many walks ran where, how many were checked, the largest deviation, and why the f64 recomputation happened if it did.
On the CPU
A step is two passes, coin_pass and edge_pass, each a sweep over the whole state. Both are generic over the real type: f64, or f32 for half the memory traffic and twice the width of the vector units, at about \(10^{-7}\) of relative error per step.
Coin pass. Each node owns the contiguous block of its \(d_x\) rows. The blocks are processed in parallel, each cut into pieces of \(2^{14}\) configurations. A node of degree 1 multiplies its row by the \(1 \times 1\) coin. A node of degree 2 updates its two rows entry by entry; a real coin, such as \(R(\theta)\), takes real-by-complex products, half the multiplications. A node of higher degree gathers the \(d_x\) amplitudes of each configuration and applies the \(d_x \times d_x\) matrix.
Edge pass. The edges own disjoint pairs of rows and are processed in parallel. In the two rows of edge \(e\), the configurations come in blocks of \(2^{e+1}\): the first \(2^e\) with the spin of \(e\) up, the next \(2^e\) with it down. Each entry of the first half is updated with its partner \(2^e\) further, in both rows. When a block is short (\(2^{e+1} \le 2^{15}\)), the rows are cut into pieces of \(2^{15}\) configurations holding whole blocks, with unrolled kernels for \(e = 0, 1, 2\); when it is long, each block is cut into runs of \(2^{14}\) entries of each half of both rows.
step runs both passes on all the threads of the rayon pool; step_serial runs them on the calling thread, for many small walks side by side.
Memory safety. The passes hand out disjoint mutable views of the state (split_at_mut, chunks_mut and their parallel versions) to the threads: the crate holds no raw pointer and no unsafe code, and the workspace lints refuse it. Every method that takes a state checks its length first and panics before writing anything (tested on both passes and on the accumulating step).
Bound by memory. Each pass reads and writes every amplitude once: 64 bytes per amplitude and per step in f64, 32 in f32, while the arithmetic is a few multiply-adds per amplitude. At \(n = 19\), a step moves 1.3 GB in f64 and 0.64 GB in f32; the benchmark's 5.3 ms and 2.5 ms per step on 14 threads are about 240 GB/s and 255 GB/s of memory traffic, close to the bandwidth that ARCHITECTURE.md gives for the machine (about 230 GB/s). One thread takes 14.5 ms in f64: the 14 threads gain only 2.7× because they share that bandwidth, and f32 halves the time because it halves the traffic.
On the GPU
caroli-gpu holds the same two passes as Metal kernels, in f32 or in double-single (an unevaluated sum of two f32, about \(10^{-14}\) relative, described in Reduced precision and the GPU):
walk_coin: one thread per (walk, node, configuration) reads the \(d_x\) amplitudes of the node's rows at that configuration and applies the coin (degrees up toMAX_DEGREE= 8);walk_edge: one thread per (walk, edge \(e\), configuration with the spin of \(e\) up) updates the four amplitudes \(a_0, a_1, b_0, b_1\);walk_accumulate_f32: adds the row probabilities of an f32 state to one accumulator per half-edge (a reduction per threadgroup, then atomic additions), for scans.
A step is two dispatches, and 256 dispatches go to the GPU in one command buffer. A batch of walks of one graph steps together, each with its own coins and coupling, walk \(b\) holding its state from entry \(b \cdot 2\lvert E \rvert \cdot 2^{\lvert E \rvert}\) on: many small walks fill the GPU. Thread indices are 32-bit, so the threads of a dispatch must number fewer than \(2^{32}\); the upload refuses a batch that does not fit, or a state larger than the largest Metal buffer. The state lives in memory shared with the CPU, which reads it in place to take norms and distances in f64.
Checked runs
evolve runs a walk on the device chosen in Options and calls an observer at \(t = 0\), every every steps and at the end:
- Calibration. The first 2 % of the steps (at least 1, at most 200) run on the CPU in f64 and on the GPU from the same state. Their distance \(\lVert \psi_{\mathrm{GPU}} - \psi_{\mathrm{CPU}} \rVert / \lVert \psi(0) \rVert\), scaled linearly to the whole run, predicts the final error. Above the tolerance, f32 gives way to double-single and double-single to the CPU, each with its own calibration. The steps of a calibration count as done: the CPU's result is kept.
- Run. An accepted precision continues on the GPU from the CPU's exact state.
- Checks. At every checkpoint the CPU sums \(\lVert \psi \rVert^2\) in f64 from the GPU's buffer. A relative drift above the tolerance, or a NaN, sends the run back to the CPU from the last good checkpoint, whose state was read back before.
The presets are Options::exploration (f32, tolerance \(10^{-3}\)), Options::accurate (double-single, \(10^{-9}\)) and Options::cpu. The Report says where the run went, every calibration and its measured distance, the predicted error, the largest norm drift, the step from which the CPU took over and why, and the steps on each device.
The benchmark's checked runs (exploration preset, a checkpoint every 100 steps, rings with \(\theta = \pi/8\) and \(J = 0.2\); raw records of 12 October 2026) show the mechanism at work. The runs are longer at small \(n\), and the f32 error grows with the number of steps:
| \(n\) | Steps | Where it ran | Predicted error | Largest norm drift | CPU steps | GPU steps |
|---|---|---|---|---|---|---|
| 13 | 100,000 | double-single (f32's calibration predicted more than \(10^{-3}\)) | \(1.1 \cdot 10^{-10}\) | \(2.2 \cdot 10^{-10}\) | 400 | 99,600 |
| 15 | 25,500 | f32, then the CPU (a drift of \(1.003 \cdot 10^{-3}\)) | \(9.2 \cdot 10^{-4}\) | \(1.0 \cdot 10^{-3}\) | 11,400 | 14,100 |
| 17 | 5,600 | f32 | \(2.0 \cdot 10^{-4}\) | \(3.9 \cdot 10^{-4}\) | 112 | 5,488 |
| 19 | 1,250 | f32 | \(4.8 \cdot 10^{-5}\) | \(8.7 \cdot 10^{-5}\) | 25 | 1,225 |
| 21 to 25 | 500 | f32 | \(2.0 \cdot 10^{-5}\) | \(3.5 \cdot 10^{-5}\) | 10 | 490 |
Validation
| Check | Test | Result asserted |
|---|---|---|
| The structured step against the explicit sparse \(U\) (built from the definitions, column by column), on rings of 3 and 5 nodes and on a graph of degree 3 with Fourier, Grover, rotation and phase coins | step_matches_matrix | \(\lVert U\psi - \mathrm{step}(\psi) \rVert \lt 10^{-13}\) for a random normalised \(\psi\) |
| Unitarity: the steps of the basis vectors are orthonormal (ring of 3, \(\theta = 0.8\), \(J = 2.1\)) | unitary | \(10^{-13}\) |
| Free walk: at \(J = 0\) the state stays a product, the walker following the coined walk on \(2\lvert E \rvert\) amplitudes (ring of 6, 25 steps) | free_walk | \(10^{-12}\) |
| f32 against f64 after 50 steps (ring of 8) | single_precision | between \(10^{-12}\) and \(10^{-4}\) |
The accumulating step, the serial step, the two passes: the same state as step | accumulated_probabilities, serial_matches_parallel, passes_make_a_step | \(10^{-15}\); accumulated \(p(h)\) to \(10^{-14}\) |
| Product states: entropies and concurrence zero, spins as prepared; a Bell pair of spins 0 and 2: \(S = 1\) bit for spin 0, \(C = 1\) | product_state_observables, bell_pair | \(10^{-12}\) |
| After 12 coupled steps, \(S_s\) equals the entropy of all the spins computed directly, and the norm is kept | walker_spin_entanglement | \(10^{-10}\), norm \(10^{-13}\) |
| A scan in f32, with the GPU, or both, against f64; an impossible tolerance gives the f64 result | scans_agree | relative \(10^{-4}\); exact |
| On a Mac with a GPU: double-single against the CPU after 300 steps; an impossible tolerance sends f32 and double-single back to the CPU; f32 with the exploration preset stays on the GPU | gpu_checked_against_cpu | \(10^{-10}\) and drift \(10^{-10}\); \(10^{-14}\); \(10^{-4}\) |
examples/paper.rs runs the set-up of the paper's Figs. 2 and 3 (ring of 13 nodes, walker on colour 0 of node 0, spins along \(+x\), \((\theta, J) = (\pi/8, 0.2)\) and \((\pi/2, 0.2)\)) and prints the mean spin and \(S_x\), \(S_c\), \(S_s\) every 100 steps up to 2000, for comparison with the published curves. The benchmark below also compares every implementation's \(p(x)\) with caroli's in f64 before its time counts: the f64 methods (the sparse \(U\), both Python versions) agree to \(10^{-12}\) or better, double-single to \(1.4 \cdot 10^{-12}\), f32 to \(2 \cdot 10^{-5}\) or better.
Speed
Measured on a Mac mini M4 Pro (10 performance and 4 efficiency cores) on 12 October 2026, against two Python versions of the same step written for the benchmark (benchmarks/walk/reference.py; the authors' code is not part of the comparison): the one-step operator as a SciPy sparse matrix, and the step as vectorised NumPy operations, both on one thread. Ring of \(n\) nodes, \(\theta = \pi/8\), \(J = 0.2\). Time per step in ms; in brackets, the speed-up over the SciPy version (benchmarks/results/walk-report-2026-10-12-c660c96.md):
| Method | \(n = 13\) | 15 | 17 | 19 | 21 | 23 | 25 |
|---|---|---|---|---|---|---|---|
| caroli CPU, 1 thread | 0.155 (3×) | 0.715 (3×) | 3.36 (3×) | 14.5 (4×) | 63.9 | ||
| caroli CPU, 14 threads | 0.089 (6×) | 0.204 (10×) | 0.725 (16×) | 5.33 (10×) | 23.5 | 106 | 454 |
| caroli CPU f32, 14 threads | 0.080 (7×) | 0.181 (11×) | 0.374 (31×) | 2.50 (20×) | 11.7 | 52.3 | 227 |
| caroli, \(U\) as a sparse matrix (CSR) | 0.111 (5×) | 0.552 (4×) | 2.67 (4×) | 12.2 (4×) | |||
| caroli GPU, double-single | 0.041 (13×) | 0.192 (11×) | 1.24 (9×) | 5.27 (10×) | 23.2 | 101 | |
| caroli GPU, f32 | 0.020 (27×) | 0.077 (26×) | 0.507 (23×) | 2.56 (20×) | 11.3 | 49.7 | 216 |
| caroli GPU, f32, checked | 0.046 (11×) | 0.144 (14×) | 0.523 (22×) | 2.76 (18×) | 12.3 | 53.6 | 257 |
| Python, vectorised NumPy | 1.07 | 4.77 | 19.2 | 120 | 448 | ||
| Python, \(U\) as a SciPy sparse matrix | 0.528 | 2.02 | 11.7 | 51.1 |
An empty cell was not run. Double-single is not run at \(n = 25\): its state is as large as the f64 one, and the f64 copy needed to upload it would not fit in memory. The checked runs include their calibration on the CPU; at \(n = 13\) and 15 they ran partly in double-single or on the CPU (see Checked runs).
From \(n = 19\) up, the CPU and the GPU take the same time at the same precision: both are bound by the same shared memory. The GPU is ahead on the small states (\(n \le 15\)); at \(n = 17\) the CPU is.
The scan of the paper's Fig. 21: ring of 13 nodes, \(64 \times 64\) points of \((\theta, J)\) at the centres of a grid over \((0, \pi/2) \times (0, \pi)\), for the initial spins "x" and "z", walker on colour 0 of the middle node: 8192 walks of 2000 steps, each giving the time-averaged \(p(x)\) and its Kolmogorov–Smirnov distance.
| Method | Time | Speed-up |
|---|---|---|
| Python, \(U\) as a SciPy sparse matrix, one process (extrapolated from 8 walks) | 4.4 h | 1× |
| caroli CPU, 14 threads, f64 | 6.7 min | 39× |
| caroli CPU, 14 threads, f32 | 6.2 min | 42× |
| caroli, 14 threads in f32 and the GPU (which ran 4151 of the walks) | 3.7 min | 70× |
The distances agree to \(4.4 \cdot 10^{-16}\) between Python and caroli, to \(2.7 \cdot 10^{-6}\) between f32 and f64, and to \(1.8 \cdot 10^{-5}\) with the GPU. Of the reduced-precision walks, 329 were recomputed in f64 by the scan's own check; they differed by at most \(1.5 \cdot 10^{-5}\), below the tolerance.
In the code
Crate caroli-walk (the CPU, the observables, the scans and the checked runs); the GPU kernels are in caroli-gpu.
| Item | What it does |
|---|---|
SpinWalk | The walk: graph, coins and \(J\). step, step_serial, step_serial_accumulate, exchange, matrix (the explicit \(U\)), product_state and the observables (entropies, spins, concurrence...) |
Graph | Nodes, numbered edges and coloured half-edges: cycle, path, from_edges, new |
rotation, grover, fourier | The coins |
UP, PLUS | Spin states for product states |
Real, to_single, to_double | f64 and f32 states |
von_neumann, concurrence, ks_distance | Entropy, concurrence and Kolmogorov–Smirnov distance of given density matrices and distributions |
scan, ScanOptions, ScanReport | Many walks side by side, checked |
evolve, Options, Report, Device | A walk on the GPU, checked against the CPU |
MetalWalk, WalkTables, MetalDevice::walks | The Metal kernels, unchecked (macOS) |
Examples in crates/caroli-walk/examples: paper (Figs. 2 and 3), timing (time per step of every method), passes (one walk on all threads against walks side by side), gpu_batch (throughput of the GPU against the batch size). The benchmark is walk in crates/caroli-bench, with benchmarks/walk/reference.py.
References
- K. Sellapillay, A. D. Verga, Quantum walk on a graph of spins: magnetism and entanglement, Phys. Rev. E 103, 032123 (2021). The model, the observables of its section 2.2, the Kolmogorov–Smirnov distance (Eq. 31) and the scan of the \((\theta, J)\) plane (Fig. 21).
- W. K. Wootters, Entanglement of formation of an arbitrary state of two qubits, Phys. Rev. Lett. 80, 2245 (1998). The concurrence.
- J. Kempe, Quantum random walks: an introductory overview, Contemp. Phys. 44, 307 (2003). Coined quantum walks, the Grover and Fourier coins.