Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ python/maxplus_solvers/*.pdb
# Notebooks
.ipynb_checkpoints/

# Local benchmark output
benchmarks/results/
# Raw benchmark records; the tables beside them are committed
benchmarks/results/*.jsonl
6 changes: 6 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ cargo test -p tiling-search # the search, on random tili
uv run maxplus-solve new5-flat --max-solutions all --validate # run a solver from the command line
uv run maxplus-solve new5 --mode relief --option lookahead=true --option order=random --seed 3
uv run maxplus-solve rat1-flat --solver cp_sat.placements --max-solutions all --option coverage=false # CP-SAT, needs the cp-sat extra
uv run maxplus-bench run benchmarks/manifests/corpus.toml --no-times # every solver on the corpus: the table in benchmarks/results/corpus.md
uv run maxplus-bench run benchmarks/manifests/tolerance.toml # an experiment; records go to benchmarks/results/<name>.jsonl
uv run maxplus-bench proxies --results benchmarks/results/corpus.jsonl # difficulty proxies against what the searches cost
uv run python scripts/import_fixtures.py --source ../tropical-puzzle-lab # regenerate fixtures and keys
uv run python scripts/import_fixtures.py --source ../tropical-puzzle-lab --check # compare, write nothing
```
Expand All @@ -47,6 +50,7 @@ uv run python scripts/import_fixtures.py --source ../tropical-puzzle-lab --check
- `models.py` holds the contracts; `schemas/instance-v1.json` is their JSON form and `tiling-core` mirrors the instance types. Change all three together.
- `sanitize.py` is the only way an answer-bearing puzzle becomes an instance. `io/tropical.py` and `synthetic.py` both go through it.
- `api.py` holds `load_puzzle` and `solve`; `solvers/` holds the registry and one module per solver, prototypes under `solvers/prototypes/`. `docs/solver-contract.md` says what a result claims and `docs/algorithms.md` why each search rule is sound; a solver change updates both.
- `experiments/` runs solvers and reads what they report: `manifest.py` (TOML manifests, in `benchmarks/manifests/`), `benchmark.py` (one JSON line per run), `report.py` (tables), `proxies.py` (difficulty proxies), `plotting.py` (figures, the `analysis` extra) and `cli.py` (`maxplus-bench`). `docs/experiments.md` has the formats and the findings.
- `validation.py` is the completion check, on Shapely (the `validate` extra). Importing the package must not load Shapely; only this module does.
- `benchmarks/fixtures/` and `tests/keys/` are generated by `scripts/import_fixtures.py`. Never edit them by hand: change the importer or the source and regenerate.

Expand Down Expand Up @@ -85,6 +89,8 @@ Rules:
- **The validator is independent of the search.** `validation.py` must not import `_native` or reuse the Rust geometry, so one bug cannot affect both. It follows the browser's completion rules and may only depart from them on the stricter side; the three places it does are listed in its module docstring.
- **Solvers never call the validator.** `api.solve(..., validate=True)` is the only place the two meet, after the search has returned. A search that consulted the validator would be checking its answer with its own oracle.
- **Search rules are switches, and the measurement is the product.** The question is what makes a puzzle hard and what helps, not how fast a solver is. A pruning rule, an ordering or a symmetry reduction added to a solver is an option that can be turned off, is tested not to change what the whole search finds, and gets its row in the ablation table of `docs/algorithms.md`. A rule that costs more than it saves stays, switched off, with its numbers.
- **Experiments are callers.** `experiments/` goes through `api.solve` like any user, and nothing outside it imports it. Only `experiments/plotting.py` imports matplotlib; running a manifest needs no plotting stack.
- **A committed table has no times.** `benchmarks/results/*.md` are written with `--no-times`: statuses and counts, which a deterministic solver reproduces exactly and a test compares. Times, CP-SAT's own counts and the `.jsonl` records belong to a machine and are not committed. When a solver change moves a count, regenerate the table with the command and say why in the commit.
- **Slow tests still run.** The `slow` marker is for deselecting locally (`-m "not slow"`); CI runs everything.
- **Completeness and uniqueness are explicit claims.** A result says whether the search was exhaustive and over which candidate set. "No solution found" and CP-SAT `INFEASIBLE` are relative to the candidates generated unless completeness is proven.
- **Layering is one-way:** core ← geometry ← search ← py. Python reaches Rust only through `_native`.
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Python owns orchestration and analysis. Rust owns the geometry and the search.

## Status

**Contracts and fixtures.** The instance format, the sanitizing importer and the benchmark corpus exist: 16 puzzles from Tropical Puzzle Lab and 4 synthetic ones with known solution counts, each with an answer key that only tests read. An independent validator checks an assembly against the browser player's completion rules. The Rust geometry kernel (separating-axis depth, convex clipping, containment, edge signatures, roof continuity) is in place and agrees with the validator on random poses of every fixture's pieces. Three solvers exist. `python.contact_dfs` is a Python prototype of the contact search. `rust.contact_dfs` is that search in Rust with roofs, pruning and symmetry handling: it solves all 16 corpus puzzles, runs every search to its end, and returns assemblies that pass the validator. `cp_sat.placements` hands the placements that search reaches to OR-Tools CP-SAT as a plain choice problem, and returns the same assemblies by other means. Each rule of either can be switched off, because the question here is what makes a puzzle hard and what helps, not how fast one solver is; [docs/algorithms.md](docs/algorithms.md) has the measurements. The work is laid out in [docs/roadmap.md](docs/roadmap.md), and the design in [docs/architecture.md](docs/architecture.md).
**Contracts and fixtures.** The instance format, the sanitizing importer and the benchmark corpus exist: 16 puzzles from Tropical Puzzle Lab and 4 synthetic ones with known solution counts, each with an answer key that only tests read. An independent validator checks an assembly against the browser player's completion rules. The Rust geometry kernel (separating-axis depth, convex clipping, containment, edge signatures, roof continuity) is in place and agrees with the validator on random poses of every fixture's pieces. Three solvers exist. `python.contact_dfs` is a Python prototype of the contact search. `rust.contact_dfs` is that search in Rust with roofs, pruning and symmetry handling: it solves all 16 corpus puzzles, runs every search to its end, and returns assemblies that pass the validator. `cp_sat.placements` hands the placements that search reaches to OR-Tools CP-SAT as a plain choice problem, and returns the same assemblies by other means. `maxplus-bench` runs experiment manifests over the corpus and writes the results table; [docs/experiments.md](docs/experiments.md) has what the first experiments found about tolerance, heuristics and difficulty proxies. Each rule of either can be switched off, because the question here is what makes a puzzle hard and what helps, not how fast one solver is; [docs/algorithms.md](docs/algorithms.md) has the measurements. The work is laid out in [docs/roadmap.md](docs/roadmap.md), and the design in [docs/architecture.md](docs/architecture.md).

```python
from maxplus_solvers import load_puzzle
Expand Down Expand Up @@ -73,13 +73,14 @@ crates/
python/maxplus_solvers/ the Python package; `_native` is the Rust extension
schemas/ versioned exchange formats (`instance-v1.json`)
benchmarks/fixtures/ sanitized puzzle instances, generated
benchmarks/manifests/ experiments: which fixtures, solvers and settings to run
benchmarks/results/ result tables, generated by `maxplus-bench`
notebooks/ a first look at results, with figures
scripts/ `import_fixtures.py` regenerates fixtures and answer keys
tests/ pytest suites: unit, property, corpus, architecture; answer keys in `tests/keys/`
docs/ architecture, roadmap, the solver contract and the algorithms
docs/ architecture, roadmap, the solver contract, the algorithms and the experiments
```

Planned, added by the roadmap phase that needs them: benchmark manifests, `notebooks/`.

## Relation to Tropical Puzzle Lab

Tropical Puzzle Lab remains the authority for constructing puzzles. This repository consumes its published `puzzle.json` format and turns it into sanitized solver instances: no reference poses, no construction metadata, pieces rotated and shuffled so that nothing about the stored form hints at the answer.
Expand Down
135 changes: 119 additions & 16 deletions benchmarks/fixtures/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,118 +5,221 @@
"commit": "9f9ed10715042c9472a91dd849fde979f048cba0"
},
"sanitizerVersion": 1,
"sourceDifficulty": {
"method": "leinster-cobbold-intrinsic-volumes",
"u": 10.0,
"q": 2.0,
"direction": "lower-diversity-is-harder",
"thresholds": [0.25, 0.3, 0.45, 0.62]
},
"fixtures": [
{
"id": "new1",
"kind": "corpus",
"regime": "relief",
"pieceCount": 16,
"instanceHash": "316f47096c88b5d96a5ebd517f536a39fea14f5b8991126f11abf05a63af91f7"
"instanceHash": "316f47096c88b5d96a5ebd517f536a39fea14f5b8991126f11abf05a63af91f7",
"construction": "new1",
"sourceDifficulty": {
"diversity": 5.446444,
"x": 0.29643,
"rating": 4
}
},
{
"id": "new1-flat",
"kind": "corpus",
"regime": "footprint",
"pieceCount": 16,
"instanceHash": "5cea41e18add833a84afe209351b407bea5c41f3b998c9c76f41b567b6cb66a1"
"instanceHash": "5cea41e18add833a84afe209351b407bea5c41f3b998c9c76f41b567b6cb66a1",
"construction": "new1",
"sourceDifficulty": {
"diversity": 6.426513,
"x": 0.361768,
"rating": 3
}
},
{
"id": "new2",
"kind": "corpus",
"regime": "relief",
"pieceCount": 16,
"instanceHash": "182cebb40e07f854b46e39d819b3b45a54838ff0345e998915a6f3ade2d1ef70"
"instanceHash": "182cebb40e07f854b46e39d819b3b45a54838ff0345e998915a6f3ade2d1ef70",
"construction": "new2",
"sourceDifficulty": {
"diversity": 4.496934,
"x": 0.233129,
"rating": 5
}
},
{
"id": "new2-flat",
"kind": "corpus",
"regime": "footprint",
"pieceCount": 16,
"instanceHash": "59a938c00227006b4c39007dbf87b40dde7fb11b50eb546cd065b9cc4df03785"
"instanceHash": "59a938c00227006b4c39007dbf87b40dde7fb11b50eb546cd065b9cc4df03785",
"construction": "new2",
"sourceDifficulty": {
"diversity": 4.78389,
"x": 0.252259,
"rating": 4
}
},
{
"id": "new3",
"kind": "corpus",
"regime": "relief",
"pieceCount": 9,
"instanceHash": "f323c0f36ee5c67a4ed9909df8647c76b7a8b5daaf1185d58b0cb599d73d4077"
"instanceHash": "f323c0f36ee5c67a4ed9909df8647c76b7a8b5daaf1185d58b0cb599d73d4077",
"construction": "new3",
"sourceDifficulty": {
"diversity": 5.681002,
"x": 0.585125,
"rating": 2
}
},
{
"id": "new3-flat",
"kind": "corpus",
"regime": "footprint",
"pieceCount": 9,
"instanceHash": "3bef95861401962974a94cc7bd3af623140579de81ce8c4a1752d3e88cb8a19b"
"instanceHash": "3bef95861401962974a94cc7bd3af623140579de81ce8c4a1752d3e88cb8a19b",
"construction": "new3",
"sourceDifficulty": {
"diversity": 6.633686,
"x": 0.704211,
"rating": 1
}
},
{
"id": "new4",
"kind": "corpus",
"regime": "relief",
"pieceCount": 9,
"instanceHash": "72113b0654c26918d6d5245a37490c80a627a30303190223603de35003c32498"
"instanceHash": "72113b0654c26918d6d5245a37490c80a627a30303190223603de35003c32498",
"construction": "new4",
"sourceDifficulty": {
"diversity": 3.500216,
"x": 0.312527,
"rating": 3
}
},
{
"id": "new4-flat",
"kind": "corpus",
"regime": "footprint",
"pieceCount": 9,
"instanceHash": "e9b5924cff70660da1d21edfbbfc0afc4379f2c2b70b27c446b9589e8aef3e0b"
"instanceHash": "e9b5924cff70660da1d21edfbbfc0afc4379f2c2b70b27c446b9589e8aef3e0b",
"construction": "new4",
"sourceDifficulty": {
"diversity": 3.939849,
"x": 0.367481,
"rating": 3
}
},
{
"id": "new5",
"kind": "corpus",
"regime": "relief",
"pieceCount": 6,
"instanceHash": "dadb5297b3ba835bc2da28201a5430cc796afbe59dac4474a0f90f2c0fe597ac"
"instanceHash": "dadb5297b3ba835bc2da28201a5430cc796afbe59dac4474a0f90f2c0fe597ac",
"construction": "new5",
"sourceDifficulty": {
"diversity": 4.466807,
"x": 0.693361,
"rating": 1
}
},
{
"id": "new5-flat",
"kind": "corpus",
"regime": "footprint",
"pieceCount": 6,
"instanceHash": "2b719a8e0e9e1b04e870a73388b596e5c7b21ed2a983a7363d5deddd31fdf692"
"instanceHash": "2b719a8e0e9e1b04e870a73388b596e5c7b21ed2a983a7363d5deddd31fdf692",
"construction": "new5",
"sourceDifficulty": {
"diversity": 4.186563,
"x": 0.637313,
"rating": 1
}
},
{
"id": "rat1",
"kind": "corpus",
"regime": "relief",
"pieceCount": 11,
"instanceHash": "3b8ac23d1a3395c8b30313ea53253973ec1e515a9dfae59b1eb7702f5546b41d"
"instanceHash": "3b8ac23d1a3395c8b30313ea53253973ec1e515a9dfae59b1eb7702f5546b41d",
"construction": "rat1",
"sourceDifficulty": {
"diversity": 4.891978,
"x": 0.389198,
"rating": 3
}
},
{
"id": "rat1-flat",
"kind": "corpus",
"regime": "footprint",
"pieceCount": 11,
"instanceHash": "ce4e5d5431c8a8daa8bd2ff3dce519e0ba669b9507868ace5376295a495c7577"
"instanceHash": "ce4e5d5431c8a8daa8bd2ff3dce519e0ba669b9507868ace5376295a495c7577",
"construction": "rat1",
"sourceDifficulty": {
"diversity": 4.538006,
"x": 0.353801,
"rating": 3
}
},
{
"id": "rat2",
"kind": "corpus",
"regime": "relief",
"pieceCount": 20,
"instanceHash": "ea656bb60309a5582eecf701870916707c8ee154182fb232845c4242e08e0ddb"
"instanceHash": "ea656bb60309a5582eecf701870916707c8ee154182fb232845c4242e08e0ddb",
"construction": "rat2",
"sourceDifficulty": {
"diversity": 5.709562,
"x": 0.247872,
"rating": 5
}
},
{
"id": "rat2-flat",
"kind": "corpus",
"regime": "footprint",
"pieceCount": 20,
"instanceHash": "dbac49368deabed47b3a50c6ed255c12dec8fe5f6442c36d25794a49114033d0"
"instanceHash": "dbac49368deabed47b3a50c6ed255c12dec8fe5f6442c36d25794a49114033d0",
"construction": "rat2",
"sourceDifficulty": {
"diversity": 6.063062,
"x": 0.266477,
"rating": 4
}
},
{
"id": "rev2",
"kind": "corpus",
"regime": "relief",
"pieceCount": 9,
"instanceHash": "bcd0168ea567cf80cdda0ffeef4fbae9a35e7db78336a6cdebe69edaadb486c5"
"instanceHash": "bcd0168ea567cf80cdda0ffeef4fbae9a35e7db78336a6cdebe69edaadb486c5",
"construction": "rev2",
"sourceDifficulty": {
"diversity": 5.09878,
"x": 0.512348,
"rating": 2
}
},
{
"id": "rev2-flat",
"kind": "corpus",
"regime": "footprint",
"pieceCount": 9,
"instanceHash": "2acb913456ef45663e8622a80085cd69b1d99b12bf3d4f5cd530881350576608"
"instanceHash": "2acb913456ef45663e8622a80085cd69b1d99b12bf3d4f5cd530881350576608",
"construction": "rev2",
"sourceDifficulty": {
"diversity": 4.482502,
"x": 0.435313,
"rating": 3
}
},
{
"id": "syn-four-squares",
Expand Down
29 changes: 29 additions & 0 deletions benchmarks/manifests/corpus.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name = "corpus"
description = """
Every registered solver on the whole corpus, each search run to its end where it can be.
`maxplus-bench run benchmarks/manifests/corpus.toml --no-times` reproduces
benchmarks/results/corpus.md; a test holds the two together.
"""
fixtures = ["corpus"]

# The Rust contact search, each puzzle in its own regime.
[[runs]]
solver = "rust.contact_dfs"

# CP-SAT choosing among the placements that search reaches.
[[runs]]
solver = "cp_sat.placements"

# The Python prototype knows footprints only, and counts every orientation of the tray.
# It is given a node limit, not a time limit, so that where it stops does not depend on
# the machine: the three largest puzzles are beyond it.
[[runs]]
solver = "python.contact_dfs"
mode = "footprint"
fixtures = [
"new1-flat", "new2-flat", "new3-flat", "new4-flat",
"new5-flat", "rat1-flat", "rat2-flat", "rev2-flat",
]

[runs.options]
node_limit = 50000
39 changes: 39 additions & 0 deletions benchmarks/manifests/factorial.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name = "factorial"
description = """
Flat against relief x tolerance x search heuristic x puzzle family, on rust.contact_dfs.
Every corpus puzzle is run in its own regime, so each construction appears with roofs and
without. Three blocks: whole searches (how many assemblies, and the cost of showing there are
no more), first solutions under the two fixed candidate orders, and first solutions under
random orders. Searches are stopped after 30 s; a stopped search is a result too.
"""
fixtures = ["corpus"]

# Whole searches: uniqueness and ambiguity, and what looking ahead does to the whole tree.
[[runs]]
solver = "rust.contact_dfs"
time_limit_s = 30.0
contact_scale = [1.0, 1000.0, 6000.0]

[runs.options]
lookahead = [false, true]

# First solutions under the fixed orders.
[[runs]]
solver = "rust.contact_dfs"
max_solutions = 1
time_limit_s = 30.0
contact_scale = [1.0, 1000.0, 6000.0]

[runs.options]
order = ["matched-edges", "generated"]
lookahead = [false, true]

# First solutions under random orders: how much of the cost is luck.
[[runs]]
solver = "rust.contact_dfs"
max_solutions = 1
time_limit_s = 30.0
seeds = [0, 1, 2, 3, 4]

[runs.options]
order = "random"
13 changes: 13 additions & 0 deletions benchmarks/manifests/smoke.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name = "smoke"
description = "The smallest corpus puzzle and its flat twin, on every solver: a quick check that the runner works."
fixtures = ["new5", "new5-flat"]

[[runs]]
solver = "rust.contact_dfs"

[[runs]]
solver = "cp_sat.placements"

[[runs]]
solver = "python.contact_dfs"
mode = "footprint"
Loading