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
9 changes: 7 additions & 2 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ 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 All @@ -25,8 +26,10 @@ cargo fmt --all
cargo clippy --workspace --all-targets -- -D warnings
cargo test --workspace --exclude tiling-py # tiling-py is a cdylib, tested through pytest
cargo test -p tiling-geometry signed_area
cargo test -p tiling-search # the search, on random tilings from tiling-geometry's `testing` feature

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 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 @@ -36,8 +39,8 @@ uv run python scripts/import_fixtures.py --source ../tropical-puzzle-lab --check
## Architecture

- `crates/tiling-core`: domain types. No dependencies on the other crates.
- `crates/tiling-geometry`: convex geometry, contact matching, candidate generation. Depends on core. Primitives take `&[Vec2]`; proptest strategies shared by its tests are in `src/testing.rs`.
- `crates/tiling-search`: custom solvers, one module each. Depends on core and geometry.
- `crates/tiling-geometry`: convex geometry, contact matching, candidate generation, cavities. Depends on core. Primitives take `&[Vec2]`; proptest strategies are in `src/testing.rs`, public behind the `testing` feature so that `tiling-search` can test on the same random tilings.
- `crates/tiling-search`: custom solvers, one module each (`contact_dfs`), and `canonical`, which decides when two assemblies are the same. Depends on core and geometry.
- `crates/tiling-py`: PyO3 bindings, built by maturin as `maxplus_solvers._native`. Converts types and forwards calls; no algorithms.
- `python/maxplus_solvers`: the user-facing package: models, importers, solver adapters, validation, experiments. When a function is added to `_native`, add it to `_native.pyi` too. `_native` takes a polygon as a sequence of pairs, a pose as `(x, y, theta)` and a roof as `(z0, gx, gy)`.
- `models.py` holds the contracts; `schemas/instance-v1.json` is their JSON form and `tiling-core` mirrors the instance types. Change all three together.
Expand Down Expand Up @@ -80,6 +83,8 @@ Rules:
- **Three information regimes stay separate:** footprint (polygons only), relief (polygons and roof planes), tropical-aware (construction data as well). A solver declares which one it uses; results from different regimes are not comparable.
- **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.
- **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`.
- **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.
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 18 additions & 2 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. A first solver exists: `python.contact_dfs`, a Python prototype of the contact search, which solves the 6-, 9- and 11-piece footprint puzzles and returns assemblies that pass the validator. 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. Two 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. Each of its rules 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 All @@ -25,6 +25,22 @@ flat = load_puzzle(
) # the same pieces without roofs
```

Solving, from Python or from the command line:

```python
from maxplus_solvers import SolverConfig, solve

result = solve(puzzle, SolverConfig("rust.contact_dfs", mode="relief", max_solutions=None))
print(result.status, len(result.solutions), result.exhaustive, result.metrics["nodes"])
```

```sh
uv run maxplus-solve new2 --mode relief --max-solutions all --validate
uv run maxplus-solve rat1-flat --max-solutions all --option closure_pruning=false
```

What a result claims, and what it does not, is in [docs/solver-contract.md](docs/solver-contract.md).

With the `validate` extra (Shapely), poses can be checked against the completion rules:

```python
Expand Down Expand Up @@ -59,7 +75,7 @@ schemas/ versioned exchange formats (`instance-v1.json`)
benchmarks/fixtures/ sanitized puzzle instances, generated
scripts/ `import_fixtures.py` regenerates fixtures and answer keys
tests/ pytest suites: unit, property, corpus, architecture; answer keys in `tests/keys/`
docs/ architecture and roadmap
docs/ architecture, roadmap, the solver contract and the algorithms
```

Planned, added by the roadmap phase that needs them: benchmark manifests, `notebooks/`.
Expand Down
5 changes: 5 additions & 0 deletions crates/tiling-geometry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@ rust-version.workspace = true
license.workspace = true
repository.workspace = true

[features]
# Proptest strategies for other crates' tests: random convex polygons and tilings.
testing = ["dep:proptest"]

[dependencies]
tiling-core.workspace = true
proptest = { workspace = true, optional = true }

[dev-dependencies]
proptest.workspace = true
Expand Down
Loading
Loading