From 669fa4414b94d7c4d3addd1bb235589f1f42a56f Mon Sep 17 00:00:00 2001
From: Behrang Shafei <50267830+bertiqwerty@users.noreply.github.com>
Date: Thu, 5 Oct 2023 07:08:22 +0200
Subject: [PATCH] mapping happens outside of runner (#296)
* mapping happens outside of runner
* notebook fixes
* fixed more and cleaned up a little
* remove type ignores
---
bofire/runners/hyperoptimize.py | 12 ++-
bofire/runners/run.py | 18 ++--
tests/bofire/runners/test_run.py | 5 +-
tutorials/benchmarks/001-Himmelblau.ipynb | 18 ++--
tutorials/benchmarks/002-DTLZ2.ipynb | 102 +++---------------
.../benchmarks/004-Aspen_benchmark.ipynb | 61 ++++++++---
.../005-Hartmann_with_nchoosek.ipynb | 75 +++----------
tutorials/benchmarks/006-30dimBranin.ipynb | 73 ++++++++-----
.../007-Benchmark_outlier_detection.ipynb | 2 +-
.../008-Himmelblau_with_outliers.ipynb | 47 ++++----
...Bayesian_optimization_over_molecules.ipynb | 15 +--
11 files changed, 191 insertions(+), 237 deletions(-)
diff --git a/bofire/runners/hyperoptimize.py b/bofire/runners/hyperoptimize.py
index 6dcf344e1..f17b610b2 100644
--- a/bofire/runners/hyperoptimize.py
+++ b/bofire/runners/hyperoptimize.py
@@ -4,6 +4,7 @@
import pandas as pd
import bofire.strategies.api as strategies
+import bofire.strategies.mapper as strategy_mapper
from bofire.benchmarks.api import Hyperopt
from bofire.data_models.domain.api import Domain
from bofire.data_models.enum import RegressionMetricsEnum
@@ -55,11 +56,16 @@ def sample(domain):
strategy.ask(candidate_count=None), return_complete=True
)
else:
+ strategy_data = (
+ RandomStrategy
+ if surrogate_data.hyperconfig.hyperstrategy == "RandomStrategy"
+ else SoboStrategy
+ )
experiments = run(
benchmark=benchmark,
- strategy_factory=RandomStrategy
- if surrogate_data.hyperconfig.hyperstrategy == "RandomStrategy" # type: ignore
- else SoboStrategy, # type: ignore
+ strategy_factory=lambda domain: strategy_mapper.map(
+ data_model=strategy_data(domain=domain)
+ ),
metric=best,
n_runs=1,
n_iterations=surrogate_data.hyperconfig.n_iterations # type: ignore
diff --git a/bofire/runners/run.py b/bofire/runners/run.py
index cf628131a..601b2d25a 100644
--- a/bofire/runners/run.py
+++ b/bofire/runners/run.py
@@ -8,14 +8,13 @@
from multiprocess.pool import Pool
from tqdm import tqdm
-import bofire.strategies.api as strategies
from bofire.benchmarks.api import Benchmark
from bofire.data_models.domain.api import Domain
-from bofire.data_models.strategies.api import AnyStrategy
+from bofire.strategies.api import Strategy
class StrategyFactory(Protocol):
- def __call__(self, domain: Domain) -> AnyStrategy:
+ def __call__(self, domain: Domain) -> Strategy:
...
@@ -51,19 +50,16 @@ def autosafe_results(benchmark):
with open(filename, "w") as file:
json.dump(parsed_domain, file)
- # sample initial values
+ strategy = strategy_factory(domain=benchmark.domain)
+ # sample initial values and tell
if initial_sampler is not None:
if isinstance(initial_sampler, Callable):
X = initial_sampler(benchmark.domain)
XY = benchmark.f(X, return_complete=True)
else:
XY = initial_sampler
- strategy_data = strategy_factory(domain=benchmark.domain)
- # map it
- strategy = strategies.map(strategy_data) # type: ignore
- # tell it
- if initial_sampler is not None:
- strategy.tell(XY) # type: ignore
+ strategy.tell(XY)
+
metric_values = np.zeros(n_iterations)
pbar = tqdm(range(n_iterations), position=run_idx)
for i in pbar:
@@ -80,7 +76,7 @@ def autosafe_results(benchmark):
)
if (i + 1) % safe_intervall == 0:
autosafe_results(benchmark=benchmark)
- return strategy.experiments, pd.Series(metric_values) # type: ignore
+ return strategy.experiments, pd.Series(metric_values)
def run(
diff --git a/tests/bofire/runners/test_run.py b/tests/bofire/runners/test_run.py
index 1abcdc3ec..6d2253884 100644
--- a/tests/bofire/runners/test_run.py
+++ b/tests/bofire/runners/test_run.py
@@ -1,6 +1,7 @@
import pandas as pd
import bofire.strategies.api as strategies
+import bofire.strategies.mapper as strategy_mapper
from bofire.benchmarks.multi import ZDT1
from bofire.data_models.domain.api import Domain
from bofire.data_models.strategies.api import (
@@ -33,7 +34,9 @@ def hypervolume(domain: Domain, experiments: pd.DataFrame) -> float:
results = run(
zdt1,
- strategy_factory=qparego_factory,
+ strategy_factory=lambda domain: strategy_mapper.map(
+ qparego_factory(domain=domain)
+ ),
n_iterations=n_iterations,
metric=hypervolume,
initial_sampler=sample,
diff --git a/tutorials/benchmarks/001-Himmelblau.ipynb b/tutorials/benchmarks/001-Himmelblau.ipynb
index 6c735f316..7a0f78d81 100644
--- a/tutorials/benchmarks/001-Himmelblau.ipynb
+++ b/tutorials/benchmarks/001-Himmelblau.ipynb
@@ -10,7 +10,7 @@
},
{
"cell_type": "code",
- "execution_count": 1,
+ "execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
@@ -36,14 +36,14 @@
},
{
"cell_type": "code",
- "execution_count": 4,
+ "execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
- "run 00 with current best 12.587: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 50/50 [00:00<00:00, 57.01it/s]\n"
+ "run 00 with current best 4.352: 100%|██████████████████████████████████████████████████| 50/50 [00:01<00:00, 28.18it/s]\n"
]
}
],
@@ -59,7 +59,7 @@
"\n",
"random_results = run(\n",
" Himmelblau(),\n",
- " strategy_factory=RandomStrategy,\n",
+ " strategy_factory=lambda domain: strategies.map(RandomStrategy(domain=domain)),\n",
" n_iterations=50 if not SMOKE_TEST else 1,\n",
" metric=best,\n",
" initial_sampler=sample,\n",
@@ -84,14 +84,18 @@
"name": "stderr",
"output_type": "stream",
"text": [
- "run 00 with current best 0.017: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 50/50 [06:22<00:00, 7.65s/it]\n"
+ "run 00 with current best 0.003: 100%|██████████████████████████████████████████████████| 50/50 [07:19<00:00, 8.79s/it]\n"
]
}
],
"source": [
+ "def strategy_factory(domain: Domain):\n",
+ " data_model = SoboStrategy(domain=domain, acquisition_function=qEI())\n",
+ " return strategies.map(data_model)\n",
+ "\n",
"bo_results = run(\n",
" Himmelblau(),\n",
- " strategy_factory=partial(SoboStrategy, acquisition_function=qEI()),\n",
+ " strategy_factory=strategy_factory,\n",
" n_iterations=50 if not SMOKE_TEST else 1,\n",
" metric=best,\n",
" initial_sampler=sample,\n",
@@ -121,5 +125,5 @@
}
},
"nbformat": 4,
- "nbformat_minor": 2
+ "nbformat_minor": 4
}
diff --git a/tutorials/benchmarks/002-DTLZ2.ipynb b/tutorials/benchmarks/002-DTLZ2.ipynb
index de214762d..88cf681fd 100644
--- a/tutorials/benchmarks/002-DTLZ2.ipynb
+++ b/tutorials/benchmarks/002-DTLZ2.ipynb
@@ -96,7 +96,7 @@
"\n",
"random_results = run(\n",
" DTLZ2(dim=6),\n",
- " strategy_factory=RandomStrategy,\n",
+ " strategy_factory=lambda domain: strategies.map(RandomStrategy(domain=domain)),\n",
" n_iterations=50 if not SMOKE_TEST else 1,\n",
" metric=hypervolume,\n",
" initial_sampler=sample,\n",
@@ -116,21 +116,25 @@
},
{
"cell_type": "code",
- "execution_count": 4,
+ "execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
- "run 00 with current best 0.381: 100%|██████████| 50/50 [02:04<00:00, 2.50s/it]\n"
+ "run 00 with current best 0.306: 34%|█████████████████ | 17/50 [03:21<05:55, 10.77s/it]"
]
}
],
"source": [
+ "def strategy_factory(domain: Domain):\n",
+ " data_model = QehviStrategy(domain=domain, ref_point={\"f_0\": 1.1, \"f_1\": 1.1})\n",
+ " return strategies.map(data_model)\n",
+ "\n",
"results = run(\n",
" DTLZ2(dim=6),\n",
- " strategy_factory=partial(QehviStrategy, ref_point={\"f_0\": 1.1, \"f_1\": 1.1}),\n",
+ " strategy_factory=strategy_factory,\n",
" n_iterations=50 if not SMOKE_TEST else 1,\n",
" metric=hypervolume,\n",
" initial_sampler=sample,\n",
@@ -151,76 +155,9 @@
},
{
"cell_type": "code",
- "execution_count": 5,
+ "execution_count": null,
"metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "
\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " x_0 | \n",
- " x_1 | \n",
- " x_2 | \n",
- " x_3 | \n",
- " x_4 | \n",
- " x_5 | \n",
- " f_0_pred | \n",
- " f_1_pred | \n",
- " f_0_sd | \n",
- " f_1_sd | \n",
- " f_0_des | \n",
- " f_1_des | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " 0 | \n",
- " 0.400517 | \n",
- " 0.417488 | \n",
- " 0.573703 | \n",
- " 0.319068 | \n",
- " 0.746549 | \n",
- " 0.225116 | \n",
- " 0.772984 | \n",
- " 0.802233 | \n",
- " 0.269332 | \n",
- " 0.295097 | \n",
- " -0.772984 | \n",
- " -0.802233 | \n",
- "
\n",
- " \n",
- "
\n",
- "
"
- ],
- "text/plain": [
- " x_0 x_1 x_2 x_3 x_4 x_5 f_0_pred \\\n",
- "0 0.400517 0.417488 0.573703 0.319068 0.746549 0.225116 0.772984 \n",
- "\n",
- " f_1_pred f_0_sd f_1_sd f_0_des f_1_des \n",
- "0 0.802233 0.269332 0.295097 -0.772984 -0.802233 "
- ]
- },
- "metadata": {},
- "output_type": "display_data"
- }
- ],
+ "outputs": [],
"source": [
"# we get the domain from the benchmark module, in real use case we have to build it on our own\n",
"# make sure that the objective is set correctly\n",
@@ -358,21 +295,13 @@
},
{
"cell_type": "code",
- "execution_count": 9,
+ "execution_count": null,
"metadata": {},
- "outputs": [
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "run 00 with current best 0.360: 100%|██████████| 50/50 [02:58<00:00, 3.57s/it]\n"
- ]
- }
- ],
+ "outputs": [],
"source": [
"results_qparego = run(\n",
" DTLZ2(dim=6),\n",
- " strategy_factory=partial(QparegoStrategy),\n",
+ " strategy_factory=lambda domain: strategies.map(QparegoStrategy(domain=domain)),\n",
" n_iterations=50 if not SMOKE_TEST else 1,\n",
" metric=hypervolume,\n",
" initial_sampler=sample,\n",
@@ -433,7 +362,7 @@
],
"metadata": {
"kernelspec": {
- "display_name": "bofire",
+ "display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
@@ -449,7 +378,6 @@
"pygments_lexer": "ipython3",
"version": "3.10.9"
},
- "orig_nbformat": 4,
"vscode": {
"interpreter": {
"hash": "6f21737eef49beedf03d74399b47fe38d73eff760737ca33d38b9fe616638e91"
@@ -457,5 +385,5 @@
}
},
"nbformat": 4,
- "nbformat_minor": 2
+ "nbformat_minor": 4
}
diff --git a/tutorials/benchmarks/004-Aspen_benchmark.ipynb b/tutorials/benchmarks/004-Aspen_benchmark.ipynb
index b9e9be7d1..4817b147e 100644
--- a/tutorials/benchmarks/004-Aspen_benchmark.ipynb
+++ b/tutorials/benchmarks/004-Aspen_benchmark.ipynb
@@ -21,15 +21,17 @@
},
{
"cell_type": "code",
- "execution_count": 1,
+ "execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
- "/opt/homebrew/Caskroom/miniforge/base/envs/bofire/lib/python3.10/site-packages/tqdm/auto.py:22: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
- " from .autonotebook import tqdm as notebook_tqdm\n"
+ "C:\\Users\\shafeib\\prj\\bofire\\bofire\\utils\\cheminformatics.py:19: UserWarning: mordred not installed. Mordred molecular descriptors cannot be used.\n",
+ " warnings.warn(\n",
+ "C:\\Users\\shafeib\\prj\\bofire\\bofire\\surrogates\\xgb.py:12: UserWarning: xgboost not installed, BoFire's `XGBoostSurrogate` cannot be used.\n",
+ " warnings.warn(\"xgboost not installed, BoFire's `XGBoostSurrogate` cannot be used.\")\n"
]
}
],
@@ -81,7 +83,7 @@
},
{
"cell_type": "code",
- "execution_count": 2,
+ "execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
@@ -206,7 +208,7 @@
},
{
"cell_type": "code",
- "execution_count": 3,
+ "execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
@@ -239,7 +241,7 @@
},
{
"cell_type": "code",
- "execution_count": 9,
+ "execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
@@ -277,9 +279,22 @@
},
{
"cell_type": "code",
- "execution_count": 10,
+ "execution_count": 6,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "ename": "ValueError",
+ "evalue": "Unable to find Aspen file ../../../../HeatPump_case_study/python/aspen_simulations/heat_pump_aspen_sim_V5.apwz",
+ "output_type": "error",
+ "traceback": [
+ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
+ "\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)",
+ "Cell \u001b[1;32mIn [6], line 7\u001b[0m\n\u001b[0;32m 3\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m SMOKE_TEST:\n\u001b[0;32m 4\u001b[0m \u001b[38;5;66;03m# Provide the filename to where the Aspen simulation file is located.\u001b[39;00m\n\u001b[0;32m 5\u001b[0m \u001b[38;5;66;03m# Make sure it is a .apwz file.\u001b[39;00m\n\u001b[0;32m 6\u001b[0m filename \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m../../../../HeatPump_case_study/python/aspen_simulations/heat_pump_aspen_sim_V5.apwz\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m----> 7\u001b[0m aspen_benchmark \u001b[38;5;241m=\u001b[39m \u001b[43mAspen_benchmark\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m 8\u001b[0m \u001b[43m \u001b[49m\u001b[43mfilename\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mfilename\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 9\u001b[0m \u001b[43m \u001b[49m\u001b[43mdomain\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mdomain\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 10\u001b[0m \u001b[43m \u001b[49m\u001b[43mpaths\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mpaths\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 11\u001b[0m \u001b[43m \u001b[49m\u001b[43mtranslate_into_aspen_readable\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mconversion_function\u001b[49m\n\u001b[0;32m 12\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n",
+ "File \u001b[1;32m~\\prj\\bofire\\bofire\\benchmarks\\aspen_benchmark.py:61\u001b[0m, in \u001b[0;36mAspen_benchmark.__init__\u001b[1;34m(self, filename, domain, paths, additional_output_keys, translate_into_aspen_readable, **kwargs)\u001b[0m\n\u001b[0;32m 59\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mfilename \u001b[38;5;241m=\u001b[39m filename\n\u001b[0;32m 60\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m---> 61\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mUnable to find Aspen file \u001b[39m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;241m+\u001b[39m filename)\n\u001b[0;32m 63\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mtranslate_into_aspen_readable \u001b[38;5;241m=\u001b[39m translate_into_aspen_readable\n\u001b[0;32m 64\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_domain \u001b[38;5;241m=\u001b[39m domain\n",
+ "\u001b[1;31mValueError\u001b[0m: Unable to find Aspen file ../../../../HeatPump_case_study/python/aspen_simulations/heat_pump_aspen_sim_V5.apwz"
+ ]
+ }
+ ],
"source": [
"# if smoke test, this is skipped as no aspen is installed then\n",
"\n",
@@ -355,14 +370,26 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 1,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "ename": "NameError",
+ "evalue": "name 'SMOKE_TEST' is not defined",
+ "output_type": "error",
+ "traceback": [
+ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
+ "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)",
+ "Cell \u001b[1;32mIn [1], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[43mSMOKE_TEST\u001b[49m:\n\u001b[0;32m 2\u001b[0m random_results \u001b[38;5;241m=\u001b[39m run(\n\u001b[0;32m 3\u001b[0m aspen_benchmark,\n\u001b[0;32m 4\u001b[0m strategy_factory\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mlambda\u001b[39;00m domain: strategies\u001b[38;5;241m.\u001b[39mmap(RandomStrategy(domain\u001b[38;5;241m=\u001b[39mdomain)),\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 8\u001b[0m n_procs\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m1\u001b[39m,\n\u001b[0;32m 9\u001b[0m )\n",
+ "\u001b[1;31mNameError\u001b[0m: name 'SMOKE_TEST' is not defined"
+ ]
+ }
+ ],
"source": [
"if not SMOKE_TEST:\n",
" random_results = run(\n",
" aspen_benchmark,\n",
- " strategy_factory=RandomStrategy,\n",
+ " strategy_factory=lambda domain: strategies.map(RandomStrategy(domain=domain)),\n",
" n_iterations=2,\n",
" metric=hypervolume,\n",
" n_runs=1,\n",
@@ -385,9 +412,12 @@
"outputs": [],
"source": [
"if not SMOKE_TEST:\n",
+ " def strategy_factory(domain: Domain):\n",
+ " data_model = QehviStrategy(domain=domain, ref_point=ref_point)\n",
+ " return strategies.map(data_model)\n",
" results = run(\n",
" aspen_benchmark,\n",
- " strategy_factory=partial(QnehviStrategy, ref_point=ref_point),\n",
+ " strategy_factory=strategy_factory,\n",
" n_iterations=15,\n",
" metric=hypervolume,\n",
" initial_sampler=sample,\n",
@@ -444,7 +474,7 @@
],
"metadata": {
"kernelspec": {
- "display_name": "bofire",
+ "display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
@@ -459,9 +489,8 @@
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.9"
- },
- "orig_nbformat": 4
+ }
},
"nbformat": 4,
- "nbformat_minor": 2
+ "nbformat_minor": 4
}
diff --git a/tutorials/benchmarks/005-Hartmann_with_nchoosek.ipynb b/tutorials/benchmarks/005-Hartmann_with_nchoosek.ipynb
index b35af05a2..6a04172fe 100644
--- a/tutorials/benchmarks/005-Hartmann_with_nchoosek.ipynb
+++ b/tutorials/benchmarks/005-Hartmann_with_nchoosek.ipynb
@@ -10,15 +10,17 @@
},
{
"cell_type": "code",
- "execution_count": 1,
+ "execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
- "/opt/homebrew/Caskroom/miniforge/base/envs/bofire/lib/python3.10/site-packages/tqdm/auto.py:22: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
- " from .autonotebook import tqdm as notebook_tqdm\n"
+ "C:\\Users\\shafeib\\prj\\bofire\\bofire\\utils\\cheminformatics.py:19: UserWarning: mordred not installed. Mordred molecular descriptors cannot be used.\n",
+ " warnings.warn(\n",
+ "C:\\Users\\shafeib\\prj\\bofire\\bofire\\surrogates\\xgb.py:12: UserWarning: xgboost not installed, BoFire's `XGBoostSurrogate` cannot be used.\n",
+ " warnings.warn(\"xgboost not installed, BoFire's `XGBoostSurrogate` cannot be used.\")\n"
]
}
],
@@ -46,14 +48,14 @@
},
{
"cell_type": "code",
- "execution_count": 13,
+ "execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
- "run 00 with current best -0.965: 100%|██████████| 50/50 [00:00<00:00, 101.10it/s]\n"
+ "run 00 with current best -1.065: 100%|█████████████████████████████████████████████████| 50/50 [00:02<00:00, 21.40it/s]\n"
]
}
],
@@ -69,7 +71,7 @@
"\n",
"random_results = run(\n",
" Hartmann(dim=6, allowed_k=4),\n",
- " strategy_factory=PolytopeSampler,\n",
+ " strategy_factory=lambda domain: strategies.map(PolytopeSampler(domain=domain)),\n",
" n_iterations= 50 if not SMOKE_TEST else 1,\n",
" metric=best,\n",
" initial_sampler=sample,\n",
@@ -88,69 +90,27 @@
},
{
"cell_type": "code",
- "execution_count": 3,
+ "execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
- "run 00 with current best -2.030: 24%|██▍ | 12/50 [01:15<04:03, 6.40s/it]/Users/j30607/sandbox/botorch/botorch/optim/optimize.py:366: RuntimeWarning: Optimization failed in `gen_candidates_scipy` with the following warning(s):\n",
- "[OptimizationWarning('Optimization failed within `scipy.optimize.minimize` with status 8 and message Positive directional derivative for linesearch.'), UserWarning('SLSQP failed to converge to a solution the satisfies the non-linear constraints. Returning the feasible starting point.')]\n",
- "Trying again with a new set of initial conditions.\n",
- " warnings.warn(first_warn_msg, RuntimeWarning)\n",
- "run 00 with current best -2.233: 26%|██▌ | 13/50 [01:29<05:13, 8.48s/it]/Users/j30607/sandbox/botorch/botorch/optim/optimize.py:366: RuntimeWarning: Optimization failed in `gen_candidates_scipy` with the following warning(s):\n",
- "[OptimizationWarning('Optimization failed within `scipy.optimize.minimize` with status 5 and message Singular matrix E in LSQ subproblem.')]\n",
- "Trying again with a new set of initial conditions.\n",
- " warnings.warn(first_warn_msg, RuntimeWarning)\n",
- "run 00 with current best -2.242: 32%|███▏ | 16/50 [01:54<04:32, 8.03s/it]/Users/j30607/sandbox/botorch/botorch/optim/optimize.py:366: RuntimeWarning: Optimization failed in `gen_candidates_scipy` with the following warning(s):\n",
- "[OptimizationWarning('Optimization failed within `scipy.optimize.minimize` with status 5 and message Singular matrix E in LSQ subproblem.')]\n",
- "Trying again with a new set of initial conditions.\n",
- " warnings.warn(first_warn_msg, RuntimeWarning)\n",
- "run 00 with current best -2.438: 48%|████▊ | 24/50 [02:53<02:58, 6.88s/it]/Users/j30607/sandbox/botorch/botorch/optim/optimize.py:366: RuntimeWarning: Optimization failed in `gen_candidates_scipy` with the following warning(s):\n",
- "[OptimizationWarning('Optimization failed within `scipy.optimize.minimize` with status 8 and message Positive directional derivative for linesearch.'), UserWarning('SLSQP failed to converge to a solution the satisfies the non-linear constraints. Returning the feasible starting point.')]\n",
- "Trying again with a new set of initial conditions.\n",
- " warnings.warn(first_warn_msg, RuntimeWarning)\n",
- "/Users/j30607/sandbox/botorch/botorch/optim/optimize.py:390: RuntimeWarning: Optimization failed on the second try, after generating a new set of initial conditions.\n",
- " warnings.warn(\n",
- "run 00 with current best -2.488: 50%|█████ | 25/50 [03:05<03:29, 8.37s/it]/Users/j30607/sandbox/botorch/botorch/optim/optimize.py:366: RuntimeWarning: Optimization failed in `gen_candidates_scipy` with the following warning(s):\n",
- "[OptimizationWarning('Optimization failed within `scipy.optimize.minimize` with status 8 and message Positive directional derivative for linesearch.'), UserWarning('SLSQP failed to converge to a solution the satisfies the non-linear constraints. Returning the feasible starting point.'), OptimizationWarning('Optimization failed within `scipy.optimize.minimize` with status 8 and message Positive directional derivative for linesearch.'), UserWarning('SLSQP failed to converge to a solution the satisfies the non-linear constraints. Returning the feasible starting point.')]\n",
- "Trying again with a new set of initial conditions.\n",
- " warnings.warn(first_warn_msg, RuntimeWarning)\n",
- "/Users/j30607/sandbox/botorch/botorch/optim/optimize.py:390: RuntimeWarning: Optimization failed on the second try, after generating a new set of initial conditions.\n",
- " warnings.warn(\n",
- "run 00 with current best -2.629: 72%|███████▏ | 36/50 [06:06<04:57, 21.27s/it]/Users/j30607/sandbox/botorch/botorch/optim/initializers.py:403: BadInitialCandidatesWarning: Unable to find non-zero acquisition function values - initial conditions are being selected randomly.\n",
- " warnings.warn(\n",
- "run 00 with current best -2.629: 74%|███████▍ | 37/50 [07:05<07:02, 32.52s/it]/Users/j30607/sandbox/botorch/botorch/optim/initializers.py:403: BadInitialCandidatesWarning: Unable to find non-zero acquisition function values - initial conditions are being selected randomly.\n",
- " warnings.warn(\n",
- "run 00 with current best -2.629: 78%|███████▊ | 39/50 [08:10<05:33, 30.32s/it]/Users/j30607/sandbox/botorch/botorch/optim/initializers.py:403: BadInitialCandidatesWarning: Unable to find non-zero acquisition function values - initial conditions are being selected randomly.\n",
- " warnings.warn(\n",
- "run 00 with current best -2.629: 82%|████████▏ | 41/50 [10:08<06:44, 44.89s/it]/Users/j30607/sandbox/botorch/botorch/optim/initializers.py:403: BadInitialCandidatesWarning: Unable to find non-zero acquisition function values - initial conditions are being selected randomly.\n",
- " warnings.warn(\n",
- "run 00 with current best -2.629: 84%|████████▍ | 42/50 [11:06<06:31, 48.89s/it]/Users/j30607/sandbox/botorch/botorch/optim/initializers.py:403: BadInitialCandidatesWarning: Unable to find non-zero acquisition function values - initial conditions are being selected randomly.\n",
- " warnings.warn(\n",
- "run 00 with current best -2.629: 86%|████████▌ | 43/50 [12:04<06:00, 51.56s/it]/Users/j30607/sandbox/botorch/botorch/optim/initializers.py:403: BadInitialCandidatesWarning: Unable to find non-zero acquisition function values - initial conditions are being selected randomly.\n",
- " warnings.warn(\n",
- "run 00 with current best -2.629: 88%|████████▊ | 44/50 [13:03<05:21, 53.61s/it]/Users/j30607/sandbox/botorch/botorch/optim/initializers.py:403: BadInitialCandidatesWarning: Unable to find non-zero acquisition function values - initial conditions are being selected randomly.\n",
- " warnings.warn(\n",
- "run 00 with current best -2.629: 90%|█████████ | 45/50 [14:00<04:33, 54.68s/it]/Users/j30607/sandbox/botorch/botorch/optim/initializers.py:403: BadInitialCandidatesWarning: Unable to find non-zero acquisition function values - initial conditions are being selected randomly.\n",
- " warnings.warn(\n",
- "run 00 with current best -2.629: 92%|█████████▏| 46/50 [14:57<03:42, 55.51s/it]/Users/j30607/sandbox/botorch/botorch/optim/initializers.py:403: BadInitialCandidatesWarning: Unable to find non-zero acquisition function values - initial conditions are being selected randomly.\n",
- " warnings.warn(\n",
- "run 00 with current best -2.629: 96%|█████████▌| 48/50 [16:03<01:23, 41.55s/it]/Users/j30607/sandbox/botorch/botorch/optim/initializers.py:403: BadInitialCandidatesWarning: Unable to find non-zero acquisition function values - initial conditions are being selected randomly.\n",
- " warnings.warn(\n",
- "run 00 with current best -2.629: 98%|█████████▊| 49/50 [17:00<00:46, 46.35s/it]/Users/j30607/sandbox/botorch/botorch/optim/initializers.py:403: BadInitialCandidatesWarning: Unable to find non-zero acquisition function values - initial conditions are being selected randomly.\n",
- " warnings.warn(\n",
- "run 00 with current best -2.629: 100%|██████████| 50/50 [17:57<00:00, 21.56s/it]\n"
+ "run 00 with current best -3.034: 30%|██████████████▋ | 15/50 [06:04<13:05, 22.45s/it]"
]
}
],
"source": [
"from functools import partial\n",
"\n",
+ "def strategy_factory(domain: Domain):\n",
+ " data_model = SoboStrategy(domain=domain, acquisition_function=qEI(), num_raw_samples=512, num_restarts=24)\n",
+ " return strategies.map(data_model)\n",
+ "\n",
"bo_results = run(\n",
" Hartmann(dim=6, allowed_k=4),\n",
- " strategy_factory=partial(SoboStrategy, acquisition_function=qEI(), num_raw_samples=512, num_restarts=24),\n",
+ " strategy_factory=strategy_factory,\n",
" n_iterations=50 if not SMOKE_TEST else 1,\n",
" metric=best,\n",
" initial_sampler=sample,\n",
@@ -162,7 +122,7 @@
],
"metadata": {
"kernelspec": {
- "display_name": "bofire",
+ "display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
@@ -178,7 +138,6 @@
"pygments_lexer": "ipython3",
"version": "3.10.9"
},
- "orig_nbformat": 4,
"vscode": {
"interpreter": {
"hash": "6f21737eef49beedf03d74399b47fe38d73eff760737ca33d38b9fe616638e91"
@@ -186,5 +145,5 @@
}
},
"nbformat": 4,
- "nbformat_minor": 2
+ "nbformat_minor": 4
}
diff --git a/tutorials/benchmarks/006-30dimBranin.ipynb b/tutorials/benchmarks/006-30dimBranin.ipynb
index 97430ee4c..b0f5c1a7d 100644
--- a/tutorials/benchmarks/006-30dimBranin.ipynb
+++ b/tutorials/benchmarks/006-30dimBranin.ipynb
@@ -12,18 +12,9 @@
},
{
"cell_type": "code",
- "execution_count": 1,
+ "execution_count": 3,
"metadata": {},
- "outputs": [
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "/opt/homebrew/Caskroom/miniforge/base/envs/bofire/lib/python3.10/site-packages/tqdm/auto.py:22: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
- " from .autonotebook import tqdm as notebook_tqdm\n"
- ]
- }
- ],
+ "outputs": [],
"source": [
"from bofire.benchmarks.single import Branin30\n",
"from bofire.runners.api import run\n",
@@ -55,14 +46,14 @@
},
{
"cell_type": "code",
- "execution_count": 9,
+ "execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
- "run 00 with current best 2.097: 100%|██████████| 10/10 [00:00<00:00, 39.90it/s]\n"
+ "run 00 with current best 3.156: 100%|██████████████████████████████████████████████████| 10/10 [00:01<00:00, 6.60it/s]\n"
]
}
],
@@ -78,7 +69,7 @@
"\n",
"random_results = run(\n",
" Branin30(),\n",
- " strategy_factory=RandomStrategy,\n",
+ " strategy_factory=lambda domain: strategies.map(RandomStrategy(domain=domain)),\n",
" n_iterations=N_ITERATIONS,\n",
" metric=best,\n",
" initial_sampler=sample,\n",
@@ -98,24 +89,50 @@
},
{
"cell_type": "code",
- "execution_count": 10,
+ "execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
- "run 00 with current best 0.399: 100%|██████████| 10/10 [10:10<00:00, 61.05s/it]\n"
+ " 0%| | 0/10 [00:36, ?it/s]\n"
+ ]
+ },
+ {
+ "ename": "RuntimeError",
+ "evalue": "The size of tensor a (1024) must match the size of tensor b (8) at non-singleton dimension 1",
+ "output_type": "error",
+ "traceback": [
+ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
+ "\u001b[1;31mRuntimeError\u001b[0m Traceback (most recent call last)",
+ "Cell \u001b[1;32mIn [6], line 17\u001b[0m\n\u001b[0;32m 4\u001b[0m data_model \u001b[38;5;241m=\u001b[39m SoboStrategy(\n\u001b[0;32m 5\u001b[0m domain\u001b[38;5;241m=\u001b[39mdomain,\n\u001b[0;32m 6\u001b[0m acquisition_function\u001b[38;5;241m=\u001b[39mqEI(),\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 12\u001b[0m num_samples\u001b[38;5;241m=\u001b[39mNUM_SAMPLES, \n\u001b[0;32m 13\u001b[0m thinning\u001b[38;5;241m=\u001b[39mTHINNING)]))\n\u001b[0;32m 14\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m strategies\u001b[38;5;241m.\u001b[39mmap(data_model)\n\u001b[1;32m---> 17\u001b[0m random_results \u001b[38;5;241m=\u001b[39m \u001b[43mrun\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m 18\u001b[0m \u001b[43m \u001b[49m\u001b[43mBranin30\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 19\u001b[0m \u001b[43m \u001b[49m\u001b[43mstrategy_factory\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mstrategy_factory\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 20\u001b[0m \u001b[43m \u001b[49m\u001b[43mn_iterations\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mN_ITERATIONS\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 21\u001b[0m \u001b[43m \u001b[49m\u001b[43mmetric\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mbest\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 22\u001b[0m \u001b[43m \u001b[49m\u001b[43minitial_sampler\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43msample\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 23\u001b[0m \u001b[43m \u001b[49m\u001b[43mn_candidates_per_proposal\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;241;43m5\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[0;32m 24\u001b[0m \u001b[43m \u001b[49m\u001b[43mn_runs\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;241;43m1\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[0;32m 25\u001b[0m \u001b[43m \u001b[49m\u001b[43mn_procs\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;241;43m1\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[0;32m 26\u001b[0m \u001b[43m)\u001b[49m\n",
+ "File \u001b[1;32m~\\prj\\bofire\\bofire\\runners\\run.py:124\u001b[0m, in \u001b[0;36mrun\u001b[1;34m(benchmark, strategy_factory, n_iterations, metric, initial_sampler, n_candidates_per_proposal, n_runs, n_procs, safe_intervall)\u001b[0m\n\u001b[0;32m 112\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m (\n\u001b[0;32m 113\u001b[0m run_idx,\n\u001b[0;32m 114\u001b[0m deepcopy(benchmark),\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 120\u001b[0m initial_sampler,\n\u001b[0;32m 121\u001b[0m )\n\u001b[0;32m 123\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m n_procs \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m1\u001b[39m:\n\u001b[1;32m--> 124\u001b[0m results \u001b[38;5;241m=\u001b[39m [_single_run(\u001b[38;5;241m*\u001b[39mmake_args(i)) \u001b[38;5;28;01mfor\u001b[39;00m i \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mrange\u001b[39m(n_runs)]\n\u001b[0;32m 125\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m 126\u001b[0m p \u001b[38;5;241m=\u001b[39m Pool(\u001b[38;5;28mmin\u001b[39m(n_procs, n_runs))\n",
+ "File \u001b[1;32m~\\prj\\bofire\\bofire\\runners\\run.py:124\u001b[0m, in \u001b[0;36m\u001b[1;34m(.0)\u001b[0m\n\u001b[0;32m 112\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m (\n\u001b[0;32m 113\u001b[0m run_idx,\n\u001b[0;32m 114\u001b[0m deepcopy(benchmark),\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 120\u001b[0m initial_sampler,\n\u001b[0;32m 121\u001b[0m )\n\u001b[0;32m 123\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m n_procs \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m1\u001b[39m:\n\u001b[1;32m--> 124\u001b[0m results \u001b[38;5;241m=\u001b[39m [\u001b[43m_single_run\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mmake_args\u001b[49m\u001b[43m(\u001b[49m\u001b[43mi\u001b[49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m \u001b[38;5;28;01mfor\u001b[39;00m i \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mrange\u001b[39m(n_runs)]\n\u001b[0;32m 125\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m 126\u001b[0m p \u001b[38;5;241m=\u001b[39m Pool(\u001b[38;5;28mmin\u001b[39m(n_procs, n_runs))\n",
+ "File \u001b[1;32m~\\prj\\bofire\\bofire\\runners\\run.py:67\u001b[0m, in \u001b[0;36m_single_run\u001b[1;34m(run_idx, benchmark, strategy_factory, n_iterations, metric, n_candidates_per_proposals, safe_intervall, initial_sampler)\u001b[0m\n\u001b[0;32m 65\u001b[0m pbar \u001b[38;5;241m=\u001b[39m tqdm(\u001b[38;5;28mrange\u001b[39m(n_iterations), position\u001b[38;5;241m=\u001b[39mrun_idx)\n\u001b[0;32m 66\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m i \u001b[38;5;129;01min\u001b[39;00m pbar:\n\u001b[1;32m---> 67\u001b[0m X \u001b[38;5;241m=\u001b[39m \u001b[43mstrategy\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mask\u001b[49m\u001b[43m(\u001b[49m\u001b[43mcandidate_count\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mn_candidates_per_proposals\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 68\u001b[0m X \u001b[38;5;241m=\u001b[39m X[benchmark\u001b[38;5;241m.\u001b[39mdomain\u001b[38;5;241m.\u001b[39minputs\u001b[38;5;241m.\u001b[39mget_keys()]\n\u001b[0;32m 69\u001b[0m Y \u001b[38;5;241m=\u001b[39m benchmark\u001b[38;5;241m.\u001b[39mf(X)\n",
+ "File \u001b[1;32m~\\prj\\bofire\\bofire\\strategies\\predictives\\predictive.py:51\u001b[0m, in \u001b[0;36mPredictiveStrategy.ask\u001b[1;34m(self, candidate_count, add_pending, raise_validation_error)\u001b[0m\n\u001b[0;32m 34\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mask\u001b[39m(\n\u001b[0;32m 35\u001b[0m \u001b[38;5;28mself\u001b[39m,\n\u001b[0;32m 36\u001b[0m candidate_count: Optional[PositiveInt] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m,\n\u001b[0;32m 37\u001b[0m add_pending: \u001b[38;5;28mbool\u001b[39m \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mFalse\u001b[39;00m,\n\u001b[0;32m 38\u001b[0m raise_validation_error: \u001b[38;5;28mbool\u001b[39m \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mTrue\u001b[39;00m,\n\u001b[0;32m 39\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m pd\u001b[38;5;241m.\u001b[39mDataFrame:\n\u001b[0;32m 40\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"Function to generate new candidates.\u001b[39;00m\n\u001b[0;32m 41\u001b[0m \n\u001b[0;32m 42\u001b[0m \u001b[38;5;124;03m Args:\u001b[39;00m\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 49\u001b[0m \u001b[38;5;124;03m pd.DataFrame: DataFrame with candidates (proposed experiments)\u001b[39;00m\n\u001b[0;32m 50\u001b[0m \u001b[38;5;124;03m \"\"\"\u001b[39;00m\n\u001b[1;32m---> 51\u001b[0m candidates \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43msuper\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mask\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m 52\u001b[0m \u001b[43m \u001b[49m\u001b[43mcandidate_count\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcandidate_count\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 53\u001b[0m \u001b[43m \u001b[49m\u001b[43madd_pending\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43madd_pending\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 54\u001b[0m \u001b[43m \u001b[49m\u001b[43mraise_validation_error\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mraise_validation_error\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 55\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 56\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mdomain\u001b[38;5;241m.\u001b[39mvalidate_candidates(\n\u001b[0;32m 57\u001b[0m candidates\u001b[38;5;241m=\u001b[39mcandidates, raise_validation_error\u001b[38;5;241m=\u001b[39mraise_validation_error\n\u001b[0;32m 58\u001b[0m )\n\u001b[0;32m 59\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m candidates\n",
+ "File \u001b[1;32m~\\prj\\bofire\\bofire\\strategies\\strategy.py:119\u001b[0m, in \u001b[0;36mStrategy.ask\u001b[1;34m(self, candidate_count, add_pending, raise_validation_error)\u001b[0m\n\u001b[0;32m 114\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mhas_sufficient_experiments():\n\u001b[0;32m 115\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\n\u001b[0;32m 116\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mNot enough experiments available to execute the strategy.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m 117\u001b[0m )\n\u001b[1;32m--> 119\u001b[0m candidates \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_ask\u001b[49m\u001b[43m(\u001b[49m\u001b[43mcandidate_count\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcandidate_count\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 121\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mdomain\u001b[38;5;241m.\u001b[39mvalidate_candidates(\n\u001b[0;32m 122\u001b[0m candidates\u001b[38;5;241m=\u001b[39mcandidates,\n\u001b[0;32m 123\u001b[0m only_inputs\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m,\n\u001b[0;32m 124\u001b[0m raise_validation_error\u001b[38;5;241m=\u001b[39mraise_validation_error,\n\u001b[0;32m 125\u001b[0m )\n\u001b[0;32m 127\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m candidate_count \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n",
+ "File \u001b[1;32m~\\prj\\bofire\\bofire\\strategies\\predictives\\botorch.py:370\u001b[0m, in \u001b[0;36mBotorchStrategy._ask\u001b[1;34m(self, candidate_count)\u001b[0m\n\u001b[0;32m 352\u001b[0m candidates, _ \u001b[38;5;241m=\u001b[39m optimize_acqf_mixed(\n\u001b[0;32m 353\u001b[0m acq_function\u001b[38;5;241m=\u001b[39macqfs[\u001b[38;5;241m0\u001b[39m],\n\u001b[0;32m 354\u001b[0m bounds\u001b[38;5;241m=\u001b[39mbounds,\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 367\u001b[0m ic_gen_kwargs\u001b[38;5;241m=\u001b[39mic_gen_kwargs,\n\u001b[0;32m 368\u001b[0m )\n\u001b[0;32m 369\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m--> 370\u001b[0m candidates, _ \u001b[38;5;241m=\u001b[39m optimize_acqf(\n\u001b[0;32m 371\u001b[0m acq_function\u001b[38;5;241m=\u001b[39macqfs[\u001b[38;5;241m0\u001b[39m],\n\u001b[0;32m 372\u001b[0m bounds\u001b[38;5;241m=\u001b[39mbounds,\n\u001b[0;32m 373\u001b[0m q\u001b[38;5;241m=\u001b[39mcandidate_count,\n\u001b[0;32m 374\u001b[0m num_restarts\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mnum_restarts,\n\u001b[0;32m 375\u001b[0m raw_samples\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mnum_raw_samples,\n\u001b[0;32m 376\u001b[0m equality_constraints\u001b[38;5;241m=\u001b[39mget_linear_constraints(\n\u001b[0;32m 377\u001b[0m domain\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mdomain, constraint\u001b[38;5;241m=\u001b[39mLinearEqualityConstraint \u001b[38;5;66;03m# type: ignore\u001b[39;00m\n\u001b[0;32m 378\u001b[0m ),\n\u001b[0;32m 379\u001b[0m inequality_constraints\u001b[38;5;241m=\u001b[39mget_linear_constraints(\n\u001b[0;32m 380\u001b[0m domain\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mdomain, constraint\u001b[38;5;241m=\u001b[39mLinearInequalityConstraint \u001b[38;5;66;03m# type: ignore\u001b[39;00m\n\u001b[0;32m 381\u001b[0m ),\n\u001b[0;32m 382\u001b[0m fixed_features\u001b[38;5;241m=\u001b[39mfixed_features,\n\u001b[0;32m 383\u001b[0m nonlinear_inequality_constraints\u001b[38;5;241m=\u001b[39mnchooseks,\n\u001b[0;32m 384\u001b[0m return_best_only\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m,\n\u001b[0;32m 385\u001b[0m ic_generator\u001b[38;5;241m=\u001b[39mic_generator, \u001b[38;5;66;03m# type: ignore\u001b[39;00m\n\u001b[0;32m 386\u001b[0m \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mic_gen_kwargs, \u001b[38;5;66;03m# type: ignore\u001b[39;00m\n\u001b[0;32m 387\u001b[0m )\n\u001b[0;32m 388\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_postprocess_candidates(candidates\u001b[38;5;241m=\u001b[39mcandidates)\n",
+ "File \u001b[1;32m~\\AppData\\Local\\miniconda3\\envs\\bofire\\lib\\site-packages\\botorch\\optim\\optimize.py:547\u001b[0m, in \u001b[0;36moptimize_acqf\u001b[1;34m(acq_function, bounds, q, num_restarts, raw_samples, options, inequality_constraints, equality_constraints, nonlinear_inequality_constraints, fixed_features, post_processing_func, batch_initial_conditions, return_best_only, gen_candidates, sequential, ic_generator, timeout_sec, return_full_tree, retry_on_optimization_warning, **ic_gen_kwargs)\u001b[0m\n\u001b[0;32m 524\u001b[0m gen_candidates \u001b[38;5;241m=\u001b[39m gen_candidates_scipy\n\u001b[0;32m 525\u001b[0m opt_acqf_inputs \u001b[38;5;241m=\u001b[39m OptimizeAcqfInputs(\n\u001b[0;32m 526\u001b[0m acq_function\u001b[38;5;241m=\u001b[39macq_function,\n\u001b[0;32m 527\u001b[0m bounds\u001b[38;5;241m=\u001b[39mbounds,\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 545\u001b[0m ic_gen_kwargs\u001b[38;5;241m=\u001b[39mic_gen_kwargs,\n\u001b[0;32m 546\u001b[0m )\n\u001b[1;32m--> 547\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43m_optimize_acqf\u001b[49m\u001b[43m(\u001b[49m\u001b[43mopt_acqf_inputs\u001b[49m\u001b[43m)\u001b[49m\n",
+ "File \u001b[1;32m~\\AppData\\Local\\miniconda3\\envs\\bofire\\lib\\site-packages\\botorch\\optim\\optimize.py:569\u001b[0m, in \u001b[0;36m_optimize_acqf\u001b[1;34m(opt_inputs)\u001b[0m\n\u001b[0;32m 566\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m _optimize_acqf_sequential_q(opt_inputs\u001b[38;5;241m=\u001b[39mopt_inputs)\n\u001b[0;32m 568\u001b[0m \u001b[38;5;66;03m# Batch optimization (including the case q=1)\u001b[39;00m\n\u001b[1;32m--> 569\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43m_optimize_acqf_batch\u001b[49m\u001b[43m(\u001b[49m\u001b[43mopt_inputs\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mopt_inputs\u001b[49m\u001b[43m)\u001b[49m\n",
+ "File \u001b[1;32m~\\AppData\\Local\\miniconda3\\envs\\bofire\\lib\\site-packages\\botorch\\optim\\optimize.py:266\u001b[0m, in \u001b[0;36m_optimize_acqf_batch\u001b[1;34m(opt_inputs)\u001b[0m\n\u001b[0;32m 263\u001b[0m batch_initial_conditions \u001b[38;5;241m=\u001b[39m opt_inputs\u001b[38;5;241m.\u001b[39mbatch_initial_conditions\n\u001b[0;32m 264\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m 265\u001b[0m \u001b[38;5;66;03m# pyre-ignore[28]: Unexpected keyword argument `acq_function` to anonymous call.\u001b[39;00m\n\u001b[1;32m--> 266\u001b[0m batch_initial_conditions \u001b[38;5;241m=\u001b[39m opt_inputs\u001b[38;5;241m.\u001b[39mget_ic_generator()(\n\u001b[0;32m 267\u001b[0m acq_function\u001b[38;5;241m=\u001b[39mopt_inputs\u001b[38;5;241m.\u001b[39macq_function,\n\u001b[0;32m 268\u001b[0m bounds\u001b[38;5;241m=\u001b[39mopt_inputs\u001b[38;5;241m.\u001b[39mbounds,\n\u001b[0;32m 269\u001b[0m q\u001b[38;5;241m=\u001b[39mopt_inputs\u001b[38;5;241m.\u001b[39mq,\n\u001b[0;32m 270\u001b[0m num_restarts\u001b[38;5;241m=\u001b[39mopt_inputs\u001b[38;5;241m.\u001b[39mnum_restarts,\n\u001b[0;32m 271\u001b[0m raw_samples\u001b[38;5;241m=\u001b[39mopt_inputs\u001b[38;5;241m.\u001b[39mraw_samples,\n\u001b[0;32m 272\u001b[0m fixed_features\u001b[38;5;241m=\u001b[39mopt_inputs\u001b[38;5;241m.\u001b[39mfixed_features,\n\u001b[0;32m 273\u001b[0m options\u001b[38;5;241m=\u001b[39moptions,\n\u001b[0;32m 274\u001b[0m inequality_constraints\u001b[38;5;241m=\u001b[39mopt_inputs\u001b[38;5;241m.\u001b[39minequality_constraints,\n\u001b[0;32m 275\u001b[0m equality_constraints\u001b[38;5;241m=\u001b[39mopt_inputs\u001b[38;5;241m.\u001b[39mequality_constraints,\n\u001b[0;32m 276\u001b[0m \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mopt_inputs\u001b[38;5;241m.\u001b[39mic_gen_kwargs,\n\u001b[0;32m 277\u001b[0m )\n\u001b[0;32m 279\u001b[0m batch_limit: \u001b[38;5;28mint\u001b[39m \u001b[38;5;241m=\u001b[39m options\u001b[38;5;241m.\u001b[39mget(\n\u001b[0;32m 280\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mbatch_limit\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[0;32m 281\u001b[0m opt_inputs\u001b[38;5;241m.\u001b[39mnum_restarts\n\u001b[0;32m 282\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m opt_inputs\u001b[38;5;241m.\u001b[39mnonlinear_inequality_constraints\n\u001b[0;32m 283\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m \u001b[38;5;241m1\u001b[39m,\n\u001b[0;32m 284\u001b[0m )\n\u001b[0;32m 286\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m_optimize_batch_candidates\u001b[39m() \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m Tuple[Tensor, Tensor, List[\u001b[38;5;167;01mWarning\u001b[39;00m]]:\n",
+ "File \u001b[1;32m~\\AppData\\Local\\miniconda3\\envs\\bofire\\lib\\site-packages\\botorch\\optim\\initializers.py:388\u001b[0m, in \u001b[0;36mgen_batch_initial_conditions\u001b[1;34m(acq_function, bounds, q, num_restarts, raw_samples, fixed_features, options, inequality_constraints, equality_constraints, generator)\u001b[0m\n\u001b[0;32m 386\u001b[0m \u001b[38;5;28;01mwhile\u001b[39;00m start_idx \u001b[38;5;241m<\u001b[39m X_rnd\u001b[38;5;241m.\u001b[39mshape[\u001b[38;5;241m0\u001b[39m]:\n\u001b[0;32m 387\u001b[0m end_idx \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mmin\u001b[39m(start_idx \u001b[38;5;241m+\u001b[39m batch_limit, X_rnd\u001b[38;5;241m.\u001b[39mshape[\u001b[38;5;241m0\u001b[39m])\n\u001b[1;32m--> 388\u001b[0m Y_rnd_curr \u001b[38;5;241m=\u001b[39m \u001b[43macq_function\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m 389\u001b[0m \u001b[43m \u001b[49m\u001b[43mX_rnd\u001b[49m\u001b[43m[\u001b[49m\u001b[43mstart_idx\u001b[49m\u001b[43m:\u001b[49m\u001b[43mend_idx\u001b[49m\u001b[43m]\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mto\u001b[49m\u001b[43m(\u001b[49m\u001b[43mdevice\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mdevice\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 390\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\u001b[38;5;241m.\u001b[39mcpu()\n\u001b[0;32m 391\u001b[0m Y_rnd_list\u001b[38;5;241m.\u001b[39mappend(Y_rnd_curr)\n\u001b[0;32m 392\u001b[0m start_idx \u001b[38;5;241m+\u001b[39m\u001b[38;5;241m=\u001b[39m batch_limit\n",
+ "File \u001b[1;32m~\\AppData\\Local\\miniconda3\\envs\\bofire\\lib\\site-packages\\torch\\nn\\modules\\module.py:1194\u001b[0m, in \u001b[0;36mModule._call_impl\u001b[1;34m(self, *input, **kwargs)\u001b[0m\n\u001b[0;32m 1190\u001b[0m \u001b[38;5;66;03m# If we don't have any hooks, we want to skip the rest of the logic in\u001b[39;00m\n\u001b[0;32m 1191\u001b[0m \u001b[38;5;66;03m# this function, and just call forward.\u001b[39;00m\n\u001b[0;32m 1192\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m (\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_backward_hooks \u001b[38;5;129;01mor\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_forward_hooks \u001b[38;5;129;01mor\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_forward_pre_hooks \u001b[38;5;129;01mor\u001b[39;00m _global_backward_hooks\n\u001b[0;32m 1193\u001b[0m \u001b[38;5;129;01mor\u001b[39;00m _global_forward_hooks \u001b[38;5;129;01mor\u001b[39;00m _global_forward_pre_hooks):\n\u001b[1;32m-> 1194\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m forward_call(\u001b[38;5;241m*\u001b[39m\u001b[38;5;28minput\u001b[39m, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n\u001b[0;32m 1195\u001b[0m \u001b[38;5;66;03m# Do not call functions when jit is used\u001b[39;00m\n\u001b[0;32m 1196\u001b[0m full_backward_hooks, non_full_backward_hooks \u001b[38;5;241m=\u001b[39m [], []\n",
+ "File \u001b[1;32m~\\AppData\\Local\\miniconda3\\envs\\bofire\\lib\\site-packages\\botorch\\utils\\transforms.py:320\u001b[0m, in \u001b[0;36mconcatenate_pending_points..decorated\u001b[1;34m(cls, X, **kwargs)\u001b[0m\n\u001b[0;32m 318\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mcls\u001b[39m\u001b[38;5;241m.\u001b[39mX_pending \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[0;32m 319\u001b[0m X \u001b[38;5;241m=\u001b[39m torch\u001b[38;5;241m.\u001b[39mcat([X, match_batch_shape(\u001b[38;5;28mcls\u001b[39m\u001b[38;5;241m.\u001b[39mX_pending, X)], dim\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m-\u001b[39m\u001b[38;5;241m2\u001b[39m)\n\u001b[1;32m--> 320\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m method(\u001b[38;5;28mcls\u001b[39m, X, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n",
+ "File \u001b[1;32m~\\AppData\\Local\\miniconda3\\envs\\bofire\\lib\\site-packages\\botorch\\utils\\transforms.py:277\u001b[0m, in \u001b[0;36mt_batch_mode_transform..decorator..decorated\u001b[1;34m(acqf, X, *args, **kwargs)\u001b[0m\n\u001b[0;32m 275\u001b[0m \u001b[38;5;66;03m# add t-batch dim\u001b[39;00m\n\u001b[0;32m 276\u001b[0m X \u001b[38;5;241m=\u001b[39m X \u001b[38;5;28;01mif\u001b[39;00m X\u001b[38;5;241m.\u001b[39mdim() \u001b[38;5;241m>\u001b[39m \u001b[38;5;241m2\u001b[39m \u001b[38;5;28;01melse\u001b[39;00m X\u001b[38;5;241m.\u001b[39munsqueeze(\u001b[38;5;241m0\u001b[39m)\n\u001b[1;32m--> 277\u001b[0m output \u001b[38;5;241m=\u001b[39m method(acqf, X, \u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n\u001b[0;32m 278\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mhasattr\u001b[39m(acqf, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mmodel\u001b[39m\u001b[38;5;124m\"\u001b[39m) \u001b[38;5;129;01mand\u001b[39;00m is_fully_bayesian(acqf\u001b[38;5;241m.\u001b[39mmodel):\n\u001b[0;32m 279\u001b[0m output \u001b[38;5;241m=\u001b[39m output\u001b[38;5;241m.\u001b[39mmean(dim\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m-\u001b[39m\u001b[38;5;241m1\u001b[39m)\n",
+ "File \u001b[1;32m~\\AppData\\Local\\miniconda3\\envs\\bofire\\lib\\site-packages\\botorch\\acquisition\\monte_carlo.py:266\u001b[0m, in \u001b[0;36mSampleReducingMCAcquisitionFunction.forward\u001b[1;34m(self, X)\u001b[0m\n\u001b[0;32m 246\u001b[0m \u001b[38;5;129m@concatenate_pending_points\u001b[39m\n\u001b[0;32m 247\u001b[0m \u001b[38;5;129m@t_batch_mode_transform\u001b[39m()\n\u001b[0;32m 248\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mforward\u001b[39m(\u001b[38;5;28mself\u001b[39m, X: Tensor) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m Tensor:\n\u001b[0;32m 249\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124mr\u001b[39m\u001b[38;5;124;03m\"\"\"Computes the acquisition value associated with the input `X`. Weighs the\u001b[39;00m\n\u001b[0;32m 250\u001b[0m \u001b[38;5;124;03m acquisition utility values by smoothed constraint indicators if `constraints`\u001b[39;00m\n\u001b[0;32m 251\u001b[0m \u001b[38;5;124;03m was passed to the constructor of the class. Applies `self.sample_reduction` and\u001b[39;00m\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 264\u001b[0m \u001b[38;5;124;03m batch shape of model and input `X`.\u001b[39;00m\n\u001b[0;32m 265\u001b[0m \u001b[38;5;124;03m \"\"\"\u001b[39;00m\n\u001b[1;32m--> 266\u001b[0m non_reduced_acqval \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_non_reduced_forward\u001b[49m\u001b[43m(\u001b[49m\u001b[43mX\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mX\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 267\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_sample_reduction(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_q_reduction(non_reduced_acqval))\n",
+ "File \u001b[1;32m~\\AppData\\Local\\miniconda3\\envs\\bofire\\lib\\site-packages\\botorch\\acquisition\\monte_carlo.py:280\u001b[0m, in \u001b[0;36mSampleReducingMCAcquisitionFunction._non_reduced_forward\u001b[1;34m(self, X)\u001b[0m\n\u001b[0;32m 270\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"Compute the constrained acquisition values at the MC-sample, q level.\u001b[39;00m\n\u001b[0;32m 271\u001b[0m \n\u001b[0;32m 272\u001b[0m \u001b[38;5;124;03mArgs:\u001b[39;00m\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 277\u001b[0m \u001b[38;5;124;03m A Tensor with shape `sample_sample x batch_shape x q`.\u001b[39;00m\n\u001b[0;32m 278\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[0;32m 279\u001b[0m samples, obj \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_get_samples_and_objectives(X)\n\u001b[1;32m--> 280\u001b[0m acqval \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_sample_forward\u001b[49m\u001b[43m(\u001b[49m\u001b[43mobj\u001b[49m\u001b[43m)\u001b[49m \u001b[38;5;66;03m# `sample_sample x batch_shape x q`\u001b[39;00m\n\u001b[0;32m 281\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_apply_constraints(acqval\u001b[38;5;241m=\u001b[39macqval, samples\u001b[38;5;241m=\u001b[39msamples)\n",
+ "File \u001b[1;32m~\\AppData\\Local\\miniconda3\\envs\\bofire\\lib\\site-packages\\botorch\\acquisition\\monte_carlo.py:402\u001b[0m, in \u001b[0;36mqExpectedImprovement._sample_forward\u001b[1;34m(self, obj)\u001b[0m\n\u001b[0;32m 393\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m_sample_forward\u001b[39m(\u001b[38;5;28mself\u001b[39m, obj: Tensor) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m Tensor:\n\u001b[0;32m 394\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124mr\u001b[39m\u001b[38;5;124;03m\"\"\"Evaluate qExpectedImprovement per sample on the candidate set `X`.\u001b[39;00m\n\u001b[0;32m 395\u001b[0m \n\u001b[0;32m 396\u001b[0m \u001b[38;5;124;03m Args:\u001b[39;00m\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 400\u001b[0m \u001b[38;5;124;03m A `sample_shape x batch_shape x q`-dim Tensor of improvement utility values.\u001b[39;00m\n\u001b[0;32m 401\u001b[0m \u001b[38;5;124;03m \"\"\"\u001b[39;00m\n\u001b[1;32m--> 402\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m (\u001b[43mobj\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m-\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mbest_f\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43munsqueeze\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m-\u001b[39;49m\u001b[38;5;241;43m1\u001b[39;49m\u001b[43m)\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mto\u001b[49m\u001b[43m(\u001b[49m\u001b[43mobj\u001b[49m\u001b[43m)\u001b[49m)\u001b[38;5;241m.\u001b[39mclamp_min(\u001b[38;5;241m0\u001b[39m)\n",
+ "\u001b[1;31mRuntimeError\u001b[0m: The size of tensor a (1024) must match the size of tensor b (8) at non-singleton dimension 1"
]
}
],
"source": [
"benchmark = Branin30()\n",
"\n",
- "random_results = run(\n",
- " Branin30(),\n",
- " strategy_factory=partial(\n",
- " SoboStrategy, \n",
+ "def strategy_factory(domain: Domain):\n",
+ " data_model = SoboStrategy(\n",
+ " domain=domain,\n",
" acquisition_function=qEI(),\n",
" surrogate_specs=BotorchSurrogates(\n",
" surrogates=[\n",
@@ -123,8 +140,13 @@
" # the following hyperparams do not need to be provided\n",
" warmup_steps=WARMUP_STEPS,\n",
" num_samples=NUM_SAMPLES, \n",
- " thinning=THINNING)])\n",
- " ),\n",
+ " thinning=THINNING)]))\n",
+ " return strategies.map(data_model)\n",
+ " \n",
+ "\n",
+ "random_results = run(\n",
+ " Branin30(),\n",
+ " strategy_factory=strategy_factory,\n",
" n_iterations=N_ITERATIONS,\n",
" metric=best,\n",
" initial_sampler=sample,\n",
@@ -137,7 +159,7 @@
],
"metadata": {
"kernelspec": {
- "display_name": "bofire",
+ "display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
@@ -152,9 +174,8 @@
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.9"
- },
- "orig_nbformat": 4
+ }
},
"nbformat": 4,
- "nbformat_minor": 2
+ "nbformat_minor": 4
}
diff --git a/tutorials/benchmarks/007-Benchmark_outlier_detection.ipynb b/tutorials/benchmarks/007-Benchmark_outlier_detection.ipynb
index a4b6fa1c4..fa3bff9d1 100644
--- a/tutorials/benchmarks/007-Benchmark_outlier_detection.ipynb
+++ b/tutorials/benchmarks/007-Benchmark_outlier_detection.ipynb
@@ -797,7 +797,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.10.11"
+ "version": "3.10.9"
}
},
"nbformat": 4,
diff --git a/tutorials/benchmarks/008-Himmelblau_with_outliers.ipynb b/tutorials/benchmarks/008-Himmelblau_with_outliers.ipynb
index e55990a16..52b634272 100644
--- a/tutorials/benchmarks/008-Himmelblau_with_outliers.ipynb
+++ b/tutorials/benchmarks/008-Himmelblau_with_outliers.ipynb
@@ -180,13 +180,23 @@
"bo_results_outliers_set=[]\n",
"bo_results_no_outliers_set=[]\n",
"n_iterations = 10 if not SMOKE_TEST else 1\n",
+ "\n",
+ "def sobo_factory(domain: Domain):\n",
+ " return strategies.map(SoboStrategy(domain=domain, acquisition_function=qEI()))\n",
+ "\n",
+ "def sobo_factory_outlier(domain: Domain, outlier_detection_specs: OutlierDetections):\n",
+ " return strategies.map(SoboStrategy(domain=domain, \n",
+ " acquisition_function=qEI(), \n",
+ " outlier_detection_specs = outlier_detection_specs,\n",
+ " min_experiments_before_outlier_check = 10, \n",
+ " frequency_check = 2))\n",
"for kk in range(n_iterations):\n",
" Benchmark = Himmelblau()\n",
" sampled = sample(Benchmark.domain)\n",
" sampled_xy = Benchmark.f(sampled, return_complete=True)\n",
" random_results = run(\n",
" Himmelblau(),\n",
- " strategy_factory=RandomStrategy,\n",
+ " strategy_factory=lambda domain: strategies.map(RandomStrategy(domain=domain)),\n",
" n_iterations=50, # random strategy \n",
" metric=best,\n",
" initial_sampler=sampled_xy,\n",
@@ -194,9 +204,10 @@
" n_procs=1,\n",
" )\n",
"\n",
+ " \n",
" bo_results = run(\n",
" Himmelblau(),\n",
- " strategy_factory=partial(SoboStrategy, acquisition_function=qEI()),\n",
+ " strategy_factory=sobo_factory,\n",
" n_iterations=50 if not SMOKE_TEST else 1,\n",
" metric=best,\n",
" initial_sampler=sampled_xy,\n",
@@ -209,7 +220,7 @@
"\n",
" bo_results_outliers = run(\n",
" Benchmark,\n",
- " strategy_factory=partial(SoboStrategy, acquisition_function=qEI()),\n",
+ " strategy_factory=sobo_factory,\n",
" n_iterations=50 if not SMOKE_TEST else 1,\n",
" metric=best,\n",
" initial_sampler=sampled_xy1,\n",
@@ -218,6 +229,7 @@
" )\n",
"\n",
" domain = Benchmark.domain\n",
+ "\n",
" detectors = []\n",
" for output_feature in domain.outputs.get_keys():\n",
" if len(domain.inputs.get(CategoricalInput, exact=True)):\n",
@@ -238,9 +250,7 @@
"\n",
" bo_results_no_outliers = run(\n",
" Benchmark,\n",
- " strategy_factory=partial(SoboStrategy, acquisition_function=qEI(), outlier_detection_specs = outlier_detection_specs,\n",
- " min_experiments_before_outlier_check = 10, \n",
- " frequency_check = 2),\n",
+ " strategy_factory=partial(sobo_factory_outlier, outlier_detection_specs=outlier_detection_specs),\n",
" n_iterations=50 if not SMOKE_TEST else 1,\n",
" metric=best,\n",
" initial_sampler=sampled_xy1,\n",
@@ -382,13 +392,14 @@
"bo_results_outliers_set=[]\n",
"bo_results_no_outliers_set=[]\n",
"n_iterations = 10 if not SMOKE_TEST else 1\n",
+ "\n",
"for kk in range(n_iterations):\n",
" Benchmark = Himmelblau()\n",
" sampled = sample(Benchmark.domain)\n",
" sampled_xy = Benchmark.f(sampled, return_complete=True)\n",
" random_results = run(\n",
" Himmelblau(),\n",
- " strategy_factory=RandomStrategy,\n",
+ " strategy_factory=lambda domain: strategies.map(RandomStrategy(domain=domain)),\n",
" n_iterations=50, # random strategy \n",
" metric=best,\n",
" initial_sampler=sampled_xy,\n",
@@ -398,7 +409,7 @@
"\n",
" bo_results = run(\n",
" Himmelblau(),\n",
- " strategy_factory=partial(SoboStrategy, acquisition_function=qEI()),\n",
+ " strategy_factory=sobo_factory,\n",
" n_iterations=50 if not SMOKE_TEST else 1,\n",
" metric=best,\n",
" initial_sampler=sampled_xy,\n",
@@ -411,7 +422,7 @@
"\n",
" bo_results_outliers = run(\n",
" Benchmark,\n",
- " strategy_factory=partial(SoboStrategy, acquisition_function=qEI()),\n",
+ " strategy_factory=sobo_factory,\n",
" n_iterations=50 if not SMOKE_TEST else 1,\n",
" metric=best,\n",
" initial_sampler=sampled_xy1,\n",
@@ -440,9 +451,7 @@
"\n",
" bo_results_no_outliers = run(\n",
" Benchmark,\n",
- " strategy_factory=partial(SoboStrategy, acquisition_function=qEI(), outlier_detection_specs = outlier_detection_specs,\n",
- " min_experiments_before_outlier_check = 10, \n",
- " frequency_check = 2),\n",
+ " strategy_factory=partial(sobo_factory_outlier, outlier_detection_specs=outlier_detection_specs),\n",
" n_iterations=50 if not SMOKE_TEST else 1,\n",
" metric=best,\n",
" initial_sampler=sampled_xy1,\n",
@@ -590,7 +599,7 @@
" sampled_xy = Benchmark.f(sampled, return_complete=True)\n",
" random_results = run(\n",
" Himmelblau(),\n",
- " strategy_factory=RandomStrategy,\n",
+ " strategy_factory=lambda domain: strategies.map(RandomStrategy(domain=domain)),\n",
" n_iterations=50, # random strategy \n",
" metric=best,\n",
" initial_sampler=sampled_xy,\n",
@@ -600,7 +609,7 @@
"\n",
" bo_results = run(\n",
" Himmelblau(),\n",
- " strategy_factory=partial(SoboStrategy, acquisition_function=qEI()),\n",
+ " strategy_factory=sobo_factory,\n",
" n_iterations=50 if not SMOKE_TEST else 1,\n",
" metric=best,\n",
" initial_sampler=sampled_xy,\n",
@@ -613,7 +622,7 @@
"\n",
" bo_results_outliers = run(\n",
" Benchmark,\n",
- " strategy_factory=partial(SoboStrategy, acquisition_function=qEI()),\n",
+ " strategy_factory=sobo_factory,\n",
" n_iterations=50 if not SMOKE_TEST else 1,\n",
" metric=best,\n",
" initial_sampler=sampled_xy1,\n",
@@ -642,9 +651,7 @@
"\n",
" bo_results_no_outliers = run(\n",
" Benchmark,\n",
- " strategy_factory=partial(SoboStrategy, acquisition_function=qEI(), outlier_detection_specs = outlier_detection_specs,\n",
- " min_experiments_before_outlier_check = 10, \n",
- " frequency_check = 2),\n",
+ " strategy_factory=partial(sobo_factory_outlier, outlier_detection_specs = outlier_detection_specs),\n",
" n_iterations=50 if not SMOKE_TEST else 1,\n",
" metric=best,\n",
" initial_sampler=sampled_xy1,\n",
@@ -738,9 +745,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.10.11"
+ "version": "3.10.9"
}
},
"nbformat": 4,
- "nbformat_minor": 2
+ "nbformat_minor": 4
}
diff --git a/tutorials/benchmarks/009-Bayesian_optimization_over_molecules.ipynb b/tutorials/benchmarks/009-Bayesian_optimization_over_molecules.ipynb
index 1e2fc6e56..f930bbb19 100644
--- a/tutorials/benchmarks/009-Bayesian_optimization_over_molecules.ipynb
+++ b/tutorials/benchmarks/009-Bayesian_optimization_over_molecules.ipynb
@@ -180,9 +180,6 @@
"def best(domain: Domain, experiments: pd.DataFrame) -> float:\n",
" return experiments[domain.outputs.get_keys()[0]].max()\n",
"\n",
- "\n",
- "\n",
- "\n",
"n_iter = 20 if not SMOKE_TEST else 1\n",
"bo_results_set=[]\n",
"random_results_set=[]\n",
@@ -194,7 +191,7 @@
" sampled_xy = Benchmark.f(sampled, return_complete=True)\n",
" random_results = run(\n",
" Benchmark,\n",
- " strategy_factory=RandomStrategy,\n",
+ " strategy_factory=lambda domain: strategies.map(RandomStrategy(domain=domain)),\n",
" n_iterations=n_iterations,\n",
" metric=best,\n",
" initial_sampler=sampled_xy,\n",
@@ -206,11 +203,15 @@
" surrogate = TanimotoGPSurrogate(inputs = Benchmark.domain.inputs,\n",
" outputs=Benchmark.domain.outputs,\n",
" input_preprocessing_specs=specs)\n",
+ " def sobo_factory(domain: Domain):\n",
+ " return strategies.map(SoboStrategy(domain=domain, \n",
+ " acquisition_function=qEI(), \n",
+ " surrogate_specs = BotorchSurrogates(surrogates=[surrogate])\n",
+ " ))\n",
" qExpectedImprovement = qEI()\n",
" bo_results = run(\n",
" Benchmark,\n",
- " strategy_factory=partial(SoboStrategy, acquisition_function=qEI(), \n",
- " surrogate_specs = BotorchSurrogates(surrogates=[surrogate])),\n",
+ " strategy_factory=sobo_factory,\n",
" n_iterations=n_iterations,\n",
" metric=best,\n",
" initial_sampler=sampled_xy,\n",
@@ -295,7 +296,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.10.11"
+ "version": "3.10.9"
}
},
"nbformat": 4,