Skip to content

Convert timed mipgap to use termination callback mechanics - #810

Open
bknueven wants to merge 13 commits into
mainfrom
generalize-timed-mipgap
Open

Convert timed mipgap to use termination callback mechanics#810
bknueven wants to merge 13 commits into
mainfrom
generalize-timed-mipgap

Conversation

@bknueven

Copy link
Copy Markdown
Collaborator

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 mpi-sppy’s time-dependent MIP gap feature to rely on the unified “termination callback” infrastructure (instead of solver-specific callback mechanics), and expands/normalizes termination-callback behavior across supported persistent solvers.

Changes:

  • Refactors TimedMIPGapCB to register a generic termination callback (CPLEX/Gurobi/Xpress persistent) and adds robust parsing/validation of the gap:time curve.
  • Enhances termination-callback support with subclass-aware dispatch and improved solver-result status normalization (notably for CPLEX and Gurobi).
  • Adds targeted unit/integration tests and documents the new CLI flags and extension behavior.

Reviewed changes

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

Show a summary per file
File Description
mpisppy/utils/callbacks/termination/tests/test_termination.py Adds tests for subclass dispatch and solver status reporting for termination callbacks.
mpisppy/utils/callbacks/termination/termination_callbacks.py Implements setter lookup via isinstance (subclass support) and improves unsupported-solver error path.
mpisppy/utils/callbacks/termination/solver_callbacks.py Updates solver-specific callback wiring; normalizes postsolve statuses for callback-triggered stops (CPLEX/Gurobi) and updates Xpress termination mechanism.
mpisppy/tests/test_timed_mipgap.py Adds parsing/unit tests plus solver-backed integration checks for timed MIP gap termination.
mpisppy/extensions/timed_mipgap.py Refactors timed MIP gap to use termination callbacks and validates the timecurve input.
doc/src/generic_cylinders.rst Documents --timed-mipgap and --timed-mipgap-options flags.
doc/src/extensions.rst Adds detailed documentation for the timed MIP gap extension, its semantics, and solver requirements.

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

Comment thread mpisppy/extensions/timed_mipgap.py
@bknueven
bknueven marked this pull request as ready for review July 21, 2026 19:23
@bknueven
bknueven requested a review from tvalenciaz July 21, 2026 19:23
@codecov

codecov Bot commented Jul 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.23810% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.24%. Comparing base (3749661) to head (2d17eb0).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
mpisppy/extensions/timed_mipgap.py 92.30% 4 Missing ⚠️
...ls/callbacks/termination/tests/test_termination.py 95.23% 2 Missing ⚠️
mpisppy/cylinders/hub.py 94.11% 1 Missing ⚠️
mpisppy/utils/cfg_vanilla.py 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #810      +/-   ##
==========================================
+ Coverage   76.33%   77.24%   +0.90%     
==========================================
  Files         170      170              
  Lines       22628    22743     +115     
==========================================
+ Hits        17274    17568     +294     
+ Misses       5354     5175     -179     

☔ View full report in Codecov by Harness.
📢 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.

@DLWoodruff DLWoodruff left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

config.checker needs two updates:
0. --timed-mipgap-options given without --timed-mipgap is an error (does nothing; alternatively, you could make it do something)

  1. fwph_obj_gab_hub is a hub

@bknueven

Copy link
Copy Markdown
Collaborator Author

config.checker needs two updates: 0. --timed-mipgap-options given without --timed-mipgap is an error (does nothing; alternatively, you could make it do something)

1. fwph_obj_gab_hub is a hub

Not sure about (1) (at least for this PR), but for (0) we went with just --timed-mipgap as the option.

@tvalenciaz tvalenciaz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I only tested gurobi and xpress because I don't have CPLEX in my system. I had an issue with xpress, probably due to having to use an older version (9.7.1), but I think it would be easy to keep it compatible with both versions. Otherwise looks good to me!

# Per the Xpress documentation, this callback is invoked every time the
# Optimizer checks if the time limit has been reached. This is broader than
# what is presently needed for our MIP-based use cases.
xpress_problem.addCheckTimeCallback(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Using xpress 9.7.1 (the most recent my license allows), I had to change this to xpress_problem.addcbchecktime( for it to work.
I know from the email thread that this was running for you so it's probably due to the older version. Do we want to check which of addcbchecktime or addCheckTimeCallback exists and call that one?

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.

4 participants