Skip to content

Fix #120: [Rule] GraphPartitioning to MaxCut#707

Merged
isPANN merged 9 commits intomainfrom
issue-120
Mar 20, 2026
Merged

Fix #120: [Rule] GraphPartitioning to MaxCut#707
isPANN merged 9 commits intomainfrom
issue-120

Conversation

@GiggleLiu
Copy link
Copy Markdown
Contributor

Summary

Add the implementation plan for the GraphPartitioning to MaxCut reduction.

Fixes #120

@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.55%. Comparing base (bb726f8) to head (1e4157d).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #707      +/-   ##
==========================================
+ Coverage   97.53%   97.55%   +0.01%     
==========================================
  Files         373      375       +2     
  Lines       47182    47272      +90     
==========================================
+ Hits        46020    46116      +96     
+ Misses       1162     1156       -6     

☔ 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

Implementation Summary

Changes

  • Added GraphPartitioning -> MaxCut with a weighted-complete-graph construction in src/rules/graphpartitioning_maxcut.rs.
  • Added focused rule tests in src/unit_tests/rules/graphpartitioning_maxcut.rs covering closed-loop optimality, target weights/size, identity extraction, and penalty overflow guarding.
  • Registered the rule and its canonical example in src/rules/mod.rs.
  • Added a reduction-rule("GraphPartitioning", "MaxCut", ...) entry with a worked 6-vertex example in docs/paper/reductions.typ.
  • Regenerated and verified the gitignored reduction graph, problem schemas, and paper example export.

Deviations from Plan

  • The plan referenced make regenerate-fixtures and tracked JSON fixture paths that do not exist in this checkout. This repo regenerates the needed example data via cargo run --features "example-db" --example export_examples, and the generated outputs under docs/src/reductions/ and docs/paper/data/ are gitignored.
  • Added one small hardening follow-up after code review: the reduction now checks that num_edges + 1 fits in i32 before using it as the MaxCut penalty weight.

Open Questions

  • None.

@GiggleLiu
Copy link
Copy Markdown
Contributor Author

Agentic Review Report

Structural Check

Structural Review: rule graphpartitioning_maxcut

Structural Completeness

# Check Status
1 Rule file exists PASS — src/rules/graphpartitioning_maxcut.rs exists
2 #[reduction(...)] macro present PASS
3 ReductionResult impl present PASS
4 ReduceTo impl present PASS
5 #[cfg(test)] + #[path = "..."] test link PASS
6 Test file exists PASS — src/unit_tests/rules/graphpartitioning_maxcut.rs exists
7 Closed-loop test present PASS
8 Registered in rules/mod.rs PASS
9 Canonical rule example registered PASS
10 Example-db lookup tests exist PASS
11 Paper reduction-rule entry PASS

Build Status

  • make test: PASS
  • make clippy: PASS

Semantic Review

  • extract_solution correctness: OK for the intended even-vertex domain.
  • Overhead accuracy: OK.
  • Example quality: OK.
  • Paper quality: OK for even-vertex instances.
  • Correctness domain: ISSUE — odd-vertex GraphPartitioning instances are infeasible in the source model, but reduce_to() still constructs an ordinary MaxCut instance and extract_solution() returns an infeasible source assignment.

Issue Compliance

# Check Status
1 Source/target match issue OK
2 Reduction algorithm matches OK
3 Solution extraction matches OK
4 Correctness preserved ISSUE — only preserved for even-vertex inputs
5 Overhead expressions match OK
6 Example matches OK

Summary

  • 11/11 structural checks passed
  • 5/6 issue compliance checks passed
  • ISSUE: the reduction does not enforce or encode the even-vertex precondition required by GraphPartitioning, so it is not correct for odd-vertex source instances.

Quality Check

Quality Review

Design Principles

  • DRY: OK.
  • KISS: ISSUE — the rule looks simple, but it silently depends on an unstated runtime precondition (num_vertices must be even).
  • HC/LC: OK.

Test Quality

  • Naive test detection: ISSUE
    • The new tests cover the happy-path example and overflow, but not the reachable odd-vertex boundary case.

Issues

Critical (Must Fix)

  • Odd-vertex source instances are not handled correctly. GraphPartitioning treats odd-vertex graphs as infeasible, but this reduction still produces a valid MaxCut instance and identity-extracts a source assignment. Because odd-vertex GraphPartitioning instances are publicly creatable, this is a real correctness hole.

Important (Should Fix)

  • Add a regression test covering odd-vertex rejection/handling.

Minor (Nice to Have)

  • None.

Summary

  • Hidden even-vertex precondition makes the reduction incomplete over the public GraphPartitioning API.
  • The new tests miss the boundary case that exposes the bug.

Agentic Feature Tests

Agentic Feature Tests

Summary

  • Discoverability: pass.
  • Setup: pass.
  • Functionality: pass on the canonical example path.

Findings

  • None confirmed on the canonical example flow.
  • Manual edge-case reproduction found a separate correctness problem outside the happy path:
    • pred solve on an odd-vertex source instance fails with Error: No solution found.
    • pred reduce of that same instance to MaxCut, followed by pred solve, returns a source evaluation: Invalid with an intermediate MaxCut optimum, showing the reduction does not preserve infeasibility.

Commands Exercised

  • pred list
  • pred show GraphPartitioning
  • pred show MaxCut
  • pred create --example GraphPartitioning
  • pred solve <canonical-source> --solver brute-force
  • pred reduce <canonical-source> --to MaxCut
  • pred solve <canonical-reduction-bundle> --solver brute-force
  • Edge case: pred create GraphPartitioning --graph 0-1,1-2 | pred reduce - --to MaxCut

isPANN and others added 2 commits March 21, 2026 01:43
- Fix mod.rs ordering for graphpartitioning_maxcut
- Fix rustfmt issues in test file and qbf.rs (from merge)
- Fix clippy needless_range_loop in closestvectorproblem_qubo.rs

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@isPANN isPANN merged commit 68c744b into main Mar 20, 2026
5 checks passed
@GiggleLiu GiggleLiu deleted the issue-120 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 MaxCut

2 participants