Skip to content

Commit d8a6168

Browse files
authored
fix issues (#1042)
1 parent 3024163 commit d8a6168

3 files changed

Lines changed: 29 additions & 5 deletions

File tree

problemreductions-cli/src/commands/graph.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,24 @@ pub(crate) fn variant_to_full_slash(variant: &BTreeMap<String, String>) -> Strin
375375
}
376376
}
377377

378+
/// Build a hint string listing available variants for a problem name.
379+
/// Returns an empty string if there is only one variant (nothing to disambiguate).
380+
pub(crate) fn variant_hint_for(graph: &ReductionGraph, name: &str) -> String {
381+
let variants = graph.variants_for(name);
382+
if variants.len() <= 1 {
383+
return String::new();
384+
}
385+
let list: Vec<String> = variants
386+
.iter()
387+
.map(|v| format!("{}{}", name, variant_to_full_slash(v)))
388+
.collect();
389+
format!(
390+
"\nTip: try specifying a variant. Available variants for {}:\n {}\n",
391+
name,
392+
list.join(", "),
393+
)
394+
}
395+
378396
/// Format a problem node as **bold name/variant** in slash notation.
379397
/// This is the single source of truth for "name/variant" display.
380398
fn fmt_node(_graph: &ReductionGraph, name: &str, variant: &BTreeMap<String, String>) -> String {
@@ -550,8 +568,10 @@ pub fn path(
550568
out.emit_with_default_name("", &text, &json)
551569
}
552570
None => {
571+
let variant_hint = variant_hint_for(&graph, &dst_spec.name);
553572
anyhow::bail!(
554-
"No reduction path from {} to {}\n\n\
573+
"No reduction path from {} to {}\n\
574+
{variant_hint}\n\
555575
Usage: pred path <SOURCE> <TARGET>\n\
556576
Example: pred path MIS QUBO\n\n\
557577
Run `pred show {}` and `pred show {}` to check available reductions.",
@@ -578,8 +598,10 @@ fn path_all(
578598
graph.find_paths_up_to(src_name, src_variant, dst_name, dst_variant, max_paths + 1);
579599

580600
if all_paths.is_empty() {
601+
let variant_hint = variant_hint_for(graph, dst_name);
581602
anyhow::bail!(
582-
"No reduction path from {} to {}\n\n\
603+
"No reduction path from {} to {}\n\
604+
{variant_hint}\n\
583605
Usage: pred path <SOURCE> <TARGET> --all\n\
584606
Example: pred path MIS QUBO --all\n\n\
585607
Run `pred show {}` and `pred show {}` to check available reductions.",

problemreductions-cli/src/commands/reduce.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,10 @@ pub fn reduce(
125125
);
126126

127127
best_path.ok_or_else(|| {
128+
let variant_hint = variant_hint_for(&graph, &dst_ref.name);
128129
anyhow::anyhow!(
129-
"No witness-capable reduction path from {} to {}\n\n\
130+
"No witness-capable reduction path from {} to {}\n\
131+
{variant_hint}\n\
130132
Hint: generate a path file first, then pass it with --via:\n\
131133
pred path {} {} -o path.json\n\
132134
pred reduce {} --via path.json -o reduced.json",
@@ -196,4 +198,4 @@ pub fn reduce(
196198
Ok(())
197199
}
198200

199-
use super::graph::variant_to_full_slash;
201+
use super::graph::{variant_hint_for, variant_to_full_slash};

src/models/graph/isomorphic_spanning_tree.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ pub(crate) fn canonical_model_example_specs() -> Vec<crate::example_db::specs::M
195195
}
196196

197197
crate::declare_variants! {
198-
default IsomorphicSpanningTree<SimpleGraph> => "num_vertices^num_vertices",
198+
default IsomorphicSpanningTree<SimpleGraph> => "2^num_vertices",
199199
}
200200

201201
#[cfg(test)]

0 commit comments

Comments
 (0)