Skip to content

Commit

Permalink
Fix callback order (#1040)
Browse files Browse the repository at this point in the history
Co-authored-by: Carolin Benjamins <benjamins@tnt.uni-hannover.de>
  • Loading branch information
benjamc and Carolin Benjamins committed Jun 26, 2023
1 parent b1695f0 commit 345d9f1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

## Bugfixes
- Fix bug in the incumbent selection in the case that multi-fidelity is combined with multi-objective (#1019).
- Fix callback order (#1040).

# 2.0.1

Expand Down
10 changes: 7 additions & 3 deletions smac/main/smbo.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,18 +461,22 @@ def _add_results(self) -> None:
logger.info("Cost threshold was reached. Abort is requested.")
self._stop = True

def register_callback(self, callback: Callback, index: int = -1) -> None:
def register_callback(self, callback: Callback, index: int | None = None) -> None:
"""
Registers a callback to be called before, in between, and after the Bayesian optimization loop.
Callback is appended to the list by default.
Parameters
----------
callback : Callback
The callback to be registered.
index : int
The index at which the callback should be registered.
index : int, optional
The index at which the callback should be registered. The default is None.
If it is None, append the callback to the list.
"""
if index is None:
index = len(self._callbacks)
self._callbacks.insert(index, callback)

def _initialize_state(self) -> None:
Expand Down

0 comments on commit 345d9f1

Please sign in to comment.