Skip to content

Fix #119: [Rule] GraphPartitioning to QUBO#706

Merged
GiggleLiu merged 7 commits intomainfrom
issue-119
Mar 21, 2026
Merged

Fix #119: [Rule] GraphPartitioning to QUBO#706
GiggleLiu merged 7 commits intomainfrom
issue-119

Conversation

@GiggleLiu
Copy link
Copy Markdown
Contributor

Summary

  • add the implementation plan for GraphPartitioning -> QUBO
  • reserve the issue branch/PR for the pipeline execution steps

Fixes #119

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.59%. Comparing base (ca2110e) to head (b98b61f).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #706      +/-   ##
==========================================
+ Coverage   97.57%   97.59%   +0.01%     
==========================================
  Files         381      383       +2     
  Lines       47649    47761     +112     
==========================================
+ Hits        46494    46611     +117     
+ Misses       1155     1150       -5     

☔ 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
Copy link
Copy Markdown
Contributor Author

Implemented issue #119 by adding a direct GraphPartitioning -> QUBO reduction using the standard balance-penalty construction with P = |E| + 1.

Included:

  • reduction wiring and canonical example export
  • focused rule tests covering round-trip behavior, matrix coefficients, and example-db registration
  • paper entry documenting the construction and the 6-vertex worked example

Verification on commit fef3e108:

  • make clippy
  • make test
  • make paper

@GiggleLiu
Copy link
Copy Markdown
Contributor Author

Agentic Review Report

Structural Check

Structural Review: rule graphpartitioning_qubo

Structural Completeness

# Check Status
1 Rule file exists PASS — src/rules/graphpartitioning_qubo.rs is present
2 #[reduction(...)] macro present PASS — reduction macro is attached to the ReduceTo<QUBO<f64>> impl
3 ReductionResult impl present PASS — ReductionGraphPartitioningToQUBO implements ReductionResult
4 ReduceTo impl present PASS — GraphPartitioning<SimpleGraph> implements ReduceTo<QUBO<f64>>
5 #[cfg(test)] + #[path = "..."] test link PASS — the rule file links ../unit_tests/rules/graphpartitioning_qubo.rs
6 Test file exists PASS — src/unit_tests/rules/graphpartitioning_qubo.rs is present
7 Closed-loop test present PASS — test_graphpartitioning_to_qubo_closed_loop exists
8 Registered in rules/mod.rs PASS — module and canonical example aggregation are wired in src/rules/mod.rs
9 Canonical rule example registered PASS — canonical_rule_example_specs() is exposed through src/rules/mod.rs and consumed by src/example_db/rule_builders.rs
10 Example-db lookup tests exist PASS — src/unit_tests/example_db.rs covers find_rule_example and build_rule_db
11 Paper reduction-rule entry PASS — docs/paper/reductions.typ includes #reduction-rule("GraphPartitioning", "QUBO", ...)
12 No blacklisted auto-generated files committed PASS — none of the blacklisted generated paths appear in the diff

Build Status

  • make test: PASS
  • make clippy: PASS

Semantic Review

  • reduction formula: OK — src/rules/graphpartitioning_qubo.rs#L48 and src/rules/graphpartitioning_qubo.rs#L55 implement Q_ii = deg(i) + P(1-n) and Q_ij = 2P-2 on edges / 2P on non-edges, with P = m + 1.
  • extract_solution correctness: ISSUE — [src/rules/graphpartitioning_qubo.rs#L27](/Users/liujinguo/rcode/problemreductions/.worktrees/review-pr-706/src/rules/graphpartitioning_qubo.rs#L27) returns the QUBO bit-vector unchanged, but [src/rules/graphpartitioning_qubo.rs#L36](/Users/liujinguo/rcode/problemreductions/.worktrees/review-pr-706/src/rules/graphpartitioning_qubo.rs#L36) never enforces the source problem’s even-nprecondition, while [src/models/graph/graph_partitioning.rs#L111](/Users/liujinguo/rcode/problemreductions/.worktrees/review-pr-706/src/models/graph/graph_partitioning.rs#L111) makes every odd-vertex instance infeasible. On oddn`, the reduction still produces a QUBO with valid optima, so extracted target optima need not be feasible source solutions.
  • overhead accuracy: OK — num_vars = "num_vertices" matches the constructed target size exactly.
  • example quality: OK — the canonical example and unit test use the issue’s 6-vertex, 9-edge instance and verify the exported matrix coefficients.
  • paper quality: OK — docs/paper/reductions.typ#L4262 states the rule precisely and gives a sound proof sketch for the even-vertex case.

Issue Compliance

# Check Status
1 Source/target match issue OK — implements GraphPartitioning -> QUBO
2 Reduction algorithm matches OK — cut term, balance penalty, coefficient expansion, and P = m + 1 match the issue for even n
3 Solution extraction matches OK — identity bit-vector extraction matches the issue’s A = {i : x_i = 0}, B = {i : x_i = 1} encoding
4 Correctness preserved ISSUE — the implementation omits the issue’s even-n precondition, so it is not correctness-preserving on all constructible GraphPartitioning instances
5 Overhead expressions match OK — num_vars = n
6 Example matches OK — same 6-vertex, 9-edge graph, P = 10, and witness/matrix data are covered

Summary


Quality Check

Quality Review

Design Principles

Test Quality

Issues

Critical (Must Fix)

Important (Should Fix)

Minor (Nice to Have)

  • None.

Summary

  • Critical: the reduction silently accepts odd-vertex GraphPartitioning instances and can return target optima that map to source-invalid partitions.
  • Important: the new tests cover only a single even-vertex example, so they do not catch that boundary-condition failure.

Agentic Feature Tests

Feature Test Report: problemreductions

Verdict: pass
Critical Issues: 0

Test Setup

  • Worktree: /Users/liujinguo/rcode/problemreductions/.worktrees/review-pr-706
  • Scratch dir: /tmp/problemreductions-pr706-LamKkl
  • Build: cargo build -p problemreductions-cli --bin pred
  • Commands tried:
    • ./target/debug/pred list
    • ./target/debug/pred show GraphPartitioning
    • ./target/debug/pred create --example GraphPartitioning -o /tmp/problemreductions-pr706-LamKkl/graphpartitioning-example.json
    • ./target/debug/pred create GraphPartitioning --graph 0-1,1-2,2-3,3-0 -o /tmp/problemreductions-pr706-LamKkl/graphpartitioning-4cycle.json
    • ./target/debug/pred reduce /tmp/problemreductions-pr706-LamKkl/graphpartitioning-4cycle.json --to QUBO -o /tmp/problemreductions-pr706-LamKkl/graphpartitioning-4cycle-qubo.json
    • ./target/debug/pred solve /tmp/problemreductions-pr706-LamKkl/graphpartitioning-4cycle.json -o /tmp/problemreductions-pr706-LamKkl/graphpartitioning-4cycle-solution.json
    • ./target/debug/pred solve /tmp/problemreductions-pr706-LamKkl/graphpartitioning-4cycle-qubo.json -o /tmp/problemreductions-pr706-LamKkl/graphpartitioning-4cycle-qubo-solution.json
    • ./target/debug/pred path GraphPartitioning QUBO
    • Repeated the same reduce/solve flow for the canonical example JSON from --example GraphPartitioning

Results

Aspect Result
Discoverability good
Setup yes
Functionality yes
Expected vs Actual matched
  • Discoverability: pred list exposed GraphPartitioning/SimpleGraph as a registered problem and pred show GraphPartitioning showed one outgoing reduction to QUBO/f64. pred path GraphPartitioning QUBO confirmed the one-step route. The generic docs in docs/src/cli.md correctly describe pred create --example <PROBLEM_SPEC> and pred reduce ... --to QUBO.
  • Setup: pred create --example GraphPartitioning succeeded and produced the canonical model example JSON. pred create GraphPartitioning --graph 0-1,1-2,2-3,3-0 also succeeded, resolving the default SimpleGraph variant as expected.
  • Functionality: pred reduce on the 4-cycle produced a bundle with path GraphPartitioning/SimpleGraph -> QUBO/f64 and a 4-variable QUBO target. pred solve on the source instance returned Valid(2) with solution [0, 1, 1, 0]. Solving the reduced bundle also worked and mapped back to the same source solution, with intermediate QUBO evaluation Valid(-18.0). The canonical example instance solved successfully as well, returning Valid(3) with solution [1, 1, 1, 0, 0, 0].
  • Expected vs Actual: matched. The new GraphPartitioning -> QUBO rule is both discoverable and usable from the CLI, and the reduced bundle round-trips correctly through solve.

Issues Found

  • Confirmed: none.
  • Not reproducible in current worktree: none.

Overall Verdict

  • Pass. The new GraphPartitioning -> QUBO rule works end-to-end from downstream CLI usage, including list, show, create --example, create, reduce, solve, and path.

Generated by review-pipeline

GiggleLiu and others added 2 commits March 21, 2026 11:56
After merging main (which added GraphPartitioning->MaxCut), the
indirect path GraphPartitioning->MaxCut->SpinGlass->QUBO dominates
the direct GraphPartitioning->QUBO reduction.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@GiggleLiu GiggleLiu merged commit d111c55 into main Mar 21, 2026
5 checks passed
@GiggleLiu GiggleLiu deleted the issue-119 branch April 12, 2026 00:50
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.

[Rule] GraphPartitioning to QUBO

1 participant