funkelab / ilpy

Unified python wrappers for popular ILP solvers
https://funkelab.github.io/ilpy/
MIT License
3 stars 2 forks source link

feat: Improve structure of data provided to event callbacks, extract more stats and provide type hints for callback data #57

Closed tlambert03 closed 5 months ago

tlambert03 commented 5 months ago

This adds more statistics to the event data passed to callbacks during solving. There is a new type stub called event_data.pyi that contains all the keys and their types that you might find. (only available inside of an if TYPE_CHECKING clause)

Suggested usage:

import ilpy

if TYPE_CHECKING:
    from ilpy import EventData

def callback(data: EventData) -> None:
    # backend and event_type are guaranteed to be present
    # they will narrow down the available keys
    if data["backend"] == "gurobi":
        if data["event_type"] == "MIP":
            print(data["gap"])

    # if you don't care about IDE type checking,
    # you may of course just also delicately look for a key:
    print(data.get("gap"))

ilpy.solve(..., on_event=callback)
codecov[bot] commented 5 months ago

Codecov Report

Attention: Patch coverage is 23.50427% with 179 lines in your changes are missing coverage. Please review.

Project coverage is 59.29%. Comparing base (0fdfae7) to head (6f062b8). Report is 2 commits behind head on main.

Files Patch % Lines
ilpy/impl/solvers/GurobiEventHandler.h 0.00% 125 Missing :warning:
ilpy/impl/solvers/ScipEventHandler.h 47.47% 52 Missing :warning:
ilpy/impl/solvers/SolverBackend.h 77.77% 1 Missing and 1 partial :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #57 +/- ## =========================================== - Coverage 75.72% 59.29% -16.44% =========================================== Files 17 19 +2 Lines 828 1076 +248 Branches 154 309 +155 =========================================== + Hits 627 638 +11 - Misses 136 414 +278 + Partials 65 24 -41 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.