Skip to content

Comments

Reduce exported functions (#77)#79

Merged
GiggleLiu merged 8 commits intomainfrom
reduce-exports
Feb 16, 2026
Merged

Reduce exported functions (#77)#79
GiggleLiu merged 8 commits intomainfrom
reduce-exports

Conversation

@GiggleLiu
Copy link
Contributor

Summary

  • Internalize ~30 ReductionXToY structs, gadget functions, and JSON serialization types from rules module
  • Internalize unitdiskmapping implementation details (CopyLine, MappingGrid, Pattern, etc.)
  • Make polynomial, truth_table modules pub(crate); delete unused graph_types module
  • Add is_valid_solution() method to all problem types (15 types) and cut_size() to MaxCut
  • Internalize 17 standalone validation free functions (is_independent_set, is_clique, etc.)
  • Internalize config_to_bits/bits_to_config utility functions
  • Slim down prelude: remove config utilities, registry metadata, variant system, ILP support types

Test plan

  • make test — all 1477 unit + 91 integration + 45 doc tests pass
  • make clippy — zero warnings with -D warnings
  • All examples compile and run correctly
  • Public API surface verified: no leaked implementation details in cargo doc

Closes #77

🤖 Generated with Claude Code

GiggleLiu and others added 8 commits February 16, 2026 23:48
Remove public re-exports of ~30 ReductionXToY structs, 6 gadget
functions, BoolVar, LogicGadget, and JSON serialization types
(EdgeJson, NodeJson, ReductionGraphJson) from rules/mod.rs. Users
interact with reductions via the ReduceTo trait or ReductionGraph,
never referencing these structs by name.

Also remove unused ReductionColoringToILP type alias and suppress
dead_code warnings on LogicGadget fields only read in tests.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Change internal type re-exports (CopyLine, MappingGrid, CellState,
Pattern, etc.) from pub to pub(crate) in unitdiskmapping/mod.rs.
Change alpha_tensor and pathdecomposition modules to pub(crate).

Add #[cfg(test)] guards on re-exports only needed by unit tests.
Add #[doc(hidden)] _internal module for the export_mapping_stages
example which needs these types.

Keep ksg, triangular modules and GridKind/MappingResult as pub.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…es module

- Change polynomial and truth_table modules from pub to pub(crate)
  since they are only used internally via crate:: imports.
- Delete graph_types.rs and its unit test file (zero internal imports,
  confirmed by codebase audit; actual graph types live in topology/).
- Remove truth_table integration tests from tests/suites/reductions.rs
  (equivalent coverage exists in src/unit_tests/truth_table.rs).
- Remove doc example from TruthTable since the module is now internal.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add public is_valid_solution(&self, config: &[usize]) -> bool methods to
all graph problem types, delegating to existing private validation helpers.
Also add cut_size method to MaxCut for computing partition cut sizes.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add public is_valid_solution methods to MaximumSetPacking,
MinimumSetCovering, BicliqueCover, CircuitSAT, and Factoring.
Each delegates to existing validation logic. PaintShop already
has count_switches and BMF is skipped per design.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Change standalone validation free functions (is_independent_set,
is_vertex_cover, is_clique, etc.) from pub to pub(crate) with #[cfg(test)]
for test-only functions. Functions still used in non-test code
(is_valid_coloring, is_hamiltonian_cycle, cut_size) remain pub(crate)
without #[cfg(test)].

- Change 17 validation functions from pub to pub(crate)
- Add #[cfg(test)] to 14 functions only used in tests
- Remove validation function re-exports from graph/set/specialized mod.rs
- Make submodules pub(crate) for crate-internal test access
- Update graph_models.rs imports to use full module paths

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Change these utility functions from pub to pub(crate) with #[cfg(test)]
since they are only used in unit tests. This reduces the public API
surface of the config module.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Remove from prelude: config utilities, registry types, variant types,
ILP/optimization internals, NumericSize, and WeightElement. These items
remain accessible via their full module paths.

Add explicit imports to 16 examples, 2 integration test files that
previously relied on the broader prelude:
- ILP type: 13 examples + 1 test file
- K3/K2 variant types: 7 examples + 2 test files
- LinearConstraint/ObjectiveSense: 1 example + 1 test file

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@codecov
Copy link

codecov bot commented Feb 16, 2026

Codecov Report

❌ Patch coverage is 31.50685% with 50 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.10%. Comparing base (ddc9f85) to head (b1e890d).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/models/graph/max_cut.rs 14.28% 6 Missing ⚠️
src/models/set/minimum_set_covering.rs 16.66% 5 Missing ⚠️
src/models/graph/kcoloring.rs 25.00% 3 Missing ⚠️
src/models/graph/maximal_is.rs 25.00% 3 Missing ⚠️
src/models/graph/maximum_clique.rs 25.00% 3 Missing ⚠️
src/models/graph/maximum_independent_set.rs 25.00% 3 Missing ⚠️
src/models/graph/maximum_matching.rs 25.00% 3 Missing ⚠️
src/models/graph/minimum_dominating_set.rs 25.00% 3 Missing ⚠️
src/models/graph/minimum_vertex_cover.rs 25.00% 3 Missing ⚠️
src/models/graph/traveling_salesman.rs 25.00% 3 Missing ⚠️
... and 5 more

❌ Your patch status has failed because the patch coverage (31.50%) is below the target coverage (95.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #79      +/-   ##
==========================================
- Coverage   96.28%   96.10%   -0.19%     
==========================================
  Files         194      193       -1     
  Lines       26546    26567      +21     
==========================================
- Hits        25561    25532      -29     
- Misses        985     1035      +50     

☔ 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.

Copy link

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

This PR significantly reduces the public API surface of the problemreductions crate to improve clarity and maintainability. The changes focus on internalizing implementation details that were unnecessarily exposed while keeping the core problem types and reduction functionality public.

Changes:

  • Internalized ~30 reduction struct types and gadget functions from the rules module, requiring users to use trait-based reductions instead
  • Made polynomial and truth_table modules pub(crate) as they are internal implementation details
  • Deleted the unused graph_types module (graph type markers now in topology module)
  • Added is_valid_solution() method to 14 problem types where validation is non-trivial
  • Internalized 17 validation helper functions (e.g., is_independent_set, is_clique) to internal module paths
  • Slimmed down the prelude by removing ILP-specific types, config utilities, registry metadata, and variant system types (still accessible via their respective modules)
  • Added _internal module in unitdiskmapping for development tools like examples

Reviewed changes

Copilot reviewed 54 out of 54 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/lib.rs Updated prelude to remove ILP types, config utilities, variant system, and internal types; removed graph_types module
src/graph_types.rs Deleted entirely - functionality moved to topology module
src/truth_table.rs Made pub(crate) and removed public documentation example
src/config.rs Made config_to_bits and bits_to_config internal test utilities
src/rules/mod.rs Removed public exports of ~30 reduction types and JSON serialization structures
src/rules/graph.rs Made JSON serialization types (ReductionGraphJson, NodeJson, EdgeJson) internal
src/rules/coloring_ilp.rs Removed backwards compatibility type alias ReductionColoringToILP
src/rules/circuit_spinglass.rs Added #[allow(dead_code)] to public fields used only in tests
src/rules/unitdiskmapping/mod.rs Internalized implementation modules; added _internal for development tools
src/rules/unitdiskmapping/*.rs Made various implementation details pub(crate) and added #[allow(dead_code)] where appropriate
src/models/graph/*.rs Added is_valid_solution() methods; made validation helpers pub(crate)
src/models/set/*.rs Added is_valid_solution() methods; made validation helpers pub(crate)
src/models/satisfiability/*.rs Added is_valid_solution() to Satisfiability; made is_satisfying_assignment internal
src/models/specialized/*.rs Added is_valid_solution() methods; made validation helpers pub(crate)
tests/suites/*.rs Updated imports for ILP types and variant types; removed truth_table tests (moved to unit tests)
examples/*.rs Added explicit imports for ILP types and variant types removed from prelude
src/unit_tests/graph_models.rs Updated imports to use internal paths for validation functions
src/unit_tests/graph_types.rs Deleted along with graph_types module
Comments suppressed due to low confidence (1)

src/rules/unitdiskmapping/pathdecomposition.rs:418

  • The documentation example has been changed from a runnable code block (rust) to a non-runnable text block (text), but the example code still contains valid Rust code that appears intended to demonstrate usage. Since the pathwidth function and PathDecompositionMethod are now pub(crate), the example can't be tested in doc tests anymore. However, consider keeping this as a proper Rust code block with the ignore or no_run attribute (e.g., rust,ignore) to maintain proper syntax highlighting and IDE support, rather than using text which loses these benefits.

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

@GiggleLiu GiggleLiu merged commit 5be5149 into main Feb 16, 2026
11 of 12 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.

Reduce exported functions

1 participant