diff --git a/dacbench/benchmarks/__init__.py b/dacbench/benchmarks/__init__.py index 726dc1740..23e323d50 100644 --- a/dacbench/benchmarks/__init__.py +++ b/dacbench/benchmarks/__init__.py @@ -51,3 +51,15 @@ "Theory Benchmark not installed. If you want to use this benchmark, " "please follow the installation guide." ) + +dacbo_spec = importlib.util.find_spec("dacboenv") +found = dacbo_spec is not None +if found: + from dacbench.benchmarks.dacbo_benchmark import DACBOBenchmark + + __all__.append("DACBOBenchmark") +else: + warnings.warn( # noqa: B028 + "DACBOEnv not installed. If you want to use this benchmark, " + "please follow the installation guide." + ) diff --git a/dacbench/benchmarks/dacbo_benchmark.py b/dacbench/benchmarks/dacbo_benchmark.py new file mode 100644 index 000000000..af6f349f4 --- /dev/null +++ b/dacbench/benchmarks/dacbo_benchmark.py @@ -0,0 +1,124 @@ +"""DACBOEnv Benchmark.""" + +from __future__ import annotations + +from importlib.resources import files +from itertools import product +from pathlib import Path + +import dacboenv +import numpy as np +import yaml +from dacboenv.env.action import AcqParameterActionSpace +from omegaconf import OmegaConf + +from dacbench.abstract_benchmark import AbstractBenchmark, objdict +from dacbench.envs.dacbo import DACBOEnv + + +def load_default_optimizer(): + """Handles dacboenv configs to configure WEI as default.""" + dacboenv_path = files("dacboenv") + base = OmegaConf.load(dacboenv_path / "configs/env/opt/base.yaml") + base.dacboenv.optimizer_cfg.smac_cfg.smac_kwargs = None + override = OmegaConf.load( + dacboenv_path / "configs/env/action/wei_alpha_continuous.yaml" + ) + cfg = OmegaConf.merge(base, override) + cfg = OmegaConf.create({"optimizer": cfg.dacboenv.optimizer_cfg}) + + def replace_refs(node): + if isinstance(node, str): + return node.replace("dacboenv.optimizer_cfg", "optimizer") + if isinstance(node, dict): + return {k: replace_refs(v) for k, v in node.items()} + if isinstance(node, list): + return [replace_refs(v) for v in node] + return node + + cfg = OmegaConf.create(replace_refs(OmegaConf.to_container(cfg, resolve=False))) + cfg.outdir = "runs/SMAC-DACBO/${benchmark_id}/${task_id}/${seed}" + + return cfg + + +INFO = { + "identifier": "DACBO", + "name": "DACBO", + "reward": f"""Default: [symlogregret]. Other options: {[ + rew.name for rew in dacboenv.env.reward.ALL_REWARDS + ]}""", + "state_description": f"""Default: {[ + "ubr_difference", + "acq_value_EI", + "acq_value_PI", + "previous_param", + ]}. Other options: {[ + obs.name for obs in dacboenv.env.observation.ALL_OBSERVATIONS + ]}""", +} + +DACBO_DEFAULTS = objdict( + { + "reward_range": [-np.inf, np.inf], + "seed": 0, + "instance_set_path": "bbob_2_default.yaml", + "optimizer_cfg": load_default_optimizer(), + "observation_keys": [ + "ubr_difference", + "acq_value_EI", + "acq_value_PI", + "previous_param", + ], + "action_space_class": AcqParameterActionSpace, + "action_space_kwargs": {"bounds": [0, 1], "adjustment_type": "continuous"}, + "reward_keys": ["symlogregret"], + "benchmark_info": INFO, + } +) + + +class DACBOBenchmark(AbstractBenchmark): + """DACBOEnv benchmark.""" + + def __init__(self, config_path=None, config=None): + """Init DACBOEnv benchmark.""" + super().__init__(config_path, config) + + if not self.config: + self.config = objdict(DACBO_DEFAULTS.copy()) + + for key in DACBO_DEFAULTS: + if key not in self.config: + self.config[key] = DACBO_DEFAULTS[key] + + def get_environment(self): + """Returns the internal env.""" + return DACBOEnv(self.config) + + def read_instance_set(self): + """Reads the instance set.""" + assert self.config.instance_set_path + if Path(self.config.instance_set_path).is_file(): + path = self.config.instance_set_path + else: + path = ( + Path(__file__).resolve().parent + / "../instance_sets/dacbo/" + / self.config.instance_set_path + ) + + with open(path) as f: + instance_data = yaml.safe_load(f) + print(instance_data) + self.config["task_ids"] = instance_data["task_ids"] + self.config["inner_seeds"] = instance_data.get("inner_seeds", None) + self.config["instance_set"] = dict( + enumerate( + product( + instance_data.get("inner_seeds", None), instance_data["task_ids"] + ) + ) + ) # Not used. Instance selection is handled by the internal env + + assert len(self.config["instance_set"]) > 0, "ERROR: empty instance set" diff --git a/dacbench/envs/dacbo.py b/dacbench/envs/dacbo.py new file mode 100644 index 000000000..7702f1050 --- /dev/null +++ b/dacbench/envs/dacbo.py @@ -0,0 +1,34 @@ +"""DACBO Env.""" + +from __future__ import annotations + +import numpy as np +from dacboenv.dacboenv import DACBOEnv as DEnv + +from dacbench.abstract_env import AbstractEnv + + +class DACBOEnv(AbstractEnv): + """DACBO env.""" + + def __init__(self, config): + """Init DACBO env.""" + self._env = DEnv(**config) + self.reset() + config[ + "cutoff" + ] = np.inf # Not used. DACBO handles BO runs (i.e. episodes) internally + config["observation_space"] = self._env.observation_space + config["action_space"] = self._env.action_space + super().__init__(config) + + def step(self, action): + """Takes one env step.""" + state, reward, terminated, truncated, info = self._env.step(action) + if truncated: # Reset BO loop, select new instance + self._env.reset() + return state, reward, terminated, truncated, info + + def reset(self, seed=None): + """Resets the internal env.""" + return self._env.reset() diff --git a/dacbench/instance_sets/dacbo/bbob_2_default.yaml b/dacbench/instance_sets/dacbo/bbob_2_default.yaml new file mode 100644 index 000000000..16c539e6e --- /dev/null +++ b/dacbench/instance_sets/dacbo/bbob_2_default.yaml @@ -0,0 +1,25 @@ +task_ids: + - "bbob/2/1/0" + - "bbob/2/2/0" + - "bbob/2/3/0" + - "bbob/2/4/0" + - "bbob/2/5/0" + - "bbob/2/6/0" + - "bbob/2/7/0" + - "bbob/2/8/0" + - "bbob/2/9/0" + - "bbob/2/10/0" + - "bbob/2/11/0" + - "bbob/2/12/0" + - "bbob/2/13/0" + - "bbob/2/14/0" + - "bbob/2/15/0" + - "bbob/2/16/0" + - "bbob/2/17/0" + - "bbob/2/18/0" + - "bbob/2/19/0" + - "bbob/2/20/0" +inner_seeds: + - 1 + - 2 + - 3 \ No newline at end of file diff --git a/examples/benchmark_notebooks/dacbo.ipynb b/examples/benchmark_notebooks/dacbo.ipynb new file mode 100644 index 000000000..9e12209ae --- /dev/null +++ b/examples/benchmark_notebooks/dacbo.ipynb @@ -0,0 +1,423 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "from rich.pretty import pprint" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## The DACBO Benchmark\n", + "Let's take a look at DACBO. This is a benchmark for controlling hyperparameters of a Bayesian Optimization (BO) loop. First, let's make an instance of the benchmark:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from dacbench.benchmarks import DACBOBenchmark\n", + "bench = DACBOBenchmark()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Now let's take a look at the elements of the config in this benchmark:" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
[\n",
+       "'reward_range',\n",
+       "'seed',\n",
+       "'instance_set_path',\n",
+       "'optimizer_cfg',\n",
+       "'observation_keys',\n",
+       "'action_space_class',\n",
+       "'action_space_kwargs',\n",
+       "'reward_keys',\n",
+       "'benchmark_info'\n",
+       "]\n",
+       "
\n" + ], + "text/plain": [ + "\u001b[1m[\u001b[0m\n", + "\u001b[2;32m│ \u001b[0m\u001b[32m'reward_range'\u001b[0m,\n", + "\u001b[2;32m│ \u001b[0m\u001b[32m'seed'\u001b[0m,\n", + "\u001b[2;32m│ \u001b[0m\u001b[32m'instance_set_path'\u001b[0m,\n", + "\u001b[2;32m│ \u001b[0m\u001b[32m'optimizer_cfg'\u001b[0m,\n", + "\u001b[2;32m│ \u001b[0m\u001b[32m'observation_keys'\u001b[0m,\n", + "\u001b[2;32m│ \u001b[0m\u001b[32m'action_space_class'\u001b[0m,\n", + "\u001b[2;32m│ \u001b[0m\u001b[32m'action_space_kwargs'\u001b[0m,\n", + "\u001b[2;32m│ \u001b[0m\u001b[32m'reward_keys'\u001b[0m,\n", + "\u001b[2;32m│ \u001b[0m\u001b[32m'benchmark_info'\u001b[0m\n", + "\u001b[1m]\u001b[0m\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "pprint(list(bench.config.keys()))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The 'benchmark_info' tells us some things about this benchmark already:" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
{\n",
+       "'identifier': 'DACBO',\n",
+       "'name': 'DACBO',\n",
+       "'reward': \"Default: [symlogregret]. Other options: ['trajectory_auc', 'incumbent_cost', 'incumbent_improvement', 'sqrt_incumbent_improvement', 'trajectory_auc_alt', 'episode_finished', 'episode_finished_scaled', 'symlogregret']\",\n",
+       "'state_description': \"Default: ['ubr_difference', 'acq_value_EI', 'acq_value_PI', 'previous_param']. Other options: ['incumbent_changes', 'trials_passed', 'trials_left', 'ubr', 'searchspace_dim', 'continuous_hps', 'categorical_hps', 'ordinal_hps', 'int_hps', 'tsp', 'knn_entropy', 'y_skewness', 'y_kurtosis', 'y_mean', 'y_std', 'y_variability', 'tsp_best', 'knn_entropy_best', 'y_skewness_best', 'y_kurtosis_best', 'y_mean_best', 'y_std_best', 'y_variability_best', 'budget_percentage', 'inc_improvement_scaled', 'has_categorical_hps', 'knn_difference', 'ubr_difference', 'acq_value_EI', 'acq_value_PI', 'previous_param']\"\n",
+       "}\n",
+       "
\n" + ], + "text/plain": [ + "\u001b[1m{\u001b[0m\n", + "\u001b[2;32m│ \u001b[0m\u001b[32m'identifier'\u001b[0m: \u001b[32m'DACBO'\u001b[0m,\n", + "\u001b[2;32m│ \u001b[0m\u001b[32m'name'\u001b[0m: \u001b[32m'DACBO'\u001b[0m,\n", + "\u001b[2;32m│ \u001b[0m\u001b[32m'reward'\u001b[0m: \u001b[32m\"Default: \u001b[0m\u001b[32m[\u001b[0m\u001b[32msymlogregret\u001b[0m\u001b[32m]\u001b[0m\u001b[32m. Other options: \u001b[0m\u001b[32m[\u001b[0m\u001b[32m'trajectory_auc', 'incumbent_cost', 'incumbent_improvement', 'sqrt_incumbent_improvement', 'trajectory_auc_alt', 'episode_finished', 'episode_finished_scaled', 'symlogregret'\u001b[0m\u001b[32m]\u001b[0m\u001b[32m\"\u001b[0m,\n", + "\u001b[2;32m│ \u001b[0m\u001b[32m'state_description'\u001b[0m: \u001b[32m\"Default: \u001b[0m\u001b[32m[\u001b[0m\u001b[32m'ubr_difference', 'acq_value_EI', 'acq_value_PI', 'previous_param'\u001b[0m\u001b[32m]\u001b[0m\u001b[32m. Other options: \u001b[0m\u001b[32m[\u001b[0m\u001b[32m'incumbent_changes', 'trials_passed', 'trials_left', 'ubr', 'searchspace_dim', 'continuous_hps', 'categorical_hps', 'ordinal_hps', 'int_hps', 'tsp', 'knn_entropy', 'y_skewness', 'y_kurtosis', 'y_mean', 'y_std', 'y_variability', 'tsp_best', 'knn_entropy_best', 'y_skewness_best', 'y_kurtosis_best', 'y_mean_best', 'y_std_best', 'y_variability_best', 'budget_percentage', 'inc_improvement_scaled', 'has_categorical_hps', 'knn_difference', 'ubr_difference', 'acq_value_EI', 'acq_value_PI', 'previous_param'\u001b[0m\u001b[32m]\u001b[0m\u001b[32m\"\u001b[0m\n", + "\u001b[1m}\u001b[0m\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "pprint(bench.config[\"benchmark_info\"])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The reward in this task has the following reward range:" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
[-inf, inf]\n",
+       "
\n" + ], + "text/plain": [ + "\u001b[1m[\u001b[0m-inf, inf\u001b[1m]\u001b[0m\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "pprint(bench.config[\"reward_range\"])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The config also contains some standard keys like the seed, instance set, list of observation keys, action space class, HP search ranges, etc. By default, the agent controls the parameter $\\alpha\\in [0,1]$ in the Weighted Expected Improvement (WEI) acquisition function of the BO loop. For further configuration details, please refer to the dacboenv package." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## DACBO Instances\n", + "Now let's take a look at how a DACBO instance looks. To do so, we first read the default instance set and look one element:" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
'bbob_2_default.yaml'\n",
+       "
\n" + ], + "text/plain": [ + "\u001b[32m'bbob_2_default.yaml'\u001b[0m\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'task_ids': ['bbob/2/1/0', 'bbob/2/2/0', 'bbob/2/3/0', 'bbob/2/4/0', 'bbob/2/5/0', 'bbob/2/6/0', 'bbob/2/7/0', 'bbob/2/8/0', 'bbob/2/9/0', 'bbob/2/10/0', 'bbob/2/11/0', 'bbob/2/12/0', 'bbob/2/13/0', 'bbob/2/14/0', 'bbob/2/15/0', 'bbob/2/16/0', 'bbob/2/17/0', 'bbob/2/18/0', 'bbob/2/19/0', 'bbob/2/20/0'], 'inner_seeds': [1, 2, 3]}\n" + ] + }, + { + "data": { + "text/html": [ + "
(1, 'bbob/2/1/0')\n",
+       "
\n" + ], + "text/plain": [ + "\u001b[1m(\u001b[0m\u001b[1;36m1\u001b[0m, \u001b[32m'bbob/2/1/0'\u001b[0m\u001b[1m)\u001b[0m\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "pprint(bench.config[\"instance_set_path\"])\n", + "bench.read_instance_set()\n", + "pprint(bench.config.instance_set[0])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "As in the instance selection is handled internally by the DACBO environment, we only provide a list of target functions to be considered as offered by CARP-S as well as a list of inner seeds. A DACBO instance consists of a single inner seed and a target function. By default, the cross product of the selected inner seeds seeds and target functions is evaluated in a round robin manner. Note that the internal DACBO environment uses the instance set as provided from the `.yaml` configuration file, not directly from the DACBench config object." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Running DACBO\n", + "Lastly, let's look at the DACBO benchmark in action. Because some observations rely on reference incumbent values, we first run SMAC to create a baseline. Additionally, the first BO run's initial design is evaluated upon resetting." + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
[15:04:32] INFO     Loading performance data from                                      reference_performance.py:243\n",
+       "                    reference_performance/reference_performance.parquet                                            \n",
+       "
\n" + ], + "text/plain": [ + "\u001b[2;36m[15:04:32]\u001b[0m\u001b[2;36m \u001b[0m\u001b[34mINFO \u001b[0m Loading performance data from \u001b]8;id=17500;file:///scratch/hpc-prf-intexml/tklenke/repos/dacboenv/dacboenv/utils/reference_performance.py\u001b\\\u001b[2mreference_performance.py\u001b[0m\u001b]8;;\u001b\\\u001b[2m:\u001b[0m\u001b]8;id=14152;file:///scratch/hpc-prf-intexml/tklenke/repos/dacboenv/dacboenv/utils/reference_performance.py#243\u001b\\\u001b[2m243\u001b[0m\u001b]8;;\u001b\\\n", + "\u001b[2;36m \u001b[0m reference_performance/reference_performance.parquet \u001b[2m \u001b[0m\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[WARNING][target_function_runner.py:74] The argument budget is not set by SMAC: Consider removing it from the target function.\n", + "[WARNING][target_function_runner.py:74] The argument instance is not set by SMAC: Consider removing it from the target function.\n", + "[WARNING][target_function_runner.py:74] The argument cutoff is not set by SMAC: Consider removing it from the target function.\n", + "[INFO][abstract_initial_design.py:139] Using 16 initial design configurations and 0 additional configurations.\n", + "[INFO][abstract_intensifier.py:307] Using only one seed for deterministic scenario.\n", + "[INFO][abstract_intensifier.py:517] Added config e9bc68 as new incumbent because there are no incumbents yet.\n", + "[INFO][abstract_intensifier.py:596] Added config 268bf5 and rejected config e9bc68 as incumbent because it is not better than the incumbents on 1 instances: \n", + "[INFO][abstract_intensifier.py:596] Added config a4ff80 and rejected config 268bf5 as incumbent because it is not better than the incumbents on 1 instances: \n", + "[INFO][abstract_intensifier.py:596] Added config 208457 and rejected config a4ff80 as incumbent because it is not better than the incumbents on 1 instances: \n", + "[INFO][abstract_intensifier.py:596] Added config c81044 and rejected config 208457 as incumbent because it is not better than the incumbents on 1 instances: \n", + "[INFO][abstract_intensifier.py:596] Added config 02dd32 and rejected config c81044 as incumbent because it is not better than the incumbents on 1 instances: \n", + "[WARNING][target_function_runner.py:74] The argument budget is not set by SMAC: Consider removing it from the target function.\n", + "[WARNING][target_function_runner.py:74] The argument instance is not set by SMAC: Consider removing it from the target function.\n", + "[WARNING][target_function_runner.py:74] The argument cutoff is not set by SMAC: Consider removing it from the target function.\n", + "[INFO][abstract_initial_design.py:139] Using 16 initial design configurations and 0 additional configurations.\n", + "[INFO][abstract_intensifier.py:307] Using only one seed for deterministic scenario.\n", + "[INFO][abstract_intensifier.py:517] Added config e9bc68 as new incumbent because there are no incumbents yet.\n", + "[INFO][abstract_intensifier.py:596] Added config 268bf5 and rejected config e9bc68 as incumbent because it is not better than the incumbents on 1 instances: \n", + "[INFO][abstract_intensifier.py:596] Added config a4ff80 and rejected config 268bf5 as incumbent because it is not better than the incumbents on 1 instances: \n", + "[INFO][abstract_intensifier.py:596] Added config 208457 and rejected config a4ff80 as incumbent because it is not better than the incumbents on 1 instances: \n", + "[INFO][abstract_intensifier.py:596] Added config c81044 and rejected config 208457 as incumbent because it is not better than the incumbents on 1 instances: \n" + ] + }, + { + "data": { + "text/html": [ + "
(\n",
+       "{\n",
+       "│   │   'ubr_difference': array([0.], dtype=float32),\n",
+       "│   │   'acq_value_EI': array([0.], dtype=float32),\n",
+       "│   │   'acq_value_PI': array([0.], dtype=float32),\n",
+       "│   │   'previous_param': array([0.5], dtype=float32)\n",
+       "},\n",
+       "{}\n",
+       ")\n",
+       "
\n" + ], + "text/plain": [ + "\u001b[1m(\u001b[0m\n", + "\u001b[2;32m│ \u001b[0m\u001b[1m{\u001b[0m\n", + "\u001b[2;32m│ │ \u001b[0m\u001b[32m'ubr_difference'\u001b[0m: \u001b[1;35marray\u001b[0m\u001b[1m(\u001b[0m\u001b[1m[\u001b[0m\u001b[1;36m0\u001b[0m.\u001b[1m]\u001b[0m, \u001b[33mdtype\u001b[0m=\u001b[35mfloat32\u001b[0m\u001b[1m)\u001b[0m,\n", + "\u001b[2;32m│ │ \u001b[0m\u001b[32m'acq_value_EI'\u001b[0m: \u001b[1;35marray\u001b[0m\u001b[1m(\u001b[0m\u001b[1m[\u001b[0m\u001b[1;36m0\u001b[0m.\u001b[1m]\u001b[0m, \u001b[33mdtype\u001b[0m=\u001b[35mfloat32\u001b[0m\u001b[1m)\u001b[0m,\n", + "\u001b[2;32m│ │ \u001b[0m\u001b[32m'acq_value_PI'\u001b[0m: \u001b[1;35marray\u001b[0m\u001b[1m(\u001b[0m\u001b[1m[\u001b[0m\u001b[1;36m0\u001b[0m.\u001b[1m]\u001b[0m, \u001b[33mdtype\u001b[0m=\u001b[35mfloat32\u001b[0m\u001b[1m)\u001b[0m,\n", + "\u001b[2;32m│ │ \u001b[0m\u001b[32m'previous_param'\u001b[0m: \u001b[1;35marray\u001b[0m\u001b[1m(\u001b[0m\u001b[1m[\u001b[0m\u001b[1;36m0.5\u001b[0m\u001b[1m]\u001b[0m, \u001b[33mdtype\u001b[0m=\u001b[35mfloat32\u001b[0m\u001b[1m)\u001b[0m\n", + "\u001b[2;32m│ \u001b[0m\u001b[1m}\u001b[0m,\n", + "\u001b[2;32m│ \u001b[0m\u001b[1m{\u001b[0m\u001b[1m}\u001b[0m\n", + "\u001b[1m)\u001b[0m\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "env = bench.get_environment()\n", + "pprint(env.reset())" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "If we take a step, we see the updated state:" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[INFO][abstract_intensifier.py:596] Added config 928ddd and rejected config c81044 as incumbent because it is not better than the incumbents on 1 instances: \n", + "[INFO][dacboenv.py:359] Step: 1, instance: (1, 'bbob/2/2/0') Reward: -5.258719929137845, terminated: False, truncated: False, info: {}\n" + ] + }, + { + "data": { + "text/html": [ + "
{\n",
+       "'ubr_difference': array([0.], dtype=float32),\n",
+       "'acq_value_EI': array([34.897663], dtype=float32),\n",
+       "'acq_value_PI': array([0.4999992], dtype=float32),\n",
+       "'previous_param': array([0.5118216], dtype=float32)\n",
+       "}\n",
+       "
\n" + ], + "text/plain": [ + "\u001b[1m{\u001b[0m\n", + "\u001b[2;32m│ \u001b[0m\u001b[32m'ubr_difference'\u001b[0m: \u001b[1;35marray\u001b[0m\u001b[1m(\u001b[0m\u001b[1m[\u001b[0m\u001b[1;36m0\u001b[0m.\u001b[1m]\u001b[0m, \u001b[33mdtype\u001b[0m=\u001b[35mfloat32\u001b[0m\u001b[1m)\u001b[0m,\n", + "\u001b[2;32m│ \u001b[0m\u001b[32m'acq_value_EI'\u001b[0m: \u001b[1;35marray\u001b[0m\u001b[1m(\u001b[0m\u001b[1m[\u001b[0m\u001b[1;36m34.897663\u001b[0m\u001b[1m]\u001b[0m, \u001b[33mdtype\u001b[0m=\u001b[35mfloat32\u001b[0m\u001b[1m)\u001b[0m,\n", + "\u001b[2;32m│ \u001b[0m\u001b[32m'acq_value_PI'\u001b[0m: \u001b[1;35marray\u001b[0m\u001b[1m(\u001b[0m\u001b[1m[\u001b[0m\u001b[1;36m0.4999992\u001b[0m\u001b[1m]\u001b[0m, \u001b[33mdtype\u001b[0m=\u001b[35mfloat32\u001b[0m\u001b[1m)\u001b[0m,\n", + "\u001b[2;32m│ \u001b[0m\u001b[32m'previous_param'\u001b[0m: \u001b[1;35marray\u001b[0m\u001b[1m(\u001b[0m\u001b[1m[\u001b[0m\u001b[1;36m0.5118216\u001b[0m\u001b[1m]\u001b[0m, \u001b[33mdtype\u001b[0m=\u001b[35mfloat32\u001b[0m\u001b[1m)\u001b[0m\n", + "\u001b[1m}\u001b[0m\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "action = env.action_space.sample()\n", + "state, reward, terminated, truncated, info = env.step(action)\n", + "pprint(state)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Furthermore, we also get a reward and a truncation signal. Truncation will be set to true after a single BO run has finished and the next instance will be selected internally." + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
'Reward -5.258719929137845'\n",
+       "
\n" + ], + "text/plain": [ + "\u001b[32m'Reward -5.258719929137845'\u001b[0m\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
'Truncated False'\n",
+       "
\n" + ], + "text/plain": [ + "\u001b[32m'Truncated False'\u001b[0m\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "pprint(f\"Reward {reward}\")\n", + "pprint(f\"Truncated {truncated}\")" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "DACBench", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.14" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/other_requirements/dacbo.json b/other_requirements/dacbo.json new file mode 100644 index 000000000..b09397c4b --- /dev/null +++ b/other_requirements/dacbo.json @@ -0,0 +1,5 @@ +{ + "dacbo": [ + "dacboenv" + ] +} \ No newline at end of file