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
3 changes: 1 addition & 2 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ uv run pytest # all Python tests
uv run pytest tests/unit/test_native.py::test_version_matches_the_package
uv run pytest tests/corpus # every committed fixture and its answer key
uv run pytest tests/corpus/test_native_agrees_with_validator.py # Rust geometry against the validator
uv run pytest -m "not slow" # without the whole searches that take tens of seconds
uv run pytest -m "not source" # without the tropical-puzzle-lab checkout
HYPOTHESIS_PROFILE=ci uv run pytest # the derandomized, larger property runs CI uses
uv run ruff check && uv run ruff format --check
Expand Down Expand Up @@ -94,7 +93,7 @@ Rules:
- **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.
- **The suite does not run million-node searches.** The footprints in `corpus.EXPENSIVE` (`tests/support/corpus.py`: `cor1-flat`, `new1-flat`, `new2-flat`) are left out of the per-fixture tests, and the table tests reproduce every other row with `maxplus-bench run --only`. Their rows are checked against a search only by running the full command, so a solver change that could move them means running it by hand. There is no `slow` marker; a test that needs one is a test to make smaller.
- **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`.
- **Production solvers cross the Python/Rust boundary once per solve.** Prototypes may call individual geometry primitives; a Rust solver receives the instance and runs to completion. `cp_sat.placements` makes its one call for the list of placements and their conflicts; everything it then needs, down to which placement a tray rotation turns each into, is in that answer.
Expand Down
3 changes: 2 additions & 1 deletion benchmarks/manifests/corpus.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ The two searches that would not end, cor1-flat's, stop at a node limit well abov
any other corpus puzzle needs (new1-flat: 1 064 878), so that where they stop does not
depend on the machine.
`maxplus-bench run benchmarks/manifests/corpus.toml --no-times` reproduces
benchmarks/results/corpus.md; a test holds the two together.
benchmarks/results/corpus.md; a test holds the two together on every fixture but the
expensive footprints (tests/support/corpus.py), whose rows only this command checks.
"""
fixtures = ["corpus"]

Expand Down
4 changes: 3 additions & 1 deletion benchmarks/manifests/edge_to_edge.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ What the edge-to-edge assumption is worth. Every corpus puzzle is searched to it
rust.contact_dfs in its own regime, assuming nothing and assuming that the pieces meet
edge to edge, and under the assumption with each of its two rules on and off.
`maxplus-bench run benchmarks/manifests/edge_to_edge.toml --no-times` reproduces
benchmarks/results/edge_to_edge.md; a test holds the two together. Rows that assume
benchmarks/results/edge_to_edge.md; a test holds the two together on every fixture but
the expensive footprints (tests/support/corpus.py), whose rows only this command
checks. Rows that assume
nothing are the corpus table's, for comparison; rows under the assumption answer a
narrower question and are not comparable with them. As there, a search that assumes
nothing stops at 1 500 000 nodes: only cor1-flat's reaches the limit.
Expand Down
6 changes: 3 additions & 3 deletions docs/experiments.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ uv run maxplus-bench table benchmarks/results/corpus.jsonl # the tab
uv run maxplus-bench proxies --results benchmarks/results/corpus.jsonl # difficulty proxies and rank correlations
```

`run` writes one JSON line per run to `benchmarks/results/<name>.jsonl` (`--out` to choose), prints the table, and with `--table FILE` writes it too. It exits with 1 if any run could not be made. `--no-times` leaves out times and CP-SAT's own counts, which depend on the machine and the OR-Tools build; what is left is reproduced exactly by a deterministic solver.
`run` writes one JSON line per run to `benchmarks/results/<name>.jsonl` (`--out` to choose), prints the table, and with `--table FILE` writes it too. It exits with 1 if any run could not be made. `--no-times` leaves out times and CP-SAT's own counts, which depend on the machine and the OR-Tools build; what is left is reproduced exactly by a deterministic solver. `--only FIXTURE...` runs a manifest on some of its fixtures, every run on them unchanged: its table is the full table's rows for those fixtures.

`benchmarks/results/corpus.md` is the committed table of the corpus manifest: every registered solver on every corpus puzzle it can run. The command above reproduces it, and `tests/corpus/test_benchmark.py` holds that. The `.jsonl` files are not committed.
`benchmarks/results/corpus.md` is the committed table of the corpus manifest: every registered solver on every corpus puzzle it can run. The command above reproduces it. `tests/corpus/test_benchmark.py` reproduces all of it but the rows of the footprints that take a million nodes or more (`cor1-flat`, `new1-flat`, `new2-flat`) and of `rat2-flat`, where CP-SAT takes over a minute: it runs the command `--only` on the rest and compares those rows exactly. The rows it leaves out are checked only by running the full command, about six minutes; the test reads them to hold them to what the documents say of them. The `.jsonl` files are not committed.

Needs the `validate` extra for the validity columns and the `cp-sat` extra for `cp_sat.placements`. A run whose solver cannot be loaded is recorded as an error and the rest go on.

Expand Down Expand Up @@ -252,7 +252,7 @@ Correlations are taken within a regime only. Across both, any number that differ

## Edge to edge

`maxplus-bench run benchmarks/manifests/edge_to_edge.toml --no-times` reproduces `benchmarks/results/edge_to_edge.md`: every corpus puzzle in its own regime, assuming nothing and assuming that the pieces meet edge to edge, with the assumption's two rules crossed. A manifest says `assume = "edge-to-edge"`, or a list with `"none"` to cross it with the other factors; the table then shows an `assumes` column on every row. What the numbers say is in [algorithms.md](algorithms.md#assuming-the-pieces-meet-edge-to-edge): the footprints that took up to a million nodes take 14 to 80, fewer than their relief twins took assuming nothing, and of `rat1-flat`'s 101 assemblies and `rat2-flat`'s 2 only the answer has no T. `cor1` stays hard under it: 967 nodes with its roofs, and 44 539 and 48 assemblies without them, where the search that assumes nothing does not end.
`maxplus-bench run benchmarks/manifests/edge_to_edge.toml --no-times` reproduces `benchmarks/results/edge_to_edge.md` (the test reproduces all but the rows of `cor1-flat`, `new1-flat` and `new2-flat`, as for the corpus table): every corpus puzzle in its own regime, assuming nothing and assuming that the pieces meet edge to edge, with the assumption's two rules crossed. A manifest says `assume = "edge-to-edge"`, or a list with `"none"` to cross it with the other factors; the table then shows an `assumes` column on every row. What the numbers say is in [algorithms.md](algorithms.md#assuming-the-pieces-meet-edge-to-edge): the footprints that took up to a million nodes take 14 to 80, fewer than their relief twins took assuming nothing, and of `rat1-flat`'s 101 assemblies and `rat2-flat`'s 2 only the answer has no T. `cor1` stays hard under it: 967 nodes with its roofs, and 44 539 and 48 assemblies without them, where the search that assumes nothing does not end.

`proxies.static(instance, edge_to_edge=True)` gives the edge-graph proxies under the assumption: mean degree 0.8 to 2.4 on the footprints, against 23 to 84 without it.

Expand Down
8 changes: 8 additions & 0 deletions docs/roadmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,14 @@ Done, with these decisions:
- `cor1` joined the corpus in this phase, re-imported from Tropical Puzzle Lab's main branch, so the corpus is 18 fixtures. `cor1-flat` is the first corpus puzzle whose plain search has not been seen to end. Tests that compare against the end of that search leave it out by name (`support.corpus.UNFINISHED`) and test it apart; the corpus and edge-to-edge manifests stop a search that assumes nothing at 1 500 000 nodes, well above the 1 064 878 of `new1-flat`, so where it stops does not depend on the machine. The exit criteria of phases 5 and 6 cover the corpus minus that one fixture.
- Findings, in [algorithms.md](algorithms.md#assuming-the-pieces-meet-edge-to-edge): the 16-piece footprints drop from a million nodes to about fifty; footprint and relief costs nearly coincide; only the answer of `rat1-flat` and `rat2-flat` is edge to edge.

## Later change to the exit criteria: no million-node searches in the suite

2026-11-15. The `slow` tests, nine whole searches run again and again, had grown to thirteen minutes, too long to be run. The exit criteria of phases 5 to 8 are narrowed rather than run less often:

- `support.corpus.EXPENSIVE` names the footprints whose whole search costs 909 750 nodes or more: `cor1-flat`, `new1-flat` and `new2-flat`. The exit criteria of phases 5 and 8 cover the corpus minus these; phase 6's also leaves out `rat2-flat`, where CP-SAT takes over a minute.
- The exit criterion of phase 7 and the table test of phase 8 run their manifest with `maxplus-bench run --only` on the other fixtures and compare those rows of the committed table exactly. The rows they leave out are read, not reproduced: a test holds them to what the documents claim of them (where `cor1-flat` stops, the margin under the node limit, one assembly where one is claimed).
- What is given up: no automated test searches `new1-flat` and `new2-flat` to the end. Their results stand in the committed tables, checked against a search only when the full command is run by hand. The `slow` marker is gone.

## Backlog

Unordered, to be scheduled once phase 7 shows where the interesting questions are:
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ xfail_strict = true
filterwarnings = ["error"]
markers = [
"source: needs a checkout of tropical-puzzle-lab (skipped locally if absent, required in CI)",
"slow: takes more than a few seconds",
]

[tool.ruff]
Expand Down
10 changes: 9 additions & 1 deletion python/maxplus_solvers/experiments/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from typing import Any

from maxplus_solvers.experiments import benchmark, proxies, report
from maxplus_solvers.experiments.manifest import ManifestError, load
from maxplus_solvers.experiments.manifest import ManifestError, load, restrict
from maxplus_solvers.io.instance import load_instance

DEFAULT_FIXTURES = Path("benchmarks") / "fixtures"
Expand All @@ -38,6 +38,12 @@ def _parser() -> argparse.ArgumentParser:
action="store_true",
help="leave out times and other machine-dependent columns: the reproducible table",
)
run.add_argument(
"--only",
nargs="+",
metavar="FIXTURE",
help="run only these of the manifest's fixtures: the full table's rows for them",
)
run.add_argument("--quiet", action="store_true", help="do not report each run as it ends")

table = commands.add_parser("table", help="print the table of a results file")
Expand Down Expand Up @@ -159,6 +165,8 @@ def main(argv: Sequence[str] | None = None) -> int:
try:
if args.command == "run":
manifest = load(args.manifest)
if args.only is not None:
manifest = restrict(manifest, args.only, benchmark.read_index(args.fixtures))
out = args.out or DEFAULT_RESULTS / f"{manifest.name}.jsonl"
out.parent.mkdir(parents=True, exist_ok=True)
records = benchmark.run(
Expand Down
18 changes: 17 additions & 1 deletion python/maxplus_solvers/experiments/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import itertools
import tomllib
from collections.abc import Iterator, Mapping, Sequence
from dataclasses import dataclass, field
from dataclasses import dataclass, field, replace
from pathlib import Path
from typing import Any

Expand Down Expand Up @@ -232,6 +232,22 @@ def fixture_ids(manifest: Manifest, index: Mapping[str, Any]) -> list[str]:
return [fixture for fixture in known if fixture in wanted]


def restrict(manifest: Manifest, only: Sequence[str], index: Mapping[str, Any]) -> Manifest:
"""The manifest with its fixtures cut down to ``only``, each of which it must name.

Every run on those fixtures is kept as it is, so the table of the
restricted manifest is the full table's rows for those fixtures.
"""
named = fixture_ids(manifest, index)
missing = [fixture for fixture in only if fixture not in named]
if missing:
listed = ", ".join(repr(fixture) for fixture in missing)
raise ManifestError(f"only: {listed} not among the fixtures of manifest {manifest.name!r}")
if not only:
raise ManifestError("only: an empty list leaves nothing to run")
return replace(manifest, fixtures=tuple(only))


def expand(manifest: Manifest, fixtures: Sequence[str]) -> Iterator[Run]:
"""Every run of the manifest, in a fixed order: block, fixture, then the factors."""
for block in manifest.runs:
Expand Down
Loading
Loading