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

Add callbacks in SolverDO.solve() #148

Merged
merged 3 commits into from
Jan 25, 2024
Merged

Add callbacks in SolverDO.solve() #148

merged 3 commits into from
Jan 25, 2024

Conversation

nhuet
Copy link
Contributor

@nhuet nhuet commented Jan 25, 2024

We create a Callback class to be used by solver.solve() to hook at some stages.

This will enable

  • logging to tools like Tensorboard or Optuna
  • timing out solvers
  • early stopping
  • discarding not promising trials during hyperparameters tuning

Callback has a few methods to overwrite in order to execute some code

  • on_solve_start(): at the beginning of solve
  • on_solve_end(): at the end of solve
  • on_step_end(): at the end of each iteration

We are deeply inspired by work from others:

In this PR, we only make local search algorithms use them, we will add gradually this possibility to all solvers.
We replace some features (logging, backup, and timer) previously used by local search algos by the use of some basic callbacks that we implement, as shown in test tests/generic_tools/callbacks/test_sa_with_callbacks.py.

nhuet added 3 commits January 23, 2024 14:00
This will enable
- logging to tools like Tensorboard or Optuna
- timing out solvers
- early stopping
- discarding not promising trials during hyperparameters tuning

Callback has a few methods to overwrite in order to execute some code
- on_solve_start(): at the beginning of solve
- on_solve_end(): at the end of solve
- on_step_end(): at the end of each iteration

As solvers can use several callbacks at the same time, we also provide a
CallbackList utility that will call the methods on each included callback.

We are deeply inspired by work from others:

keras: https://github.com/keras-team/keras/blob/v3.0.2/keras/callbacks/callback.py
tensorflow: https://github.com/tensorflow/tensorflow/blob/cafa8f3bd9b5740d1d37db799eec3168edc7e97b/tensorflow/python/training/session_run_hook.py#L94
or-tools: https://developers.google.com/optimization/reference/python/sat/python/cp_model#cp_model.CpSolverSolutionCallback
sklearn-genetic-opt: https://github.com/rodrigo-arenas/Sklearn-genetic-opt/blob/0.10.1/sklearn_genetic/callbacks/base.py

For now no solvers use them, the next step being using it in each
solvers
Time-out, log and backup features can be implemented via callbacks
to be reused in any solver.

Thus we remove the "hard-coded" corresponding features in local search
algorithms and implement them as callbacks.

This is tested in tests/generic_tools/callbacks/test_sa_with_callbacks.py.
Copy link
Collaborator

@g-poveda g-poveda left a comment

Choose a reason for hiding this comment

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

this looks excellent/promising for the future !

@g-poveda g-poveda merged commit 073efb7 into airbus:master Jan 25, 2024
16 checks passed
@nhuet nhuet deleted the callbacks branch January 30, 2024 12:26
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