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

Make None as candidate count possible during benchmarks #491

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions bofire/runners/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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)


Expand All @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion bofire/strategies/predictives/botorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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.")
Expand Down
Loading