Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 40 additions & 46 deletions problemreductions-cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ use std::path::PathBuf;
version,
after_help = "\
Typical workflow:
pred create MIS --edges 0-1,1-2,2-3 -o problem.json
pred create MIS --graph 0-1,1-2,2-3 -o problem.json
pred solve problem.json
pred evaluate problem.json --config 1,0,1,0

Piping (use - to read from stdin):
pred create MIS --edges 0-1,1-2 | pred solve -
pred create MIS --edges 0-1,1-2 | pred evaluate - --config 1,0,1
pred create MIS --edges 0-1,1-2 | pred reduce - --to QUBO
pred create MIS --graph 0-1,1-2 | pred solve -
pred create MIS --graph 0-1,1-2 | pred evaluate - --config 1,0,1
pred create MIS --graph 0-1,1-2 | pred reduce - --to QUBO

JSON output (any command):
pred list --json # JSON to stdout
Expand Down Expand Up @@ -61,22 +61,22 @@ Examples:
pred show MIS/UnitDiskGraph # specific graph variant

Use `pred list` to see all available problem types and aliases.
Use `pred to MIS --hops 2` to explore outgoing neighbors.
Use `pred from QUBO --hops 1` to explore incoming neighbors.")]
Use `pred to MIS --hops 2` to explore what reduces to MIS.
Use `pred from QUBO --hops 1` to explore what QUBO reduces to.")]
Show {
/// Problem name or alias (e.g., MIS, QUBO, MIS/UnitDiskGraph)
#[arg(value_parser = crate::problem_name::ProblemNameParser)]
problem: String,
},

/// Explore outgoing neighbors in the reduction graph (problems this reduces TO)
/// Explore problems that reduce TO this one (incoming neighbors)
#[command(after_help = "\
Examples:
pred to MIS # 1-hop outgoing neighbors
pred to MIS --hops 2 # 2-hop outgoing neighbors
pred to MIS # what reduces to MIS? (1 hop)
pred to MIS --hops 2 # 2-hop incoming neighbors
pred to MIS -o out.json # save as JSON

Use `pred from <problem>` for incoming neighbors.")]
Use `pred from <problem>` for outgoing neighbors (what this reduces to).")]
To {
/// Problem name or alias (e.g., MIS, QUBO, MIS/UnitDiskGraph)
#[arg(value_parser = crate::problem_name::ProblemNameParser)]
Expand All @@ -86,14 +86,14 @@ Use `pred from <problem>` for incoming neighbors.")]
hops: usize,
},

/// Explore incoming neighbors in the reduction graph (problems that reduce FROM this)
/// Explore problems this reduces to, starting FROM it (outgoing neighbors)
#[command(after_help = "\
Examples:
pred from QUBO # 1-hop incoming neighbors
pred from QUBO --hops 2 # 2-hop incoming neighbors
pred from QUBO -o in.json # save as JSON
pred from MIS # what does MIS reduce to? (1 hop)
pred from MIS --hops 2 # 2-hop outgoing neighbors
pred from MIS -o out.json # save as JSON

Use `pred to <problem>` for outgoing neighbors.")]
Use `pred to <problem>` for incoming neighbors (what reduces to this).")]
From {
/// Problem name or alias (e.g., MIS, QUBO, MIS/UnitDiskGraph)
#[arg(value_parser = crate::problem_name::ProblemNameParser)]
Expand Down Expand Up @@ -146,7 +146,7 @@ Examples:
Examples:
pred inspect problem.json
pred inspect bundle.json
pred create MIS --edges 0-1,1-2 | pred inspect -")]
pred create MIS --graph 0-1,1-2 | pred inspect -")]
Inspect(InspectArgs),
/// Solve a problem instance
Solve(SolveArgs),
Expand Down Expand Up @@ -197,23 +197,7 @@ Setup: add one line to your shell rc file:

#[derive(clap::Args)]
#[command(after_help = "\
Options by problem type:
Graph problems (MIS, MVC, MaxCut, MaxClique, ...):
--edges Edge list, e.g., 0-1,1-2,2-3 [required]
--weights Vertex weights, e.g., 2,1,3,1 [default: all 1s]
SAT problems (SAT, 3SAT, KSAT):
--num-vars Number of variables [required]
--clauses Semicolon-separated clauses, e.g., \"1,2;-1,3\" [required]
QUBO:
--matrix Semicolon-separated rows, e.g., \"1,0.5;0.5,2\" [required]
KColoring:
--edges Edge list [required]
--k Number of colors [required]

Factoring:
--target Number to factor [required]
--bits-m Bits for first factor [required]
--bits-n Bits for second factor [required]
Run `pred create <PROBLEM>` without arguments to see problem-specific parameters.

Random generation (graph-based problems only):
--random Generate a random Erdos-Renyi graph instance
Expand All @@ -222,27 +206,37 @@ Random generation (graph-based problems only):
--seed Random seed for reproducibility

Examples:
pred create MIS --edges 0-1,1-2,2-3 -o problem.json
pred create MIS --edges 0-1,1-2 --weights 2,1,3 -o weighted.json
pred create MIS --graph 0-1,1-2,2-3 -o problem.json
pred create MIS --graph 0-1,1-2 --weights 2,1,3 -o weighted.json
pred create SAT --num-vars 3 --clauses \"1,2;-1,3\" -o sat.json
pred create QUBO --matrix \"1,0.5;0.5,2\" -o qubo.json
pred create KColoring --k 3 --edges 0-1,1-2,2-0 -o kcol.json
pred create KColoring --k 3 --graph 0-1,1-2,2-0 -o kcol.json
pred create MaxCut --graph 0-1,1-2 --edge-weights 2,3
pred create SpinGlass --graph 0-1,1-2 --couplings 1,-1
pred create MIS --random --num-vertices 10 --edge-prob 0.3
pred create MIS --random --num-vertices 10 --seed 42 -o big.json
pred create Factoring --target 15 --bits-m 4 --bits-n 4
pred create Factoring --target 15 --m 4 --n 4

Output (`-o`) uses the standard problem JSON format:
{\"type\": \"...\", \"variant\": {...}, \"data\": {...}}")]
pub struct CreateArgs {
/// Problem type (e.g., MIS, QUBO, SAT)
#[arg(value_parser = crate::problem_name::ProblemNameParser)]
pub problem: String,
/// Edges for graph problems (e.g., 0-1,1-2,2-3)
/// Graph edge list (e.g., 0-1,1-2,2-3)
#[arg(long)]
pub edges: Option<String>,
pub graph: Option<String>,
/// Vertex weights (e.g., 1,1,1,1) [default: all 1s]
#[arg(long)]
pub weights: Option<String>,
/// Edge weights (e.g., 2,3,1) [default: all 1s]
#[arg(long)]
pub edge_weights: Option<String>,
/// Pairwise couplings J_ij for SpinGlass (e.g., 1,-1,1) [default: all 1s]
#[arg(long)]
pub couplings: Option<String>,
/// On-site fields h_i for SpinGlass (e.g., 0,0,1) [default: all 0s]
#[arg(long)]
pub fields: Option<String>,
/// Clauses for SAT problems (semicolon-separated, e.g., "1,2;-1,3")
#[arg(long)]
pub clauses: Option<String>,
Expand Down Expand Up @@ -272,10 +266,10 @@ pub struct CreateArgs {
pub target: Option<u64>,
/// Bits for first factor (for Factoring)
#[arg(long)]
pub bits_m: Option<usize>,
pub m: Option<usize>,
/// Bits for second factor (for Factoring)
#[arg(long)]
pub bits_n: Option<usize>,
pub n: Option<usize>,
}

#[derive(clap::Args)]
Expand All @@ -285,11 +279,11 @@ Examples:
pred solve problem.json --solver brute-force # brute-force (exhaustive search)
pred solve reduced.json # solve a reduction bundle
pred solve reduced.json -o solution.json # save result to file
pred create MIS --edges 0-1,1-2 | pred solve - # read from stdin
pred create MIS --graph 0-1,1-2 | pred solve - # read from stdin
pred solve problem.json --timeout 10 # abort after 10 seconds

Typical workflow:
pred create MIS --edges 0-1,1-2,2-3 -o problem.json
pred create MIS --graph 0-1,1-2,2-3 -o problem.json
pred solve problem.json

Solve via explicit reduction:
Expand Down Expand Up @@ -321,7 +315,7 @@ Examples:
pred reduce problem.json --to QUBO -o reduced.json
pred reduce problem.json --to ILP -o reduced.json
pred reduce problem.json --via path.json -o reduced.json
pred create MIS --edges 0-1,1-2 | pred reduce - --to QUBO # read from stdin
pred create MIS --graph 0-1,1-2 | pred reduce - --to QUBO # read from stdin

Input: a problem JSON from `pred create`. Use - to read from stdin.
The --via path file is from `pred path <SRC> <DST> -o path.json`.
Expand Down Expand Up @@ -350,7 +344,7 @@ pub struct InspectArgs {
Examples:
pred evaluate problem.json --config 1,0,1,0
pred evaluate problem.json --config 1,0,1,0 -o result.json
pred create MIS --edges 0-1,1-2 | pred evaluate - --config 1,0,1 # read from stdin
pred create MIS --graph 0-1,1-2 | pred evaluate - --config 1,0,1 # read from stdin

Input: a problem JSON from `pred create`. Use - to read from stdin.")]
pub struct EvaluateArgs {
Expand Down
Loading