You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: use directed edges instead of bidirectional in reduction graph (#42)
* fix: use directed edges instead of bidirectional in reduction graph
The JSON export used a single edge with `bidirectional: true` for
reversible reductions, but the source/target direction depended on
non-deterministic inventory iteration order. This broke the Typst
paper's label resolution in CI (Deploy Documentation workflow).
Replace with two separate directed edges per reversible reduction.
This makes the JSON deterministic and the paper's link resolution
trivial. Add reduction-rule entries for the 5 newly-explicit reverse
directions.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* test: add negative assertion for removed bidirectional field
Address Copilot review comment: assert that the legacy "bidirectional"
field is absent in test_to_json_string to catch accidental regressions.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* docs: update .claude/rules to match actual codebase APIs
Full audit of all rule files against source code:
- adding-models.md: Fix Problem trait template (was missing NAME,
variant(), Size, num_flavors(), energy_mode(), solution_size();
had non-existent is_valid_solution(); wrong import path for
ProblemSize). Add specialized category.
- testing.md: Fix closed-loop test pattern to use actual API
(ReduceTo::<T>::reduce_to, solution_size().is_valid). Remove
stale cargo-tarpaulin reference (project uses cargo-llvm-cov).
- documentation.md: Fix problem-def signature (name, body not
name, title). Fix reduction-rule params (example is bool, no
overhead param). Note JSON-based examples, not Rust code.
- adding-reductions.md: Fix make export-graph -> cargo run.
- CLAUDE.md: Fix problem-def signature, add directed reduction note.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* docs: simplify .claude/rules by pointing to reference implementations
Replace verbose pseudo-code templates with references to actual files
(kcoloring.rs, VC↔IS reduction, etc.) so rules stay in sync with code.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
- Test naming: `test_<source>_to_<target>_closed_loop`
98
98
99
99
### Paper (docs/paper/reductions.typ)
100
-
-`problem-def(name, title, body)` — defines a problem with auto-generated schema, reductions list, and label `<def:ProblemName>`
101
-
-`reduction-rule(source, target, ...)` — generates a theorem with label `<thm:Source-to-Target>` and registers in `covered-rules` state
100
+
-`problem-def(name)[body]` — defines a problem with auto-generated schema, reductions list, and label `<def:ProblemName>`. Title comes from `display-name` dict.
101
+
-`reduction-rule(source, target, example: bool, ...)[rule][proof]` — generates a theorem with label `<thm:Source-to-Target>` and registers in `covered-rules` state. Overhead auto-derived from JSON edge data.
102
+
- Every directed reduction needs its own `reduction-rule` entry
102
103
- Completeness warnings auto-check that all JSON graph nodes/edges are covered in the paper
103
104
-`display-name` dict maps `ProblemName` to display text
1.**Create**`src/models/<category>/<name>.rs` — follow the reference for struct definition, `Problem` impl, and optionally `ConstraintSatisfactionProblem` impl.
13
+
2.**Register** in `src/models/<category>/mod.rs`.
14
+
3.**Add tests** in `src/unit_tests/models/<category>/<name>.rs` (linked via `#[path]`).
15
+
4.**Document** in `docs/paper/reductions.typ`: add `display-name` entry and `#problem-def("Name")[definition...]`.
52
16
53
-
## 6. Documentation
54
-
Document in `docs/paper/reductions.typ` using `#problem-def("ProblemName", "Display Title")[...]`
17
+
## Categories
55
18
56
-
## Anti-patterns
57
-
- Don't create models without JSON serialization support
58
-
- Don't forget to implement `is_valid_solution()` correctly
59
-
- Don't use concrete types when generic `W` is appropriate
- Read reference implementations in the codebase (e.g., `src/rules/spinglass_qubo.rs`) to understand conventions
17
-
- Agree on scope (weighted vs unweighted, specific graph types, const generics)
18
-
2.**Generate ground truth test data** — use an existing library (e.g., Python with qubogen, qubovert, or networkx) to create small instances, reduce them, brute-force solve both sides, and export as JSON to `tests/data/<target>/`. It is recommended to download the relevant package and check the existing tests to understand how to construct tests. To generate the test data, you can use the following command:
19
-
```bash
20
-
# Example: generate QUBO test data
21
-
cd scripts && uv run python generate_qubo_tests.py
22
-
```
23
-
3.**Create a practical example** — design a small, explainable instance for `examples/` (e.g., "wireless tower placement" for MaximumIndependentSet, "map coloring" for KColoring). This example will also appear in the `docs/paper/reductions.typ`.
24
-
4.**Write the implementation plan** — save to `docs/plans/` using `superpowers:writing-plans`. The plan must include implementation details from the brainstorming session (formulas, penalty terms, matrix construction, variable indexing).
15
+
1.**Brainstorm** — use `superpowers:brainstorming` to discuss with the user:
16
+
- The math (variable mapping, constraint encoding, penalty terms)
17
+
- Which example instance to use in `examples/` (must be small, human-explainable, and agreed with the user)
18
+
2.**Generate ground truth** — use Python scripts in `scripts/` (run with `uv`) to create test data in `tests/data/<target>/`.
19
+
3.**Write plan** — save to `docs/plans/` using `superpowers:writing-plans`.
25
20
26
-
## 1. Implementation
21
+
## 1. Implement
27
22
28
-
Create `src/rules/<source>_<target>.rs` following the pattern in `src/rules/spinglass_qubo.rs`:
23
+
Create `src/rules/<source>_<target>.rs` following the reference. Key pieces:
Copy file name to clipboardExpand all lines: .claude/rules/documentation.md
+10-28Lines changed: 10 additions & 28 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,50 +5,32 @@ paths:
5
5
6
6
# Documentation Requirements
7
7
8
-
The technical paper (`docs/paper/reductions.typ`) must include:
9
-
10
-
1.**Problem Definitions** — using `problem-def` wrapper
11
-
2.**Reduction Theorems** — using `reduction-rule` function
12
-
3.**Reduction Examples** — minimal working example showing reduce → solve → extract
8
+
**Reference:** search `docs/paper/reductions.typ` for `MinimumVertexCover``MaximumIndependentSet` to see a complete problem-def + reduction-rule example.
13
9
14
10
## Adding a Problem Definition
15
11
16
12
```typst
17
-
#problem-def("MaximumIndependentSet", "Maximum Independent Set (MIS)")[
13
+
#problem-def("ProblemName")[
18
14
Mathematical definition...
19
15
]
20
16
```
21
17
22
-
This auto-generates:
23
-
- A label `<def:MaximumIndependentSet>` for cross-references
24
-
- The problem's schema (fields from Rust struct)
25
-
- The list of available reductions
26
-
27
-
Also add an entry to the `display-name` dictionary:
18
+
Also add to the `display-name` dictionary:
28
19
```typst
29
-
"MaximumIndependentSet": "MIS",
20
+
"ProblemName": [Problem Name],
30
21
```
31
22
32
23
## Adding a Reduction Theorem
33
24
34
25
```typst
35
-
#reduction-rule(
36
-
"MaximumIndependentSet", "QUBO",
37
-
example: "maximumindependentset_to_qubo",
38
-
overhead: (n: 0, m: 1),
26
+
#reduction-rule("Source", "Target",
27
+
example: true,
28
+
example-caption: [caption text],
39
29
)[
30
+
Rule statement...
31
+
][
40
32
Proof sketch...
41
33
]
42
34
```
43
35
44
-
This auto-generates:
45
-
- A theorem label `<thm:MaximumIndependentSet-to-QUBO>`
46
-
- References to source/target problem definitions (if they exist)
47
-
- Registration in `covered-rules` state for completeness checking
48
-
- The example code block from `examples/reduction_<example>.rs`
49
-
50
-
## Completeness Warnings
51
-
52
-
The paper auto-checks completeness:
53
-
- After Problem Definitions: warns if JSON graph nodes are missing from `display-name`
54
-
- After Reductions section: warns if JSON graph edges are missing from `covered-rules`
36
+
Every directed reduction in the graph needs its own `reduction-rule` entry. The paper auto-checks completeness against `reduction_graph.json`.
0 commit comments