-
Notifications
You must be signed in to change notification settings - Fork 6
feat: display Big O notation in CLI output #263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
3374bdf
9748b85
9cdb10a
309b551
dcd0e4c
682845c
528b09e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -86,3 +86,4 @@ claude-output.log | |
| *.json | ||
| .claude/worktrees/ | ||
| docs/test-reports/ | ||
| docs/superpowers/ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| # Features | ||
|
|
||
| - [Library API] — Define NP-hard problems, evaluate configurations, and reduce between problem types using Rust traits | ||
| - [CLI Tool (pred)] — Explore the reduction graph, create/inspect/reduce/solve problem instances from the terminal | ||
| - [MCP Server] — AI assistant integration via Model Context Protocol for graph queries and problem manipulation | ||
| - [Reduction Graph] — Automatic shortest-path search through registered reductions between problem types | ||
| - [BruteForce Solver] — Enumerate all configurations to find optimal or satisfying solutions | ||
| - [Variant System] — Graph/weight type parameterization with compile-time complexity registration | ||
| - [Overhead System] — Symbolic expressions describing how target problem size relates to source after reduction | ||
| - [Serialization] — JSON schema export and serde-based serialization for all problem types |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # Skills | ||
|
|
||
| - [issue-to-pr] — Convert a GitHub issue into a PR with an implementation plan | ||
| - [add-model] — Add a new problem model to the codebase | ||
| - [add-rule] — Add a new reduction rule to the codebase | ||
| - [review-implementation] — Review implementation completeness via parallel subagents | ||
| - [fix-pr] — Resolve PR review comments, CI failures, and coverage gaps | ||
| - [check-issue] — Quality gate for Rule and Model GitHub issues | ||
| - [check-rule-redundancy] — Check if a reduction rule is redundant via composite paths | ||
| - [write-model-in-paper] — Write or improve a problem-def entry in the Typst paper | ||
| - [write-rule-in-paper] — Write or improve a reduction-rule entry in the Typst paper | ||
| - [release] — Create a new crate release with version bump | ||
| - [meta-power] — Batch-resolve all open Model and Rule issues autonomously |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| # cli-tool-dr-sarah-chen | ||
|
|
||
| ## Target | ||
| CLI Tool (pred) | ||
|
|
||
| ## Use Case | ||
| End-to-end workflow: create an MIS instance, reduce it to QUBO, solve the QUBO, and verify the mapped-back solution matches the known optimum. | ||
|
|
||
| ## Expected Outcome | ||
| The full create → reduce → solve → evaluate pipeline completes successfully with correct optimal results. JSON output is well-formed and machine-readable at every stage. | ||
|
|
||
| ## Agent | ||
|
|
||
| ### Background | ||
| Dr. Sarah Chen is a computational physicist at a national lab who regularly uses optimization solvers (Gurobi, CPLEX, HiGHS) in her research on quantum annealing benchmarks. She evaluates new tools by running them against problems with known optimal solutions. | ||
|
|
||
| ### Experience Level | ||
| Expert | ||
|
|
||
| ### Decision Tendencies | ||
| Tests edge cases proactively — tries empty graphs, disconnected components, and large instances. Expects precise, actionable error messages when things go wrong. Compares solver output against independently computed optima. Will read --help but also try undocumented flag combinations. | ||
|
|
||
| ### Quirks | ||
| Will try both file-based and piped workflows to check consistency. Inspects JSON output with jq for machine-readability. Gets impatient with vague error messages like "invalid input" — wants to know exactly what's wrong and where. |
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -31,6 +31,15 @@ pub fn evaluate(input: &Path, config_str: &str, out: &OutputConfig) -> Result<() | |||||||||||||
| ); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| for (i, (val, dim)) in config.iter().zip(dims.iter()).enumerate() { | ||||||||||||||
| if *val >= *dim { | ||||||||||||||
| anyhow::bail!( | ||||||||||||||
| "Config value {} at position {} is out of range: variable {} has {} possible values (0..{})", | ||||||||||||||
| val, i, i, dim, dim - 1 | ||||||||||||||
|
||||||||||||||
| val, i, i, dim, dim - 1 | |
| val, | |
| i, | |
| i, | |
| dim, | |
| dim.saturating_sub(1) |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,6 +1,7 @@ | ||||||||||||||||||||
| use crate::output::OutputConfig; | ||||||||||||||||||||
| use crate::problem_name::{aliases_for, parse_problem_spec, resolve_variant}; | ||||||||||||||||||||
| use anyhow::{Context, Result}; | ||||||||||||||||||||
| use problemreductions::{asymptotic_normal_form, Expr}; | ||||||||||||||||||||
| use problemreductions::registry::collect_schemas; | ||||||||||||||||||||
| use problemreductions::rules::{Minimize, MinimizeSteps, ReductionGraph, TraversalDirection}; | ||||||||||||||||||||
| use problemreductions::types::ProblemSize; | ||||||||||||||||||||
|
|
@@ -124,7 +125,10 @@ pub fn show(problem: &str, out: &OutputConfig) -> Result<()> { | |||||||||||||||||||
| crate::output::fmt_problem_name(&format!("{}{}", spec.name, slash)) | ||||||||||||||||||||
| ); | ||||||||||||||||||||
| if let Some(c) = graph.variant_complexity(&spec.name, v) { | ||||||||||||||||||||
| text.push_str(&format!("{label} complexity: {c}\n")); | ||||||||||||||||||||
| text.push_str(&format!( | ||||||||||||||||||||
| "{label} complexity: {}\n", | ||||||||||||||||||||
| big_o_of(&Expr::parse(c)) | ||||||||||||||||||||
| )); | ||||||||||||||||||||
|
Comment on lines
127
to
+131
|
||||||||||||||||||||
| text.push_str(&format!( | |
| "{label} complexity: {}\n", | |
| big_o_of(&Expr::parse(c)) | |
| )); | |
| let mut complexity_str = big_o_of(&Expr::parse(c)); | |
| if !complexity_str.contains("O(") { | |
| complexity_str = format!("O({})", complexity_str); | |
| } | |
| text.push_str(&format!("{label} complexity: {complexity_str}\n")); |
Copilot
AI
Mar 12, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This JSON branch also uses Expr::parse(complexity), which can panic and crash pred show -o ... if a complexity string is malformed. Using a fallible parse here would keep JSON export robust and allow you to omit/empty the big_o field (or fall back to the original string) on parse errors.
| big_o_of(&Expr::parse(complexity)) | |
| std::panic::catch_unwind(|| big_o_of(&Expr::parse(complexity))) | |
| .unwrap_or_else(|_| String::new()) |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -58,7 +58,7 @@ pub mod prelude { | |||||
|
|
||||||
| // Re-export commonly used items at crate root | ||||||
| pub use error::{ProblemError, Result}; | ||||||
| pub use expr::{asymptotic_normal_form, AsymptoticAnalysisError}; | ||||||
| pub use expr::{asymptotic_normal_form, AsymptoticAnalysisError, Expr}; | ||||||
|
||||||
| pub use expr::{asymptotic_normal_form, AsymptoticAnalysisError, Expr}; | |
| pub use expr::{asymptotic_normal_form, AsymptoticAnalysisError}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message computes
dim - 1for display. Ifdimis ever 0, this will underflow (usize) and produce a bogus upper bound (or panic in debug builds). Prefer printing an exclusive range like0..{dim}(or handledim == 0explicitly) so the message can’t underflow.