Skip to content

docs: improve example instances implementation plan#41

Merged
GiggleLiu merged 15 commits intomainfrom
docs/improve-example-instances-plan-v2
Feb 11, 2026
Merged

docs: improve example instances implementation plan#41
GiggleLiu merged 15 commits intomainfrom
docs/improve-example-instances-plan-v2

Conversation

@GiggleLiu
Copy link
Contributor

@GiggleLiu GiggleLiu commented Feb 10, 2026

Summary

  • Updates all 30 reduction examples with non-trivial instances (Petersen graph, 5-variable SAT, full adder circuit, etc.)
  • Implements new 3-SAT to QUBO reduction using Rosenberg quadratization with auxiliary variables
  • Documents the 3-SAT→QUBO reduction in reductions.typ

Test plan

  • make test — all tests pass
  • make clippy — no warnings
  • All 30 examples run successfully with verified solutions
  • New 3-SAT reduction has closed-loop, single-clause, and all-negated unit tests

🤖 Generated with Claude Code

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

[action]

@codecov
Copy link

codecov bot commented Feb 10, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.37%. Comparing base (c400651) to head (6381f98).

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #41   +/-   ##
=======================================
  Coverage   97.37%   97.37%           
=======================================
  Files         176      176           
  Lines       26217    26217           
=======================================
  Hits        25530    25530           
  Misses        687      687           

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

Add an interactive Cytoscape.js-based reduction graph page to the mdBook
documentation. The page loads reduction_graph.json, filters to base
problem nodes, deduplicates edges, and renders an explorable directed
graph with category-colored nodes and two-click shortest-path highlighting.

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

Plan Execution Summary: JSON Schema & Interactive Viz

Executed docs/plans/2026-02-10-json-schema-and-interactive-viz.md.

Status

Tasks 1–5 were already completed and merged (PRs #36 and #38). This execution completed the remaining work:

Task Status
1. Add FieldInfo/ProblemSchemaEntry to registry Already merged (PR #36)
2. Register all 20 problem schemas Already merged (PR #36)
3. Create export_schemas example + Makefile target Already merged (PR #36)
4. Update typst to read from JSON Already merged (PR #38)
5. Remove reduction diagram from typst Already merged (PR #36)
6. Interactive Cytoscape.js page in mdBook Done
7. Final verification Done

What was done (Task 6)

Created interactive Cytoscape.js reduction graph page:

  • docs/src/reductions/graph.md — Embedded Cytoscape.js visualization with:
    • Cose force-directed layout with ~15 base problem nodes
    • Category-colored nodes (graph/set/optimization/satisfiability/specialized)
    • Directed/bidirectional edge arrows
    • Two-click shortest-path highlighting using Dijkstra
    • Color legend and "Clear Path" controls
    • Non-blocking "no path found" notification
  • docs/src/SUMMARY.md — Added "Reductions" section linking to the graph page

Verification

  • make test: 1662 tests pass (1551 unit + 62 integration + 49 doc-tests)
  • make clippy: Clean (0 warnings)
  • make paper: Pre-existing typst label errors for bidirectional reduction references (not introduced by this change)
  • make doc: mdbook not available on this runner; export_graph + JSON copy verified

@GiggleLiu
Copy link
Contributor Author

[action]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Remove this file.

- [Solvers](./solvers.md)
- [File I/O](./io.md)

# Reductions
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Remove the added lines.

@GiggleLiu
Copy link
Contributor Author

[action] implement first 10 examples.

GiggleLiu and others added 10 commits February 11, 2026 02:41
Replace trivial P4 path graph (4 vertices, 3 edges, MIS=2) with the
Petersen graph (10 vertices, 15 edges, 3-regular, MIS=4) in all four
MIS reduction examples: QUBO, ILP, MinimumVertexCover, MaximumSetPacking.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace trivial K3/triangle instances with more interesting graphs:
- kcoloring_to_ilp: Petersen graph (10v, 15e) with ILPSolver
- kcoloring_to_qubo: house graph (5v, 6e) to keep BruteForce feasible
- maxcut_to_spinglass: Petersen graph (10v, 15e) with unit weights

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace trivial 3-set instances with richer 6-set instances over
8 elements in SetPacking (QUBO and ILP) and SetCovering (ILP) examples.
The new instances have interesting overlap structure and produce
max packing size 2 and min cover size 3.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace trivial 2-3 variable SAT formulas with richer 5-variable instances
across 4 SAT reduction examples:
- sat_to_mis: 5-var, 7-clause 3-SAT (21 vertices, fast BruteForce)
- sat_to_coloring: 5-var, 3 unit clauses (13 vertices; OR-gadgets make
  multi-literal clauses infeasible for BruteForce on 3-coloring)
- sat_to_mds: 5-var, 7-clause 3-SAT (22 vertices, fast BruteForce)
- sat_to_ksat: 5-var, 6-clause mixed sizes (1,2,3,3,4,5 literals) to
  demonstrate both padding and splitting transformations

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Generalize the KSatisfiability-to-QUBO reduction to support K=3 using
Rosenberg quadratization (one auxiliary variable per 3-literal clause).
Update the example from a trivial 2-SAT/3-variable instance to a
3-SAT instance with 5 variables and 7 clauses, producing a 12-variable
QUBO (5 original + 7 auxiliary).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace trivial 3-spin/3-variable instances with 10-variable Petersen
graph instances for SpinGlass-QUBO and SpinGlass-MaxCut reductions.

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

Improved Example Instances — Tasks 1–10 Complete

Implemented the first 10 tasks from the improvement plan. All 27 example files across tasks 1–10 have been updated with non-trivial instances.

Summary of Changes

Task Files Old Instance New Instance
1 4 MIS→{QUBO,ILP,MVC,MSP} Path P4 (4v, 3e) Petersen (10v, 15e, MIS=4)
2 4 MVC→{ILP,QUBO,MIS,MSC} Cycle C4 / Triangle K3 Petersen (10v, 15e, VC=6)
3 3 {Matching,DomSet}→{ILP,MSP} Path P4 (4v, 3e) Petersen (Matching=5, DomSet=3)
4 3 {Coloring,MaxCut}→{ILP,QUBO,SG} Triangle K3 Petersen (ILP, MaxCut) / House (QUBO, χ=3)
5 1 Clique→ILP 4-vertex graph Octahedron K₂,₂,₂ (6v, 12e, ω=3)
6 3 {SetPacking,SetCovering}→{QUBO,ILP} 3 sets / universe 3–5 6 sets over universe {0..7}
7 4 SAT→{MIS,Coloring,DomSet,kSAT} 2–4 var, 1–2 clause 5 var, 3–7 clause 3-SAT
8 1 kSAT→QUBO 2-SAT, 3 vars 3-SAT, 5 vars, 7 clauses
9 3 {SG↔QUBO↔MaxCut} 3-spin chain/triangle Petersen ±1 couplings (10 spins)
10 1 ILP→QUBO 3-var project selection 6-var binary knapsack

Notable Implementation Details

  • Task 4 (Coloring→QUBO): Used house graph (5v) instead of Petersen (10v) to keep QUBO at 15 variables (vs 30 which is too slow for BruteForce)
  • Task 4 (Coloring→ILP): Switched from BruteForce to ILPSolver since Petersen×3colors = 30 ILP variables
  • Task 7 (SAT→Coloring): Used unit clauses to keep the 3-Coloring target graph small enough for BruteForce
  • Task 8 (3-SAT→QUBO): Implemented new ReduceTo<QUBO> for KSatisfiability<3> using Rosenberg quadratization (cubic→quadratic), with 3 new unit tests

Verification

  • ✅ All examples run without panics and produce verified solutions
  • make test — all 1554+ tests pass
  • make clippy — no warnings
  • ✅ 10 clean commits, one per task

Remaining (Tasks 11–13)

Tasks 11 (CircuitSAT), 12 (Factoring), and 13 (JSON regeneration) are not included in this batch.

🤖 Generated with Claude Code

@GiggleLiu
Copy link
Contributor Author

[action] implement the next batch of 10 examples refactor.

GiggleLiu and others added 2 commits February 11, 2026 09:52
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions
Copy link

Batch 3: Tasks 11-13 completed

Task 11: CircuitSAT → SpinGlass (cdb00cb)

  • Replaced trivial AND gate circuit (2 inputs, 3 variables) with 1-bit full adder (3 inputs: a, b, cin → 2 outputs: sum, cout)
  • 5 gates (2 XOR, 2 AND, 1 OR), 8 CircuitSAT variables → 15 SpinGlass spins, 24 interactions
  • All 8 ground states (2³ input combinations) map to valid circuit assignments

Task 12: Factoring → CircuitSAT & ILP (53d8b7d)

  • Replaced Factoring(2, 2, 6) (factor 6 = 2×3, 4 variables) with Factoring(3, 3, 35) (factor 35 = 5×7, 6 variables)
  • factoring_to_circuitsat: 60 CircuitSAT variables, 60 gates; finds both 5×7 and 7×5
  • factoring_to_ilp: 21 ILP variables, 34 constraints; solved with ILPSolver

Task 13: Verification

  • make examples — all 30 examples ran successfully, 60 JSON files exported
  • make test — 1554 unit + 62 integration + 49 doc tests: all passing
  • make clippy — no warnings

All 13 tasks from the plan are now complete (Tasks 1-10 in previous batches, Tasks 11-13 in this batch).

🤖 Generated with Claude Code

/// Result of reducing KSatisfiability<3> to QUBO.
#[derive(Debug, Clone)]
pub struct ReductionK3SatToQUBO {
target: QUBO<f64>,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should not it be 3SAT rather than K3Sat?

//! - (x_i ∨ ¬x_j): penalty (1-x_i)x_j → Q[j][j]+=1, Q[i][j]-=1
//! - (¬x_i ∨ ¬x_j): penalty x_i·x_j → Q[i][j]+=1
//!
//! For K≥3, we use the Rosenberg quadratization to reduce degree-K penalty terms
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Describe this in detail in reductions.typ

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 updates example instances across all 30 reduction examples, replacing trivial test cases with non-trivial ones to generate better demonstration data. The PR includes significant code changes beyond just documentation updates:

Changes:

  • Implements new K=3 SAT to QUBO reduction using Rosenberg quadratization with auxiliary variables
  • Updates 24 example files to use Petersen graph (10 vertices, 15 edges) instead of trivial graphs (K3, P4, etc.)
  • Updates SAT examples to use 5-variable, 7-clause formulas instead of 2-3 variable formulas
  • Adds interactive reduction graph visualization documentation
  • Switches from BruteForce to ILPSolver where appropriate for performance

Reviewed changes

Copilot reviewed 36 out of 36 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/rules/ksatisfiability_qubo.rs Implements K=3 SAT to QUBO reduction with Rosenberg quadratization, introduces auxiliary variables, updates extract_solution
src/unit_tests/rules/ksatisfiability_qubo.rs Adds comprehensive tests for 3-SAT reduction including closed-loop, single clause, and all-negated cases
src/rules/mod.rs Exports new ReductionK3SatToQUBO type
examples/reduction_spinglass_to_*.rs Updates SpinGlass examples to use Petersen graph with frustrated ±1 couplings
examples/reduction_satisfiability_to_*.rs Updates SAT examples to use 5-variable, 7-clause 3-SAT formulas
examples/reduction_to.rs (graph-based) Updates graph examples to use Petersen or House graphs depending on performance constraints
examples/reduction_*_to_ilp.rs Switches several examples from BruteForce to ILPSolver for better performance on larger instances
examples/reduction_ilp_to_qubo.rs Replaces 3-variable project selection with 6-variable knapsack problem
examples/reduction_factoring_to_*.rs Updates from factoring 15 (4-bit) to factoring 35 (3-bit)
examples/reduction_maximumsetpacking_to_*.rs Updates from 3 sets to 6 sets with more complex overlap patterns
examples/reduction_kcoloring_to_*.rs Uses House graph (5 vertices) for QUBO to keep BruteForce feasible, uses Petersen for ILP with ILPSolver
examples/reduction_satisfiability_to_kcoloring.rs Uses unit clauses to avoid OR-gadget vertex explosion
examples/reduction_circuitsat_to_spinglass.rs Updates from simple AND gate to 1-bit full adder circuit
docs/src/reductions/graph.md Adds interactive Cytoscape-based reduction graph visualization
docs/src/SUMMARY.md Adds Reduction Graph section to documentation
docs/plans/2026-02-10-improve-example-instances-impl.md Updates plan title to v2

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

Comment on lines +1 to 15
//! Reduction from KSatisfiability to QUBO (Max-K-SAT).
//!
//! Each clause contributes to Q based on literal signs:
//! For K=2 (quadratic penalty), each clause contributes to Q based on literal signs:
//! - (x_i ∨ x_j): penalty (1-x_i)(1-x_j) → Q[i][i]-=1, Q[j][j]-=1, Q[i][j]+=1, const+=1
//! - (¬x_i ∨ x_j): penalty x_i(1-x_j) → Q[i][i]+=1, Q[i][j]-=1
//! - (x_i ∨ ¬x_j): penalty (1-x_i)x_j → Q[j][j]+=1, Q[i][j]-=1
//! - (¬x_i ∨ ¬x_j): penalty x_i·x_j → Q[i][j]+=1
//!
//! For K≥3, we use the Rosenberg quadratization to reduce degree-K penalty terms
//! to quadratic form by introducing auxiliary variables. Each clause of K literals
//! requires K−2 auxiliary variables.
//!
//! CNFClause uses 1-indexed signed integers: positive = variable, negative = negated.

use crate::models::optimization::QUBO;
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

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

The PR description states "No code changes; documentation only" in the test plan, but this PR contains significant code changes including:

  1. New K=3 SAT to QUBO reduction implementation with Rosenberg quadratization
  2. New unit tests for the 3-SAT reduction
  3. Modified extract_solution to handle auxiliary variables
  4. New reduction result type ReductionK3SatToQUBO
  5. Export updates in mod.rs

The PR description should be updated to accurately reflect that this includes both code changes and documentation updates.

Copilot uses AI. Check for mistakes.
@GiggleLiu
Copy link
Contributor Author

[fix]

- Remove interactive reduction graph page (docs/src/reductions/graph.md)
- Remove Reductions section from SUMMARY.md
- Rename ReductionK3SatToQUBO to Reduction3SATToQUBO
- Document 3-SAT→QUBO Rosenberg quadratization in reductions.typ
- Update PR description to reflect code changes

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

Review Feedback Addressed

All review comments have been fixed in commit 96b1736:

Review Comment Action
"Remove this file" (graph.md) Deleted docs/src/reductions/graph.md
"Remove the added lines" (SUMMARY.md) Removed Reductions section from docs/src/SUMMARY.md
"Should not it be 3SAT rather than K3Sat?" Renamed ReductionK3SatToQUBOReduction3SATToQUBO
"Describe this in detail in reductions.typ" Added K=3 Rosenberg quadratization description to the KSatisfiability→QUBO reduction rule
"PR description should be updated" (Copilot) Updated PR body to reflect code + documentation changes

Verification

  • make test — all tests pass (1554 unit + 62 integration + 49 doc-tests)
  • make clippy — clean, no warnings

🤖 Generated with Claude Code

@GiggleLiu GiggleLiu merged commit 142d3c2 into main Feb 11, 2026
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.

2 participants