{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Running BOA Optimization Directly in Python\n", "\n", "This notebook demonstrates how to:\n", "\n", "Write a basic Wrapper in Python and launch a optimization from Python.\n", "If you wanted to launch it from command line, you would do a similar thing of defining the Wrapper, and then put in your configuration file the information about where the wrapper is, and use `BOA's ` CLI tools. See :doc:`.example_py_run` for more information." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stderr", "output_type": "stream", "text": [ "[INFO 11-30 12:25:37] ax.utils.notebook.plotting: Injecting Plotly library into cell. Do not overwrite or delete cell.\n" ] }, { "data": { "text/html": [ " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import pathlib\n", "\n", "from ax import Trial\n", "from ax.utils.notebook.plotting import init_notebook_plotting\n", "from ax.utils.measurement.synthetic_functions import from_botorch\n", "from botorch.test_functions.synthetic import Cosine8\n", "from ax.service.utils.report_utils import exp_to_df\n", "import numpy as np\n", "import yaml\n", "\n", "import boa\n", "\n", "init_notebook_plotting()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Loading the Config File" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "config_path = pathlib.Path().resolve() / \"single_config.yaml\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Here we can load the configuration and see what it looks like\n", "\n", "We don't normalize it so we can see it in its original form,\n", "but we will need to normalize it later for downstream libraries" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "optimization_options:\n", " objective_options:\n", " objectives:\n", " - boa_metric: mean\n", " name: Cosine8\n", " scheduler:\n", " total_trials: 100\n", "parameters:\n", " x0:\n", " bounds:\n", " - 0.0\n", " - 1.0\n", " type: range\n", " x1:\n", " bounds:\n", " - 0.0\n", " - 1.0\n", " type: range\n", " x2:\n", " bounds:\n", " - 0.0\n", " - 1.0\n", " type: range\n", " x3:\n", " bounds:\n", " - 0.0\n", " - 1.0\n", " type: range\n", " x4:\n", " bounds:\n", " - 0.0\n", " - 1.0\n", " type: range\n", " x5:\n", " bounds:\n", " - 0.0\n", " - 1.0\n", " type: range\n", " x6:\n", " bounds:\n", " - 0.0\n", " - 1.0\n", " type: range\n", " x7:\n", " bounds:\n", " - 0.0\n", " - 1.0\n", " type: range\n", "\n" ] } ], "source": [ "config = boa.load_jsonlike(config_path, normalize=False)\n", "print(yaml.dump(config))" ] }, { "cell_type": "markdown", "metadata": { "tags": [] }, "source": [ "we need the config normalized, which modifies the parameter section\n", "into a less user friendly form, but what the downstream libraries need" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "optimization_options:\n", " experiment:\n", " name: boa_runs\n", " generation_strategy: {}\n", " objective_options:\n", " objectives:\n", " - boa_metric: mean\n", " name: Cosine8\n", " scheduler:\n", " total_trials: 100\n", "parameter_constraints_orig: []\n", "parameters:\n", "- bounds:\n", " - 0.0\n", " - 1.0\n", " name: x0\n", " type: range\n", "- bounds:\n", " - 0.0\n", " - 1.0\n", " name: x1\n", " type: range\n", "- bounds:\n", " - 0.0\n", " - 1.0\n", " name: x2\n", " type: range\n", "- bounds:\n", " - 0.0\n", " - 1.0\n", " name: x3\n", " type: range\n", "- bounds:\n", " - 0.0\n", " - 1.0\n", " name: x4\n", " type: range\n", "- bounds:\n", " - 0.0\n", " - 1.0\n", " name: x5\n", " type: range\n", "- bounds:\n", " - 0.0\n", " - 1.0\n", " name: x6\n", " type: range\n", "- bounds:\n", " - 0.0\n", " - 1.0\n", " name: x7\n", " type: range\n", "parameters_orig:\n", " x0:\n", " bounds:\n", " - 0.0\n", " - 1.0\n", " type: range\n", " x1:\n", " bounds:\n", " - 0.0\n", " - 1.0\n", " type: range\n", " x2:\n", " bounds:\n", " - 0.0\n", " - 1.0\n", " type: range\n", " x3:\n", " bounds:\n", " - 0.0\n", " - 1.0\n", " type: range\n", " x4:\n", " bounds:\n", " - 0.0\n", " - 1.0\n", " type: range\n", " x5:\n", " bounds:\n", " - 0.0\n", " - 1.0\n", " type: range\n", " x6:\n", " bounds:\n", " - 0.0\n", " - 1.0\n", " type: range\n", " x7:\n", " bounds:\n", " - 0.0\n", " - 1.0\n", " type: range\n", "\n" ] } ], "source": [ "config = boa.load_jsonlike(config_path)\n", "print(yaml.dump(config))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Define Our Wrapper" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This is a silly toy function, in reality, you could instead import your model main() function and use that, and then collect the results. You could also call an external script to start a model run from Bash or elsewhere." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "cosine8 = from_botorch(Cosine8())\n", "\n", "\n", "def run_hartmann6_from_trial(X) -> float:\n", " result = -cosine8(X)\n", " return result" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "class Wrapper(boa.BaseWrapper):\n", " def __init__(self, *args, **kwargs):\n", " super().__init__(*args, **kwargs)\n", " self.data = {}\n", "\n", " def run_model(self, trial: Trial) -> None:\n", " X = np.array([parameter for parameter in trial.arm.parameters.values()])\n", " self.data[trial.index] = run_hartmann6_from_trial(X)\n", "\n", " def set_trial_status(self, trial: Trial) -> None:\n", " data_exists = self.data.get(trial.index)\n", " if data_exists:\n", " trial.mark_completed()\n", "\n", " def fetch_trial_data_single(self, trial: Trial, metric_properties: dict, metric_name: str, *args, **kwargs) -> dict:\n", " return dict(a=self.data[trial.index])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Initialize our Setup" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Start time: 20221130T122537\n", "[INFO 11-30 12:25:37] ax.service.utils.instantiation: Inferred value type of ParameterType.FLOAT for parameter x0. If that is not the expected value type, you can explicity specify 'value_type' ('int', 'float', 'bool' or 'str') in parameter dict.\n", "[INFO 11-30 12:25:37] ax.service.utils.instantiation: Inferred value type of ParameterType.FLOAT for parameter x1. If that is not the expected value type, you can explicity specify 'value_type' ('int', 'float', 'bool' or 'str') in parameter dict.\n", "[INFO 11-30 12:25:37] ax.service.utils.instantiation: Inferred value type of ParameterType.FLOAT for parameter x2. If that is not the expected value type, you can explicity specify 'value_type' ('int', 'float', 'bool' or 'str') in parameter dict.\n", "[INFO 11-30 12:25:37] ax.service.utils.instantiation: Inferred value type of ParameterType.FLOAT for parameter x3. If that is not the expected value type, you can explicity specify 'value_type' ('int', 'float', 'bool' or 'str') in parameter dict.\n", "[INFO 11-30 12:25:37] ax.service.utils.instantiation: Inferred value type of ParameterType.FLOAT for parameter x4. If that is not the expected value type, you can explicity specify 'value_type' ('int', 'float', 'bool' or 'str') in parameter dict.\n", "[INFO 11-30 12:25:37] ax.service.utils.instantiation: Inferred value type of ParameterType.FLOAT for parameter x5. If that is not the expected value type, you can explicity specify 'value_type' ('int', 'float', 'bool' or 'str') in parameter dict.\n", "[INFO 11-30 12:25:37] ax.service.utils.instantiation: Inferred value type of ParameterType.FLOAT for parameter x6. If that is not the expected value type, you can explicity specify 'value_type' ('int', 'float', 'bool' or 'str') in parameter dict.\n", "[INFO 11-30 12:25:37] ax.service.utils.instantiation: Inferred value type of ParameterType.FLOAT for parameter x7. If that is not the expected value type, you can explicity specify 'value_type' ('int', 'float', 'bool' or 'str') in parameter dict.\n", "[INFO 11-30 12:25:37] ax.service.utils.instantiation: Created search space: SearchSpace(parameters=[RangeParameter(name='x0', parameter_type=FLOAT, range=[0.0, 1.0]), RangeParameter(name='x1', parameter_type=FLOAT, range=[0.0, 1.0]), RangeParameter(name='x2', parameter_type=FLOAT, range=[0.0, 1.0]), RangeParameter(name='x3', parameter_type=FLOAT, range=[0.0, 1.0]), RangeParameter(name='x4', parameter_type=FLOAT, range=[0.0, 1.0]), RangeParameter(name='x5', parameter_type=FLOAT, range=[0.0, 1.0]), RangeParameter(name='x6', parameter_type=FLOAT, range=[0.0, 1.0]), RangeParameter(name='x7', parameter_type=FLOAT, range=[0.0, 1.0])], parameter_constraints=[]).\n", "[INFO 11-30 12:25:37] ax.modelbridge.dispatch_utils: Using Bayesian optimization since there are more ordered parameters than there are categories for the unordered categorical parameters.\n", "[INFO 11-30 12:25:37] ax.modelbridge.dispatch_utils: Using Bayesian Optimization generation strategy: GenerationStrategy(name='Sobol+GPEI', steps=[Sobol for 16 trials, GPEI for subsequent trials]). Iterations after 16 will take longer to generate due to model-fitting.\n", "[INFO 11-30 12:25:37] Scheduler: `Scheduler` requires experiment to have immutable search space and optimization config. Setting property immutable_search_space_and_opt_config to `True` on experiment.\n" ] }, { "data": { "text/plain": [ "(Scheduler(experiment=Experiment(boa_runs), generation_strategy=GenerationStrategy(name='Sobol+GPEI', steps=[Sobol for 16 trials, GPEI for subsequent trials]), options=SchedulerOptions(max_pending_trials=10, trial_type=, batch_size=None, total_trials=100, tolerated_trial_failure_rate=0.5, min_failed_trials_for_failure_rate_check=5, log_filepath=None, logging_level=20, ttl_seconds_for_trials=None, init_seconds_between_polls=1, min_seconds_before_poll=1.0, seconds_between_polls_backoff_factor=1.5, timeout_hours=None, run_trials_in_batches=False, debug_log_run_metadata=False, early_stopping_strategy=None, global_stopping_strategy=None, suppress_storage_errors_after_retries=False)),\n", " <__main__.Wrapper at 0x15254b2e0>)" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "controller = boa.Controller(config_path=config_path, wrapper=Wrapper)\n", "\n", "# In general, it is nice to append the time stamp, but we don't here\n", "# so another notebook can always know the exact output folder name\n", "\n", "# we also say exist_ok=True so that we can use an existing directory\n", "# for the experiment outcome directory and overwrite it.\n", "controller.setup(working_dir=\".\", append_timestamp=False, exist_ok=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Run our Experiment" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The Controller will save our scheduler to JSON after it completes the run so we can reload it at a later time for analysis or to resume our experiment" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "jupyter": { "outputs_hidden": false } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "[INFO 11-30 12:25:37] Scheduler: Running trials [0]...\n", "[INFO 11-30 12:25:38] Scheduler: Running trials [1]...\n", "[INFO 11-30 12:25:39] Scheduler: Running trials [2]...\n", "[INFO 11-30 12:25:41] Scheduler: Running trials [3]...\n", "[INFO 11-30 12:25:41] Scheduler: Running trials [4]...\n", "[INFO 11-30 12:25:42] Scheduler: Running trials [5]...\n", "[INFO 11-30 12:25:43] Scheduler: Running trials [6]...\n", "[INFO 11-30 12:25:44] Scheduler: Running trials [7]...\n", "[INFO 11-30 12:25:45] Scheduler: Running trials [8]...\n", "[INFO 11-30 12:25:46] Scheduler: Running trials [9]...\n", "[INFO 11-30 12:25:47] Scheduler: Retrieved COMPLETED trials: 0 - 9.\n", "[INFO 11-30 12:25:47] Scheduler: Fetching data for trials: 0 - 9.\n", "[INFO 11-30 12:25:47] Scheduler: Running trials [10]...\n", "[INFO 11-30 12:25:48] Scheduler: Running trials [11]...\n", "[INFO 11-30 12:25:49] Scheduler: Running trials [12]...\n", "[INFO 11-30 12:25:49] Scheduler: Running trials [13]...\n", "[INFO 11-30 12:25:50] Scheduler: Running trials [14]...\n", "[INFO 11-30 12:25:51] Scheduler: Running trials [15]...\n", "[INFO 11-30 12:25:53] Scheduler: Running trials [16]...\n", "[INFO 11-30 12:25:56] Scheduler: Running trials [17]...\n", "[INFO 11-30 12:25:57] Scheduler: Running trials [18]...\n", "[INFO 11-30 12:25:59] Scheduler: Generated all trials that can be generated currently. Max parallelism currently reached.\n", "[INFO 11-30 12:25:59] Scheduler: Retrieved COMPLETED trials: 10 - 18.\n", "[INFO 11-30 12:25:59] Scheduler: Fetching data for trials: 10 - 18.\n", "[INFO 11-30 12:26:00] Scheduler: Running trials [19]...\n", "[INFO 11-30 12:26:02] Scheduler: Running trials [20]...\n", "[INFO 11-30 12:26:04] Scheduler: Running trials [21]...\n", "[INFO 11-30 12:26:04] Scheduler: Generated all trials that can be generated currently. Max parallelism currently reached.\n", "[INFO 11-30 12:26:04] Scheduler: Retrieved COMPLETED trials: 19 - 21.\n", "[INFO 11-30 12:26:04] Scheduler: Fetching data for trials: 19 - 21.\n", "[INFO 11-30 12:26:05] Scheduler: Running trials [22]...\n", "[INFO 11-30 12:26:08] Scheduler: Running trials [23]...\n", "[INFO 11-30 12:26:11] Scheduler: Running trials [24]...\n", "[INFO 11-30 12:26:12] Scheduler: Generated all trials that can be generated currently. Max parallelism currently reached.\n", "[INFO 11-30 12:26:12] Scheduler: Retrieved COMPLETED trials: 22 - 24.\n", "[INFO 11-30 12:26:12] Scheduler: Fetching data for trials: 22 - 24.\n", "[INFO 11-30 12:26:13] Scheduler: Running trials [25]...\n", "[INFO 11-30 12:26:15] Scheduler: Running trials [26]...\n", "[INFO 11-30 12:26:18] Scheduler: Running trials [27]...\n", "[INFO 11-30 12:26:19] Scheduler: Generated all trials that can be generated currently. Max parallelism currently reached.\n", "[INFO 11-30 12:26:19] Scheduler: Retrieved COMPLETED trials: 25 - 27.\n", "[INFO 11-30 12:26:19] Scheduler: Fetching data for trials: 25 - 27.\n", "[INFO 11-30 12:26:20] Scheduler: Running trials [28]...\n", "[INFO 11-30 12:26:21] Scheduler: Running trials [29]...\n", "[INFO 11-30 12:26:23] Scheduler: Running trials [30]...\n", "[INFO 11-30 12:26:24] Scheduler: Generated all trials that can be generated currently. Max parallelism currently reached.\n", "[INFO 11-30 12:26:24] Scheduler: Retrieved COMPLETED trials: 28 - 30.\n", "[INFO 11-30 12:26:24] Scheduler: Fetching data for trials: 28 - 30.\n", "[INFO 11-30 12:26:25] Scheduler: Running trials [31]...\n", "[INFO 11-30 12:26:27] Scheduler: Running trials [32]...\n", "[INFO 11-30 12:26:30] Scheduler: Running trials [33]...\n", "[INFO 11-30 12:26:31] Scheduler: Generated all trials that can be generated currently. Max parallelism currently reached.\n", "[INFO 11-30 12:26:31] Scheduler: Retrieved COMPLETED trials: 31 - 33.\n", "[INFO 11-30 12:26:31] Scheduler: Fetching data for trials: 31 - 33.\n", "[INFO 11-30 12:26:32] Scheduler: Running trials [34]...\n", "[INFO 11-30 12:26:33] Scheduler: Running trials [35]...\n", "[INFO 11-30 12:26:36] Scheduler: Running trials [36]...\n", "[INFO 11-30 12:26:37] Scheduler: Generated all trials that can be generated currently. Max parallelism currently reached.\n", "[INFO 11-30 12:26:37] Scheduler: Retrieved COMPLETED trials: 34 - 36.\n", "[INFO 11-30 12:26:37] Scheduler: Fetching data for trials: 34 - 36.\n", "[INFO 11-30 12:26:39] Scheduler: Running trials [37]...\n", "[INFO 11-30 12:26:40] Scheduler: Running trials [38]...\n", "[INFO 11-30 12:26:42] Scheduler: Running trials [39]...\n", "[INFO 11-30 12:26:43] Scheduler: Generated all trials that can be generated currently. Max parallelism currently reached.\n", "[INFO 11-30 12:26:43] Scheduler: Retrieved COMPLETED trials: 37 - 39.\n", "[INFO 11-30 12:26:43] Scheduler: Fetching data for trials: 37 - 39.\n", "[INFO 11-30 12:26:45] Scheduler: Running trials [40]...\n", "[INFO 11-30 12:26:46] Scheduler: Running trials [41]...\n", "[INFO 11-30 12:26:48] Scheduler: Running trials [42]...\n", "[INFO 11-30 12:26:49] Scheduler: Generated all trials that can be generated currently. Max parallelism currently reached.\n", "[INFO 11-30 12:26:49] Scheduler: Retrieved COMPLETED trials: 40 - 42.\n", "[INFO 11-30 12:26:49] Scheduler: Fetching data for trials: 40 - 42.\n", "[INFO 11-30 12:26:51] Scheduler: Running trials [43]...\n", "[INFO 11-30 12:26:52] Scheduler: Running trials [44]...\n", "[INFO 11-30 12:26:54] Scheduler: Running trials [45]...\n", "[INFO 11-30 12:26:55] Scheduler: Generated all trials that can be generated currently. Max parallelism currently reached.\n", "[INFO 11-30 12:26:55] Scheduler: Retrieved COMPLETED trials: 43 - 45.\n", "[INFO 11-30 12:26:55] Scheduler: Fetching data for trials: 43 - 45.\n", "[INFO 11-30 12:26:56] Scheduler: Running trials [46]...\n", "[INFO 11-30 12:26:57] Scheduler: Running trials [47]...\n", "[INFO 11-30 12:26:58] Scheduler: Running trials [48]...\n", "[INFO 11-30 12:26:59] Scheduler: Generated all trials that can be generated currently. Max parallelism currently reached.\n", "[INFO 11-30 12:26:59] Scheduler: Retrieved COMPLETED trials: 46 - 48.\n", "[INFO 11-30 12:26:59] Scheduler: Fetching data for trials: 46 - 48.\n", "[INFO 11-30 12:26:59] Scheduler: Running trials [49]...\n", "[INFO 11-30 12:27:01] Scheduler: Running trials [50]...\n", "[INFO 11-30 12:27:02] Scheduler: Running trials [51]...\n", "[INFO 11-30 12:27:03] Scheduler: Generated all trials that can be generated currently. Max parallelism currently reached.\n", "[INFO 11-30 12:27:03] Scheduler: Retrieved COMPLETED trials: 49 - 51.\n", "[INFO 11-30 12:27:03] Scheduler: Fetching data for trials: 49 - 51.\n", "[INFO 11-30 12:27:03] Scheduler: Running trials [52]...\n", "[INFO 11-30 12:27:05] Scheduler: Running trials [53]...\n", "[INFO 11-30 12:27:09] Scheduler: Running trials [54]...\n", "[INFO 11-30 12:27:10] Scheduler: Generated all trials that can be generated currently. Max parallelism currently reached.\n", "[INFO 11-30 12:27:10] Scheduler: Retrieved COMPLETED trials: 52 - 54.\n", "[INFO 11-30 12:27:10] Scheduler: Fetching data for trials: 52 - 54.\n", "[INFO 11-30 12:27:10] Scheduler: Running trials [55]...\n", "[INFO 11-30 12:27:11] Scheduler: Running trials [56]...\n", "[INFO 11-30 12:27:15] Scheduler: Running trials [57]...\n", "[INFO 11-30 12:27:16] Scheduler: Generated all trials that can be generated currently. Max parallelism currently reached.\n", "[INFO 11-30 12:27:16] Scheduler: Retrieved COMPLETED trials: 55 - 57.\n", "[INFO 11-30 12:27:16] Scheduler: Fetching data for trials: 55 - 57.\n", "[INFO 11-30 12:27:16] Scheduler: Running trials [58]...\n", "[INFO 11-30 12:27:18] Scheduler: Running trials [59]...\n", "[INFO 11-30 12:27:20] Scheduler: Running trials [60]...\n", "[INFO 11-30 12:27:21] Scheduler: Generated all trials that can be generated currently. Max parallelism currently reached.\n", "[INFO 11-30 12:27:21] Scheduler: Retrieved COMPLETED trials: 58 - 60.\n", "[INFO 11-30 12:27:21] Scheduler: Fetching data for trials: 58 - 60.\n", "[INFO 11-30 12:27:21] Scheduler: Running trials [61]...\n", "[INFO 11-30 12:27:22] Scheduler: Running trials [62]...\n", "[INFO 11-30 12:27:24] Scheduler: Running trials [63]...\n", "[INFO 11-30 12:27:25] Scheduler: Generated all trials that can be generated currently. Max parallelism currently reached.\n", "[INFO 11-30 12:27:25] Scheduler: Retrieved COMPLETED trials: 61 - 63.\n", "[INFO 11-30 12:27:25] Scheduler: Fetching data for trials: 61 - 63.\n", "[INFO 11-30 12:27:26] Scheduler: Running trials [64]...\n", "[INFO 11-30 12:27:27] Scheduler: Running trials [65]...\n", "[INFO 11-30 12:27:29] Scheduler: Running trials [66]...\n", "[INFO 11-30 12:27:30] Scheduler: Generated all trials that can be generated currently. Max parallelism currently reached.\n", "[INFO 11-30 12:27:30] Scheduler: Retrieved COMPLETED trials: 64 - 66.\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "[INFO 11-30 12:27:30] Scheduler: Fetching data for trials: 64 - 66.\n", "[INFO 11-30 12:27:30] Scheduler: Running trials [67]...\n", "[INFO 11-30 12:27:32] Scheduler: Running trials [68]...\n", "[INFO 11-30 12:27:35] Scheduler: Running trials [69]...\n", "[INFO 11-30 12:27:36] Scheduler: Generated all trials that can be generated currently. Max parallelism currently reached.\n", "[INFO 11-30 12:27:36] Scheduler: Retrieved COMPLETED trials: 67 - 69.\n", "[INFO 11-30 12:27:36] Scheduler: Fetching data for trials: 67 - 69.\n", "[INFO 11-30 12:27:36] Scheduler: Running trials [70]...\n", "[INFO 11-30 12:27:37] Scheduler: Running trials [71]...\n", "[INFO 11-30 12:27:39] Scheduler: Running trials [72]...\n", "[INFO 11-30 12:27:39] Scheduler: Generated all trials that can be generated currently. Max parallelism currently reached.\n", "[INFO 11-30 12:27:39] Scheduler: Retrieved COMPLETED trials: 70 - 72.\n", "[INFO 11-30 12:27:39] Scheduler: Fetching data for trials: 70 - 72.\n", "[INFO 11-30 12:27:39] Scheduler: Running trials [73]...\n", "[INFO 11-30 12:27:40] Scheduler: Running trials [74]...\n", "[INFO 11-30 12:27:43] Scheduler: Running trials [75]...\n", "[INFO 11-30 12:27:44] Scheduler: Generated all trials that can be generated currently. Max parallelism currently reached.\n", "[INFO 11-30 12:27:44] Scheduler: Retrieved COMPLETED trials: 73 - 75.\n", "[INFO 11-30 12:27:44] Scheduler: Fetching data for trials: 73 - 75.\n", "[INFO 11-30 12:27:45] Scheduler: Running trials [76]...\n", "[INFO 11-30 12:27:46] Scheduler: Running trials [77]...\n", "[INFO 11-30 12:27:48] Scheduler: Running trials [78]...\n", "[INFO 11-30 12:27:49] Scheduler: Generated all trials that can be generated currently. Max parallelism currently reached.\n", "[INFO 11-30 12:27:49] Scheduler: Retrieved COMPLETED trials: 76 - 78.\n", "[INFO 11-30 12:27:49] Scheduler: Fetching data for trials: 76 - 78.\n", "[INFO 11-30 12:27:49] Scheduler: Running trials [79]...\n", "[INFO 11-30 12:27:50] Scheduler: Running trials [80]...\n", "[INFO 11-30 12:27:52] Scheduler: Running trials [81]...\n", "[INFO 11-30 12:27:53] Scheduler: Generated all trials that can be generated currently. Max parallelism currently reached.\n", "[INFO 11-30 12:27:53] Scheduler: Retrieved COMPLETED trials: 79 - 81.\n", "[INFO 11-30 12:27:53] Scheduler: Fetching data for trials: 79 - 81.\n", "[INFO 11-30 12:27:53] Scheduler: Running trials [82]...\n", "[INFO 11-30 12:27:57] Scheduler: Running trials [83]...\n", "[INFO 11-30 12:28:01] Scheduler: Running trials [84]...\n", "[INFO 11-30 12:28:02] Scheduler: Generated all trials that can be generated currently. Max parallelism currently reached.\n", "[INFO 11-30 12:28:02] Scheduler: Retrieved COMPLETED trials: 82 - 84.\n", "[INFO 11-30 12:28:02] Scheduler: Fetching data for trials: 82 - 84.\n", "[INFO 11-30 12:28:03] Scheduler: Running trials [85]...\n", "[INFO 11-30 12:28:05] Scheduler: Running trials [86]...\n", "[INFO 11-30 12:28:06] Scheduler: Running trials [87]...\n", "[INFO 11-30 12:28:07] Scheduler: Generated all trials that can be generated currently. Max parallelism currently reached.\n", "[INFO 11-30 12:28:07] Scheduler: Retrieved COMPLETED trials: 85 - 87.\n", "[INFO 11-30 12:28:07] Scheduler: Fetching data for trials: 85 - 87.\n", "[INFO 11-30 12:28:08] Scheduler: Running trials [88]...\n", "[INFO 11-30 12:28:09] Scheduler: Running trials [89]...\n", "[INFO 11-30 12:28:10] Scheduler: Running trials [90]...\n", "[INFO 11-30 12:28:11] Scheduler: Generated all trials that can be generated currently. Max parallelism currently reached.\n", "[INFO 11-30 12:28:11] Scheduler: Retrieved COMPLETED trials: 88 - 90.\n", "[INFO 11-30 12:28:11] Scheduler: Fetching data for trials: 88 - 90.\n", "[INFO 11-30 12:28:12] Scheduler: Running trials [91]...\n", "[INFO 11-30 12:28:14] Scheduler: Running trials [92]...\n", "[INFO 11-30 12:28:15] Scheduler: Running trials [93]...\n", "[INFO 11-30 12:28:16] Scheduler: Generated all trials that can be generated currently. Max parallelism currently reached.\n", "[INFO 11-30 12:28:16] Scheduler: Retrieved COMPLETED trials: 91 - 93.\n", "[INFO 11-30 12:28:16] Scheduler: Fetching data for trials: 91 - 93.\n", "[INFO 11-30 12:28:16] Scheduler: Running trials [94]...\n", "[INFO 11-30 12:28:17] Scheduler: Running trials [95]...\n", "[INFO 11-30 12:28:19] Scheduler: Running trials [96]...\n", "[INFO 11-30 12:28:20] Scheduler: Generated all trials that can be generated currently. Max parallelism currently reached.\n", "[INFO 11-30 12:28:20] Scheduler: Retrieved COMPLETED trials: 94 - 96.\n", "[INFO 11-30 12:28:20] Scheduler: Fetching data for trials: 94 - 96.\n", "[INFO 11-30 12:28:20] Scheduler: Running trials [97]...\n", "[INFO 11-30 12:28:21] Scheduler: Running trials [98]...\n", "[INFO 11-30 12:28:22] Scheduler: Running trials [99]...\n", "[INFO 11-30 12:28:23] Scheduler: Retrieved COMPLETED trials: 97 - 99.\n", "[INFO 11-30 12:28:23] Scheduler: Fetching data for trials: 97 - 99.\n", "\n", "Trials completed! Total run time: 165\n", "Saved JSON-serialized state of optimization to `boa_runs/scheduler.json`.\n" ] } ], "source": [ "scheduler = controller.run()" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "jupyter": { "outputs_hidden": false } }, "outputs": [], "source": [ "## Get the Best Trial and Output All Trials" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "99" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "best_trial, best_params, obj = scheduler.get_best_trial()\n", "best_trial" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Cosine8trial_indexarm_namex0x1x2x3x4x5x6x7trial_statusgeneration_method
02.16712400_00.7745440.4688050.0680630.3623160.8795790.2736480.8329610.104289COMPLETEDSobol
11.33269211_00.4909800.1225340.2860720.1355330.4072120.5164110.5529750.209887COMPLETEDSobol
22.23977922_00.3705150.4378680.6132050.6304940.1351830.4723510.5525780.686980COMPLETEDSobol
33.41718433_00.1368360.6952780.9362320.8445620.0991370.9714490.4679570.413035COMPLETEDSobol
44.00973944_00.7470550.2032360.9846400.2578930.5422770.7426400.6820410.910413COMPLETEDSobol
..........................................
953.1579639595_00.4281700.8751730.9481100.4396050.6634190.4385040.6039670.475487COMPLETEDGPEI
961.8032109696_00.5161410.6350450.3597970.2229310.5879800.1717130.4711700.425680COMPLETEDGPEI
972.4267939797_00.3857000.4148250.1686690.7689330.4463030.6648910.7974530.790683COMPLETEDGPEI
983.7708189898_00.5686600.7639750.8165660.9320600.5710920.5173280.8336060.391031COMPLETEDGPEI
993.3414489999_00.7792550.2451770.9755800.8670210.3154990.4686690.4967130.597464COMPLETEDGPEI
\n", "

100 rows × 13 columns

\n", "
" ], "text/plain": [ " Cosine8 trial_index arm_name x0 x1 x2 x3 \\\n", "0 2.167124 0 0_0 0.774544 0.468805 0.068063 0.362316 \n", "1 1.332692 1 1_0 0.490980 0.122534 0.286072 0.135533 \n", "2 2.239779 2 2_0 0.370515 0.437868 0.613205 0.630494 \n", "3 3.417184 3 3_0 0.136836 0.695278 0.936232 0.844562 \n", "4 4.009739 4 4_0 0.747055 0.203236 0.984640 0.257893 \n", ".. ... ... ... ... ... ... ... \n", "95 3.157963 95 95_0 0.428170 0.875173 0.948110 0.439605 \n", "96 1.803210 96 96_0 0.516141 0.635045 0.359797 0.222931 \n", "97 2.426793 97 97_0 0.385700 0.414825 0.168669 0.768933 \n", "98 3.770818 98 98_0 0.568660 0.763975 0.816566 0.932060 \n", "99 3.341448 99 99_0 0.779255 0.245177 0.975580 0.867021 \n", "\n", " x4 x5 x6 x7 trial_status generation_method \n", "0 0.879579 0.273648 0.832961 0.104289 COMPLETED Sobol \n", "1 0.407212 0.516411 0.552975 0.209887 COMPLETED Sobol \n", "2 0.135183 0.472351 0.552578 0.686980 COMPLETED Sobol \n", "3 0.099137 0.971449 0.467957 0.413035 COMPLETED Sobol \n", "4 0.542277 0.742640 0.682041 0.910413 COMPLETED Sobol \n", ".. ... ... ... ... ... ... \n", "95 0.663419 0.438504 0.603967 0.475487 COMPLETED GPEI \n", "96 0.587980 0.171713 0.471170 0.425680 COMPLETED GPEI \n", "97 0.446303 0.664891 0.797453 0.790683 COMPLETED GPEI \n", "98 0.571092 0.517328 0.833606 0.391031 COMPLETED GPEI \n", "99 0.315499 0.468669 0.496713 0.597464 COMPLETED GPEI \n", "\n", "[100 rows x 13 columns]" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "experiment = scheduler.experiment\n", "exp_to_df(experiment)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.9.13" } }, "nbformat": 4, "nbformat_minor": 4 }