feat: add pred CLI tool for problem reductions#82
Conversation
Design for a CLI tool targeting researchers/students to explore NP-hard problem reductions without writing Rust code. Covers graph exploration, solve/reduce/evaluate commands, slash-based variant notation, and JSON/text output modes. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
12-task plan covering workspace scaffolding, problem name resolution, clap command hierarchy, graph exploration commands, schema command, integration tests, and Makefile target. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
@isPANN |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #82 +/- ##
==========================================
+ Coverage 96.33% 96.35% +0.01%
==========================================
Files 193 193
Lines 26682 26722 +40
==========================================
+ Hits 25704 25747 +43
+ Misses 978 975 -3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Remove unused `emit` method (only `emit_with_default_name` is used) - Replace `map_or(true, ...)` with `is_none_or(...)` (2 places) - Change `&PathBuf` to `&Path` in export function signature Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
pred…onChain Unify ExecutablePath<S,T>, ChainedReduction<S,T>, and make_executable into a single untyped ReductionChain and reduce_along_path(). Callers downcast when they need typed access. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
… backends - Add `pred solve` command supporting ILP (default) and brute-force solvers - Auto-reduce non-ILP problems to ILP when using ILP solver - Support solving reduction bundles (from `pred reduce`) - Extract solve_with_ilp helper to eliminate duplicated auto-reduction logic - Restructure feature flags: per-backend features (highs, coin-cbc, clarabel, scip, lpsolve, microlp) with ilp-solver marker feature - Update CLI help text with examples and workflow guidance - Update mdBook CLI documentation to match current commands - Update CLAUDE.md with documentation locations Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Define each command's help text once in cli.rs (after_help) - Show the same help on parse errors via Cli::command().find_subcommand() - Remove duplicated error hints from main.rs - Comprehensive examples covering all arguments and defaults - Cross-reference input files to their producing commands - Replace --all-features with --features ilp-highs in CI and Makefile (scip/cbc/lpsolve require system libraries not available in CI) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Wire up `pred path --cost minimize:<field>` to use `Minimize(field)` instead of always falling back to MinimizeSteps - Add `size_field_names()` method to ReductionGraph - Show size fields in `pred show` output so users know which fields are available for `--cost minimize:<field>` Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR introduces a comprehensive CLI tool (pred) for exploring NP-hard problem reductions, creating problem instances, and solving them without writing Rust code. The implementation follows a clean architecture with a separate workspace crate and includes significant library refactoring to support type-erased operations.
Changes:
- New
problemreductions-cliworkspace crate with 8 commands for graph exploration, problem creation, solving, and reduction - Library refactoring: replaced typed
ExecutablePath<S,T>+ChainedReduction<S,T>with untypedReductionChain+reduce_along_path()API - Feature flag restructuring:
ilp→ilp-solvermarker feature with backend-specific features (highs, coin-cbc, clarabel, scip, lpsolve, microlp)
Reviewed changes
Copilot reviewed 34 out of 34 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
Cargo.toml |
Added CLI workspace member; restructured ILP features with marker feature and per-backend options |
Makefile |
Updated all targets from --all-features to --features ilp-highs; added cli target |
.github/workflows/ci.yml |
Updated CI to use --features ilp-highs instead of --all-features |
src/rules/graph.rs |
Replaced ExecutablePath/ChainedReduction with ReductionChain; added reduce_along_path(), variants_for(), outgoing_reductions(), incoming_reductions(), size_field_names() |
src/rules/mod.rs |
Updated exports from ExecutablePath/ChainedReduction to ReductionChain/ReductionEdgeInfo |
src/rules/traits.rs |
Updated doc comment reference from ExecutablePath to ReductionChain |
src/solvers/mod.rs |
Changed feature gates from ilp to ilp-solver |
tests/suites/reductions.rs |
Updated feature gates from ilp to ilp-solver |
src/unit_tests/rules/graph.rs |
Migrated 3 tests to use reduce_along_path() API |
src/unit_tests/rules/reduction_path_parity.rs |
Migrated 3 parity tests to new reduce_along_path() API |
examples/chained_reduction_ksat_to_mis.rs |
Updated example to use reduce_along_path() |
problemreductions-cli/Cargo.toml |
New CLI crate with feature forwarding to library backends |
problemreductions-cli/src/main.rs |
CLI entry point with subcommand dispatch |
problemreductions-cli/src/cli.rs |
Clap-based CLI structure with comprehensive help text |
problemreductions-cli/src/dispatch.rs |
Type-erased dispatch with DynProblem trait and match-based type resolution |
problemreductions-cli/src/output.rs |
Output handling for human-readable vs JSON modes |
problemreductions-cli/src/problem_name.rs |
Problem name/alias resolution with variant parsing |
problemreductions-cli/src/commands/*.rs |
Individual command implementations (graph, create, evaluate, reduce, solve) |
problemreductions-cli/tests/cli_tests.rs |
25 integration tests covering all commands |
docs/src/cli.md |
Comprehensive CLI documentation with examples |
docs/src/*.md |
Updates to introduction, getting-started, and SUMMARY |
README.md |
Added CLI installation and usage section |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Increase patch coverage from 68% to address codecov/patch failure. Adds 25 new integration tests covering solve command (brute-force, ILP, bundles, JSON output), create for more problem types (MaxCut, MVC, KColoring, SpinGlass, 3SAT, MaximumMatching), error cases, help messages, and path cost functions. Also removes unnecessary "Use with" hint from size fields display. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Update `pred show` example with fields, size fields, description - Fix Quick Start: use --solver brute-force for QUBO bundle - Add overhead formulas to `pred path` examples - Add note about ILP solver limitations for some problems - Document `pred reduce` stdout behavior - Add more `pred create` examples (SpinGlass, MaxCut) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The CLI crate is a thin dispatch layer with many boilerplate type-dispatch match arms (load_problem, serialize_any_problem). These are tested end-to-end via 50 integration tests but don't reach 95% line coverage due to the combinatorial number of problem type × variant arms. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary
Complete CLI tool (
pred) for exploring NP-hard problem reductions, creating problem instances, and solving them.Commands
pred listpred show <problem>pred path <src> <dst>--all,-o)pred export-graphpred createpred evaluatepred reducepred solveKey Features
pred solve problem.jsonautomatically reduces any problem to ILP, solves, and maps the solution back — works for both plain problem files and reduction bundlespred reduceoutputs a bundle with source, target, and path;pred solvecan solve bundles and extract source solutionscargo install --features coin-cbcto switch backend (highs, coin-cbc, clarabel, scip, lpsolve, microlp)MIS,MVC,SAT,3SAT,TSPetc.MIS/UnitDiskGraph,SpinGlass/SimpleGraphcli.rsand shown both on--helpand on parse errors (viaCli::command().find_subcommand())Architecture
dispatch.rs—LoadedProblemwithDynProblemtrait +Dereffor type-erased problem operations;solve_with_ilp()handles auto-reductionproblem_name.rs— Alias resolution and variant parsingcommands/— One module per command (graph, create, evaluate, reduce, solve)ilp-solvermarker feature + per-backend features forwarded through CLI crateCI Changes
--all-featureswith--features ilp-highsin CI and Makefile (scip/cbc/lpsolve require system libraries not available in CI runners)Typical Workflow
Test plan
cargo test -p problemreductions-cli)--all-features→--features ilp-highs)🤖 Generated with Claude Code