Skip to content

solution_callback for Hexaly#787

Merged
IgnaceBleukx merged 3 commits intomasterfrom
hexaly_callback
Dec 24, 2025
Merged

solution_callback for Hexaly#787
IgnaceBleukx merged 3 commits intomasterfrom
hexaly_callback

Conversation

@ThomSerg
Copy link
Collaborator

@ThomSerg ThomSerg commented Nov 3, 2025

Hexaly has support for intermediate solution callbacks. Added the necessary code on CPMpy's side for the solution_callback argument of a .solve() call, similar to OR-Tools.

Also very small fix for setting solver-native arguments, setattr(self.hex_solver, arg, val) should have been setattr(self.hex_solver.param, arg, val).

Copy link
Collaborator

@IgnaceBleukx IgnaceBleukx left a comment

Choose a reason for hiding this comment

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

This will be very useful!
Ideally add some tests, I came up with some tests for a (future) generic callbacking system in #558; you could steal some from there.

@ThomSerg
Copy link
Collaborator Author

Stole your callback test and its succeeds. But I can't really add it in this PR, since it requires some out-of-scope changes, e.g. to make the test also properly work for other solvers. Will become a different PR.

@ThomSerg
Copy link
Collaborator Author

When I look at your PR again (#561) I would basically be re-implementing 90% of your work to make the tests work (I.e. implement a <solvername>SolutionPrinter class for each of the solvers, the logic of which you already made). And I'm not sure if your PR adds so much code debt compared to the current <solvername>SolutionPrinter class approach (which is definitely not as user friendly).

So I would recommend reviving that PR, maybe extracting the logic of the nested solution_callback functions back into some classes at the bottom of the file (so that people can still use them as starting points for their own native callback functions), whilst keeping your generalised "display" argument that would instantiate the class for a generic CPMpy callback. And definitely your code on populating solutions would need some standardisation, since the current pre-made callbacks we provide don't always populate the objective value.

@IgnaceBleukx
Copy link
Collaborator

Ok I see, yes let's merge this already so people can use the Hexaly-specific callback. If and when we revive the other PR, we can add structured testing for this as well

@IgnaceBleukx IgnaceBleukx merged commit f4bf418 into master Dec 24, 2025
1 check passed
tias pushed a commit that referenced this pull request Jan 5, 2026
* solution_callback for Hexaly

* Gracefully exit when not properly initialised

* Populate objective on callback
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