Skip to content

Fix #210: [Model] Partition#664

Merged
isPANN merged 6 commits intomainfrom
issue-210-partition-v2
Mar 19, 2026
Merged

Fix #210: [Model] Partition#664
isPANN merged 6 commits intomainfrom
issue-210-partition-v2

Conversation

@GiggleLiu
Copy link
Copy Markdown
Contributor

Summary

Add the Partition problem model — a classical NP-complete satisfaction problem (Karp #20, Garey & Johnson SP12). Given a multiset of positive integers, decide whether it can be partitioned into two subsets of equal sum.

Implements the full model with brute-force solver support, canonical example, unit tests (>95% coverage), trait consistency, and paper entry.

Fixes #210

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 16, 2026

Codecov Report

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

Additional details and impacted files
@@           Coverage Diff            @@
##             main     #664    +/-   ##
========================================
  Coverage   97.42%   97.42%            
========================================
  Files         345      347     +2     
  Lines       44343    44459   +116     
========================================
+ Hits        43199    43315   +116     
  Misses       1144     1144            

☔ 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

  • src/models/misc/partition.rs — New Partition satisfaction problem model (Metric = bool, Vec<u64> sizes, evaluate checks selected_sum * 2 == total_sum)
  • src/unit_tests/models/misc/partition.rs — 14 unit tests covering basic accessors, satisfying/unsatisfying evaluation, edge cases (odd total, single element, two elements), solver integration, serialization, and panic paths
  • src/models/misc/mod.rs — Module registration + canonical example spec wiring
  • src/models/mod.rs — Re-export Partition
  • src/lib.rs — Added Partition to prelude
  • src/unit_tests/trait_consistency.rs — Added check_problem_trait entry
  • src/example_db/fixtures/examples.json — Regenerated (32 → 33 model examples)
  • docs/paper/reductions.typ — Added display-name entry + problem-def block after SubsetSum
  • docs/src/reductions/problem_schemas.json — Regenerated (41 → 42 schemas)
  • docs/src/reductions/reduction_graph.json — Regenerated

Deviations from Plan

  • None

Open Questions

  • None

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds the Partition satisfaction problem model to the misc model catalog, integrating it into the registry/docs/example DB and ensuring it participates in the project’s shared solver + trait infrastructure.

Changes:

  • Introduces Partition model (Problem<Metric=bool>) with schema registration, variant declaration, and canonical example specs.
  • Adds a dedicated unit test suite for Partition and wires it into trait-consistency checks.
  • Updates generated documentation artifacts (problem schemas, reduction graph), paper catalog entry, and example DB fixtures.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/unit_tests/trait_consistency.rs Adds Partition to the cross-model trait sanity test.
src/unit_tests/models/misc/partition.rs New unit tests for Partition behavior, solver integration, and serialization.
src/models/mod.rs Re-exports Partition from models::misc.
src/models/misc/partition.rs New Partition model implementation, schema inventory entry, variants, and example spec hook.
src/models/misc/mod.rs Registers the new module and exposes Partition in misc.
src/lib.rs Adds Partition to the public prelude exports.
src/example_db/fixtures/examples.json Adds canonical Partition fixture (samples + satisfying set).
docs/src/reductions/reduction_graph.json Adds Partition node and shifts indices accordingly (generated artifact).
docs/src/reductions/problem_schemas.json Adds Partition schema entry (generated artifact).
docs/paper/reductions.typ Adds Partition to the paper’s problem catalog and definition section.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

}

#[test]
#[should_panic(expected = "All sizes must be positive")]
Comment on lines +102 to +108
let selected_sum: u64 = config
.iter()
.enumerate()
.filter(|(_, &x)| x == 1)
.map(|(i, _)| self.sizes[i])
.sum();
selected_sum * 2 == self.total_sum()
Comment on lines +102 to +109
let selected_sum: u64 = config
.iter()
.enumerate()
.filter(|(_, &x)| x == 1)
.map(|(i, _)| self.sizes[i])
.sum();
selected_sum * 2 == self.total_sum()
}
@GiggleLiu
Copy link
Copy Markdown
Contributor Author

Agentic Review Report

Structural Check

Structural Review: model Partition

Structural Completeness

# Check Status
1 Model file exists PASS
2 inventory::submit! present PASS
3 #[derive(...Serialize, Deserialize)] on struct PASS
4 Problem trait impl PASS
5 SatisfactionProblem impl PASS
6 #[cfg(test)] + #[path = ...] test link PASS
7 Test file exists PASS
8 Test file has at least 3 tests PASS — 13 tests in src/unit_tests/models/misc/partition.rs
9 Registered in src/models/misc/mod.rs PASS
10 Re-exported in src/models/mod.rs PASS
11 declare_variants! entry exists PASS
12 CLI problem resolution PASS — pred show Partition works via the registry-backed resolver
13 CLI direct create support FAIL — pred create Partition --sizes 3,1,1,2,2,1 falls through to unknown_problem_error instead of constructing the model
14 Canonical model example registered PASS
15 Paper display-name entry PASS
16 Paper problem-def block PASS
17 No blacklisted auto-generated files committed FAIL — diff includes docs/src/reductions/problem_schemas.json, docs/src/reductions/reduction_graph.json, and src/example_db/fixtures/examples.json

Build Status

  • make test: PASS
  • make clippy: PASS

Semantic Review

  • evaluate() correctness: ISSUE — selected_sum * 2 == self.total_sum() in src/models/misc/partition.rs:108 can overflow on valid u64 inputs and panic instead of returning bool. total_sum() in src/models/misc/partition.rs:78 also uses unchecked fixed-width summation.
  • dims() correctness: OK — vec![2; self.num_elements()] matches one binary variable per element.
  • Size getter consistency: OK — num_elements() and total_sum() match the model definition and complexity string.
  • Weight handling: OK / N/A — model has no weight-type variant machinery.

Issue Compliance

# Check Status
1 Problem name matches issue OK
2 Mathematical definition matches issue OK
3 Problem type (sat) matches issue OK
4 Type parameters / schema match issue OK — sizes: Vec<u64>
5 Configuration space matches issue OK — one binary variable per element
6 Feasibility check matches issue ISSUE — valid large u64 inputs can panic during evaluation instead of returning the intended yes/no answer
7 Objective / metric matches issue OK — satisfaction problem with bool metric
8 Complexity matches issue OK — declared as 2^(num_elements / 2)

Summary

  • 15/17 structural checks passed
  • 7/8 issue compliance checks passed
  • FAIL: direct CLI creation for Partition is missing
  • FAIL: blacklisted auto-generated files are committed in the PR diff
  • ISSUE: Partition::evaluate() and total_sum() can overflow and panic on valid u64 inputs

Quality Check

Quality Review

Design Principles

  • DRY: ISSUE — the Partition schema is registered in the model catalog, but the hand-maintained direct-create dispatcher in problemreductions-cli/src/commands/create.rs was not updated. The result is split behavior: list, show, and create --example work, while direct create does not.
  • KISS: OK — the model itself is straightforward and easy to follow.
  • HC/LC: ISSUE — user-visible model support depends on several disconnected registration points. This PR updated the registry/example surfaces but not the direct-create switch, producing contradictory CLI behavior for the same model.

Test Quality

  • Naive test detection: ISSUE
    • src/unit_tests/models/misc/partition.rs covers only small integers and never exercises overflow boundaries for the public Vec<u64> schema.
    • No CLI test covers pred create Partition --sizes ..., so the broken direct-create path was not caught.

Issues

Critical (Must Fix)

  • pred solve partition-overflow.json --solver brute-force --json panics on a valid Partition instance with sizes=[18446744073709551615]. Root cause: unchecked arithmetic in src/models/misc/partition.rs:78 and src/models/misc/partition.rs:108.

Important (Should Fix)

  • pred create Partition --sizes 3,1,1,2,2,1 fails with Unknown problem: Partition even though pred show Partition and pred create Partition help both work. The dispatcher in problemreductions-cli/src/commands/create.rs has no Partition arm and falls through to unknown_problem_error at problemreductions-cli/src/commands/create.rs:1104.
  • The PR commits generated artifacts: docs/src/reductions/problem_schemas.json, docs/src/reductions/reduction_graph.json, and src/example_db/fixtures/examples.json. The graph JSON also introduces broad unrelated node-index churn.

Minor (Nice to Have)

  • Add a CLI-facing regression test for direct Partition creation and a model-level overflow boundary test so future model additions do not regress in the same way.

Summary

  • ISSUE: direct-create support drifted out of sync with the registered Partition schema
  • ISSUE: overflow on valid u64 inputs causes a user-visible panic
  • ISSUE: tests miss both the direct CLI path and large-input arithmetic boundaries
  • ISSUE: generated artifacts are committed in the PR

Agentic Feature Tests

Feature Test Report: problem-reductions

Date: 2026-03-19 22:52:42 +0800
Project type: CLI + library
Features tested: Partition model
Profile: ephemeral
Use Case: Discover the new Partition model from the CLI, materialize an example, solve it, and create a custom instance from raw sizes.
Expected Outcome: Partition should appear in the catalog, pred show Partition should describe it, pred create --example Partition should emit a usable instance, pred solve should solve that instance, and pred create Partition --sizes ... should work for custom inputs without panicking on valid values.
Verdict: fail
Critical Issues: 2

Summary

Feature Discoverable Setup Works Expected Outcome Met Doc Quality
Partition model yes yes partial no partial

Per-Feature Details

Partition model

  • Role: CLI user validating a newly added model from docs and built-in examples.
  • Use Case: Find the new model in the catalog, inspect it, create an example instance, solve it, then create and solve a custom instance.
  • What they tried: pred list --json, pred show Partition --json, pred create --example Partition, pred solve partition-example.json --solver brute-force --json, pred create Partition --sizes 3,1,1,2,2,1, and pred solve partition-overflow.json --solver brute-force --json.
  • Discoverability: Good. Partition appears in pred list, pred show Partition works, and pred create Partition with no data flags prints schema-driven help listing --sizes.
  • Setup: Good. No special setup beyond building the CLI in the review worktree.
  • Functionality: Partial. The example flow works end to end, but direct CLI creation of a custom Partition instance fails, and solving a valid large-input instance panics.
  • Expected vs Actual Outcome: The documented example path works, but the custom-instance path is broken and large valid inputs are not handled safely.
  • Blocked steps: None.
  • Friction points: pred create Partition advertises --sizes in help, but pred create Partition --sizes ... fails with Unknown problem: Partition, which is contradictory and surprising.
  • Doc suggestions: Once fixed, add an explicit Partition example to the CLI docs alongside SubsetSum, or clearly document that only --example creation is supported if that is intentional.

Expected vs Actual Outcome

The expected user path was only partially achieved. Catalog discovery, problem inspection, canonical example creation, and brute-force solving all worked. Custom Partition instance creation from raw sizes did not work, and a valid u64 input caused a panic during solving instead of returning a result.

Issues Found

  • Critical: Valid u64 inputs can panic during evaluation and solve. Reproduction: solving {"type":"Partition","variant":{},"data":{"sizes":[18446744073709551615]}} with pred solve ... --solver brute-force panics at src/models/misc/partition.rs:108.
  • Critical: Direct custom instance creation is broken. Reproduction: pred create Partition --sizes 3,1,1,2,2,1 returns Unknown problem: Partition even though pred list and pred show Partition both succeed.

Suggestions

  • Handle Partition arithmetic without fixed-width overflow, or reject oversized inputs explicitly instead of panicking.
  • Add the missing direct-create support for Partition in the CLI dispatcher so pred create Partition --sizes ... matches the schema help and catalog visibility.

Generated by review-pipeline

@isPANN isPANN self-assigned this Mar 19, 2026
isPANN added 2 commits March 20, 2026 00:20
# Conflicts:
#	docs/src/reductions/problem_schemas.json
#	docs/src/reductions/reduction_graph.json
#	src/example_db/fixtures/examples.json
#	src/lib.rs
#	src/models/misc/mod.rs
#	src/models/mod.rs
#	src/unit_tests/trait_consistency.rs
@isPANN isPANN mentioned this pull request Mar 19, 2026
3 tasks
@isPANN isPANN merged commit 14d8ea0 into main Mar 19, 2026
5 checks passed
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.

[Model] Partition

3 participants