Skip to content

Commit 0474f09

Browse files
authored
Merge pull request #651 from CodingThrust/fixture-based-example-db
perf: store example DB as fixtures, 850x faster export
2 parents f7a7cac + 9dcd95b commit 0474f09

50 files changed

Lines changed: 1823 additions & 907 deletions

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: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,14 @@ make fmt-check # Check code formatting
4141
make clippy # Run clippy lints
4242
make doc # Build mdBook documentation (includes reduction graph export)
4343
make mdbook # Build and serve mdBook with live reload
44-
make paper # Build Typst paper (runs examples + exports first)
44+
make paper # Build Typst paper from checked-in example fixtures
4545
make coverage # Generate coverage report (>95% required)
4646
make check # Quick pre-commit check (fmt + clippy + test)
4747
make rust-export # Generate Julia parity test data (mapping stages)
4848
make export-schemas # Regenerate problem schemas JSON
4949
make qubo-testdata # Regenerate QUBO ground truth JSON
5050
make clean # Clean build artifacts
5151
make diagrams # Generate SVG diagrams from Typst (light + dark)
52-
make examples # Generate example JSON for paper
5352
make compare # Generate and compare Rust mapping exports
5453
make jl-testdata # Regenerate Julia parity test data (requires julia)
5554
make cli # Build the pred CLI tool (without MCP, fast)

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,18 +155,17 @@ Step-by-step walkthrough with concrete numbers from JSON data. Required steps:
155155
1. Show source instance (dimensions, structure, graph visualization if applicable)
156156
2. Walk through construction with intermediate values
157157
3. Verify a concrete solution end-to-end
158-
4. Solution count: `#src_tgt.solutions.len()` with combinatorial justification
158+
4. Witness semantics: state that the fixture stores one canonical witness; if multiplicity matters mathematically, explain it from the construction rather than from `solutions.len()`
159159

160160
Use `graph-colors`, `g-node()`, `g-edge()` for graph visualization — see reference examples.
161161

162162
### 5d. Build and verify
163163

164164
```bash
165-
make examples # Regenerate example JSON
166165
make paper # Must compile without errors
167166
```
168167

169-
Checklist: notation self-contained, complexity cited, overhead consistent, example uses JSON data (not hardcoded), solution verified end-to-end, solution count stated, paper compiles.
168+
Checklist: notation self-contained, complexity cited, overhead consistent, example uses JSON data (not hardcoded), solution verified end-to-end, witness semantics respected, paper compiles.
170169

171170
## Step 6: Regenerate exports and verify
172171

.claude/skills/final-review/SKILL.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,10 @@ Verify the PR includes all required components. Check:
197197

198198
**Paper-example consistency check (both Model and Rule PRs):**
199199

200-
The paper example must use data from the generated JSON (`docs/paper/examples/generated/`), not hand-written data. To verify:
201-
1. Run `make examples` on the PR branch to regenerate `docs/paper/examples/generated/models.json` and `rules.json`.
202-
2. For **[Rule] PRs**: the paper's `reduction-rule` entry must call `load-example(source, target)` (defined in `reductions.typ`) to load the canonical example from `rules.json`, and derive all concrete values from the loaded data using Typst array operations — no hand-written instance data.
203-
3. For **[Model] PRs**: read the problem's entry in `models.json` and compare its `instance` field against the paper's `problem-def` example. The paper example must use the same instance (allowing 0-indexed JSON vs 1-indexed math notation). If they differ, flag: "Paper example does not match `example_db` canonical instance in `models.json`."
200+
The paper example must use data from the canonical fixture JSON (`src/example_db/fixtures/examples.json`), not hand-written data. To verify:
201+
1. If the PR changes example builders/specs, run `make regenerate-fixtures` on the PR branch.
202+
2. For **[Rule] PRs**: the paper's `reduction-rule` entry must call `load-example(source, target, ...)` (defined in `reductions.typ`) to load the canonical example from `examples.json`, and derive all concrete values from the loaded data using Typst array operations — no hand-written instance data.
203+
3. For **[Model] PRs**: read the problem's entry in `examples.json` under `models` and compare its `instance` field against the paper's `problem-def` example. The paper example must use the same instance (allowing 0-indexed JSON vs 1-indexed math notation). If they differ, flag: "Paper example does not match `example_db` canonical instance in `examples.json`."
204204

205205
**Issue–test round-trip consistency check (both Model and Rule PRs):**
206206

.claude/skills/write-model-in-paper/SKILL.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,16 +126,16 @@ achieves $O^*(2^n)$ @bjorklund2009.
126126

127127
### 3c. Example with Visualization
128128

129-
A concrete small instance that illustrates the problem. **The example must use data from the generated `models.json`**, not an independently invented instance.
129+
A concrete small instance that illustrates the problem. **The example must use data from the checked-in canonical fixture DB**, not an independently invented instance.
130130

131131
#### Sourcing example data
132132

133-
1. Run `make examples` to ensure `docs/paper/examples/generated/models.json` is up to date.
134-
2. Find the problem's entry in `models.json` — it contains the canonical `instance`, `samples`, and `optimal` fields.
133+
1. If you changed example builders/specs, run `make regenerate-fixtures` to refresh `src/example_db/fixtures/examples.json`.
134+
2. Find the problem's entry in `src/example_db/fixtures/examples.json` under `models` — it contains the canonical `instance`, `samples`, and `optimal` fields.
135135
3. Use the values from `instance` in the paper example (translating 0-indexed code values to 1-indexed math notation where conventional, e.g., vertices {0,...,n-1} → {1,...,n}).
136136
4. Use `optimal` configurations to show the solution.
137137

138-
**Do not invent a different instance.** If the canonical example is too large or not pedagogically ideal, fix it in `canonical_model_example_specs()` first, re-run `make examples`, then write the paper entry from the updated JSON.
138+
**Do not invent a different instance.** If the canonical example is too large or not pedagogically ideal, fix it in `canonical_model_example_specs()` first, re-run `make regenerate-fixtures`, then write the paper entry from the updated JSON.
139139

140140
#### Requirements
141141

@@ -147,7 +147,7 @@ A concrete small instance that illustrates the problem. **The example must use d
147147
#### Structure
148148

149149
```typst
150-
*Example.* Consider [instance description with concrete numbers from models.json].
150+
*Example.* Consider [instance description with concrete numbers from `examples.json`].
151151
[Describe the solution and why it's valid/optimal].
152152
153153
#figure({
@@ -185,7 +185,7 @@ make paper
185185
- [ ] **Notation self-contained**: every symbol in `def` is defined before first use
186186
- [ ] **Background present**: historical context, applications, or structural properties
187187
- [ ] **Algorithms cited**: every complexity claim has `@citation` or footnote warning
188-
- [ ] **Example from JSON**: instance data matches `models.json` canonical example (not independently invented)
188+
- [ ] **Example from JSON**: instance data matches `src/example_db/fixtures/examples.json` canonical example (not independently invented)
189189
- [ ] **Evaluation shown**: objective/verifier computed on the example solution
190190
- [ ] **Diagram included**: figure with caption and label for graph/matrix/set visualization
191191
- [ ] **Paper compiles**: `make paper` succeeds without errors

.claude/skills/write-rule-in-paper/SKILL.md

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Full authoring guide for writing a `reduction-rule` entry in `docs/paper/reducti
1818
Before using this skill, ensure:
1919
- The reduction is implemented and tested (`src/rules/<source>_<target>.rs`)
2020
- A canonical example exists in `src/example_db/rule_builders.rs`
21-
- Example JSON is generated (`make examples`)
21+
- If the canonical example changed, fixtures are regenerated (`make regenerate-fixtures`)
2222
- The reduction graph and schemas are up to date (`cargo run --example export_graph && cargo run --example export_schemas`)
2323

2424
## Step 1: Load Example Data
@@ -29,8 +29,8 @@ Before using this skill, ensure:
2929
```
3030

3131
Where:
32-
- `load-example(source, target)` looks up the canonical rule entry from the generated rule database
33-
- The returned record contains `source`, `target`, `overhead`, and `solutions`
32+
- `load-example(source, target, ...)` looks up the canonical rule entry from `src/example_db/fixtures/examples.json`
33+
- The returned record contains `source`, `target`, and `solutions`
3434
- Access fields: `src_tgt.source.instance`, `src_tgt.target.instance`, `src_tgt_sol.source_config`, `src_tgt_sol.target_config`
3535

3636
## Step 2: Write the Theorem Body (Rule Statement)
@@ -158,7 +158,7 @@ Detailed by default. Only use a brief example for trivially obvious reductions (
158158
159159
*Step N -- Verify a solution.* [end-to-end verification]
160160
161-
*Count:* #src_tgt.solutions.len() optimal solutions ...
161+
*Multiplicity:* The fixture stores one canonical witness. If total multiplicity matters, explain it from the construction.
162162
],
163163
)
164164
```
@@ -177,7 +177,7 @@ Each step should:
177177
| First | Show the source instance (dimensions, structure). Include graph visualization if applicable. |
178178
| Middle | Walk through the construction. Show intermediate values. Explicitly quantify overhead. |
179179
| Second-to-last | Verify a concrete solution end-to-end (source config → target config, check validity). |
180-
| Last | Solution count: `#src_tgt.solutions.len()` with brief combinatorial justification. |
180+
| Last | State that the fixture stores one canonical witness; if multiplicity matters, justify it mathematically from the construction. |
181181

182182
### 4d. Graph Visualization (if applicable)
183183

@@ -202,8 +202,8 @@ Each step should:
202202
// Target configuration (e.g., binary encoding)
203203
#src_tgt_sol.target_config.map(str).join(", ")
204204
205-
// Number of optimal solutions
206-
#src_tgt.solutions.len()
205+
// The canonical witness pair
206+
#src_tgt.solutions.at(0)
207207
208208
// Source instance fields
209209
#src_tgt.source.instance.num_vertices
@@ -220,9 +220,6 @@ If this is a new problem not yet in the paper, add to the `display-name` diction
220220
## Step 6: Build and Verify
221221

222222
```bash
223-
# Regenerate example JSON (if not already done)
224-
make examples
225-
226223
# Build the paper
227224
make paper
228225
```
@@ -234,7 +231,7 @@ make paper
234231
- [ ] **Overhead consistent**: prose dimensions match auto-derived overhead from JSON edge data
235232
- [ ] **Example uses JSON data**: concrete values come from `load-example`/`load-results`, not hardcoded
236233
- [ ] **Solution verified**: at least one solution checked end-to-end in the example
237-
- [ ] **Solution count**: `solutions.len()` stated with combinatorial explanation
234+
- [ ] **Witness semantics**: text treats `solutions.at(0)` as the canonical witness; any multiplicity claim is derived mathematically, not from fixture length
238235
- [ ] **Paper compiles**: `make paper` succeeds without errors
239236
- [ ] **Completeness check**: no new warnings about missing edges in the paper
240237

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ claude-output.log
8484
.worktrees/
8585
.worktree/
8686
*.json
87+
!src/example_db/fixtures/*.json
8788
.claude/worktrees/
8889
docs/test-reports/
8990
docs/superpowers/

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ name = "solver_benchmarks"
4646
harness = false
4747

4848
[[example]]
49-
name = "export_examples"
50-
path = "examples/export_examples.rs"
49+
name = "regenerate_fixtures"
50+
path = "examples/regenerate_fixtures.rs"
5151
required-features = ["example-db"]
5252

5353
[profile.release]

Makefile

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Makefile for problemreductions
22

3-
.PHONY: help build test mcp-test fmt clippy doc mdbook paper examples clean coverage rust-export compare qubo-testdata export-schemas release run-plan run-issue run-pipeline run-pipeline-forever run-review run-review-forever board-next board-claim board-ack board-move issue-context issue-guards pr-context pr-wait-ci worktree-issue worktree-pr diagrams jl-testdata cli cli-demo copilot-review
3+
.PHONY: help build test mcp-test fmt clippy doc mdbook paper clean coverage rust-export compare qubo-testdata export-schemas release run-plan run-issue run-pipeline run-pipeline-forever run-review run-review-forever board-next board-claim board-ack board-move issue-context issue-guards pr-context pr-wait-ci worktree-issue worktree-pr diagrams jl-testdata cli cli-demo copilot-review regenerate-fixtures
44

55
RUNNER ?= codex
66
CLAUDE_MODEL ?= opus
@@ -18,13 +18,13 @@ help:
1818
@echo " doc - Build mdBook documentation"
1919
@echo " diagrams - Generate SVG diagrams from Typst (light + dark)"
2020
@echo " mdbook - Build and serve mdBook (with live reload)"
21-
@echo " paper - Build Typst paper (requires typst)"
21+
@echo " paper - Build Typst paper from checked-in fixtures (requires typst)"
2222
@echo " coverage - Generate coverage report (requires cargo-llvm-cov)"
2323
@echo " clean - Clean build artifacts"
2424
@echo " check - Quick check (fmt + clippy + test)"
2525
@echo " rust-export - Generate Rust mapping JSON exports"
2626
@echo " compare - Generate and compare Rust mapping exports"
27-
@echo " examples - Generate example JSON for paper"
27+
@echo " regenerate-fixtures - Recompute example DB fixtures (BruteForce/ILP, slow)"
2828
@echo " export-schemas - Export problem schemas to JSON"
2929
@echo " qubo-testdata - Regenerate QUBO test data (requires uv)"
3030
@echo " jl-testdata - Regenerate Julia parity test data (requires julia)"
@@ -113,20 +113,20 @@ mdbook:
113113
python3 -m http.server 3001 -d book &
114114
@sleep 1 && (command -v xdg-open >/dev/null && xdg-open http://localhost:3001 || open http://localhost:3001)
115115

116-
# Generate all example JSON files for the paper
117-
examples:
118-
cargo run --features "ilp-highs example-db" --example export_examples
119-
cargo run --features ilp-highs --example export_petersen_mapping
116+
# Regenerate example DB fixtures from code (runs BruteForce/ILP — slow)
117+
regenerate-fixtures:
118+
cargo run --release --features "ilp-highs example-db" --example regenerate_fixtures
120119

121120
# Export problem schemas to JSON
122121
export-schemas:
123122
cargo run --example export_schemas
124123

125-
# Build Typst paper (generates examples first)
126-
paper: examples
124+
# Build Typst paper (reads canonical examples directly from fixtures)
125+
paper:
126+
cargo run --example export_petersen_mapping
127127
cargo run --example export_graph
128128
cargo run --example export_schemas
129-
cd docs/paper && typst compile --root .. reductions.typ reductions.pdf
129+
typst compile --root . docs/paper/reductions.typ docs/paper/reductions.pdf
130130

131131
# Generate coverage report (requires: cargo install cargo-llvm-cov)
132132
coverage:

docs/agent-profiles/SKILLS.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# Skills
22

3-
Example generation now goes through the example catalog and dedicated exporter.
3+
Example generation now goes through the example catalog and checked-in fixture DB.
44
When a workflow needs a paper/example instance, prefer the catalog path over ad hoc `examples/reduction_*.rs` binaries:
55

6-
- use `make examples` or `cargo run --features "ilp-highs example-db" --example export_examples`
6+
- use `src/example_db/fixtures/examples.json` directly for paper/example data
7+
- use `make regenerate-fixtures` when canonical examples change
78
- use `pred create --example <PROBLEM_SPEC>` to materialize a canonical model example as normal problem JSON
89
- use `pred create --example <SOURCE_SPEC> --to <TARGET_SPEC>` to materialize a canonical rule example as normal problem JSON
910
- when adding new example coverage, register a catalog entry instead of creating a new standalone reduction example file

0 commit comments

Comments
 (0)