Your first Bayesian optimization with Blop#
In this tutorial, you will learn the three core concepts of Blop: DOFs (the parameters you can adjust), objectives (what you want to optimize), and the Agent (which coordinates the optimization). We’ll optimize a simple mathematical function using simulated devices—the same patterns apply to real hardware.
Setup#
First, let’s import what we need and start the data infrastructure:
import logging
import time
from typing import Any
import warnings
from blop.ax import Agent, RangeDOF, Objective
from bluesky.protocols import NamedMovable, Readable, Status, Hints, HasHints, HasParent
from bluesky.run_engine import RunEngine
from bluesky_tiled_plugins import TiledWriter
from tiled.client import from_uri
from tiled.client.container import Container
from tiled.server import SimpleTiledServer
# Suppress noisy logs from httpx
logging.getLogger("httpx").setLevel(logging.WARNING)
# Suppress noisy dependency deprecations from within Ax
warnings.filterwarnings('ignore',category=FutureWarning)
/home/runner/work/blop/blop/.pixi/envs/docs/lib/python3.13/site-packages/torch/jit/_script.py:1491: FutureWarning: `torch.jit.script` is deprecated. Please switch to `torch.compile` or `torch.export`.
warnings.warn(
[INFO 09-03 14:30:35] ax.storage.sqa_store.with_db_settings_base: Ax SQL storage initialized with SQLAlchemy 2.0.52
# Start a local Tiled server for data storage
tiled_server = SimpleTiledServer()
# Set up the Bluesky RunEngine and connect it to Tiled
RE = RunEngine({})
tiled_client = from_uri(tiled_server.uri)
tiled_writer = TiledWriter(tiled_client)
RE.subscribe(tiled_writer)
0
Creating simulated devices#
Bluesky controls devices through protocols. For this tutorial, we create simple simulated “movable” devices. In real experiments, you would use Ophyd devices or similar—the code below is just boilerplate to simulate hardware:
class AlwaysSuccessfulStatus(Status):
def add_callback(self, callback) -> None:
callback(self)
def exception(self, timeout = 0.0):
return None
@property
def done(self) -> bool:
return True
@property
def success(self) -> bool:
return True
class ReadableSignal(Readable, HasHints, HasParent):
def __init__(self, name: str) -> None:
self._name = name
self._value = 0.0
@property
def name(self) -> str:
return self._name
@property
def hints(self) -> Hints:
return {"fields": [self._name], "dimensions": [], "gridding": "rectilinear"}
@property
def parent(self) -> Any | None:
return None
def read(self):
return {self._name: {"value": self._value, "timestamp": time.time()}}
def describe(self):
return {self._name: {"source": self._name, "dtype": "number", "shape": []}}
class MovableSignal(ReadableSignal, NamedMovable):
def __init__(self, name: str, initial_value: float = 0.0) -> None:
super().__init__(name)
self._value: float = initial_value
def set(self, value: float) -> Status:
self._value = value
return AlwaysSuccessfulStatus()
Defining DOFs and objectives#
DOFs (degrees of freedom) are the parameters the optimizer can adjust. Objectives are what you want to optimize. Here we define two DOFs (x1 and x2) that can range from -5 to 5, and one objective (the Himmelblau function) that we want to minimize:
x1 = MovableSignal("x1", initial_value=0.1)
x2 = MovableSignal("x2", initial_value=0.23)
dofs = [
RangeDOF(actuator=x1, bounds=(-5, 5), parameter_type="float"),
RangeDOF(actuator=x2, bounds=(-5, 5), parameter_type="float"),
]
objectives = [
Objective(name="himmelblau_2d", minimize=True),
]
sensors = []
Writing the evaluation function#
The evaluation function computes objective values from experimental data. Blop passes it the hashable identifier returned by the acquisition plan and the suggestions that were tried. This tutorial uses the default acquisition plan, so the identifier is a Bluesky run UID and blop_acquisition_order associates measurements with outcomes.
from collections.abc import Hashable, Mapping, Sequence
class Himmelblau2DEvaluation():
def __init__(self, tiled_client: Container):
self.tiled_client = tiled_client
def __call__(self, uid: Hashable, suggestions: Sequence[Mapping]) -> Sequence[Mapping]:
if not isinstance(uid, str):
raise TypeError(f"Himmelblau2DEvaluation requires a Bluesky run UID string, got {uid!r}")
run = self.tiled_client[uid]
outcomes = []
acquisition_order = run.start["blop_acquisition_order"]
x1_data = run["primary/x1"].read()
x2_data = run["primary/x2"].read()
print("[Himmelblau] evaluating acquired order: ", acquisition_order)
for index, suggestion_id in enumerate(acquisition_order):
x1 = x1_data[index]
x2 = x2_data[index]
# Himmelblau function: has four global minima where value = 0
outcomes.append({
"himmelblau_2d": (x1 ** 2 + x2 - 11) ** 2 + (x1 + x2 ** 2 - 7) ** 2,
"_id": suggestion_id
})
return outcomes
Running the optimization#
The Agent brings everything together. Create one with your DOFs, objectives, and evaluation function, then run the optimization:
agent = Agent(
sensors=sensors,
dofs=dofs,
objectives=objectives,
evaluation_function=Himmelblau2DEvaluation(tiled_client=tiled_client),
name="simple-experiment",
description="A simple experiment optimizing the Himmelblau function",
)
RE(agent.optimize(5,n_points=8))
╭───────────────────────────────────────────────── Optimization ──────────────────────────────────────────────────╮ │ Optimizer AxOptimizer │ │ Actuators x1, x2 │ │ Sensors N/A │ │ Iterations 5 Points/iter 8 │ │ Run UID 695220f3-f87b-4b9b-915c-562c26dacf84 │ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
[Himmelblau] evaluating acquired order:
[0, 2, 5, 1, 7, 3, 6, 4]
[Himmelblau] evaluating acquired order:
[12, 14, 10, 8, 13, 9, 15, 11]
[Himmelblau] evaluating acquired order:
[19, 23, 20, 18, 17, 22, 21, 16]
[Himmelblau] evaluating acquired order:
[25, 24, 28, 29, 31, 26, 30, 27]
[Himmelblau] evaluating acquired order:
[38, 32, 37, 33, 35, 39, 34, 36]
[INFO 09-03 14:30:40] ax.api.client: GenerationStrategy(name='Center+Sobol+MBM:fast', nodes=[CenterGenerationNode(next_node_name='Sobol', use_existing_trials_for_initialization=True), GenerationNode(name='Sobol', generator_specs=[GeneratorSpec(generator_enum=Sobol, generator_key_override=None)], transition_criteria=[MinTrials(transition_to='MBM'), MinTrials(transition_to='MBM')], suggested_experiment_status=ExperimentStatus.INITIALIZATION, pausing_criteria=[MaxTrialsAwaitingData(threshold=5)]), GenerationNode(name='MBM', generator_specs=[GeneratorSpec(generator_enum=BoTorch, generator_key_override=None)], transition_criteria=None, suggested_experiment_status=ExperimentStatus.OPTIMIZATION, pausing_criteria=None)]) chosen based on user input and problem structure.
[INFO 09-03 14:30:40] ax.api.client: Generated new trial 0 with parameters {'x1': 0.0, 'x2': 0.0} using GenerationNode CenterOfSearchSpace.
[INFO 09-03 14:30:40] ax.api.client: Generated new trial 1 with parameters {'x1': 4.19982, 'x2': 3.038247} using GenerationNode Sobol.
[INFO 09-03 14:30:40] ax.api.client: Generated new trial 2 with parameters {'x1': -0.062134, 'x2': -0.574649} using GenerationNode Sobol.
[INFO 09-03 14:30:40] ax.api.client: Generated new trial 3 with parameters {'x1': -3.187397, 'x2': 1.819061} using GenerationNode Sobol.
[INFO 09-03 14:30:40] ax.api.client: Generated new trial 4 with parameters {'x1': 2.326078, 'x2': -4.292002} using GenerationNode Sobol.
[INFO 09-03 14:30:40] ax.api.client: Generated new trial 5 with parameters {'x1': 1.110098, 'x2': 0.602459} using GenerationNode Sobol.
[INFO 09-03 14:30:40] ax.api.client: Generated new trial 6 with parameters {'x1': -4.628888, 'x2': -2.973204} using GenerationNode Sobol.
[INFO 09-03 14:30:40] ax.api.client: Generated new trial 7 with parameters {'x1': -1.501503, 'x2': 4.22765} using GenerationNode Sobol.
[INFO 09-03 14:30:41] ax.api.client: Trial 0 marked COMPLETED.
[INFO 09-03 14:30:41] ax.api.client: Trial 2 marked COMPLETED.
[INFO 09-03 14:30:41] ax.api.client: Trial 5 marked COMPLETED.
[INFO 09-03 14:30:41] ax.api.client: Trial 1 marked COMPLETED.
[INFO 09-03 14:30:41] ax.api.client: Trial 7 marked COMPLETED.
[INFO 09-03 14:30:41] ax.api.client: Trial 3 marked COMPLETED.
[INFO 09-03 14:30:41] ax.api.client: Trial 6 marked COMPLETED.
[INFO 09-03 14:30:41] ax.api.client: Trial 4 marked COMPLETED.
[INFO 09-03 14:30:45] ax.api.client: Generated new trial 8 with parameters {'x1': -4.181839, 'x2': 0.174944} using GenerationNode MBM.
[INFO 09-03 14:30:45] ax.api.client: Generated new trial 9 with parameters {'x1': -3.618073, 'x2': 4.283337} using GenerationNode MBM.
[INFO 09-03 14:30:45] ax.api.client: Generated new trial 10 with parameters {'x1': -3.238268, 'x2': -1.347188} using GenerationNode MBM.
[INFO 09-03 14:30:45] ax.api.client: Generated new trial 11 with parameters {'x1': 1.727107, 'x2': 4.397523} using GenerationNode MBM.
[INFO 09-03 14:30:45] ax.api.client: Generated new trial 12 with parameters {'x1': -3.630069, 'x2': -5.0} using GenerationNode MBM.
[INFO 09-03 14:30:45] ax.api.client: Generated new trial 13 with parameters {'x1': -5.0, 'x2': 1.484998} using GenerationNode MBM.
[INFO 09-03 14:30:45] ax.api.client: Generated new trial 14 with parameters {'x1': -5.0, 'x2': -5.0} using GenerationNode MBM.
[INFO 09-03 14:30:45] ax.api.client: Generated new trial 15 with parameters {'x1': -5.0, 'x2': 5.0} using GenerationNode MBM.
[INFO 09-03 14:30:45] ax.api.client: Trial 12 marked COMPLETED.
[INFO 09-03 14:30:45] ax.api.client: Trial 14 marked COMPLETED.
[INFO 09-03 14:30:45] ax.api.client: Trial 10 marked COMPLETED.
[INFO 09-03 14:30:45] ax.api.client: Trial 8 marked COMPLETED.
[INFO 09-03 14:30:45] ax.api.client: Trial 13 marked COMPLETED.
[INFO 09-03 14:30:45] ax.api.client: Trial 9 marked COMPLETED.
[INFO 09-03 14:30:45] ax.api.client: Trial 15 marked COMPLETED.
[INFO 09-03 14:30:45] ax.api.client: Trial 11 marked COMPLETED.
[INFO 09-03 14:30:56] ax.api.client: Generated new trial 16 with parameters {'x1': -4.425598, 'x2': -4.970557} using GenerationNode MBM.
[INFO 09-03 14:30:56] ax.api.client: Generated new trial 17 with parameters {'x1': -2.89662, 'x2': -0.074709} using GenerationNode MBM.
[INFO 09-03 14:30:56] ax.api.client: Generated new trial 18 with parameters {'x1': -3.380211, 'x2': 1.453249} using GenerationNode MBM.
[INFO 09-03 14:30:56] ax.api.client: Generated new trial 19 with parameters {'x1': 0.677539, 'x2': 3.576455} using GenerationNode MBM.
[INFO 09-03 14:30:56] ax.api.client: Generated new trial 20 with parameters {'x1': -3.253807, 'x2': 5.0} using GenerationNode MBM.
[INFO 09-03 14:30:56] ax.api.client: Generated new trial 21 with parameters {'x1': 0.717192, 'x2': -3.390997} using GenerationNode MBM.
[INFO 09-03 14:30:56] ax.api.client: Generated new trial 22 with parameters {'x1': -1.497899, 'x2': -1.676488} using GenerationNode MBM.
[INFO 09-03 14:30:56] ax.api.client: Generated new trial 23 with parameters {'x1': -1.989265, 'x2': 5.0} using GenerationNode MBM.
[INFO 09-03 14:30:56] ax.api.client: Trial 19 marked COMPLETED.
[INFO 09-03 14:30:56] ax.api.client: Trial 23 marked COMPLETED.
[INFO 09-03 14:30:56] ax.api.client: Trial 20 marked COMPLETED.
[INFO 09-03 14:30:56] ax.api.client: Trial 18 marked COMPLETED.
[INFO 09-03 14:30:56] ax.api.client: Trial 17 marked COMPLETED.
[INFO 09-03 14:30:56] ax.api.client: Trial 22 marked COMPLETED.
[INFO 09-03 14:30:56] ax.api.client: Trial 21 marked COMPLETED.
[INFO 09-03 14:30:56] ax.api.client: Trial 16 marked COMPLETED.
[INFO 09-03 14:31:06] ax.api.client: Generated new trial 24 with parameters {'x1': -3.165345, 'x2': 0.562693} using GenerationNode MBM.
[INFO 09-03 14:31:06] ax.api.client: Generated new trial 25 with parameters {'x1': -4.562655, 'x2': -1.069194} using GenerationNode MBM.
[INFO 09-03 14:31:06] ax.api.client: Generated new trial 26 with parameters {'x1': 0.973625, 'x2': 4.130264} using GenerationNode MBM.
[INFO 09-03 14:31:06] ax.api.client: Generated new trial 27 with parameters {'x1': -3.910927, 'x2': 4.597795} using GenerationNode MBM.
[INFO 09-03 14:31:06] ax.api.client: Generated new trial 28 with parameters {'x1': -3.767511, 'x2': 1.8659} using GenerationNode MBM.
[INFO 09-03 14:31:06] ax.api.client: Generated new trial 29 with parameters {'x1': -1.238337, 'x2': 2.087124} using GenerationNode MBM.
[INFO 09-03 14:31:06] ax.api.client: Generated new trial 30 with parameters {'x1': 0.370831, 'x2': 4.566838} using GenerationNode MBM.
[INFO 09-03 14:31:06] ax.api.client: Generated new trial 31 with parameters {'x1': 0.515086, 'x2': 1.136697} using GenerationNode MBM.
[INFO 09-03 14:31:06] ax.api.client: Trial 25 marked COMPLETED.
[INFO 09-03 14:31:06] ax.api.client: Trial 24 marked COMPLETED.
[INFO 09-03 14:31:06] ax.api.client: Trial 28 marked COMPLETED.
[INFO 09-03 14:31:06] ax.api.client: Trial 29 marked COMPLETED.
[INFO 09-03 14:31:06] ax.api.client: Trial 31 marked COMPLETED.
[INFO 09-03 14:31:06] ax.api.client: Trial 26 marked COMPLETED.
[INFO 09-03 14:31:06] ax.api.client: Trial 30 marked COMPLETED.
[INFO 09-03 14:31:06] ax.api.client: Trial 27 marked COMPLETED.
[INFO 09-03 14:31:15] ax.api.client: Generated new trial 32 with parameters {'x1': -3.40132, 'x2': 3.045053} using GenerationNode MBM.
[INFO 09-03 14:31:15] ax.api.client: Generated new trial 33 with parameters {'x1': -2.007575, 'x2': 2.754078} using GenerationNode MBM.
[INFO 09-03 14:31:15] ax.api.client: Generated new trial 34 with parameters {'x1': 1.182725, 'x2': 2.484993} using GenerationNode MBM.
[INFO 09-03 14:31:15] ax.api.client: Generated new trial 35 with parameters {'x1': -0.859376, 'x2': 3.095207} using GenerationNode MBM.
[INFO 09-03 14:31:15] ax.api.client: Generated new trial 36 with parameters {'x1': -3.882716, 'x2': -2.829839} using GenerationNode MBM.
[INFO 09-03 14:31:15] ax.api.client: Generated new trial 37 with parameters {'x1': -3.130026, 'x2': 3.075887} using GenerationNode MBM.
[INFO 09-03 14:31:15] ax.api.client: Generated new trial 38 with parameters {'x1': -3.572554, 'x2': 3.079422} using GenerationNode MBM.
[INFO 09-03 14:31:15] ax.api.client: Generated new trial 39 with parameters {'x1': -0.37066, 'x2': 2.617325} using GenerationNode MBM.
[INFO 09-03 14:31:15] ax.api.client: Trial 38 marked COMPLETED.
[INFO 09-03 14:31:15] ax.api.client: Trial 32 marked COMPLETED.
[INFO 09-03 14:31:15] ax.api.client: Trial 37 marked COMPLETED.
[INFO 09-03 14:31:15] ax.api.client: Trial 33 marked COMPLETED.
[INFO 09-03 14:31:15] ax.api.client: Trial 35 marked COMPLETED.
[INFO 09-03 14:31:15] ax.api.client: Trial 39 marked COMPLETED.
[INFO 09-03 14:31:15] ax.api.client: Trial 34 marked COMPLETED.
[INFO 09-03 14:31:15] ax.api.client: Trial 36 marked COMPLETED.
─────────────────────────────────────────── Iteration 1 / 5 (8 points) ───────────────────────────────────────────
Acquire UID 29eec052-04c1-4520-882a-5f9d79ca62aa
┏━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓ ┃ Event ┃ Suggestion ID ┃ x1 ┃ x2 ┃ himmelblau_2d ┃ ┡━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩ │ 0 │ 0 │ 0 │ 0 │ 170 │ │ 1 │ 1 │ 4.19982 │ 3.03825 │ 134.994 │ │ 2 │ 2 │ -0.062134 │ -0.574649 │ 179.202 │ │ 3 │ 3 │ -3.1874 │ 1.81906 │ 48.2702 │ │ 4 │ 4 │ 2.32608 │ -4.292 │ 286.631 │ │ 5 │ 5 │ 1.1101 │ 0.602459 │ 114.548 │ │ 6 │ 6 │ -4.62889 │ -2.9732 │ 63.3314 │ │ 7 │ 7 │ -1.5015 │ 4.22765 │ 108.236 │ └───────┴───────────────┴───────────┴───────────┴───────────────┘
himmelblau_2d min: 48.2702 max: 286.631 mean: 138.152 (8 pts sampled)
─────────────────────────────────────────── Iteration 2 / 5 (8 points) ───────────────────────────────────────────
Acquire UID 3c2874a5-ec45-4f83-b09f-bab20fd3cb3b
┏━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━━━━━┓ ┃ Event ┃ Suggestion ID ┃ x1 ┃ x2 ┃ himmelblau_2d ┃ ┡━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━━━━━━┩ │ 0 │ 10 │ -3.23827 │ -1.34719 │ 74.4155 │ │ 1 │ 11 │ 1.72711 │ 4.39752 │ 210.934 │ │ 2 │ 12 │ -3.63007 │ -5 │ 214.462 │ │ 3 │ 13 │ -5 │ 1.485 │ 335.723 │ │ 4 │ 14 │ -5 │ -5 │ 250 │ │ 5 │ 15 │ -5 │ 5 │ 530 │ │ 6 │ 8 │ -4.18184 │ 0.174944 │ 168.742 │ │ 7 │ 9 │ -3.61807 │ 4.28334 │ 100.361 │ └───────┴───────────────┴──────────┴──────────┴───────────────┘
himmelblau_2d min: 48.2702 max: 530 mean: 186.866 (16 pts sampled)
─────────────────────────────────────────── Iteration 3 / 5 (8 points) ───────────────────────────────────────────
Acquire UID 15f3af1f-6a6e-454c-83cc-6721f773f11e
┏━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓ ┃ Event ┃ Suggestion ID ┃ x1 ┃ x2 ┃ himmelblau_2d ┃ ┡━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩ │ 0 │ 16 │ -4.4256 │ -4.97056 │ 189.451 │ │ 1 │ 17 │ -2.89662 │ -0.0747093 │ 105.038 │ │ 2 │ 18 │ -3.38021 │ 1.45325 │ 71.8954 │ │ 3 │ 19 │ 0.677539 │ 3.57646 │ 90.3465 │ │ 4 │ 20 │ -3.25381 │ 5 │ 238.493 │ │ 5 │ 21 │ 0.717192 │ -3.391 │ 219.768 │ │ 6 │ 22 │ -1.4979 │ -1.67649 │ 141.188 │ │ 7 │ 23 │ -1.98926 │ 5 │ 260.517 │ └───────┴───────────────┴──────────┴────────────┴───────────────┘
himmelblau_2d min: 48.2702 max: 530 mean: 179.44 (24 pts sampled)
─────────────────────────────────────────── Iteration 4 / 5 (8 points) ───────────────────────────────────────────
Acquire UID 1dcd32e3-bb60-42d3-81a2-ed69fff085d1
┏━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━━━━━┓ ┃ Event ┃ Suggestion ID ┃ x1 ┃ x2 ┃ himmelblau_2d ┃ ┡━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━━━━━━┩ │ 0 │ 24 │ -3.16535 │ 0.562693 │ 97.172 │ │ 1 │ 25 │ -4.56265 │ -1.06919 │ 185.104 │ │ 2 │ 26 │ 0.973625 │ 4.13026 │ 156.788 │ │ 3 │ 27 │ -3.91093 │ 4.59779 │ 183.716 │ │ 4 │ 28 │ -3.76751 │ 1.8659 │ 78.6887 │ │ 5 │ 29 │ -1.23834 │ 2.08712 │ 69.5274 │ │ 6 │ 30 │ 0.370831 │ 4.56684 │ 242.038 │ │ 7 │ 31 │ 0.515086 │ 1.1367 │ 119.087 │ └───────┴───────────────┴──────────┴──────────┴───────────────┘
himmelblau_2d min: 48.2702 max: 530 mean: 169.958 (32 pts sampled)
─────────────────────────────────────────── Iteration 5 / 5 (8 points) ───────────────────────────────────────────
Acquire UID 6193bf48-f2ce-4a84-ad15-880d0e90c190
┏━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━━━━━┓ ┃ Event ┃ Suggestion ID ┃ x1 ┃ x2 ┃ himmelblau_2d ┃ ┡━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━━━━━━┩ │ 0 │ 32 │ -3.40132 │ 3.04505 │ 14.3358 │ │ 1 │ 33 │ -2.00757 │ 2.75408 │ 19.7949 │ │ 2 │ 34 │ 1.18272 │ 2.48499 │ 50.768 │ │ 3 │ 35 │ -0.859376 │ 3.09521 │ 54.317 │ │ 4 │ 36 │ -3.88272 │ -2.82984 │ 9.81571 │ │ 5 │ 37 │ -3.13003 │ 3.07589 │ 3.95542 │ │ 6 │ 38 │ -3.57255 │ 3.07942 │ 24.6379 │ │ 7 │ 39 │ -0.37066 │ 2.61733 │ 68.2554 │ └───────┴───────────────┴───────────┴──────────┴───────────────┘
himmelblau_2d min: 3.95542 max: 530 mean: 142.114 (40 pts sampled)
Summary Statistics ┏━━━━━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━┓ ┃ Name ┃ Type ┃ Min ┃ Max ┃ Mean ┃ Std ┃ Count ┃ ┡━━━━━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━┩ │ x1 │ param │ -5 │ 4.19982 │ -1.91401 │ 2.37345 │ 40 │ │ x2 │ param │ -5 │ 5 │ 1.14896 │ 3.04784 │ 40 │ │ himmelblau_2d │ outcome │ 3.95542 │ 530 │ 142.114 │ 104.51 │ 40 │ └───────────────┴─────────┴─────────┴─────────┴──────────┴─────────┴───────┘
────────────────────────────────────────────── Optimization Complete ──────────────────────────────────────────────
('695220f3-f87b-4b9b-915c-562c26dacf84',
'29eec052-04c1-4520-882a-5f9d79ca62aa',
'3c2874a5-ec45-4f83-b09f-bab20fd3cb3b',
'15f3af1f-6a6e-454c-83cc-6721f773f11e',
'1dcd32e3-bb60-42d3-81a2-ed69fff085d1',
'6193bf48-f2ce-4a84-ad15-880d0e90c190')
Viewing the results#
After optimization, visualize what the Agent learned and see the best parameters found:
agent.plot_objective("x1", "x2", "himmelblau_2d")
agent.ax_client.summarize()
| trial_index | arm_name | trial_status | generation_node | himmelblau_2d | x1 | x2 | |
|---|---|---|---|---|---|---|---|
| 0 | 0 | 0_0 | COMPLETED | CenterOfSearchSpace | 170.000000 | 0.000000 | 0.000000 |
| 1 | 1 | 1_0 | COMPLETED | Sobol | 134.993930 | 4.199820 | 3.038247 |
| 2 | 2 | 2_0 | COMPLETED | Sobol | 179.201791 | -0.062134 | -0.574649 |
| 3 | 3 | 3_0 | COMPLETED | Sobol | 48.270153 | -3.187397 | 1.819061 |
| 4 | 4 | 4_0 | COMPLETED | Sobol | 286.631191 | 2.326078 | -4.292002 |
| 5 | 5 | 5_0 | COMPLETED | Sobol | 114.548428 | 1.110098 | 0.602459 |
| 6 | 6 | 6_0 | COMPLETED | Sobol | 63.331395 | -4.628888 | -2.973204 |
| 7 | 7 | 7_0 | COMPLETED | Sobol | 108.236283 | -1.501503 | 4.227650 |
| 8 | 8 | 8_0 | COMPLETED | MBM | 168.741935 | -4.181839 | 0.174944 |
| 9 | 9 | 9_0 | COMPLETED | MBM | 100.361186 | -3.618073 | 4.283337 |
| 10 | 10 | 10_0 | COMPLETED | MBM | 74.415458 | -3.238268 | -1.347188 |
| 11 | 11 | 11_0 | COMPLETED | MBM | 210.934457 | 1.727107 | 4.397523 |
| 12 | 12 | 12_0 | COMPLETED | MBM | 214.461996 | -3.630069 | -5.000000 |
| 13 | 13 | 13_0 | COMPLETED | MBM | 335.722888 | -5.000000 | 1.484998 |
| 14 | 14 | 14_0 | COMPLETED | MBM | 250.000000 | -5.000000 | -5.000000 |
| 15 | 15 | 15_0 | COMPLETED | MBM | 530.000000 | -5.000000 | 5.000000 |
| 16 | 16 | 16_0 | COMPLETED | MBM | 189.451491 | -4.425598 | -4.970557 |
| 17 | 17 | 17_0 | COMPLETED | MBM | 105.038123 | -2.896620 | -0.074709 |
| 18 | 18 | 18_0 | COMPLETED | MBM | 71.895360 | -3.380211 | 1.453249 |
| 19 | 19 | 19_0 | COMPLETED | MBM | 90.346464 | 0.677539 | 3.576455 |
| 20 | 20 | 20_0 | COMPLETED | MBM | 238.493157 | -3.253807 | 5.000000 |
| 21 | 21 | 21_0 | COMPLETED | MBM | 219.768158 | 0.717192 | -3.390997 |
| 22 | 22 | 22_0 | COMPLETED | MBM | 141.188293 | -1.497899 | -1.676488 |
| 23 | 23 | 23_0 | COMPLETED | MBM | 260.516785 | -1.989265 | 5.000000 |
| 24 | 24 | 24_0 | COMPLETED | MBM | 97.171966 | -3.165345 | 0.562693 |
| 25 | 25 | 25_0 | COMPLETED | MBM | 185.103993 | -4.562655 | -1.069194 |
| 26 | 26 | 26_0 | COMPLETED | MBM | 156.788150 | 0.973625 | 4.130264 |
| 27 | 27 | 27_0 | COMPLETED | MBM | 183.716137 | -3.910927 | 4.597795 |
| 28 | 28 | 28_0 | COMPLETED | MBM | 78.688735 | -3.767511 | 1.865900 |
| 29 | 29 | 29_0 | COMPLETED | MBM | 69.527386 | -1.238337 | 2.087124 |
| 30 | 30 | 30_0 | COMPLETED | MBM | 242.038240 | 0.370831 | 4.566838 |
| 31 | 31 | 31_0 | COMPLETED | MBM | 119.086940 | 0.515086 | 1.136697 |
| 32 | 32 | 32_0 | COMPLETED | MBM | 14.335789 | -3.401320 | 3.045053 |
| 33 | 33 | 33_0 | COMPLETED | MBM | 19.794878 | -2.007575 | 2.754078 |
| 34 | 34 | 34_0 | COMPLETED | MBM | 50.767975 | 1.182725 | 2.484993 |
| 35 | 35 | 35_0 | COMPLETED | MBM | 54.316963 | -0.859376 | 3.095207 |
| 36 | 36 | 36_0 | COMPLETED | MBM | 9.815705 | -3.882716 | -2.829839 |
| 37 | 37 | 37_0 | COMPLETED | MBM | 3.955424 | -3.130026 | 3.075887 |
| 38 | 38 | 38_0 | COMPLETED | MBM | 24.637874 | -3.572554 | 3.079422 |
| 39 | 39 | 39_0 | COMPLETED | MBM | 68.255421 | -0.370660 | 2.617325 |
The Himmelblau function has four global minima (all with value 0). The summarize output shows which one(s) the optimizer found.
What you learned#
You now understand the three core concepts of Blop:
DOFs: The parameters the optimizer adjusts (here,
x1andx2with bounds)Objectives: What you’re optimizing (here, minimizing the Himmelblau function)
Agent: Coordinates the optimization loop between Bluesky and the evaluation function
Next steps#
For a more comprehensive tutorial with multiple objectives and diagnostic tools, see Optimizing KB Mirrors.