Method#

The method has two halves: a network that scores states, and a search that uses those scores. Both are written as batched tensor operations so that a single GPU can process the entire beam at once.

Learning the diffusion distance#

Training data is generated by random walks from the solved state. For each walk length \( K \in [K_{\min}, K_{\max}] \), \( k \) walkers take \( K \) random steps from \( V_0 \), and the resulting state is labelled with \( K \):

\[ \mathcal{D} = \{ (V_0 \cdot s_{i_1} \cdots s_{i_K},\; K) \;:\; K_{\min} \le K \le K_{\max} \} \]

The only structural prior applied is that a walk never immediately undoes its previous move (Trainer.do_random_step masks the inverse of the last move) — a non-backtracking random walk. This is not a minor detail: because a non-backtracking walk drifts away from the solved state more directly, its length is a tighter, less noisy estimate of the true distance than a plain random walk. The CayleyPy RL paper reports (its Table 6) that on the harder LRX graphs a single-epoch model trained on plain random walks often fails to solve at all, while the same model trained on non-backtracking walks succeeds.

The label \( K \) is not the true distance — a walk can revisit states, so \( K \) is an upper bound, \( d(g, e) \le K \). What the network learns by regressing on \( K \) under an MSE loss is the conditional expectation

\[ V_\theta(g) \;\approx\; \mathbb{E}\!\left[\,K \mid \text{state } g \text{ after } K \text{ random steps}\,\right], \]

a diffusion distance: monotone in the true distance, cheap to evaluate, and — this is the point — good enough to rank neighbours even where it is badly calibrated in absolute terms.

The network itself is deliberately plain: one-hot encode the state (state_size × num_classes), a linear layer to hd1, an optional layer to hd2, nrd residual blocks with BatchNorm+ReLU, and a scalar output. See the PathSolver package.

Bellman refinement (Modified DQN)#

This phase comes from the follow-up paper CayleyPy RL (arXiv:2502.18663), which combines the diffusion-distance approach with reinforcement learning. Optionally the random-walk labels are sharpened by a Bellman update on the Cayley graph (pathsolver/dqn.py):

\[ V(g) \;\leftarrow\; \min\Big( 1 + \min_{s \in S} V_\theta(g s),\; K_{\mathrm{rw}}(g) \Big), \qquad V(e) = 0 \]

The estimate is clipped against the random-walk label because that label is a valid upper bound, and clamped below by 1 everywhere except the solved state. This is enabled with --epochs_dqn (see Training).

The refinement is best understood as a sharpening of the diffusion-distance warm-up, not a replacement for it. The paper reports that DQN epochs consistently improve on the warm-up — both solution length and solve rate — but that the gain is modest, and that DQN training from scratch, without the diffusion warm-up, performs poorly. The warm-up gives the network a globally sensible value landscape that the Bellman update then refines locally; starting from a random landscape, the local update has little to build on.

At search time (pathsolver/searcher.py) the model replaces the heuristic in a beam search of width \( B \):

  1. Expand. For the current beam of \( B \) states, generate all \( B \cdot |S| \) neighbours with a single torch.gather against the permutation table.
  2. Deduplicate. Hash each state (state2hash: a random integer vector dotted with the state) and drop duplicates and previously visited states via sort + isin.
  3. Score. Run the network over the surviving neighbours in chunks.
  4. Prune. Keep the \( B \) lowest-scoring states as the next beam.
  5. Check. Stop as soon as the solved state appears in the beam.

Nothing in this loop is per-state Python — every step is one or a few tensor kernels over the whole beam. That is what makes \( B = 2^{20} \) practical and where the reported 20× speedup over prior work comes from: the search visits comparably many nodes but spends far less wall-clock per node.

The trade-offs available at search time:

KnobFlagEffect
Beam width \( B \)--BLarger → higher solve rate and shorter solutions, linear GPU memory cost
Max depth--num_stepsMust exceed the expected solution length
Restarts--num_attemptsRetries with a fresh hash seed on failure

Because the search is complete only up to the beam width, longer solutions are traded against compute — which is exactly the curve reported in Results.