Skip to content

Commit f75a28c

Browse files
GiggleLiuclaude
andauthored
Finalize structural example database (#647)
* save * docs: add variant default resolution design * save * docs: refine CLI path behavior in variant plan * refactor(example-db): make rule builders canonical Remove the legacy exporter bridge (LegacyRuleEntry, legacy_rule! macro, LEGACY_RULES, temp-dir helpers, env-var guards, stdout silencing, and build_legacy_rule) from src/example_db/mod.rs. The in-memory builders in rule_builders.rs are now the only rule source with no filesystem round-trip. Add crate-level integration tests proving canonical rule examples carry full problem JSON (MVC→MIS graph fields, SAT→KColoring clauses/graph). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * test(cli): round-trip canonical examples through solve Add end-to-end tests proving that `pred create --example` output can be fed directly to `pred solve --solver brute-force` for both model examples (MIS/SimpleGraph/i32) and rule examples (MVC→MIS). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat(example-db): finalize structural example database Add structural invariant tests: - unique keys for both rule and model databases - count assertions (42 rules, 28 models) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * update plan * docs: add variant implementation plan * test: add failing tests for VariantSpec, default_variant_for, and export normalization Add stub types and methods with failing tests that establish the contract for the variant default resolution feature: - VariantSpec type in src/variant.rs with try_from_pairs, normalize (no-op), and is_default (always false) stubs - ReductionGraph::default_variant_for stub (always returns None) - 13 new tests: 8 pass (basic construction), 5 fail (normalization, defaults) - Format fixes from cargo fmt Failing tests (to be made green in Tasks 2-3): - variant_spec_normalizes_empty_graph_to_simple_graph - variant_spec_is_default_for_default_values - default_variant_for_mis_uses_declared_default - default_variant_for_sat_returns_empty - export_variant_to_map_normalizes_empty_graph Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat: add explicit variant defaults Implement `default` metadata in `declare_variants!` macro and `VariantSpec`: - Extend `declare_variants!` parsing to accept optional `default` keyword - Add `is_default: bool` to `VariantEntry` for runtime tracking - Implement backwards-compatible default resolution: if no `default` marker is present, the first entry is implicitly the default - Reject multiple `default` markers for the same problem at compile time - Implement `VariantSpec::normalize()` to fill empty graph with "SimpleGraph" - Implement `VariantSpec::is_default()` to detect default dimension values - Add `try_from_map`, `into_map`, `update_dimension` to `VariantSpec` - Populate `default_variants` in `ReductionGraph::new()` from inventory - Implement `ReductionGraph::default_variant_for()` using stored defaults - Normalize empty graph values in `export::variant_to_map()` Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat: mark default problem variants Add explicit `default` keyword to every `declare_variants!` block across all 38 model files, following the selection rules: - Graph families: prefer SimpleGraph - Weighted/unweighted: prefer One (unweighted) when available - K-families: prefer KN as generic default - Integer-vs-float without One: prefer integer variant - Single-variant problems: mark the only variant Add regression tests for MinimumVertexCover, QUBO, and KSatisfiability default variant resolution. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat: unify CLI problem resolution with exact-node semantics Switch CLI commands to use declared default variants for bare problem names instead of searching across all variants. Add capped multi-path support (--max-paths flag) to prevent unbounded enumeration. Key changes: - Add parse_problem_type() for type-level show command (rejects slashes) - Add resolve_problem_ref() shared resolver using declared defaults - Show command now marks default variant with (default) annotation - Path/neighbors/reduce commands use exact default variant nodes - Add find_paths_up_to() capped path enumeration to ReductionGraph - Multi-path JSON output uses structured envelope with truncation metadata - Directory output includes manifest.json Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * docs: align MCP tools and CLI docs with exact-node variant semantics Update MCP server tools to use the same resolver semantics as CLI: - show_problem_inner: use parse_problem_type (rejects slash specs), add is_default field to variant JSON output - neighbors_inner: use resolve_problem_ref for exact default resolution - find_path_inner: use resolve_problem_ref, add max_paths param, use find_paths_up_to with truncation detection, return structured envelope {paths, truncated, returned, max_paths} for all=true - create_problem_inner: use resolve_problem_ref for name resolution - reduce_inner: use resolve_problem_ref for target resolution Add new MCP tests: slash spec rejection, is_default marking, structured envelope validation. Update docs with type-level show semantics, --max-paths flag, and default variant resolution note. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: require exact source+target variant match in find_best_entry Remove the unsafe name-only fallback from find_best_entry() that could return overhead for the wrong variant. Now both source and target variants must match exactly. Update lookup_overhead() to pass the target variant through instead of ignoring it. Fix direct_overhead() in rule_builders to fall back to default variants when a concrete variant (e.g. K3) has no registered reduction entry. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * style: fix formatting in MCP tools and tests Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * grand clean up * feat(registry): add core dynamic problem types Add DynProblem trait and LoadedDynProblem wrapper for type-erased problem dispatch via the registry. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat(macros): add transitional solver-kind dispatch generation Extend declare_variants! to accept optional `opt` and `sat` markers that generate factory, serialize_fn, and solve_fn dispatch metadata in VariantEntry. Legacy entries without markers emit None for these fields during the transition period. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat(registry): register load serialize and solve dispatch metadata Annotate all declare_variants! blocks with opt/sat solver kind markers. Add load_dyn, serialize_any, and find_variant_entry registry helpers with integration tests for exact-match lookup, round-trip serialization, and brute-force solving. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * refactor(registry): require solver kind in variant registrations Remove transitional Option wrappers from VariantEntry dispatch fields. The parser now requires opt or sat markers — legacy entries without solver kind are rejected at compile time. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * refactor(cli): use registry-backed dynamic problem dispatch Replace CLI-local DynProblem trait, match tables, and helper functions with the core registry's load_dyn and serialize_any. Add SAT solve regression test. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * test(dispatch): finalize registry-backed dispatch verification Add SolveFn type alias to fix clippy::type_complexity warnings. Format files to pass fmt check. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * update * feat(registry): add problem type catalog and typed refs Introduce ProblemType catalog with alias lookup, VariantDimension for schema-validated variant dimensions, and typed ProblemRef for catalog- backed variant resolution. Extend ProblemSchemaEntry with display_name, aliases, and dimensions fields (populated for MIS, placeholders for rest). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * refactor(cli): resolve problem specs through the catalog Add catalog-backed alias resolution (tries ProblemSchemaEntry aliases first, falls back to legacy ALIASES table). Add resolve_catalog_problem_ref for schema-only validation without graph reachability. Update shell completion to include catalog aliases. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat(models): declare catalog metadata alongside schemas Populate display_name, aliases, and dimensions for all 38 problem models. Add invariant tests: display_name non-empty, aliases globally unique, dimension defaults valid, catalog covers all declared variants, and catalog defaults match reduction graph defaults. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * update * feat(rules): add stable auto-generated rule IDs to reduction entries Each ReductionEntry now has a unique rule_id auto-generated from source/target type names and generic arguments. The proc macro computes IDs at compile time (e.g., minimumvertexcover_to_maximumindependentset_simplegraph_i32). Optional explicit id = "..." attribute supported for overrides. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * save * refactor(example-db): finalize per-module specs with invariant tests Add uniqueness tests for model and rule example spec IDs. Clean up remaining rule_builders.rs to delegate to per-module specs. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat(core): add Problem::problem_type() catalog bridge method Adds a default method on the Problem trait that bridges to the catalog registry, giving typed access to display names, aliases, and variant dimensions. Problem::NAME is preserved as the zero-cost compile-time source of truth; the bridge adds runtime catalog access. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: remove unused imports and suppress dead_code warnings in specs The `id` field on ModelExampleSpec/RuleExampleSpec is only read in test code, so allow(dead_code) is appropriate. Also drops unused Minimize and MinimizeSteps imports. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * update * update * update * test: improve coverage for export, variant, analysis, and registry - Add tests for ProblemSide::from_problem, ModelExample::from_problem, default_expr, examples_output_dir env override, write_rule/model_example_to - Add error-path tests for find_rule/model_example (not-found) - Add VariantSpec coverage: try_from_map, into_map, update_dimension, normalize without graph key, is_default edge cases - Add analysis tests: missing_proof_chains filter, connectivity components, isolated problem variant info - Fix clippy type_complexity warning in registry test (extract EndpointKey alias) - Remove deprecated id attribute from reduction macro Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * chore: remove ephemeral plan files from PR Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * update * docs: update CLAUDE.md model lists and trait hierarchy - Add 10 missing graph models (GraphPartitioning, HamiltonianPath, IsomorphicSpanningTree, MinFeedbackArcSet, MinFeedbackVertexSet, MinSumMulticenter, OptimalLinearArrangement, PartitionIntoTriangles, RuralPostman, SubgraphIsomorphism) - Add 5 missing misc models (FlowShopScheduling, Knapsack, LongestCommonSubsequence, ShortestCommonSupersequence, SubsetSum) - Add problem_type() to Problem trait hierarchy - Update Problem Names to include all current types - Add specs.rs to example_db documentation Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * docs: replace hardcoded model/rule lists with CLI commands in CLAUDE.md Point agents to `pred list` and `pred show <name>` instead of maintaining exhaustive lists that go stale. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * feat(cli): add `pred list --rules` to enumerate all reduction rules Shows source, target, and overhead for every registered primitive reduction. Supports --json output. Replaces the need to maintain hardcoded rule lists in documentation. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * feat(cli): add complexity to `pred list`, improve `--rules` format, upgrade rmcp to 1.2 - `pred list`: add Complexity column showing best-known complexity (Big O) for the default variant of each problem type - `pred list --rules`: show overhead fields on separate continuation lines instead of a single wide column; JSON overhead is now an array - Upgrade rmcp from 0.16 to 1.2: migrate MCP server and prompts to builder patterns required by #[non_exhaustive] structs - Add merge conflict guidance for skill changes to review-pipeline skill Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix(cli): improve `pred list` and `pred list --rules` table formatting - `pred list`: expand rows per variant (show variant slash notation, complexity, and default marker *) instead of aggregating per problem - `pred list --rules`: fix ANSI padding (pad plain text first, then colorize) so columns align correctly; multi-field overhead uses continuation lines Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * refactor: remove 3SAT alias, use KSAT/K3 instead 3SAT was a type-level alias for KSatisfiability which was confusing because it displayed next to the KN default variant. Replace all references with KSAT (the type alias) and KSAT/K3 (the explicit variant). Remove the special-case resolution code. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * perf: remove mcp from default CLI features for faster dev builds MCP (rmcp + tokio + schemars + tracing) adds ~14s to clean builds. Move it out of default features so `cargo build` and `make cli` are fast. MCP is still available via `--features mcp` or `--features all`. CI already uses explicit `--features ilp-highs` (no mcp). MCP tests use `make mcp-test` which passes `--features mcp`. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * feat: add `make mcp` target for CLI with MCP support `make cli` stays fast (no MCP). Use `make mcp` to build with MCP server support when needed. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: remove unused mut from variant_values Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * revert: restore single-line overhead in `pred list --rules` Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix cli * fix tests --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 60ec662 commit f75a28c

189 files changed

Lines changed: 7433 additions & 7529 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.claude/CLAUDE.md

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ make diagrams # Generate SVG diagrams from Typst (light + dark)
4444
make examples # Generate example JSON for paper
4545
make compare # Generate and compare Rust mapping exports
4646
make jl-testdata # Regenerate Julia parity test data (requires julia)
47-
make cli # Build the pred CLI tool (release mode)
47+
make cli # Build the pred CLI tool (without MCP, fast)
48+
make mcp # Build the pred CLI tool with MCP server support
4849
make cli-demo # Run closed-loop CLI demo (exercises all commands)
4950
make mcp-test # Run MCP server tests (unit + integration)
5051
make run-plan # Execute a plan with Claude autorun
@@ -64,11 +65,12 @@ make release V=x.y.z # Tag and push a new release (CI publishes to crates.io)
6465

6566
### Core Modules
6667
- `src/models/` - Problem implementations organized by input structure:
67-
- `graph/` - Problems on graphs (MIS, MaxClique, MaxCut, MinVC, MinDS, MaxMatching, MaximalIS, KColoring, TSP, SpinGlass, BicliqueCover)
68-
- `formula/` - Logical formulas and circuits (SAT, k-SAT, CircuitSAT)
69-
- `set/` - Set systems (MinSetCovering, MaxSetPacking)
70-
- `algebraic/` - Matrices, linear systems, lattices (QUBO, ILP, CVP, BMF)
71-
- `misc/` - Unique input structures (BinPacking, PaintShop, Factoring)
68+
- `graph/` - Graph-input problems
69+
- `formula/` - Boolean formulas and circuits
70+
- `set/` - Set systems (universe + subsets)
71+
- `algebraic/` - Matrices, linear systems, lattices
72+
- `misc/` - Unique input structures
73+
- Run `pred list` for the full catalog of problems, variants, and reductions; `pred show <name>` for details on a specific problem
7274
- `src/rules/` - Reduction rules + inventory registration
7375
- `src/solvers/` - BruteForce solver, ILP solver (feature-gated)
7476
- `src/traits.rs` - `Problem`, `OptimizationProblem`, `SatisfactionProblem` traits
@@ -91,7 +93,8 @@ Problem (core trait — all problems must implement)
9193
├── fn dims(&self) -> Vec<usize> // config space: [2, 2, 2] for 3 binary variables
9294
├── fn evaluate(&self, config) -> Metric
9395
├── fn variant() -> Vec<(&str, &str)> // e.g., [("graph","SimpleGraph"), ("weight","i32")]
94-
└── fn num_variables(&self) -> usize // default: dims().len()
96+
├── fn num_variables(&self) -> usize // default: dims().len()
97+
└── fn problem_type() -> ProblemType // catalog bridge: registry lookup by NAME
9598
9699
OptimizationProblem : Problem<Metric = SolutionSize<Self::Value>> (extension for optimization)
97100
@@ -111,7 +114,7 @@ enum Direction { Maximize, Minimize }
111114

112115
### Key Patterns
113116
- `variant_params!` macro implements `Problem::variant()` — e.g., `crate::variant_params![G, W]` for two type params, `crate::variant_params![]` for none (see `src/variant.rs`)
114-
- `declare_variants!` proc macro registers concrete type instantiations with best-known complexity must appear in every model file (see `src/models/graph/maximum_independent_set.rs`). Variable names in complexity strings are validated at compile time against actual getter methods.
117+
- `declare_variants!` proc macro registers concrete type instantiations with best-known complexity and registry-backed dynamic dispatch metadata — every entry must specify `opt` or `sat`, and one entry per problem may be marked `default` (see `src/models/graph/maximum_independent_set.rs`). Variable names in complexity strings are validated at compile time against actual getter methods.
115118
- Problems parameterized by graph type `G` and optionally weight type `W` (problem-dependent)
116119
- `ReductionResult` provides `target_problem()` and `extract_solution()`
117120
- `Solver::find_best()``Option<Vec<usize>>` for optimization problems; `Solver::find_satisfying()``Option<Vec<usize>>` for `Metric = bool`
@@ -142,25 +145,31 @@ impl ReduceTo<Target> for Source { ... }
142145
- `Expr::parse()` provides runtime parsing for cross-check tests that compare compiled vs symbolic evaluation
143146

144147
### Problem Names
145-
Problem types use explicit optimization prefixes:
146-
- `MaximumIndependentSet`, `MaximumClique`, `MaximumMatching`, `MaximumSetPacking`
147-
- `MinimumVertexCover`, `MinimumDominatingSet`, `MinimumSetCovering`
148-
- No prefix: `MaxCut`, `SpinGlass`, `QUBO`, `ILP`, `Satisfiability`, `KSatisfiability`, `CircuitSAT`, `Factoring`, `MaximalIS`, `PaintShop`, `BicliqueCover`, `BMF`, `KColoring`, `TravelingSalesman`
148+
Problem types use explicit optimization prefixes (`Maximum...`, `Minimum...`) or no prefix. Run `pred list` for the full catalog. Common aliases (e.g., `MIS``MaximumIndependentSet`, `MVC``MinimumVertexCover`) are shown in the `Aliases` column.
149149

150-
### Problem Variant IDs
150+
### Problem Variants
151151
Reduction graph nodes use variant key-value pairs from `Problem::variant()`:
152152
- Base: `MaximumIndependentSet` (empty variant = defaults)
153153
- Graph variant: `MaximumIndependentSet {graph: "KingsSubgraph", weight: "One"}`
154154
- Weight variant: `MaximumIndependentSet {graph: "SimpleGraph", weight: "f64"}`
155155
- Default variant ranking: `SimpleGraph`, `One`, `KN` are considered default values; variants with the most default values sort first
156156
- Nodes come exclusively from `#[reduction]` registrations; natural edges between same-name variants are inferred from the graph/weight subtype partial order
157+
- Each primitive reduction is determined by the exact `(source_variant, target_variant)` endpoint pair
158+
- `#[reduction]` accepts only `overhead = { ... }`
159+
160+
### Extension Points
161+
- New models register dynamic load/serialize/brute-force dispatch through `declare_variants!` in the model file, not by adding manual match arms in the CLI
162+
- Exact registry dispatch lives in `src/registry/`; alias resolution and partial/default variant resolution live in `problemreductions-cli/src/problem_name.rs`
163+
- `pred create` UX lives in `problemreductions-cli/src/commands/create.rs`
164+
- Canonical paper and CLI examples live in `src/example_db/model_builders.rs` and `src/example_db/rule_builders.rs`
157165

158166
## Conventions
159167

160168
### File Naming
161169
- Reduction files: `src/rules/<source>_<target>.rs` (e.g., `maximumindependentset_qubo.rs`)
162170
- Model files: `src/models/<category>/<name>.rs` — category is by input structure: `graph/` (graph input), `formula/` (boolean formula/circuit), `set/` (universe + subsets), `algebraic/` (matrix/linear system/lattice), `misc/` (other)
163-
- Example files: `examples/reduction_<source>_to_<target>.rs` (must have `pub fn run()` + `fn main() { run() }`)
171+
- Canonical examples: builder functions in `src/example_db/rule_builders.rs` and `src/example_db/model_builders.rs`
172+
- Example binaries in `examples/`: utility/export tools and pedagogical demos only (not per-reduction files)
164173
- Test naming: `test_<source>_to_<target>_closed_loop`
165174

166175
### Paper (docs/paper/reductions.typ)
@@ -194,14 +203,15 @@ See Key Patterns above for solver API signatures. Follow the reference files for
194203

195204
### File Organization
196205

197-
Unit tests in `src/unit_tests/` linked via `#[path]` (see Core Modules above). Integration tests in `tests/suites/`, consolidated through `tests/main.rs`. Example tests in `tests/suites/examples.rs` using `include!` for direct invocation.
206+
Unit tests in `src/unit_tests/` linked via `#[path]` (see Core Modules above). Integration tests in `tests/suites/`, consolidated through `tests/main.rs`. Canonical example-db coverage lives in `src/unit_tests/example_db.rs`.
198207

199208
## Documentation Locations
200209
- `README.md` — Project overview and quickstart
201210
- `.claude/` — Claude Code instructions and skills
202211
- `docs/book/` — mdBook user documentation (built with `make doc`)
203212
- `docs/paper/reductions.typ` — Typst paper with problem definitions and reduction theorems
204-
- `examples/` — Reduction example code (also used in paper and tests)
213+
- `src/example_db/` — Canonical model/rule examples: `model_builders.rs`, `rule_builders.rs` (in-memory builders), `specs.rs` (per-module invariant specs), consumed by `pred create --example` and paper exports
214+
- `examples/` — Export utilities, graph-analysis helpers, and pedagogical demos
205215

206216
## Documentation Requirements
207217

@@ -254,3 +264,4 @@ Overhead expressions describe how target problem size relates to source problem
254264
2. Check that each field (e.g., `num_vertices`, `num_edges`, `num_sets`) matches the constructed target problem
255265
3. Watch for common errors: universe elements mismatch (edge indices vs vertex indices), worst-case edge counts in intersection graphs (quadratic, not linear), constant factors in circuit constructions
256266
4. Test with concrete small instances: construct a source problem, run the reduction, and compare target sizes against the formula
267+
5. Ensure there is only one primitive reduction registration for each exact source/target variant pair; wrap shared helpers instead of registering duplicate endpoints

.claude/skills/add-model/SKILL.md

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@ Read these first to understand the patterns:
3636
- **Satisfaction problem:** `src/models/formula/sat.rs`
3737
- **Model tests:** `src/unit_tests/models/graph/maximum_independent_set.rs`
3838
- **Trait definitions:** `src/traits.rs` (`Problem`, `OptimizationProblem`, `SatisfactionProblem`)
39-
- **CLI dispatch:** `problemreductions-cli/src/dispatch.rs`
39+
- **Registry dispatch boundary:** `src/registry/mod.rs`, `src/registry/variant.rs`
4040
- **CLI aliases:** `problemreductions-cli/src/problem_name.rs`
41+
- **CLI creation:** `problemreductions-cli/src/commands/create.rs`
42+
- **Canonical model examples:** `src/example_db/model_builders.rs`
4143

4244
## Step 1: Determine the category
4345

@@ -92,16 +94,20 @@ Add `declare_variants!` at the bottom of the model file (after the trait impls,
9294

9395
```rust
9496
crate::declare_variants! {
95-
ProblemName<SimpleGraph, i32> => "1.1996^num_vertices",
96-
ProblemName<SimpleGraph, One> => "1.1996^num_vertices",
97+
opt ProblemName<SimpleGraph, i32> => "1.1996^num_vertices",
98+
default opt ProblemName<SimpleGraph, One> => "1.1996^num_vertices",
9799
}
98100
```
99101

102+
- Each entry must include an explicit solver kind:
103+
- `opt` for optimization problems (`BruteForce::find_best`)
104+
- `sat` for satisfaction problems (`BruteForce::find_satisfying`)
105+
- Mark exactly one concrete variant `default` when the problem has multiple registered variants
100106
- The complexity string references the getter method names from Step 1.5 (e.g., `num_vertices`) — variable names are validated at compile time against actual getters, so typos cause compile errors
101107
- One entry per supported `(graph, weight)` combination
102108
- The string is parsed as an `Expr` AST — supports `+`, `-`, `*`, `/`, `^`, `exp()`, `log()`, `sqrt()`
103109
- Use only concrete numeric values (e.g., `"1.1996^num_vertices"`, not `"(2-epsilon)^num_vertices"`)
104-
- A compiled `complexity_eval_fn` is auto-generated alongside the symbolic expression
110+
- A compiled `complexity_eval_fn` plus registry-backed load/serialize/solve dispatch metadata are auto-generated alongside the symbolic expression
105111
- See `src/models/graph/maximum_independent_set.rs` for the reference pattern
106112

107113
## Step 3: Register the model
@@ -112,13 +118,14 @@ Update these files to register the new problem type:
112118
2. `src/models/mod.rs` -- add to the appropriate re-export line
113119
3. `src/lib.rs` or `prelude` -- if the type should be in `prelude::*`, add it there
114120

115-
## Step 4: Register in CLI
121+
## Step 4: Register for CLI discovery
116122

117-
Update the CLI dispatch table so `pred` can load, solve, and serialize the new problem:
123+
The CLI now loads, serializes, and brute-force solves problems through the core registry. Do **not** add manual match arms in `problemreductions-cli/src/dispatch.rs`.
118124

119-
1. **`problemreductions-cli/src/dispatch.rs`:**
120-
- Add a match arm in `load_problem()` -- use `deser_opt::<T>` for optimization or `deser_sat::<T>` for satisfaction
121-
- Add a match arm in `serialize_any_problem()` -- use `try_ser::<T>`
125+
1. **Registry-backed dispatch comes from `declare_variants!`:**
126+
- Make sure every concrete variant you want the CLI to load is listed in `declare_variants!`
127+
- Use the correct `opt`/`sat` marker per entry
128+
- Mark the intended default variant with `default` when applicable
122129

123130
2. **`problemreductions-cli/src/problem_name.rs`:**
124131
- Add a lowercase alias mapping in `resolve_alias()` (e.g., `"newproblem" => "NewProblem".to_string()`)
@@ -139,6 +146,15 @@ Update `problemreductions-cli/src/commands/create.rs` so `pred create <ProblemNa
139146

140147
4. **Schema alignment**: The `ProblemSchemaEntry` fields should list **constructor parameters** (what the user provides), not internal derived fields. For example, if `m` and `n` are derived from a matrix, only list `matrix` and `k` in the schema.
141148

149+
## Step 4.6: Add canonical model example to example_db
150+
151+
Add a builder function in `src/example_db/model_builders.rs` that constructs a small, canonical instance for this model. Register it in `build_model_examples()`.
152+
153+
This example is now the canonical source for:
154+
- `pred create --example <PROBLEM_SPEC>`
155+
- paper/example exports
156+
- example-db invariants tested in `src/unit_tests/example_db.rs`
157+
142158
## Step 5: Write unit tests
143159

144160
Create `src/unit_tests/models/<category>/<name>.rs`:
@@ -233,12 +249,13 @@ If running standalone (not inside `make run-plan`), invoke [review-implementatio
233249
| Missing `#[path]` test link | Add `#[cfg(test)] #[path = "..."] mod tests;` at file bottom |
234250
| Wrong `dims()` | Must match the actual configuration space (e.g., `vec![2; n]` for binary) |
235251
| Not registering in `mod.rs` | Must update both `<category>/mod.rs` and `models/mod.rs` |
236-
| Forgetting `declare_variants!` | Required for variant complexity metadata used by the paper's auto-generated table |
237-
| Forgetting CLI dispatch | Must add match arms in `dispatch.rs` (`load_problem` + `serialize_any_problem`) |
252+
| Forgetting `declare_variants!` | Required for variant complexity metadata and registry-backed load/serialize/solve dispatch |
253+
| Wrong `declare_variants!` syntax | Every entry now needs `opt` or `sat`; one entry per problem may be marked `default` |
238254
| Forgetting CLI alias | Must add lowercase entry in `problem_name.rs` `resolve_alias()` |
239255
| Inventing short aliases | Only use well-established literature abbreviations (MIS, SAT, TSP); do NOT invent new ones |
240256
| Forgetting CLI create | Must add creation handler in `commands/create.rs` and flags in `cli.rs` |
241257
| Missing from CLI help table | Must add entry to "Flags by problem type" table in `cli.rs` `after_help` |
242258
| Schema lists derived fields | Schema should list constructor params, not internal fields (e.g., `matrix, k` not `matrix, m, n, k`) |
259+
| Missing canonical model example | Add a builder in `src/example_db/model_builders.rs` and keep it aligned with paper/example workflows |
243260
| Forgetting trait_consistency | Must add entry in `test_all_problems_implement_trait_correctly` (and `test_direction` for optimization) in `src/unit_tests/trait_consistency.rs` |
244261
| Paper example not tested | Must include `test_<name>_paper_example` that verifies the exact instance, solution, and solution count shown in the paper |

0 commit comments

Comments
 (0)