Skip to content

Re-introduce event subscription? #610

@peanutfun

Description

@peanutfun

Is your feature request related to a problem? Please describe.
In https://github.com/CLIMADA-project/climada_python, we use Bayesian optimization for a calibration task. In our use case, we found it feasible to run the optimizer multiple times, switching between random samples and probing of the parameter space with a kappa decay. Since probing the space is relatively expensive in our case, we want to stop probing early if the optimization seems to only probe a local maximum with very little improvement.

We have been using the event subscription mechanism for that, which (in this library) was only used for logging and has been removed in v3. Now, there is no way of controlling the maximize algorithm while it runs, except manually creating random samples and probing. However, the maximize function does more and relies on private attributes for its functionality:

def maximize(self, init_points: int = 5, n_iter: int = 25) -> None:

Describe the solution you'd like
Could the event subscription mechanism be re-introduced for users to control the maximize algorithm while it runs? If not, is there a recommended way of achieving it otherwise? Maybe deriving a new class from BayesianOptimization in our project?

References or alternative approaches
-/-

Additional context
We created a Controller class
https://github.com/CLIMADA-project/climada_python/blob/a423c783a6051a0d8d25be540e43f072e98bf3e1/climada/util/calibrate/bayesian_optimizer.py#L315
that is subscribed to particular events of the optimizer
https://github.com/CLIMADA-project/climada_python/blob/a423c783a6051a0d8d25be540e43f072e98bf3e1/climada/util/calibrate/bayesian_optimizer.py#L656
in addition to the logger.

Are you able and willing to implement this feature yourself and open a pull request?

  • Yes, I can provide this feature

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions