{ "cells": [ { "cell_type": "markdown", "id": "a7da1f46", "metadata": { "customInput": null, "originalKey": "06e172a0-2da3-4c90-93c2-be01bf4f6d45", "papermill": { "duration": 0.003642, "end_time": "2025-01-31T07:10:00.421673", "exception": false, "start_time": "2025-01-31T07:10:00.418031", "status": "completed" }, "showInput": false, "tags": [] }, "source": [ "This tutorial illustrates use of a Global Stopping Strategy (GSS) in combination with the Service API. For background on the Service API, see the Service API Tutorial: https://ax.dev/tutorials/gpei_hartmann_service.html GSS is also supported in the Scheduler API, where it can be provided as part of `SchedulerOptions`. For more on `Scheduler`, see the Scheduler tutorial: https://ax.dev/tutorials/scheduler.html\n", "\n", "Global Stopping stops an optimization loop when some data-based criteria are met which suggest that future trials will not be very helpful. For example, we might stop when there has been very little improvement in the last five trials. This is as opposed to trial-level early stopping, which monitors the results of expensive evaluations and terminates those that are unlikely to produce promising results, freeing resources to explore more promising configurations. For more on trial-level early stopping, see the tutorial: https://ax.dev/tutorials/early_stopping/early_stopping.html" ] }, { "cell_type": "code", "execution_count": 1, "id": "f0f36eb8", "metadata": { "customOutput": null, "execution": { "iopub.execute_input": "2025-01-31T07:10:00.430089Z", "iopub.status.busy": "2025-01-31T07:10:00.429520Z", "iopub.status.idle": "2025-01-31T07:10:03.329692Z", "shell.execute_reply": "2025-01-31T07:10:03.328712Z" }, "executionStartTime": 1683829335587, "executionStopTime": 1683829339370, "originalKey": "00a04d2c-d990-41c1-9eef-bbb05fba000d", "papermill": { "duration": 2.924124, "end_time": "2025-01-31T07:10:03.349180", "exception": false, "start_time": "2025-01-31T07:10:00.425056", "status": "completed" }, "requestMsgId": "1c560539-1c7d-4c7a-ae55-e87c3b601859", "tags": [] }, "outputs": [ { "data": { "text/html": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stderr", "output_type": "stream", "text": [ "[INFO 01-31 07:10:03] ax.utils.notebook.plotting: Injecting Plotly library into cell. Do not overwrite or delete cell.\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "[INFO 01-31 07:10:03] ax.utils.notebook.plotting: Please see\n", " (https://ax.dev/tutorials/visualizations.html#Fix-for-plots-that-are-not-rendering)\n", " if visualizations are not rendering.\n" ] }, { "data": { "text/html": [ " \n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import numpy as np\n", "\n", "from ax.service.ax_client import AxClient, ObjectiveProperties\n", "from ax.utils.measurement.synthetic_functions import Branin, branin\n", "from ax.utils.notebook.plotting import init_notebook_plotting, render\n", "\n", "init_notebook_plotting()" ] }, { "cell_type": "markdown", "id": "9107a404", "metadata": { "customInput": null, "originalKey": "8688d729-b402-4a4c-b796-94fdcf5e022c", "papermill": { "duration": 0.041324, "end_time": "2025-01-31T07:10:03.432155", "exception": false, "start_time": "2025-01-31T07:10:03.390831", "status": "completed" }, "showInput": false, "tags": [] }, "source": [ "# 1. What happens without global stopping? Optimization can run for too long.\n", "This example uses the Branin test problem. We run 25 trials, which turns out to be far more than needed, because we get close to the optimum quite quickly." ] }, { "cell_type": "code", "execution_count": 2, "id": "2ccdc863", "metadata": { "customInput": null, "customOutput": null, "execution": { "iopub.execute_input": "2025-01-31T07:10:03.516115Z", "iopub.status.busy": "2025-01-31T07:10:03.515625Z", "iopub.status.idle": "2025-01-31T07:10:03.519446Z", "shell.execute_reply": "2025-01-31T07:10:03.518875Z" }, "executionStartTime": 1683829339516, "executionStopTime": 1683829339531, "originalKey": "320a952b-9e78-43e1-a55b-76a355e90f83", "papermill": { "duration": 0.047281, "end_time": "2025-01-31T07:10:03.520737", "exception": false, "start_time": "2025-01-31T07:10:03.473456", "status": "completed" }, "requestMsgId": "14e3a517-c7d0-4300-92d9-57ceb5afca34", "showInput": true, "tags": [] }, "outputs": [], "source": [ "def evaluate(parameters):\n", " x = np.array([parameters.get(f\"x{i+1}\") for i in range(2)])\n", " return {\"branin\": (branin(x), 0.0)}" ] }, { "cell_type": "code", "execution_count": 3, "id": "c3236db2", "metadata": { "customInput": null, "customOutput": null, "execution": { "iopub.execute_input": "2025-01-31T07:10:03.605092Z", "iopub.status.busy": "2025-01-31T07:10:03.604501Z", "iopub.status.idle": "2025-01-31T07:10:03.608278Z", "shell.execute_reply": "2025-01-31T07:10:03.607662Z" }, "executionStartTime": 1683829339659, "executionStopTime": 1683829339668, "originalKey": "5740fbc2-97d6-465b-b01c-61e6c34c0220", "papermill": { "duration": 0.047504, "end_time": "2025-01-31T07:10:03.609709", "exception": false, "start_time": "2025-01-31T07:10:03.562205", "status": "completed" }, "requestMsgId": "ff819cc9-ff17-4763-a857-83662b01e955", "showInput": true, "tags": [] }, "outputs": [], "source": [ "params = [\n", " {\n", " \"name\": f\"x{i + 1}\",\n", " \"type\": \"range\",\n", " \"bounds\": [*Branin._domain[i]],\n", " \"value_type\": \"float\",\n", " \"log_scale\": False,\n", " }\n", "\n", " for i in range(2)\n", "]" ] }, { "cell_type": "code", "execution_count": 4, "id": "ec04a5cf", "metadata": { "customInput": null, "customOutput": null, "execution": { "iopub.execute_input": "2025-01-31T07:10:03.694091Z", "iopub.status.busy": "2025-01-31T07:10:03.693633Z", "iopub.status.idle": "2025-01-31T07:10:03.704453Z", "shell.execute_reply": "2025-01-31T07:10:03.703921Z" }, "executionStartTime": 1683829339782, "executionStopTime": 1683829339834, "originalKey": "65667172-14df-437b-bdd0-5a59580e4054", "papermill": { "duration": 0.054491, "end_time": "2025-01-31T07:10:03.705790", "exception": false, "start_time": "2025-01-31T07:10:03.651299", "status": "completed" }, "requestMsgId": "e0bc2847-17a5-43d7-bf49-ed97c90f1d50", "showInput": true, "tags": [] }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "[WARNING 01-31 07:10:03] ax.service.ax_client: Random seed set to 0. Note that this setting only affects the Sobol quasi-random generator and BoTorch-powered Bayesian optimization models. For the latter models, setting random seed to the same number for two optimizations will make the generated trials similar, but not exactly the same, and over time the trials will diverge more.\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "[INFO 01-31 07:10:03] ax.service.utils.instantiation: Created search space: SearchSpace(parameters=[RangeParameter(name='x1', parameter_type=FLOAT, range=[-5.0, 10.0]), RangeParameter(name='x2', parameter_type=FLOAT, range=[0.0, 15.0])], parameter_constraints=[]).\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "[INFO 01-31 07:10:03] ax.core.experiment: The is_test flag has been set to True. This flag is meant purely for development and integration testing purposes. If you are running a live experiment, please set this flag to False\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "[INFO 01-31 07:10:03] ax.modelbridge.dispatch_utils: Using Models.BOTORCH_MODULAR since there is at least one ordered parameter and there are no unordered categorical parameters.\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "[INFO 01-31 07:10:03] ax.modelbridge.dispatch_utils: Calculating the number of remaining initialization trials based on num_initialization_trials=None max_initialization_trials=None num_tunable_parameters=2 num_trials=None use_batch_trials=False\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "[INFO 01-31 07:10:03] ax.modelbridge.dispatch_utils: calculated num_initialization_trials=5\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "[INFO 01-31 07:10:03] ax.modelbridge.dispatch_utils: num_completed_initialization_trials=0 num_remaining_initialization_trials=5\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "[INFO 01-31 07:10:03] ax.modelbridge.dispatch_utils: `verbose`, `disable_progbar`, and `jit_compile` are not yet supported when using `choose_generation_strategy` with ModularBoTorchModel, dropping these arguments.\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "[INFO 01-31 07:10:03] ax.modelbridge.dispatch_utils: Using Bayesian Optimization generation strategy: GenerationStrategy(name='Sobol+BoTorch', steps=[Sobol for 5 trials, BoTorch for subsequent trials]). Iterations after 5 will take longer to generate due to model-fitting.\n" ] } ], "source": [ "ax_client = AxClient(random_seed=0, verbose_logging=False)\n", "\n", "ax_client.create_experiment(\n", " name=\"branin_test_experiment\",\n", " parameters=params,\n", " objectives={\"branin\": ObjectiveProperties(minimize=True)},\n", " is_test=True,\n", ")" ] }, { "cell_type": "code", "execution_count": 5, "id": "60b360c3", "metadata": { "customInput": null, "customOutput": null, "execution": { "iopub.execute_input": "2025-01-31T07:10:03.790631Z", "iopub.status.busy": "2025-01-31T07:10:03.790177Z", "iopub.status.idle": "2025-01-31T07:10:24.252338Z", "shell.execute_reply": "2025-01-31T07:10:24.251666Z" }, "executionStartTime": 1683829339928, "executionStopTime": 1683829356006, "originalKey": "1f208de3-5189-4847-a779-940795977845", "papermill": { "duration": 20.506345, "end_time": "2025-01-31T07:10:24.253803", "exception": false, "start_time": "2025-01-31T07:10:03.747458", "status": "completed" }, "requestMsgId": "95f327f2-327f-4284-93ae-3053c9b6ec45", "showInput": true, "tags": [] }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/tmp/tmp.8SPGnWMU26/Ax-main/ax/modelbridge/cross_validation.py:439: UserWarning:\n", "\n", "Encountered exception in computing model fit quality: RandomModelBridge does not support prediction.\n", "\n", "/tmp/tmp.8SPGnWMU26/Ax-main/ax/modelbridge/cross_validation.py:439: UserWarning:\n", "\n", "Encountered exception in computing model fit quality: RandomModelBridge does not support prediction.\n", "\n", "/tmp/tmp.8SPGnWMU26/Ax-main/ax/modelbridge/cross_validation.py:439: UserWarning:\n", "\n", "Encountered exception in computing model fit quality: RandomModelBridge does not support prediction.\n", "\n", "/tmp/tmp.8SPGnWMU26/Ax-main/ax/modelbridge/cross_validation.py:439: UserWarning:\n", "\n", "Encountered exception in computing model fit quality: RandomModelBridge does not support prediction.\n", "\n", "/tmp/tmp.8SPGnWMU26/Ax-main/ax/modelbridge/cross_validation.py:439: UserWarning:\n", "\n", "Encountered exception in computing model fit quality: RandomModelBridge does not support prediction.\n", "\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "CPU times: user 40 s, sys: 88.7 ms, total: 40.1 s\n", "Wall time: 20.5 s\n" ] } ], "source": [ "%%time\n", "for i in range(25):\n", " parameters, trial_index = ax_client.get_next_trial()\n", " # Local evaluation here can be replaced with deployment to external system.\n", " ax_client.complete_trial(\n", " trial_index=trial_index, raw_data=evaluate(parameters)\n", " )" ] }, { "cell_type": "code", "execution_count": 6, "id": "e492ba88", "metadata": { "customInput": null, "customOutput": null, "execution": { "iopub.execute_input": "2025-01-31T07:10:24.341894Z", "iopub.status.busy": "2025-01-31T07:10:24.341169Z", "iopub.status.idle": "2025-01-31T07:10:24.550906Z", "shell.execute_reply": "2025-01-31T07:10:24.550009Z" }, "executionStartTime": 1683829356136, "executionStopTime": 1683829356616, "originalKey": "a369aafa-8ee4-4c02-bea6-673271da81ab", "papermill": { "duration": 0.273313, "end_time": "2025-01-31T07:10:24.570546", "exception": false, "start_time": "2025-01-31T07:10:24.297233", "status": "completed" }, "requestMsgId": "b601e1e9-fd2d-4faf-a369-04e5c4a9f8cb", "showInput": true, "tags": [] }, "outputs": [ { "data": { "application/vnd.plotly.v1+json": { "config": { "linkText": "Export to plot.ly", "plotlyServerURL": "https://plot.ly", "showLink": false }, "data": [ { "hoverinfo": "none", "legendgroup": "", "line": { "width": 0 }, "mode": "lines", "showlegend": false, "type": "scatter", "x": { "bdata": "AQIDBAUGBwgJCgsMDQ4PEBESExQVFhcYGQ==", "dtype": "i1" }, "y": { "bdata": "mQZRdxClQkAOU/vijlwMQA5T++KOXAxADlP74o5cDEAOU/vijlwMQA5T++KOXAxADlP74o5cDEBW6NZjA4UCQFbo1mMDhQJAuIZwAgjS8z/gI/9wNKTZP+Aj/3A0pNk/4CP/cDSk2T/gI/9wNKTZP+Aj/3A0pNk/4CP/cDSk2T/gI/9wNKTZP+Aj/3A0pNk/4CP/cDSk2T/gI/9wNKTZP+Aj/3A0pNk/4CP/cDSk2T/gI/9wNKTZP+Aj/3A0pNk/4CP/cDSk2T8=", "dtype": "f8" } }, { "fill": "tonexty", "fillcolor": "rgba(128,177,211,0.3)", "legendgroup": "objective value", "line": { "color": "rgba(128,177,211,1)" }, "mode": "lines", "name": "objective value", "text": [ "
Parameterization:
x1: 2.126607894897461
x2: 8.887859880924225", "
Parameterization:
x1: 3.681450095027685
x2: 0.5568291060626507", "
Parameterization:
x1: 9.260048242285848
x2: 12.935160705819726", "
Parameterization:
x1: -3.1931319646537304
x2: 3.921633088029921", "
Parameterization:
x1: -1.7758215544745326
x2: 14.612732883542776", "
Parameterization:
x1: 5.70186191066915
x2: 0.0", "
Parameterization:
x1: 2.4660013741396933
x2: 0.0", "
Parameterization:
x1: 3.722070407790855
x2: 2.452559342957278", "
Parameterization:
x1: -5.0
x2: 15.0", "
Parameterization:
x1: 3.56163530730146
x2: 1.8915229322291607", "
Parameterization:
x1: 3.124884206549607
x2: 2.2503884481535903", "
Parameterization:
x1: -5.0
x2: 11.154326917761699", "
Parameterization:
x1: 3.0144015004876605
x2: 2.4319654304993987", "
Parameterization:
x1: 10.0
x2: 0.0", "
Parameterization:
x1: 10.0
x2: 3.4605227195453736", "
Parameterization:
x1: 9.18561733647954
x2: 2.841819234221108", "
Parameterization:
x1: 9.658339907381855
x2: 2.4353497085612195", "
Parameterization:
x1: 9.527500364091175
x2: 2.9493395733373227", "
Parameterization:
x1: 4.288436025833104
x2: 15.0", "
Parameterization:
x1: 3.155771603274337
x2: 2.3554534809354974", "
Parameterization:
x1: -5.0
x2: 0.0", "
Parameterization:
x1: -0.8362944089794805
x2: 8.337814000243501", "
Parameterization:
x1: -3.6858337337409113
x2: 15.0", "
Parameterization:
x1: -2.9170559070456363
x2: 11.870405131162068", "
Parameterization:
x1: -3.2513908037957746
x2: 12.93991753384132" ], "type": "scatter", "x": { "bdata": "AQIDBAUGBwgJCgsMDQ4PEBESExQVFhcYGQ==", "dtype": "i1" }, "y": { "bdata": "mQZRdxClQkAOU/vijlwMQA5T++KOXAxADlP74o5cDEAOU/vijlwMQA5T++KOXAxADlP74o5cDEBW6NZjA4UCQFbo1mMDhQJAuIZwAgjS8z/gI/9wNKTZP+Aj/3A0pNk/4CP/cDSk2T/gI/9wNKTZP+Aj/3A0pNk/4CP/cDSk2T/gI/9wNKTZP+Aj/3A0pNk/4CP/cDSk2T/gI/9wNKTZP+Aj/3A0pNk/4CP/cDSk2T/gI/9wNKTZP+Aj/3A0pNk/4CP/cDSk2T8=", "dtype": "f8" } }, { "fill": "tonexty", "fillcolor": "rgba(128,177,211,0.3)", "hoverinfo": "none", "legendgroup": "", "line": { "width": 0 }, "mode": "lines", "showlegend": false, "type": "scatter", "x": { "bdata": "AQIDBAUGBwgJCgsMDQ4PEBESExQVFhcYGQ==", "dtype": "i1" }, "y": { "bdata": "mQZRdxClQkAOU/vijlwMQA5T++KOXAxADlP74o5cDEAOU/vijlwMQA5T++KOXAxADlP74o5cDEBW6NZjA4UCQFbo1mMDhQJAuIZwAgjS8z/gI/9wNKTZP+Aj/3A0pNk/4CP/cDSk2T/gI/9wNKTZP+Aj/3A0pNk/4CP/cDSk2T/gI/9wNKTZP+Aj/3A0pNk/4CP/cDSk2T/gI/9wNKTZP+Aj/3A0pNk/4CP/cDSk2T/gI/9wNKTZP+Aj/3A0pNk/4CP/cDSk2T8=", "dtype": "f8" } } ], "layout": { "showlegend": true, "template": { "data": { "bar": [ { "error_x": { "color": "#2a3f5f" }, "error_y": { "color": "#2a3f5f" }, "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "bar" } ], "barpolar": [ { "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "barpolar" } ], "carpet": [ { "aaxis": { "endlinecolor": "#2a3f5f", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "#2a3f5f" }, "baxis": { "endlinecolor": "#2a3f5f", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "#2a3f5f" }, "type": "carpet" } ], "choropleth": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "choropleth" } ], "contour": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0.0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1.0, "#f0f921" ] ], "type": "contour" } ], "contourcarpet": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "contourcarpet" } ], "heatmap": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0.0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1.0, "#f0f921" ] ], "type": "heatmap" } ], "histogram": [ { "marker": { "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "histogram" } ], "histogram2d": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0.0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1.0, "#f0f921" ] ], "type": "histogram2d" } ], "histogram2dcontour": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0.0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1.0, "#f0f921" ] ], "type": "histogram2dcontour" } ], "mesh3d": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "mesh3d" } ], "parcoords": [ { "line": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "parcoords" } ], "pie": [ { "automargin": true, "type": "pie" } ], "scatter": [ { "fillpattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 }, "type": "scatter" } ], "scatter3d": [ { "line": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatter3d" } ], "scattercarpet": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattercarpet" } ], "scattergeo": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattergeo" } ], "scattergl": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattergl" } ], "scattermap": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattermap" } ], "scattermapbox": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattermapbox" } ], "scatterpolar": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterpolar" } ], "scatterpolargl": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterpolargl" } ], "scatterternary": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterternary" } ], "surface": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0.0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1.0, "#f0f921" ] ], "type": "surface" } ], "table": [ { "cells": { "fill": { "color": "#EBF0F8" }, "line": { "color": "white" } }, "header": { "fill": { "color": "#C8D4E3" }, "line": { "color": "white" } }, "type": "table" } ] }, "layout": { "annotationdefaults": { "arrowcolor": "#2a3f5f", "arrowhead": 0, "arrowwidth": 1 }, "autotypenumbers": "strict", "coloraxis": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "colorscale": { "diverging": [ [ 0, "#8e0152" ], [ 0.1, "#c51b7d" ], [ 0.2, "#de77ae" ], [ 0.3, "#f1b6da" ], [ 0.4, "#fde0ef" ], [ 0.5, "#f7f7f7" ], [ 0.6, "#e6f5d0" ], [ 0.7, "#b8e186" ], [ 0.8, "#7fbc41" ], [ 0.9, "#4d9221" ], [ 1, "#276419" ] ], "sequential": [ [ 0.0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1.0, "#f0f921" ] ], "sequentialminus": [ [ 0.0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1.0, "#f0f921" ] ] }, "colorway": [ "#636efa", "#EF553B", "#00cc96", "#ab63fa", "#FFA15A", "#19d3f3", "#FF6692", "#B6E880", "#FF97FF", "#FECB52" ], "font": { "color": "#2a3f5f" }, "geo": { "bgcolor": "white", "lakecolor": "white", "landcolor": "#E5ECF6", "showlakes": true, "showland": true, "subunitcolor": "white" }, "hoverlabel": { "align": "left" }, "hovermode": "closest", "mapbox": { "style": "light" }, "paper_bgcolor": "white", "plot_bgcolor": "#E5ECF6", "polar": { "angularaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "bgcolor": "#E5ECF6", "radialaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" } }, "scene": { "xaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" }, "yaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" }, "zaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" } }, "shapedefaults": { "line": { "color": "#2a3f5f" } }, "ternary": { "aaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "baxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "bgcolor": "#E5ECF6", "caxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" } }, "title": { "x": 0.05 }, "xaxis": { "automargin": true, "gridcolor": "white", "linecolor": "white", "ticks": "", "title": { "standoff": 15 }, "zerolinecolor": "white", "zerolinewidth": 2 }, "yaxis": { "automargin": true, "gridcolor": "white", "linecolor": "white", "ticks": "", "title": { "standoff": 15 }, "zerolinecolor": "white", "zerolinewidth": 2 } } }, "title": { "text": "Best objective found vs. # of iterations" }, "xaxis": { "title": { "text": "Iteration" } }, "yaxis": { "title": { "text": "Branin" } } } }, "text/html": [ "
\n", "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "render(ax_client.get_optimization_trace())" ] }, { "cell_type": "markdown", "id": "ed9aa99a", "metadata": { "customInput": null, "originalKey": "ca391462-4695-44f1-bc53-070a947c5648", "papermill": { "duration": 0.082572, "end_time": "2025-01-31T07:10:24.735384", "exception": false, "start_time": "2025-01-31T07:10:24.652812", "status": "completed" }, "showInput": false, "tags": [] }, "source": [ "# 2. Optimization with global stopping, with the Service API" ] }, { "cell_type": "markdown", "id": "a9ed1113", "metadata": { "customInput": null, "originalKey": "5a2690ef-0990-4cbd-9bc9-529b1455a4c3", "papermill": { "duration": 0.082592, "end_time": "2025-01-31T07:10:24.900998", "exception": false, "start_time": "2025-01-31T07:10:24.818406", "status": "completed" }, "showInput": false, "tags": [] }, "source": [ "Rather than running a fixed number of trials, we can use a GlobalStoppingStrategy (GSS), which checks whether some stopping criteria have been met when `get_next_trial` is called. Here, we use an `ImprovementGlobalStoppingStrategy`, which checks whether the the last `window_size` trials have improved by more than some threshold amount.\n", "\n", "For single-objective optimization, which we are doing here, `ImprovementGlobalStoppingStrategy` checks if an improvement is \"significant\" by comparing it to the inter-quartile range (IQR) of the objective values attained so far. \n", "\n", "`ImprovementGlobalStoppingStrategy` also supports multi-objective optimization (MOO), in which case it checks whether the percentage improvement in hypervolume over the last `window_size` trials exceeds `improvement_bar`." ] }, { "cell_type": "code", "execution_count": 7, "id": "6ca602dc", "metadata": { "customInput": null, "customOutput": null, "execution": { "iopub.execute_input": "2025-01-31T07:10:25.068109Z", "iopub.status.busy": "2025-01-31T07:10:25.067831Z", "iopub.status.idle": "2025-01-31T07:10:25.071163Z", "shell.execute_reply": "2025-01-31T07:10:25.070559Z" }, "executionStartTime": 1683829356716, "executionStopTime": 1683829356725, "originalKey": "a6634232-448a-4b84-98cd-399c755537df", "papermill": { "duration": 0.088545, "end_time": "2025-01-31T07:10:25.072463", "exception": false, "start_time": "2025-01-31T07:10:24.983918", "status": "completed" }, "requestMsgId": "7e428336-eeeb-4e5b-91c4-fcf5a671773d", "showInput": true, "tags": [] }, "outputs": [], "source": [ "from ax.global_stopping.strategies.improvement import ImprovementGlobalStoppingStrategy\n", "from ax.exceptions.core import OptimizationShouldStop" ] }, { "cell_type": "code", "execution_count": 8, "id": "464e585a", "metadata": { "customInput": null, "customOutput": null, "execution": { "iopub.execute_input": "2025-01-31T07:10:25.239977Z", "iopub.status.busy": "2025-01-31T07:10:25.239489Z", "iopub.status.idle": "2025-01-31T07:10:25.243015Z", "shell.execute_reply": "2025-01-31T07:10:25.242463Z" }, "executionStartTime": 1683829356822, "executionStopTime": 1683829356829, "originalKey": "c313de63-03ee-4a65-aa5c-5e7b6f436480", "papermill": { "duration": 0.088828, "end_time": "2025-01-31T07:10:25.244304", "exception": false, "start_time": "2025-01-31T07:10:25.155476", "status": "completed" }, "requestMsgId": "953b064b-8db6-430f-909d-872469bc1e16", "showInput": true, "tags": [] }, "outputs": [], "source": [ "# Start considering stopping only after the 5 initialization trials + 5 GPEI trials.\n", "# Stop if the improvement in the best point in the past 5 trials is less than\n", "# 1% of the IQR thus far.\n", "stopping_strategy = ImprovementGlobalStoppingStrategy(\n", " min_trials=5 + 5, window_size=5, improvement_bar=0.01\n", ")" ] }, { "cell_type": "code", "execution_count": 9, "id": "dfa3734b", "metadata": { "customInput": null, "customOutput": null, "execution": { "iopub.execute_input": "2025-01-31T07:10:25.412157Z", "iopub.status.busy": "2025-01-31T07:10:25.411653Z", "iopub.status.idle": "2025-01-31T07:10:25.424122Z", "shell.execute_reply": "2025-01-31T07:10:25.423476Z" }, "executionStartTime": 1683829356961, "executionStopTime": 1683829356997, "originalKey": "a2c6c699-f0d2-4001-9bee-3964594e435c", "papermill": { "duration": 0.098316, "end_time": "2025-01-31T07:10:25.425714", "exception": false, "start_time": "2025-01-31T07:10:25.327398", "status": "completed" }, "requestMsgId": "2ba6f82b-1443-4274-83d1-03c56f0190d0", "showInput": true, "tags": [] }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "[WARNING 01-31 07:10:25] ax.service.ax_client: Random seed set to 0. Note that this setting only affects the Sobol quasi-random generator and BoTorch-powered Bayesian optimization models. For the latter models, setting random seed to the same number for two optimizations will make the generated trials similar, but not exactly the same, and over time the trials will diverge more.\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "[INFO 01-31 07:10:25] ax.service.utils.instantiation: Created search space: SearchSpace(parameters=[RangeParameter(name='x1', parameter_type=FLOAT, range=[-5.0, 10.0]), RangeParameter(name='x2', parameter_type=FLOAT, range=[0.0, 15.0])], parameter_constraints=[]).\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "[INFO 01-31 07:10:25] ax.core.experiment: The is_test flag has been set to True. This flag is meant purely for development and integration testing purposes. If you are running a live experiment, please set this flag to False\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "[INFO 01-31 07:10:25] ax.modelbridge.dispatch_utils: Using Models.BOTORCH_MODULAR since there is at least one ordered parameter and there are no unordered categorical parameters.\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "[INFO 01-31 07:10:25] ax.modelbridge.dispatch_utils: Calculating the number of remaining initialization trials based on num_initialization_trials=None max_initialization_trials=None num_tunable_parameters=2 num_trials=None use_batch_trials=False\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "[INFO 01-31 07:10:25] ax.modelbridge.dispatch_utils: calculated num_initialization_trials=5\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "[INFO 01-31 07:10:25] ax.modelbridge.dispatch_utils: num_completed_initialization_trials=0 num_remaining_initialization_trials=5\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "[INFO 01-31 07:10:25] ax.modelbridge.dispatch_utils: `verbose`, `disable_progbar`, and `jit_compile` are not yet supported when using `choose_generation_strategy` with ModularBoTorchModel, dropping these arguments.\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "[INFO 01-31 07:10:25] ax.modelbridge.dispatch_utils: Using Bayesian Optimization generation strategy: GenerationStrategy(name='Sobol+BoTorch', steps=[Sobol for 5 trials, BoTorch for subsequent trials]). Iterations after 5 will take longer to generate due to model-fitting.\n" ] } ], "source": [ "ax_client_gss = AxClient(\n", " global_stopping_strategy=stopping_strategy, random_seed=0, verbose_logging=False\n", ")\n", "\n", "ax_client_gss.create_experiment(\n", " name=\"branin_test_experiment\",\n", " parameters=params,\n", " objectives={\"branin\": ObjectiveProperties(minimize=True)},\n", " is_test=True,\n", ")" ] }, { "cell_type": "markdown", "id": "99bcebb9", "metadata": { "customInput": null, "originalKey": "7ff170a1-e885-429f-9695-8b64b5b8e209", "papermill": { "duration": 0.083493, "end_time": "2025-01-31T07:10:25.594696", "exception": false, "start_time": "2025-01-31T07:10:25.511203", "status": "completed" }, "showInput": false, "tags": [] }, "source": [ "If there has not been much improvement, `ImprovementGlobalStoppingStrategy` will raise an exception. If the exception is raised, we catch it and terminate optimization." ] }, { "cell_type": "code", "execution_count": 10, "id": "476c3b4c", "metadata": { "customInput": null, "customOutput": null, "execution": { "iopub.execute_input": "2025-01-31T07:10:25.763367Z", "iopub.status.busy": "2025-01-31T07:10:25.762913Z", "iopub.status.idle": "2025-01-31T07:10:33.593426Z", "shell.execute_reply": "2025-01-31T07:10:33.592749Z" }, "executionStartTime": 1683829357114, "executionStopTime": 1683829363866, "originalKey": "3db097cb-1e6e-4320-806a-981dcef6bade", "papermill": { "duration": 7.916366, "end_time": "2025-01-31T07:10:33.594892", "exception": false, "start_time": "2025-01-31T07:10:25.678526", "status": "completed" }, "requestMsgId": "fd039109-2a23-4287-8935-b74274405e56", "showInput": true, "tags": [] }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/tmp/tmp.8SPGnWMU26/Ax-main/ax/modelbridge/cross_validation.py:439: UserWarning:\n", "\n", "Encountered exception in computing model fit quality: RandomModelBridge does not support prediction.\n", "\n", "/tmp/tmp.8SPGnWMU26/Ax-main/ax/modelbridge/cross_validation.py:439: UserWarning:\n", "\n", "Encountered exception in computing model fit quality: RandomModelBridge does not support prediction.\n", "\n", "/tmp/tmp.8SPGnWMU26/Ax-main/ax/modelbridge/cross_validation.py:439: UserWarning:\n", "\n", "Encountered exception in computing model fit quality: RandomModelBridge does not support prediction.\n", "\n", "/tmp/tmp.8SPGnWMU26/Ax-main/ax/modelbridge/cross_validation.py:439: UserWarning:\n", "\n", "Encountered exception in computing model fit quality: RandomModelBridge does not support prediction.\n", "\n", "/tmp/tmp.8SPGnWMU26/Ax-main/ax/modelbridge/cross_validation.py:439: UserWarning:\n", "\n", "Encountered exception in computing model fit quality: RandomModelBridge does not support prediction.\n", "\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "The improvement in best objective in the past 5 trials (=0.000) is less than 0.01 times the interquartile range (IQR) of objectives attained so far (IQR=34.901).\n" ] } ], "source": [ "for i in range(25):\n", " try:\n", " parameters, trial_index = ax_client_gss.get_next_trial()\n", " except OptimizationShouldStop as exc:\n", " print(exc.message)\n", " break\n", " ax_client_gss.complete_trial(trial_index=trial_index, raw_data=evaluate(parameters))" ] }, { "cell_type": "code", "execution_count": 11, "id": "2d003a6a", "metadata": { "customInput": null, "customOutput": null, "execution": { "iopub.execute_input": "2025-01-31T07:10:33.768418Z", "iopub.status.busy": "2025-01-31T07:10:33.767814Z", "iopub.status.idle": "2025-01-31T07:10:33.851883Z", "shell.execute_reply": "2025-01-31T07:10:33.850976Z" }, "executionStartTime": 1683829363988, "executionStopTime": 1683829364103, "originalKey": "ffb53ed2-8775-492d-a357-348957637454", "papermill": { "duration": 0.190225, "end_time": "2025-01-31T07:10:33.871399", "exception": false, "start_time": "2025-01-31T07:10:33.681174", "status": "completed" }, "requestMsgId": "f0f765dd-85db-4519-90d0-064a1bf64b6d", "showInput": true, "tags": [] }, "outputs": [ { "data": { "application/vnd.plotly.v1+json": { "config": { "linkText": "Export to plot.ly", "plotlyServerURL": "https://plot.ly", "showLink": false }, "data": [ { "hoverinfo": "none", "legendgroup": "", "line": { "width": 0 }, "mode": "lines", "showlegend": false, "type": "scatter", "x": { "bdata": "AQIDBAUGBwgJCgsMDQ4P", "dtype": "i1" }, "y": { "bdata": "mQZRdxClQkAOU/vijlwMQA5T++KOXAxADlP74o5cDEAOU/vijlwMQA5T++KOXAxADlP74o5cDEBW6NZjA4UCQFbo1mMDhQJAuIZwAgjS8z/gI/9wNKTZP+Aj/3A0pNk/4CP/cDSk2T/gI/9wNKTZP+Aj/3A0pNk/", "dtype": "f8" } }, { "fill": "tonexty", "fillcolor": "rgba(128,177,211,0.3)", "legendgroup": "objective value", "line": { "color": "rgba(128,177,211,1)" }, "mode": "lines", "name": "objective value", "text": [ "
Parameterization:
x1: 2.126607894897461
x2: 8.887859880924225", "
Parameterization:
x1: 3.681450095027685
x2: 0.5568291060626507", "
Parameterization:
x1: 9.260048242285848
x2: 12.935160705819726", "
Parameterization:
x1: -3.1931319646537304
x2: 3.921633088029921", "
Parameterization:
x1: -1.7758215544745326
x2: 14.612732883542776", "
Parameterization:
x1: 5.70186191066915
x2: 0.0", "
Parameterization:
x1: 2.4660013741396933
x2: 0.0", "
Parameterization:
x1: 3.722070407790855
x2: 2.452559342957278", "
Parameterization:
x1: -5.0
x2: 15.0", "
Parameterization:
x1: 3.56163530730146
x2: 1.8915229322291607", "
Parameterization:
x1: 3.124884206549607
x2: 2.2503884481535903", "
Parameterization:
x1: -5.0
x2: 11.154326917761699", "
Parameterization:
x1: 3.0144015004876605
x2: 2.4319654304993987", "
Parameterization:
x1: 10.0
x2: 0.0", "
Parameterization:
x1: 10.0
x2: 3.4605227195453736" ], "type": "scatter", "x": { "bdata": "AQIDBAUGBwgJCgsMDQ4P", "dtype": "i1" }, "y": { "bdata": "mQZRdxClQkAOU/vijlwMQA5T++KOXAxADlP74o5cDEAOU/vijlwMQA5T++KOXAxADlP74o5cDEBW6NZjA4UCQFbo1mMDhQJAuIZwAgjS8z/gI/9wNKTZP+Aj/3A0pNk/4CP/cDSk2T/gI/9wNKTZP+Aj/3A0pNk/", "dtype": "f8" } }, { "fill": "tonexty", "fillcolor": "rgba(128,177,211,0.3)", "hoverinfo": "none", "legendgroup": "", "line": { "width": 0 }, "mode": "lines", "showlegend": false, "type": "scatter", "x": { "bdata": "AQIDBAUGBwgJCgsMDQ4P", "dtype": "i1" }, "y": { "bdata": "mQZRdxClQkAOU/vijlwMQA5T++KOXAxADlP74o5cDEAOU/vijlwMQA5T++KOXAxADlP74o5cDEBW6NZjA4UCQFbo1mMDhQJAuIZwAgjS8z/gI/9wNKTZP+Aj/3A0pNk/4CP/cDSk2T/gI/9wNKTZP+Aj/3A0pNk/", "dtype": "f8" } } ], "layout": { "showlegend": true, "template": { "data": { "bar": [ { "error_x": { "color": "#2a3f5f" }, "error_y": { "color": "#2a3f5f" }, "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "bar" } ], "barpolar": [ { "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "barpolar" } ], "carpet": [ { "aaxis": { "endlinecolor": "#2a3f5f", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "#2a3f5f" }, "baxis": { "endlinecolor": "#2a3f5f", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "#2a3f5f" }, "type": "carpet" } ], "choropleth": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "choropleth" } ], "contour": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0.0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1.0, "#f0f921" ] ], "type": "contour" } ], "contourcarpet": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "contourcarpet" } ], "heatmap": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0.0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1.0, "#f0f921" ] ], "type": "heatmap" } ], "histogram": [ { "marker": { "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "histogram" } ], "histogram2d": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0.0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1.0, "#f0f921" ] ], "type": "histogram2d" } ], "histogram2dcontour": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0.0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1.0, "#f0f921" ] ], "type": "histogram2dcontour" } ], "mesh3d": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "mesh3d" } ], "parcoords": [ { "line": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "parcoords" } ], "pie": [ { "automargin": true, "type": "pie" } ], "scatter": [ { "fillpattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 }, "type": "scatter" } ], "scatter3d": [ { "line": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatter3d" } ], "scattercarpet": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattercarpet" } ], "scattergeo": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattergeo" } ], "scattergl": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattergl" } ], "scattermap": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattermap" } ], "scattermapbox": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattermapbox" } ], "scatterpolar": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterpolar" } ], "scatterpolargl": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterpolargl" } ], "scatterternary": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterternary" } ], "surface": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0.0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1.0, "#f0f921" ] ], "type": "surface" } ], "table": [ { "cells": { "fill": { "color": "#EBF0F8" }, "line": { "color": "white" } }, "header": { "fill": { "color": "#C8D4E3" }, "line": { "color": "white" } }, "type": "table" } ] }, "layout": { "annotationdefaults": { "arrowcolor": "#2a3f5f", "arrowhead": 0, "arrowwidth": 1 }, "autotypenumbers": "strict", "coloraxis": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "colorscale": { "diverging": [ [ 0, "#8e0152" ], [ 0.1, "#c51b7d" ], [ 0.2, "#de77ae" ], [ 0.3, "#f1b6da" ], [ 0.4, "#fde0ef" ], [ 0.5, "#f7f7f7" ], [ 0.6, "#e6f5d0" ], [ 0.7, "#b8e186" ], [ 0.8, "#7fbc41" ], [ 0.9, "#4d9221" ], [ 1, "#276419" ] ], "sequential": [ [ 0.0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1.0, "#f0f921" ] ], "sequentialminus": [ [ 0.0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1.0, "#f0f921" ] ] }, "colorway": [ "#636efa", "#EF553B", "#00cc96", "#ab63fa", "#FFA15A", "#19d3f3", "#FF6692", "#B6E880", "#FF97FF", "#FECB52" ], "font": { "color": "#2a3f5f" }, "geo": { "bgcolor": "white", "lakecolor": "white", "landcolor": "#E5ECF6", "showlakes": true, "showland": true, "subunitcolor": "white" }, "hoverlabel": { "align": "left" }, "hovermode": "closest", "mapbox": { "style": "light" }, "paper_bgcolor": "white", "plot_bgcolor": "#E5ECF6", "polar": { "angularaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "bgcolor": "#E5ECF6", "radialaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" } }, "scene": { "xaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" }, "yaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" }, "zaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" } }, "shapedefaults": { "line": { "color": "#2a3f5f" } }, "ternary": { "aaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "baxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "bgcolor": "#E5ECF6", "caxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" } }, "title": { "x": 0.05 }, "xaxis": { "automargin": true, "gridcolor": "white", "linecolor": "white", "ticks": "", "title": { "standoff": 15 }, "zerolinecolor": "white", "zerolinewidth": 2 }, "yaxis": { "automargin": true, "gridcolor": "white", "linecolor": "white", "ticks": "", "title": { "standoff": 15 }, "zerolinecolor": "white", "zerolinewidth": 2 } } }, "title": { "text": "Best objective found vs. # of iterations" }, "xaxis": { "title": { "text": "Iteration" } }, "yaxis": { "title": { "text": "Branin" } } } }, "text/html": [ "
\n", "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "render(ax_client_gss.get_optimization_trace())" ] }, { "cell_type": "markdown", "id": "0165b24d", "metadata": { "customInput": null, "originalKey": "b01707f3-0bbf-4003-9222-29ba5e3c77b2", "papermill": { "duration": 0.125693, "end_time": "2025-01-31T07:10:34.121626", "exception": false, "start_time": "2025-01-31T07:10:33.995933", "status": "completed" }, "showInput": false, "tags": [] }, "source": [ "# 3. Write your own custom Global Stopping Strategy" ] }, { "cell_type": "markdown", "id": "50bf292d", "metadata": { "customInput": null, "originalKey": "23b8372b-0067-4934-b599-210b994e06f1", "papermill": { "duration": 0.12589, "end_time": "2025-01-31T07:10:34.373305", "exception": false, "start_time": "2025-01-31T07:10:34.247415", "status": "completed" }, "showInput": false, "tags": [] }, "source": [ "You can write a custom Global Stopping Strategy by subclassing `BaseGlobalStoppingStrategy` and use it where `ImprovementGlobalStoppingStrategy` was used above." ] }, { "cell_type": "code", "execution_count": 12, "id": "fb4f3cc4", "metadata": { "customInput": null, "customOutput": null, "execution": { "iopub.execute_input": "2025-01-31T07:10:34.627122Z", "iopub.status.busy": "2025-01-31T07:10:34.626834Z", "iopub.status.idle": "2025-01-31T07:10:34.630722Z", "shell.execute_reply": "2025-01-31T07:10:34.630092Z" }, "executionStartTime": 1683829364214, "executionStopTime": 1683829364222, "originalKey": "2e5512a9-82ed-43a0-8616-6cee7f648b0f", "papermill": { "duration": 0.133097, "end_time": "2025-01-31T07:10:34.632141", "exception": false, "start_time": "2025-01-31T07:10:34.499044", "status": "completed" }, "requestMsgId": "d5c268a1-fefe-49d5-8ff4-a2cb40fe278b", "showInput": true, "tags": [] }, "outputs": [], "source": [ "from ax.global_stopping.strategies.base import BaseGlobalStoppingStrategy\n", "from typing import Tuple\n", "from ax.core.experiment import Experiment\n", "from ax.core.base_trial import TrialStatus\n", "from ax.global_stopping.strategies.improvement import constraint_satisfaction" ] }, { "cell_type": "markdown", "id": "74f4fa0a", "metadata": { "customInput": null, "originalKey": "584df5ac-c0f6-4c48-8cec-f9765a04e635", "papermill": { "duration": 0.127176, "end_time": "2025-01-31T07:10:34.885596", "exception": false, "start_time": "2025-01-31T07:10:34.758420", "status": "completed" }, "showInput": false, "tags": [] }, "source": [ "Here, we define `SimpleThresholdGlobalStoppingStrategy`, which stops when we observe a point better than a provided threshold. This can be useful when there is a known optimum. For example, the Branin function has an optimum of zero. When the optimum is not known, this can still be useful from a satisficing perspective: For example, maybe we need a model to take up less than a certain amount of RAM so it doesn't crash our usual hardware, but there is no benefit to further improvements." ] }, { "cell_type": "code", "execution_count": 13, "id": "47612da1", "metadata": { "customInput": null, "customOutput": null, "execution": { "iopub.execute_input": "2025-01-31T07:10:35.142174Z", "iopub.status.busy": "2025-01-31T07:10:35.141875Z", "iopub.status.idle": "2025-01-31T07:10:35.148345Z", "shell.execute_reply": "2025-01-31T07:10:35.147782Z" }, "executionStartTime": 1683829490325, "executionStopTime": 1683829490340, "originalKey": "bbd24d6e-a873-49d6-abe3-4d832acb8a60", "papermill": { "duration": 0.136528, "end_time": "2025-01-31T07:10:35.149632", "exception": false, "start_time": "2025-01-31T07:10:35.013104", "status": "completed" }, "requestMsgId": "74b77cb7-54eb-4321-afae-942b62b90f5d", "showInput": true, "tags": [] }, "outputs": [], "source": [ "class SimpleThresholdGlobalStoppingStrategy(BaseGlobalStoppingStrategy):\n", " \"\"\"\n", " A GSS that stops when we observe a point better than `threshold`.\n", " \"\"\"\n", " def __init__(\n", " self,\n", " min_trials: int,\n", " inactive_when_pending_trials: bool = True,\n", " threshold: float = 0.1\n", " ):\n", " self.threshold = threshold\n", " super().__init__(\n", " min_trials=min_trials,\n", " inactive_when_pending_trials=inactive_when_pending_trials\n", " )\n", " \n", " def _should_stop_optimization(\n", " self, experiment: Experiment\n", " ) -> Tuple[bool, str]:\n", " \"\"\"\n", " Check if the best seen is better than `self.threshold`.\n", " \"\"\"\n", " feasible_objectives = [\n", " trial.objective_mean\n", " for trial in experiment.trials_by_status[TrialStatus.COMPLETED]\n", " if constraint_satisfaction(trial)\n", " ]\n", "\n", " # Computing the interquartile for scaling the difference\n", " if len(feasible_objectives) <= 1:\n", " message = \"There are not enough feasible arms tried yet.\"\n", " return False, message\n", " \n", " minimize = experiment.optimization_config.objective.minimize\n", " if minimize:\n", " best = np.min(feasible_objectives)\n", " stop = best < self.threshold\n", " else:\n", " best = np.max(feasible_objectives)\n", " stop = best > self.threshold\n", "\n", " comparison = \"less\" if minimize else \"greater\"\n", " if stop:\n", " message = (\n", " f\"The best objective seen is {best:.3f}, which is {comparison} \"\n", " f\"than the threshold of {self.threshold:.3f}.\"\n", " )\n", " else:\n", " message = \"\"\n", "\n", " return stop, message" ] }, { "cell_type": "code", "execution_count": 14, "id": "a87f6fc5", "metadata": { "customInput": null, "customOutput": null, "execution": { "iopub.execute_input": "2025-01-31T07:10:35.404586Z", "iopub.status.busy": "2025-01-31T07:10:35.404255Z", "iopub.status.idle": "2025-01-31T07:10:35.407752Z", "shell.execute_reply": "2025-01-31T07:10:35.407165Z" }, "executionStartTime": 1683829491609, "executionStopTime": 1683829491626, "originalKey": "f3dc5682-0539-4c85-a66a-0d3128f0cc1c", "papermill": { "duration": 0.133183, "end_time": "2025-01-31T07:10:35.409067", "exception": false, "start_time": "2025-01-31T07:10:35.275884", "status": "completed" }, "requestMsgId": "9ee9e413-be32-49fc-a7bc-8e1898d1dbf5", "showInput": true, "tags": [] }, "outputs": [], "source": [ "stopping_strategy = SimpleThresholdGlobalStoppingStrategy(min_trials=5, threshold=1.)" ] }, { "cell_type": "code", "execution_count": 15, "id": "1c0e63f6", "metadata": { "customInput": null, "customOutput": null, "execution": { "iopub.execute_input": "2025-01-31T07:10:35.669752Z", "iopub.status.busy": "2025-01-31T07:10:35.669459Z", "iopub.status.idle": "2025-01-31T07:10:35.680556Z", "shell.execute_reply": "2025-01-31T07:10:35.679859Z" }, "executionStartTime": 1683829491833, "executionStopTime": 1683829491894, "originalKey": "3d6c1ab2-c3ee-49c8-9969-45f2455bbd60", "papermill": { "duration": 0.145793, "end_time": "2025-01-31T07:10:35.682004", "exception": false, "start_time": "2025-01-31T07:10:35.536211", "status": "completed" }, "requestMsgId": "08232010-46f8-4b28-b581-454ddacdc57b", "showInput": true, "tags": [] }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "[WARNING 01-31 07:10:35] ax.service.ax_client: Random seed set to 0. Note that this setting only affects the Sobol quasi-random generator and BoTorch-powered Bayesian optimization models. For the latter models, setting random seed to the same number for two optimizations will make the generated trials similar, but not exactly the same, and over time the trials will diverge more.\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "[INFO 01-31 07:10:35] ax.service.utils.instantiation: Created search space: SearchSpace(parameters=[RangeParameter(name='x1', parameter_type=FLOAT, range=[-5.0, 10.0]), RangeParameter(name='x2', parameter_type=FLOAT, range=[0.0, 15.0])], parameter_constraints=[]).\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "[INFO 01-31 07:10:35] ax.core.experiment: The is_test flag has been set to True. This flag is meant purely for development and integration testing purposes. If you are running a live experiment, please set this flag to False\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "[INFO 01-31 07:10:35] ax.modelbridge.dispatch_utils: Using Models.BOTORCH_MODULAR since there is at least one ordered parameter and there are no unordered categorical parameters.\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "[INFO 01-31 07:10:35] ax.modelbridge.dispatch_utils: Calculating the number of remaining initialization trials based on num_initialization_trials=None max_initialization_trials=None num_tunable_parameters=2 num_trials=None use_batch_trials=False\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "[INFO 01-31 07:10:35] ax.modelbridge.dispatch_utils: calculated num_initialization_trials=5\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "[INFO 01-31 07:10:35] ax.modelbridge.dispatch_utils: num_completed_initialization_trials=0 num_remaining_initialization_trials=5\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "[INFO 01-31 07:10:35] ax.modelbridge.dispatch_utils: `verbose`, `disable_progbar`, and `jit_compile` are not yet supported when using `choose_generation_strategy` with ModularBoTorchModel, dropping these arguments.\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "[INFO 01-31 07:10:35] ax.modelbridge.dispatch_utils: Using Bayesian Optimization generation strategy: GenerationStrategy(name='Sobol+BoTorch', steps=[Sobol for 5 trials, BoTorch for subsequent trials]). Iterations after 5 will take longer to generate due to model-fitting.\n" ] } ], "source": [ "ax_client_custom_gss = AxClient(\n", " global_stopping_strategy=stopping_strategy,\n", " random_seed=0,\n", " verbose_logging=False,\n", ")\n", "\n", "ax_client_custom_gss.create_experiment(\n", " name=\"branin_test_experiment\",\n", " parameters=params,\n", " objectives={\"branin\": ObjectiveProperties(minimize=True)},\n", " is_test=True,\n", ")" ] }, { "cell_type": "code", "execution_count": 16, "id": "3343607b", "metadata": { "customInput": null, "customOutput": null, "execution": { "iopub.execute_input": "2025-01-31T07:10:35.936625Z", "iopub.status.busy": "2025-01-31T07:10:35.936317Z", "iopub.status.idle": "2025-01-31T07:10:40.047683Z", "shell.execute_reply": "2025-01-31T07:10:40.047011Z" }, "executionStartTime": 1683829492064, "executionStopTime": 1683829495338, "originalKey": "a306cb15-364f-4e91-b569-9067843a7578", "papermill": { "duration": 4.240488, "end_time": "2025-01-31T07:10:40.049103", "exception": false, "start_time": "2025-01-31T07:10:35.808615", "status": "completed" }, "requestMsgId": "81121dac-3a2a-4dde-b866-44e448e73ad5", "showInput": true, "tags": [] }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/tmp/tmp.8SPGnWMU26/Ax-main/ax/modelbridge/cross_validation.py:439: UserWarning:\n", "\n", "Encountered exception in computing model fit quality: RandomModelBridge does not support prediction.\n", "\n", "/tmp/tmp.8SPGnWMU26/Ax-main/ax/modelbridge/cross_validation.py:439: UserWarning:\n", "\n", "Encountered exception in computing model fit quality: RandomModelBridge does not support prediction.\n", "\n", "/tmp/tmp.8SPGnWMU26/Ax-main/ax/modelbridge/cross_validation.py:439: UserWarning:\n", "\n", "Encountered exception in computing model fit quality: RandomModelBridge does not support prediction.\n", "\n", "/tmp/tmp.8SPGnWMU26/Ax-main/ax/modelbridge/cross_validation.py:439: UserWarning:\n", "\n", "Encountered exception in computing model fit quality: RandomModelBridge does not support prediction.\n", "\n", "/tmp/tmp.8SPGnWMU26/Ax-main/ax/modelbridge/cross_validation.py:439: UserWarning:\n", "\n", "Encountered exception in computing model fit quality: RandomModelBridge does not support prediction.\n", "\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "The best objective seen is 0.401, which is less than the threshold of 1.000.\n" ] } ], "source": [ "for i in range(25):\n", " try:\n", " parameters, trial_index = ax_client_custom_gss.get_next_trial()\n", " except OptimizationShouldStop as exc:\n", " print(exc.message)\n", " break\n", " ax_client_custom_gss.complete_trial(\n", " trial_index=trial_index, raw_data=evaluate(parameters)\n", " )" ] }, { "cell_type": "code", "execution_count": 17, "id": "1df70311", "metadata": { "customInput": null, "customOutput": null, "execution": { "iopub.execute_input": "2025-01-31T07:10:40.307622Z", "iopub.status.busy": "2025-01-31T07:10:40.307320Z", "iopub.status.idle": "2025-01-31T07:10:40.387804Z", "shell.execute_reply": "2025-01-31T07:10:40.386858Z" }, "executionStartTime": 1683829495351, "executionStopTime": 1683829495740, "originalKey": "3cb59624-d9bb-4b7a-9f57-7cb968dce889", "papermill": { "duration": 0.22854, "end_time": "2025-01-31T07:10:40.407418", "exception": false, "start_time": "2025-01-31T07:10:40.178878", "status": "completed" }, "requestMsgId": "4dd4ed93-07ab-4dd1-92a9-f003f405ccbc", "showInput": true, "tags": [] }, "outputs": [ { "data": { "application/vnd.plotly.v1+json": { "config": { "linkText": "Export to plot.ly", "plotlyServerURL": "https://plot.ly", "showLink": false }, "data": [ { "hoverinfo": "none", "legendgroup": "", "line": { "width": 0 }, "mode": "lines", "showlegend": false, "type": "scatter", "x": { "bdata": "AQIDBAUGBwgJCgs=", "dtype": "i1" }, "y": { "bdata": "mQZRdxClQkAOU/vijlwMQA5T++KOXAxADlP74o5cDEAOU/vijlwMQA5T++KOXAxADlP74o5cDEBW6NZjA4UCQFbo1mMDhQJAuIZwAgjS8z/gI/9wNKTZPw==", "dtype": "f8" } }, { "fill": "tonexty", "fillcolor": "rgba(128,177,211,0.3)", "legendgroup": "objective value", "line": { "color": "rgba(128,177,211,1)" }, "mode": "lines", "name": "objective value", "text": [ "
Parameterization:
x1: 2.126607894897461
x2: 8.887859880924225", "
Parameterization:
x1: 3.681450095027685
x2: 0.5568291060626507", "
Parameterization:
x1: 9.260048242285848
x2: 12.935160705819726", "
Parameterization:
x1: -3.1931319646537304
x2: 3.921633088029921", "
Parameterization:
x1: -1.7758215544745326
x2: 14.612732883542776", "
Parameterization:
x1: 5.70186191066915
x2: 0.0", "
Parameterization:
x1: 2.4660013741396933
x2: 0.0", "
Parameterization:
x1: 3.722070407790855
x2: 2.452559342957278", "
Parameterization:
x1: -5.0
x2: 15.0", "
Parameterization:
x1: 3.56163530730146
x2: 1.8915229322291607", "
Parameterization:
x1: 3.124884206549607
x2: 2.2503884481535903" ], "type": "scatter", "x": { "bdata": "AQIDBAUGBwgJCgs=", "dtype": "i1" }, "y": { "bdata": "mQZRdxClQkAOU/vijlwMQA5T++KOXAxADlP74o5cDEAOU/vijlwMQA5T++KOXAxADlP74o5cDEBW6NZjA4UCQFbo1mMDhQJAuIZwAgjS8z/gI/9wNKTZPw==", "dtype": "f8" } }, { "fill": "tonexty", "fillcolor": "rgba(128,177,211,0.3)", "hoverinfo": "none", "legendgroup": "", "line": { "width": 0 }, "mode": "lines", "showlegend": false, "type": "scatter", "x": { "bdata": "AQIDBAUGBwgJCgs=", "dtype": "i1" }, "y": { "bdata": "mQZRdxClQkAOU/vijlwMQA5T++KOXAxADlP74o5cDEAOU/vijlwMQA5T++KOXAxADlP74o5cDEBW6NZjA4UCQFbo1mMDhQJAuIZwAgjS8z/gI/9wNKTZPw==", "dtype": "f8" } } ], "layout": { "showlegend": true, "template": { "data": { "bar": [ { "error_x": { "color": "#2a3f5f" }, "error_y": { "color": "#2a3f5f" }, "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "bar" } ], "barpolar": [ { "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "barpolar" } ], "carpet": [ { "aaxis": { "endlinecolor": "#2a3f5f", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "#2a3f5f" }, "baxis": { "endlinecolor": "#2a3f5f", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "#2a3f5f" }, "type": "carpet" } ], "choropleth": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "choropleth" } ], "contour": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0.0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1.0, "#f0f921" ] ], "type": "contour" } ], "contourcarpet": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "contourcarpet" } ], "heatmap": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0.0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1.0, "#f0f921" ] ], "type": "heatmap" } ], "histogram": [ { "marker": { "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "histogram" } ], "histogram2d": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0.0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1.0, "#f0f921" ] ], "type": "histogram2d" } ], "histogram2dcontour": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0.0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1.0, "#f0f921" ] ], "type": "histogram2dcontour" } ], "mesh3d": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "mesh3d" } ], "parcoords": [ { "line": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "parcoords" } ], "pie": [ { "automargin": true, "type": "pie" } ], "scatter": [ { "fillpattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 }, "type": "scatter" } ], "scatter3d": [ { "line": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatter3d" } ], "scattercarpet": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattercarpet" } ], "scattergeo": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattergeo" } ], "scattergl": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattergl" } ], "scattermap": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattermap" } ], "scattermapbox": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattermapbox" } ], "scatterpolar": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterpolar" } ], "scatterpolargl": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterpolargl" } ], "scatterternary": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterternary" } ], "surface": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0.0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1.0, "#f0f921" ] ], "type": "surface" } ], "table": [ { "cells": { "fill": { "color": "#EBF0F8" }, "line": { "color": "white" } }, "header": { "fill": { "color": "#C8D4E3" }, "line": { "color": "white" } }, "type": "table" } ] }, "layout": { "annotationdefaults": { "arrowcolor": "#2a3f5f", "arrowhead": 0, "arrowwidth": 1 }, "autotypenumbers": "strict", "coloraxis": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "colorscale": { "diverging": [ [ 0, "#8e0152" ], [ 0.1, "#c51b7d" ], [ 0.2, "#de77ae" ], [ 0.3, "#f1b6da" ], [ 0.4, "#fde0ef" ], [ 0.5, "#f7f7f7" ], [ 0.6, "#e6f5d0" ], [ 0.7, "#b8e186" ], [ 0.8, "#7fbc41" ], [ 0.9, "#4d9221" ], [ 1, "#276419" ] ], "sequential": [ [ 0.0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1.0, "#f0f921" ] ], "sequentialminus": [ [ 0.0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1.0, "#f0f921" ] ] }, "colorway": [ "#636efa", "#EF553B", "#00cc96", "#ab63fa", "#FFA15A", "#19d3f3", "#FF6692", "#B6E880", "#FF97FF", "#FECB52" ], "font": { "color": "#2a3f5f" }, "geo": { "bgcolor": "white", "lakecolor": "white", "landcolor": "#E5ECF6", "showlakes": true, "showland": true, "subunitcolor": "white" }, "hoverlabel": { "align": "left" }, "hovermode": "closest", "mapbox": { "style": "light" }, "paper_bgcolor": "white", "plot_bgcolor": "#E5ECF6", "polar": { "angularaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "bgcolor": "#E5ECF6", "radialaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" } }, "scene": { "xaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" }, "yaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" }, "zaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" } }, "shapedefaults": { "line": { "color": "#2a3f5f" } }, "ternary": { "aaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "baxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "bgcolor": "#E5ECF6", "caxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" } }, "title": { "x": 0.05 }, "xaxis": { "automargin": true, "gridcolor": "white", "linecolor": "white", "ticks": "", "title": { "standoff": 15 }, "zerolinecolor": "white", "zerolinewidth": 2 }, "yaxis": { "automargin": true, "gridcolor": "white", "linecolor": "white", "ticks": "", "title": { "standoff": 15 }, "zerolinecolor": "white", "zerolinewidth": 2 } } }, "title": { "text": "Best objective found vs. # of iterations" }, "xaxis": { "title": { "text": "Iteration" } }, "yaxis": { "title": { "text": "Branin" } } } }, "text/html": [ "
\n", "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "render(ax_client_custom_gss.get_optimization_trace())" ] }, { "cell_type": "code", "execution_count": null, "id": "4e70a43f", "metadata": { "customInput": null, "originalKey": "5f4eaa42-a8cb-42b2-b8b4-b2fa53398270", "papermill": { "duration": 0.17834, "end_time": "2025-01-31T07:10:40.754525", "exception": false, "start_time": "2025-01-31T07:10:40.576185", "status": "completed" }, "showInput": true, "tags": [] }, "outputs": [], "source": [] } ], "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.10.16" }, "papermill": { "default_parameters": {}, "duration": 44.073009, "end_time": "2025-01-31T07:10:43.685540", "environment_variables": {}, "exception": null, "input_path": "/tmp/tmp.8SPGnWMU26/Ax-main/tutorials/gss.ipynb", "output_path": "/tmp/tmp.8SPGnWMU26/Ax-main/tutorials/gss.ipynb", "parameters": {}, "start_time": "2025-01-31T07:09:59.612531", "version": "2.6.0" } }, "nbformat": 4, "nbformat_minor": 5 }