Skip to content

Commit

Permalink
add pbar support for hyperopt
Browse files Browse the repository at this point in the history
  • Loading branch information
jduerholt committed Jan 8, 2025
1 parent 9bb1a36 commit ef3fb45
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
9 changes: 8 additions & 1 deletion bofire/benchmarks/hyperopt.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Optional

import pandas as pd
from tqdm import tqdm

import bofire.surrogates.api as surrogates
from bofire.benchmarks.benchmark import Benchmark
Expand All @@ -15,6 +16,7 @@ def __init__(
training_data: pd.DataFrame,
folds: int,
random_state: Optional[int] = None,
show_progress_bar: bool = False,
) -> None:
super().__init__()
if surrogate_data.hyperconfig is None:
Expand All @@ -24,6 +26,7 @@ def __init__(
self.folds = folds
self.results = None
self.random_state = random_state
self.show_progress_bar = show_progress_bar

@property
def domain(self) -> Domain:
Expand All @@ -34,7 +37,11 @@ def target_metric(self):
return self.surrogate_data.hyperconfig.target_metric # type: ignore

def _f(self, candidates: pd.DataFrame) -> pd.DataFrame:
for i, candidate in candidates.iterrows():
for i, candidate in tqdm(
candidates.iterrows(),
total=candidates.shape[0],
disable=self.show_progress_bar is False,
):
self.surrogate_data.update_hyperparameters(candidate)
surrogate = surrogates.map(self.surrogate_data)
_, cv_test, _ = surrogate.cross_validate( # type: ignore
Expand Down
3 changes: 3 additions & 0 deletions bofire/runners/hyperoptimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ def sample(domain):
training_data=training_data,
folds=folds,
random_state=random_state,
show_progress_bar=True
if surrogate_data.hyperconfig.hyperstrategy == "FractionalFactorialStrategy"
else False,
)

if surrogate_data.hyperconfig.hyperstrategy == "FractionalFactorialStrategy":
Expand Down

0 comments on commit ef3fb45

Please sign in to comment.