Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 5 commits into from
Mar 29, 2024

Conversation

tlambert03
Copy link
Member

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)

@tlambert03 tlambert03 changed the title Improve data Improve structure of data provided to event callbacks, extract more stats and provide type hints for callback data Mar 28, 2024
Copy link

codecov bot commented Mar 28, 2024

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 ⚠️
ilpy/impl/solvers/ScipEventHandler.h 47.47% 52 Missing ⚠️
ilpy/impl/solvers/SolverBackend.h 77.77% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@             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     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@tlambert03 tlambert03 merged commit 20f6ab7 into funkelab:main Mar 29, 2024
17 of 19 checks passed
@tlambert03 tlambert03 deleted the improve-data branch March 29, 2024 00:20
@tlambert03 tlambert03 changed the title Improve structure of data provided to event callbacks, extract more stats and provide type hints for callback data feat: Improve structure of data provided to event callbacks, extract more stats and provide type hints for callback data Mar 29, 2024
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.

1 participant