Introduction#

Pathsolver finds short paths between two vertices of a very large Cayley graph — a graph whose vertices are the elements of a group and whose edges are generated by a fixed set of moves. Permutation puzzles are the canonical example: the Rubik’s Cube 3×3×3 is a Cayley graph with \( 4 \times 10^{19} \) vertices, the Pancake graph on 55 elements has \( 3 \times 10^{73} \).

Solving a puzzle means finding a path from a scrambled state to the solved state. The graphs are far too large to store, so classical search (BFS, IDA*, pattern databases) either does not fit in memory or requires puzzle-specific human-designed heuristics.

The idea in one paragraph#

Train a neural network to estimate, for any state, the diffusion distance to the solved state — roughly, how many random moves it takes to get there. Then run a beam search that keeps the \( B \) most promising states at each depth, ranked by that estimate. Both halves are pure PyTorch tensor operations, so the entire beam (up to \( B = 2^{20} \) states) is scored in parallel on one GPU.

The training signal is free: generate random walks from the solved state and label each visited state with the walk length. No solved examples, no human heuristics, no domain knowledge — hence zero-knowledge.

Why one configuration covers every puzzle#

A puzzle enters the pipeline as nothing more than:

  • a list of permutations (the generators / legal moves),
  • a target state vector,
  • optionally a set of scrambles to evaluate on.

Nothing in the model or the search is puzzle-aware. The network is a plain MLP over a one-hot encoded state vector, and the search only ever applies permutations and compares states. Consequently the same architecture and the same hyperparameters (hidden sizes hd1/hd2, residual depth nrd, batch size, learning rate) produce the results in the results table for the Rubik’s Cube, the Pancake graph, Klotski and the sliding puzzles alike. The only per-puzzle knob is \( K_{\max} \), the maximum random-walk length used to generate training data, which just needs to exceed the graph’s diameter.

What is in the repository#

PathWhat it is
pathsolver/The library: model, trainer, searcher, DQN refinement, tensor utilities
train.py, test.pyCLI entry points for training and beam-search evaluation
generators/, targets/, datasets/Puzzle definitions, solved states, scrambles
weights/Pretrained checkpoints (3×3×3, 4×4×4, 5×5×5)
export_onnx.py, onnx/, ui/ONNX export and the client-side browser solver
logs/, read-test-logs*.pyEvaluation output and its aggregation scripts

Continue with Research for the method, or jump straight to Usage → Testing to run a solve.