Skip to content

feat: add pred CLI tool for problem reductions#82

Merged
GiggleLiu merged 29 commits intomainfrom
cli-tool-design
Feb 18, 2026
Merged

feat: add pred CLI tool for problem reductions#82
GiggleLiu merged 29 commits intomainfrom
cli-tool-design

Conversation

@GiggleLiu
Copy link
Contributor

@GiggleLiu GiggleLiu commented Feb 17, 2026

Summary

Complete CLI tool (pred) for exploring NP-hard problem reductions, creating problem instances, and solving them.

Commands

Command Description
pred list List all registered problem types with aliases
pred show <problem> Show variants and reductions for a problem
pred path <src> <dst> Find cheapest reduction path (supports --all, -o)
pred export-graph Export the reduction graph as JSON
pred create Create a problem instance from CLI args
pred evaluate Evaluate a configuration against a problem
pred reduce Reduce a problem to a target type (outputs bundle)
pred solve Solve a problem with ILP (default) or brute-force

Key Features

  • ILP auto-reduction: pred solve problem.json automatically reduces any problem to ILP, solves, and maps the solution back — works for both plain problem files and reduction bundles
  • Reduction bundles: pred reduce outputs a bundle with source, target, and path; pred solve can solve bundles and extract source solutions
  • Configurable ILP backends: cargo install --features coin-cbc to switch backend (highs, coin-cbc, clarabel, scip, lpsolve, microlp)
  • Problem aliases: MIS, MVC, SAT, 3SAT, TSP etc.
  • Variant support: MIS/UnitDiskGraph, SpinGlass/SimpleGraph
  • Type-erased dispatch: Single dispatch table with monomorphized solver function pointers — no duplicated match tables
  • Single-source help: Each command's help is defined once in cli.rs and shown both on --help and on parse errors (via Cli::command().find_subcommand())

Architecture

  • dispatch.rsLoadedProblem with DynProblem trait + Deref for type-erased problem operations; solve_with_ilp() handles auto-reduction
  • problem_name.rs — Alias resolution and variant parsing
  • commands/ — One module per command (graph, create, evaluate, reduce, solve)
  • Feature flags: ilp-solver marker feature + per-backend features forwarded through CLI crate

CI Changes

  • Replaced --all-features with --features ilp-highs in CI and Makefile (scip/cbc/lpsolve require system libraries not available in CI runners)

Typical Workflow

pred create MIS --edges 0-1,1-2,2-3 -o problem.json
pred solve problem.json                    # auto-reduces to ILP
pred evaluate problem.json --config 1,0,1,0
pred reduce problem.json --to QUBO -o reduced.json
pred solve reduced.json                    # solves QUBO, maps back to MIS

Test plan

  • 25 CLI integration tests pass (cargo test -p problemreductions-cli)
  • All library tests pass
  • Clippy clean
  • Manual smoke tests for all commands
  • Help messages shown on error (single source in cli.rs)
  • CI passes (fixed --all-features--features ilp-highs)

🤖 Generated with Claude Code

GiggleLiu and others added 2 commits February 18, 2026 07:53
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>
@GiggleLiu GiggleLiu requested a review from isPANN February 17, 2026 23:58
@GiggleLiu
Copy link
Contributor Author

GiggleLiu commented Feb 18, 2026

@isPANN
This is a CLI tool for problem reductions. I hope you could review the design document.

@codecov
Copy link

codecov bot commented Feb 18, 2026

Codecov Report

❌ Patch coverage is 95.90164% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.35%. Comparing base (e8d1804) to head (458208a).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/rules/graph.rs 93.67% 5 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

GiggleLiu and others added 11 commits February 18, 2026 08:12
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>
@GiggleLiu GiggleLiu changed the title Add CLI tool design and implementation plan for pred feat: add pred CLI tool for exploring reductions Feb 18, 2026
GiggleLiu and others added 7 commits February 18, 2026 09:51
…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>
@GiggleLiu GiggleLiu changed the title feat: add pred CLI tool for exploring reductions feat: add pred CLI tool with evaluate and reduce commands Feb 18, 2026
GiggleLiu and others added 3 commits February 18, 2026 13:07
… 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>
@GiggleLiu GiggleLiu changed the title feat: add pred CLI tool with evaluate and reduce commands feat: add pred CLI tool for problem reductions Feb 18, 2026
- 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>
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-cli workspace crate with 8 commands for graph exploration, problem creation, solving, and reduction
  • Library refactoring: replaced typed ExecutablePath<S,T> + ChainedReduction<S,T> with untyped ReductionChain + reduce_along_path() API
  • Feature flag restructuring: ilpilp-solver marker 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.

GiggleLiu and others added 4 commits February 18, 2026 20:36
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>
@GiggleLiu GiggleLiu merged commit 7267e16 into main Feb 18, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants