From c4089594a2798a46e402dcd2dfdede5d52e20e29 Mon Sep 17 00:00:00 2001 From: Behrang Shafei <50267830+bertiqwerty@users.noreply.github.com> Date: Thu, 2 Jan 2025 16:57:48 +0100 Subject: [PATCH 1/3] make none as candidate count possible during benchmarks --- bofire/runners/run.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bofire/runners/run.py b/bofire/runners/run.py index 89729bf2d..9df64e6fe 100644 --- a/bofire/runners/run.py +++ b/bofire/runners/run.py @@ -23,7 +23,7 @@ def _single_run( strategy_factory: StrategyFactory, n_iterations: int, metric: Callable[[Domain, pd.DataFrame], float], - n_candidates_per_proposals: int, + n_candidates_per_proposals: Optional[int], safe_interval: int, initial_sampler: Optional[ Union[Callable[[Domain], pd.DataFrame], pd.DataFrame] @@ -70,11 +70,13 @@ def autosafe_results(benchmark): # pd.concat() changes datatype of str to np.int32 if column contains whole numbers. # column needs to be converted back to str to be added to the benchmark domain. strategy.tell(XY) + assert isinstance(strategy.experiments, pd.DataFrame) metric_values[i] = metric(strategy.domain, strategy.experiments) pbar.set_description(f"Run {run_idx}") pbar.set_postfix({"Current Best:": f"{metric_values[i]:0.3f}"}) if (i + 1) % safe_interval == 0: autosafe_results(benchmark=benchmark) + assert isinstance(strategy.experiments, pd.DataFrame) return strategy.experiments, pd.Series(metric_values) @@ -84,7 +86,7 @@ def run( n_iterations: int, metric: Callable[[Domain, pd.DataFrame], float], initial_sampler: Optional[Callable[[Domain], pd.DataFrame]] = None, - n_candidates_per_proposal: int = 1, + n_candidates_per_proposal: Optional[int] = None, n_runs: int = 5, n_procs: int = 5, safe_interval: int = 1000, From b645f77bec251f1f01328272148df20536f2be28 Mon Sep 17 00:00:00 2001 From: Behrang Shafei <50267830+bertiqwerty@users.noreply.github.com> Date: Thu, 2 Jan 2025 17:01:23 +0100 Subject: [PATCH 2/3] stepwise strategy should not change candidate count --- bofire/strategies/stepwise/stepwise.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/bofire/strategies/stepwise/stepwise.py b/bofire/strategies/stepwise/stepwise.py index 55567c921..c2f9d638b 100644 --- a/bofire/strategies/stepwise/stepwise.py +++ b/bofire/strategies/stepwise/stepwise.py @@ -51,8 +51,6 @@ def get_step(self) -> Tuple[Strategy, Optional[Transform]]: def _ask(self, candidate_count: Optional[PositiveInt]) -> pd.DataFrame: # type: ignore strategy, transform = self.get_step() - candidate_count = candidate_count or 1 - # handle a possible transform, no need to apply transforms to domains, as domains # do not have to be exactly the same for each step, they only have to be compatible # to the master domain of the stepwise strategy From e2ce5091b38b118b9be4bd31b42d0135e0409031 Mon Sep 17 00:00:00 2001 From: Behrang Shafei <50267830+bertiqwerty@users.noreply.github.com> Date: Thu, 2 Jan 2025 17:18:30 +0100 Subject: [PATCH 3/3] undo previous commit, _ask-signature needs fix in a separate PR --- bofire/strategies/predictives/botorch.py | 3 ++- bofire/strategies/stepwise/stepwise.py | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/bofire/strategies/predictives/botorch.py b/bofire/strategies/predictives/botorch.py index 71c48c67e..dadab03ad 100644 --- a/bofire/strategies/predictives/botorch.py +++ b/bofire/strategies/predictives/botorch.py @@ -403,7 +403,7 @@ def _optimize_acqf_continuous( ) return candidates, acqf_vals - def _ask(self, candidate_count: int) -> pd.DataFrame: # type: ignore + def _ask(self, candidate_count: Optional[int] = None) -> pd.DataFrame: """[summary] Args: @@ -413,6 +413,7 @@ def _ask(self, candidate_count: int) -> pd.DataFrame: # type: ignore pd.DataFrame: [description] """ + candidate_count = candidate_count or 1 assert candidate_count > 0, "candidate_count has to be larger than zero." if self.experiments is None: raise ValueError("No experiments have been provided yet.") diff --git a/bofire/strategies/stepwise/stepwise.py b/bofire/strategies/stepwise/stepwise.py index c2f9d638b..55567c921 100644 --- a/bofire/strategies/stepwise/stepwise.py +++ b/bofire/strategies/stepwise/stepwise.py @@ -51,6 +51,8 @@ def get_step(self) -> Tuple[Strategy, Optional[Transform]]: def _ask(self, candidate_count: Optional[PositiveInt]) -> pd.DataFrame: # type: ignore strategy, transform = self.get_step() + candidate_count = candidate_count or 1 + # handle a possible transform, no need to apply transforms to domains, as domains # do not have to be exactly the same for each step, they only have to be compatible # to the master domain of the stepwise strategy