-
Notifications
You must be signed in to change notification settings - Fork 166
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
ENH: Add callbacks to highspy
, use std::function
#1447
Conversation
242be41
to
6c0f5cd
Compare
highspy
highspy
, use std::function
a9c53e1
to
082957f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Many thanks for tidying up some code that I was not really qualified to write, but was needed by a major user.
I have a reservation and a question
- Changing the user call-back function from
void (*user_callback)
toHighsCallbackFunctionType
, whereHighsCallbackFunctionType
is
std::function<void(int, const std::string&, const HighsCallbackDataOut*, HighsCallbackDataIn*, void*)>
)
breaks the API that's been defined in 1.6.0 - surely. I've already announced the new call-back definition at a workshop, and at least two major users are writing callbacks on this basis. I guess that we can communicate with them - they are "friends" - rather than postpone your modifications to the release of HiGHS 2.0. I'm inclined to do this, as the advance that you've made - in cleaning-up the call-backs code and extending call-backs to the Python API - is worth the trouble.
- It looks to me as if the use of the unwieldy
std::function<void(int, const std::string&, const HighsCallbackDataOut*, HighsCallbackDataIn*, void*)>
incheck/TestCallbacks.cpp
can be replaced byHighsCallbackFunctionType
I think it is a well thought out design with very clear test cases (which are really the most important, these sort of second order refactors are easy when test suites guarantee correctness :) )
Not as badly as it might, since for the C-API compatibility there's also
That would be great. In terms of compatibility, if users are not able / willing to make the switch to the new type, they can replace All things considered equal, users of the C++ API will likely prefer to use
Yup, good catch, updated. This PR is almost ready to go from the |
Thanks: that's a level I understand, and at which I feel I operate reasonably well. It's just the detailed knowledge of C/C++ that I don't have , since I learned it "on the job" after jumping from Fortran 77 at the age of 53! |
Needed for calling python functions without keeping global variables around
Needs work, tests, and stuff
Co-authored-by: jajhall <jajhall@users.noreply.github.com>
fe62927
to
58cc6c2
Compare
d3a7477
to
58cc6c2
Compare
Since the SciPy callbacks require some more discussion (here and at SciPy) I think this should be ready to go in as is, @jajhall, it improves (cleans up) the implementation in |
This also updates the callback mechanism to use
std::function
, as it interfaces a lot better with native Python functions. Since it is logically separate from #1405, and required changes to the existing HiGHs API, I think it should be reviewed separately.Closes #911