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)
[INFO 07-28 17:28:09] ax.storage.sqa_store.with_db_settings_base: Ax SQL storage initialized with SQLAlchemy 2.0.51
# 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)
Tiled version 0.2.14
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. After each run, Blop calls this function with the run’s unique ID and the suggestions that were tried. It returns the computed objective values:

class Himmelblau2DEvaluation():
    def __init__(self, tiled_client: Container):
        self.tiled_client = tiled_client

    def __call__(self, uid: str, suggestions: list[dict]) -> list[dict]:
        run = self.tiled_client[uid]
        outcomes = []
        reordered_suggestions = run.start["blop_suggestions"]
        x1_data = run["primary/x1"].read()
        x2_data = run["primary/x2"].read()

        print("[Himmelblau] evaluating suggestions: ", [s["_id"] for s in suggestions], " reordered to: ", [s["_id"] for s in reordered_suggestions])
        for index, suggestion in enumerate(reordered_suggestions):
            # Special key to identify a suggestion
            suggestion_id = suggestion["_id"]
            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    6f7f133f-f65e-4804-89ef-ae3b09d2124d                                                                 
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
[Himmelblau] evaluating suggestions:
[0, 1, 2, 3, 4, 5, 6, 7]
 reordered to:
[0, 5, 3, 7, 2, 6, 4, 1]
[Himmelblau] evaluating suggestions:
[8, 9, 10, 11, 12, 13, 14, 15]
 reordered to:
[12, 9, 8, 11, 13, 10, 15, 14]
[Himmelblau] evaluating suggestions:
[16, 17, 18, 19, 20, 21, 22, 23]
 reordered to:
[23, 18, 16, 19, 22, 20, 21, 17]
[Himmelblau] evaluating suggestions:
[24, 25, 26, 27, 28, 29, 30, 31]
 reordered to:
[30, 31, 29, 28, 24, 27, 25, 26]
[Himmelblau] evaluating suggestions:
[32, 33, 34, 35, 36, 37, 38, 39]
 reordered to:
[34, 32, 36, 38, 39, 37, 35, 33]
[INFO 07-28 17:28:14] 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 07-28 17:28:14] ax.api.client: Generated new trial 0 with parameters {'x1': 0.0, 'x2': 0.0} using GenerationNode CenterOfSearchSpace.
[INFO 07-28 17:28:14] ax.api.client: Generated new trial 1 with parameters {'x1': -3.489242, 'x2': 0.309227} using GenerationNode Sobol.
[INFO 07-28 17:28:14] ax.api.client: Generated new trial 2 with parameters {'x1': 3.669652, 'x2': -0.584508} using GenerationNode Sobol.
[INFO 07-28 17:28:14] ax.api.client: Generated new trial 3 with parameters {'x1': 1.293341, 'x2': 4.18891} using GenerationNode Sobol.
[INFO 07-28 17:28:14] ax.api.client: Generated new trial 4 with parameters {'x1': -1.47438, 'x2': -3.833065} using GenerationNode Sobol.
[INFO 07-28 17:28:14] ax.api.client: Generated new trial 5 with parameters {'x1': -0.044495, 'x2': 3.274535} using GenerationNode Sobol.
[INFO 07-28 17:28:14] ax.api.client: Generated new trial 6 with parameters {'x1': 0.215139, 'x2': -3.547335} using GenerationNode Sobol.
[INFO 07-28 17:28:14] ax.api.client: Generated new trial 7 with parameters {'x1': 4.743123, 'x2': 2.461702} using GenerationNode Sobol.
[INFO 07-28 17:28:15] ax.api.client: Trial 0 marked COMPLETED.
[INFO 07-28 17:28:15] ax.api.client: Trial 5 marked COMPLETED.
[INFO 07-28 17:28:15] ax.api.client: Trial 3 marked COMPLETED.
[INFO 07-28 17:28:15] ax.api.client: Trial 7 marked COMPLETED.
[INFO 07-28 17:28:15] ax.api.client: Trial 2 marked COMPLETED.
[INFO 07-28 17:28:15] ax.api.client: Trial 6 marked COMPLETED.
[INFO 07-28 17:28:15] ax.api.client: Trial 4 marked COMPLETED.
[INFO 07-28 17:28:15] ax.api.client: Trial 1 marked COMPLETED.
[INFO 07-28 17:28:20] ax.api.client: Generated new trial 8 with parameters {'x1': 4.566686, 'x2': -0.892104} using GenerationNode MBM.
[INFO 07-28 17:28:20] ax.api.client: Generated new trial 9 with parameters {'x1': 3.708838, 'x2': -0.007655} using GenerationNode MBM.
[INFO 07-28 17:28:20] ax.api.client: Generated new trial 10 with parameters {'x1': 3.041952, 'x2': -1.050081} using GenerationNode MBM.
[INFO 07-28 17:28:20] ax.api.client: Generated new trial 11 with parameters {'x1': 4.916381, 'x2': -0.243857} using GenerationNode MBM.
[INFO 07-28 17:28:20] ax.api.client: Generated new trial 12 with parameters {'x1': 2.852204, 'x2': -0.368686} using GenerationNode MBM.
[INFO 07-28 17:28:20] ax.api.client: Generated new trial 13 with parameters {'x1': 3.98451, 'x2': -1.397775} using GenerationNode MBM.
[INFO 07-28 17:28:20] ax.api.client: Generated new trial 14 with parameters {'x1': -1.826909, 'x2': 2.576162} using GenerationNode MBM.
[INFO 07-28 17:28:20] ax.api.client: Generated new trial 15 with parameters {'x1': -2.003859, 'x2': 3.890549} using GenerationNode MBM.
[INFO 07-28 17:28:20] ax.api.client: Trial 12 marked COMPLETED.
[INFO 07-28 17:28:20] ax.api.client: Trial 9 marked COMPLETED.
[INFO 07-28 17:28:20] ax.api.client: Trial 8 marked COMPLETED.
[INFO 07-28 17:28:20] ax.api.client: Trial 11 marked COMPLETED.
[INFO 07-28 17:28:20] ax.api.client: Trial 13 marked COMPLETED.
[INFO 07-28 17:28:20] ax.api.client: Trial 10 marked COMPLETED.
[INFO 07-28 17:28:20] ax.api.client: Trial 15 marked COMPLETED.
[INFO 07-28 17:28:20] ax.api.client: Trial 14 marked COMPLETED.
[INFO 07-28 17:28:25] ax.api.client: Generated new trial 16 with parameters {'x1': 4.055819, 'x2': -4.109752} using GenerationNode MBM.
[INFO 07-28 17:28:25] ax.api.client: Generated new trial 17 with parameters {'x1': -1.042798, 'x2': 4.220131} using GenerationNode MBM.
[INFO 07-28 17:28:25] ax.api.client: Generated new trial 18 with parameters {'x1': 3.618731, 'x2': -1.755162} using GenerationNode MBM.
[INFO 07-28 17:28:25] ax.api.client: Generated new trial 19 with parameters {'x1': 4.490632, 'x2': -5.0} using GenerationNode MBM.
[INFO 07-28 17:28:25] ax.api.client: Generated new trial 20 with parameters {'x1': -5.0, 'x2': -5.0} using GenerationNode MBM.
[INFO 07-28 17:28:25] ax.api.client: Generated new trial 21 with parameters {'x1': -5.0, 'x2': 5.0} using GenerationNode MBM.
[INFO 07-28 17:28:25] ax.api.client: Generated new trial 22 with parameters {'x1': 3.504528, 'x2': -5.0} using GenerationNode MBM.
[INFO 07-28 17:28:25] ax.api.client: Generated new trial 23 with parameters {'x1': 3.162337, 'x2': 5.0} using GenerationNode MBM.
[INFO 07-28 17:28:25] ax.api.client: Trial 23 marked COMPLETED.
[INFO 07-28 17:28:25] ax.api.client: Trial 18 marked COMPLETED.
[INFO 07-28 17:28:25] ax.api.client: Trial 16 marked COMPLETED.
[INFO 07-28 17:28:25] ax.api.client: Trial 19 marked COMPLETED.
[INFO 07-28 17:28:25] ax.api.client: Trial 22 marked COMPLETED.
[INFO 07-28 17:28:25] ax.api.client: Trial 20 marked COMPLETED.
[INFO 07-28 17:28:25] ax.api.client: Trial 21 marked COMPLETED.
[INFO 07-28 17:28:25] ax.api.client: Trial 17 marked COMPLETED.
[INFO 07-28 17:28:29] ax.api.client: Generated new trial 24 with parameters {'x1': 4.126131, 'x2': -2.757846} using GenerationNode MBM.
[INFO 07-28 17:28:29] ax.api.client: Generated new trial 25 with parameters {'x1': 2.233637, 'x2': 1.8384} using GenerationNode MBM.
[INFO 07-28 17:28:29] ax.api.client: Generated new trial 26 with parameters {'x1': -3.225121, 'x2': 2.752523} using GenerationNode MBM.
[INFO 07-28 17:28:29] ax.api.client: Generated new trial 27 with parameters {'x1': 3.219664, 'x2': -2.91254} using GenerationNode MBM.
[INFO 07-28 17:28:29] ax.api.client: Generated new trial 28 with parameters {'x1': 5.0, 'x2': -2.828056} using GenerationNode MBM.
[INFO 07-28 17:28:29] ax.api.client: Generated new trial 29 with parameters {'x1': -2.613063, 'x2': -1.452091} using GenerationNode MBM.
[INFO 07-28 17:28:29] ax.api.client: Generated new trial 30 with parameters {'x1': -5.0, 'x2': -1.218155} using GenerationNode MBM.
[INFO 07-28 17:28:29] ax.api.client: Generated new trial 31 with parameters {'x1': -3.721742, 'x2': -2.691551} using GenerationNode MBM.
[INFO 07-28 17:28:30] ax.api.client: Trial 30 marked COMPLETED.
[INFO 07-28 17:28:30] ax.api.client: Trial 31 marked COMPLETED.
[INFO 07-28 17:28:30] ax.api.client: Trial 29 marked COMPLETED.
[INFO 07-28 17:28:30] ax.api.client: Trial 28 marked COMPLETED.
[INFO 07-28 17:28:30] ax.api.client: Trial 24 marked COMPLETED.
[INFO 07-28 17:28:30] ax.api.client: Trial 27 marked COMPLETED.
[INFO 07-28 17:28:30] ax.api.client: Trial 25 marked COMPLETED.
[INFO 07-28 17:28:30] ax.api.client: Trial 26 marked COMPLETED.
[INFO 07-28 17:28:35] ax.api.client: Generated new trial 32 with parameters {'x1': 3.01036, 'x2': 1.104547} using GenerationNode MBM.
[INFO 07-28 17:28:35] ax.api.client: Generated new trial 33 with parameters {'x1': -2.535544, 'x2': 3.042677} using GenerationNode MBM.
[INFO 07-28 17:28:35] ax.api.client: Generated new trial 34 with parameters {'x1': 0.961734, 'x2': 1.984885} using GenerationNode MBM.
[INFO 07-28 17:28:35] ax.api.client: Generated new trial 35 with parameters {'x1': -3.073538, 'x2': 1.824058} using GenerationNode MBM.
[INFO 07-28 17:28:35] ax.api.client: Generated new trial 36 with parameters {'x1': -2.981361, 'x2': -2.82705} using GenerationNode MBM.
[INFO 07-28 17:28:35] ax.api.client: Generated new trial 37 with parameters {'x1': -4.973582, 'x2': 1.672803} using GenerationNode MBM.
[INFO 07-28 17:28:35] ax.api.client: Generated new trial 38 with parameters {'x1': -3.720657, 'x2': -3.476443} using GenerationNode MBM.
[INFO 07-28 17:28:35] ax.api.client: Generated new trial 39 with parameters {'x1': -5.0, 'x2': -3.194673} using GenerationNode MBM.
[INFO 07-28 17:28:36] ax.api.client: Trial 34 marked COMPLETED.
[INFO 07-28 17:28:36] ax.api.client: Trial 32 marked COMPLETED.
[INFO 07-28 17:28:36] ax.api.client: Trial 36 marked COMPLETED.
[INFO 07-28 17:28:36] ax.api.client: Trial 38 marked COMPLETED.
[INFO 07-28 17:28:36] ax.api.client: Trial 39 marked COMPLETED.
[INFO 07-28 17:28:36] ax.api.client: Trial 37 marked COMPLETED.
[INFO 07-28 17:28:36] ax.api.client: Trial 35 marked COMPLETED.
[INFO 07-28 17:28:36] ax.api.client: Trial 33 marked COMPLETED.
─────────────────────────────────────────── Iteration 1 / 5  (8 points) ───────────────────────────────────────────
  Acquire UID  65ea1e50-9e3a-4ef4-a7e7-563273dcaab1
┏━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓
 Event  Suggestion ID          x1         x2  himmelblau_2d 
┡━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩
│     0 │             0 │          0          0            170 
│     1 │             1 │   -3.48924   0.309227         110.23 
│     2 │             2 │    3.66965  -0.584508        12.4736 
│     3 │             3 │    1.29334    4.18891        166.596 
│     4 │             4 │   -1.47438   -3.83306        198.921 
│     5 │             5 │ -0.0444949    3.27453        73.1805 
│     6 │             6 │   0.215139   -3.54734        243.906 
│     7 │             7 │    4.74312     2.4617        209.315 
└───────┴───────────────┴────────────┴───────────┴───────────────┘
  himmelblau_2d  min: 12.4736  max: 243.906  mean: 148.078
  (8 pts sampled)
─────────────────────────────────────────── Iteration 2 / 5  (8 points) ───────────────────────────────────────────
  Acquire UID  22bbbcf6-fb2e-4919-9e19-13545089ec48
┏━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓
 Event  Suggestion ID        x1           x2  himmelblau_2d 
┡━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩
│     0 │            10 │  3.04195     -1.05008        15.9742 
│     1 │            11 │  4.91638    -0.243857        171.203 
│     2 │            12 │   2.8522    -0.368686        26.5514 
│     3 │            13 │  3.98451     -1.39778        13.2275 
│     4 │            14 │ -1.82691      2.57616        30.6672 
│     5 │            15 │ -2.00386      3.89055        47.1805 
│     6 │             8 │  4.56669    -0.892104         83.008 
│     7 │             9 │  3.70884  -0.00765519        18.3819 
└───────┴───────────────┴──────────┴─────────────┴───────────────┘
  himmelblau_2d  min: 12.4736  max: 243.906  mean: 99.4259
  (16 pts sampled)
─────────────────────────────────────────── Iteration 3 / 5  (8 points) ───────────────────────────────────────────
  Acquire UID  7f71fdcc-7cb3-4e39-8897-c038978dc620
┏━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━━━━━┓
 Event  Suggestion ID       x1        x2  himmelblau_2d 
┡━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━━━━━━┩
│     0 │            16 │ 4.05582  -4.10975        196.283 
│     1 │            17 │ -1.0428   4.22013        127.793 
│     2 │            18 │ 3.61873  -1.75516       0.206041 
│     3 │            19 │ 4.49063        -5        523.182 
│     4 │            20 │      -5        -5            250 
│     5 │            21 │      -5         5            530 
│     6 │            22 │ 3.50453        -5         476.27 
│     7 │            23 │ 3.16234         5        463.847 
└───────┴───────────────┴─────────┴──────────┴───────────────┘
  himmelblau_2d  min: 0.206041  max: 530  mean: 173.267
  (24 pts sampled)
─────────────────────────────────────────── Iteration 4 / 5  (8 points) ───────────────────────────────────────────
  Acquire UID  81088b98-cce6-471c-8c56-22893e1af9a4
┏━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━━━━━┓
 Event  Suggestion ID        x1        x2  himmelblau_2d 
┡━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━━━━━━┩
│     0 │            24 │  4.12613  -2.75785        33.0643 
│     1 │            25 │  2.23364    1.8384        19.3323 
│     2 │            26 │ -3.22512   2.75252        11.6552 
│     3 │            27 │  3.21966  -2.91254        34.6903 
│     4 │            28 │        5  -2.82806        160.787 
│     5 │            29 │ -2.61306  -1.45209        87.9467 
│     6 │            30 │       -5  -1.21815        273.964 
│     7 │            31 │ -3.72174  -2.69155        12.1171 
└───────┴───────────────┴──────────┴──────────┴───────────────┘
  himmelblau_2d  min: 0.206041  max: 530  mean: 149.749
  (32 pts sampled)
─────────────────────────────────────────── Iteration 5 / 5  (8 points) ───────────────────────────────────────────
  Acquire UID  db5e3fb3-1e19-414a-bb57-e13490b2c4fb
┏━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━━━━━┓
 Event  Suggestion ID        x1        x2  himmelblau_2d 
┡━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━━━━━━┩
│     0 │            32 │  3.01036   1.10455        8.36497 
│     1 │            33 │ -2.53554   3.04268        2.41291 
│     2 │            34 │ 0.961734   1.98488        69.8547 
│     3 │            35 │ -3.07354   1.82406        45.5865 
│     4 │            36 │ -2.98136  -2.82705        28.3459 
│     5 │            37 │ -4.97358    1.6728        321.634 
│     6 │            38 │ -3.72066  -3.47644        2.26412 
│     7 │            39 │       -5  -3.19467        119.974 
└───────┴───────────────┴──────────┴──────────┴───────────────┘
  himmelblau_2d  min: 0.206041  max: 530  mean: 134.76
  (40 pts sampled)

                            Summary Statistics                            
┏━━━━━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━┳━━━━━┳━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━┓
 Name           Type          Min  Max       Mean      Std  Count 
┡━━━━━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━╇━━━━━╇━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━┩
 x1            │ param   │       -5    5   0.341228  3.51425 │    40 │
 x2            │ param   │       -5    5  -0.275182  2.97132 │    40 │
 himmelblau_2d │ outcome │ 0.206041  530     134.76  150.458 │    40 │
└───────────────┴─────────┴──────────┴─────┴───────────┴─────────┴───────┘
────────────────────────────────────────────── Optimization Complete ──────────────────────────────────────────────

('6f7f133f-f65e-4804-89ef-ae3b09d2124d',
 '65ea1e50-9e3a-4ef4-a7e7-563273dcaab1',
 '22bbbcf6-fb2e-4919-9e19-13545089ec48',
 '7f71fdcc-7cb3-4e39-8897-c038978dc620',
 '81088b98-cce6-471c-8c56-22893e1af9a4',
 'db5e3fb3-1e19-414a-bb57-e13490b2c4fb')

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()
himmelblau_2d (Mean) vs. x1, x2
The contour plot visualizes the predicted outcomes for himmelblau_2d across a two-dimensional parameter space, with other parameters held fixed at their best trial value (Arm 18_0). This plot helps in identifying regions of optimal performance and understanding how changes in the selected parameters influence the predicted outcomes. Contour lines represent levels of constant predicted values, providing insights into the gradient and potential optima within the parameter space.
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 110.229710 -3.489242 0.309227
2 2 2_0 COMPLETED Sobol 12.473618 3.669652 -0.584508
3 3 3_0 COMPLETED Sobol 166.595583 1.293341 4.188910
4 4 4_0 COMPLETED Sobol 198.920619 -1.474380 -3.833065
5 5 5_0 COMPLETED Sobol 73.180529 -0.044495 3.274535
6 6 6_0 COMPLETED Sobol 243.905708 0.215139 -3.547335
7 7 7_0 COMPLETED Sobol 209.315068 4.743123 2.461702
8 8 8_0 COMPLETED MBM 83.008012 4.566686 -0.892104
9 9 9_0 COMPLETED MBM 18.381911 3.708838 -0.007655
10 10 10_0 COMPLETED MBM 15.974199 3.041952 -1.050081
11 11 11_0 COMPLETED MBM 171.203073 4.916381 -0.243857
12 12 12_0 COMPLETED MBM 26.551372 2.852204 -0.368686
13 13 13_0 COMPLETED MBM 13.227494 3.984510 -1.397775
14 14 14_0 COMPLETED MBM 30.667243 -1.826909 2.576162
15 15 15_0 COMPLETED MBM 47.180506 -2.003859 3.890549
16 16 16_0 COMPLETED MBM 196.283012 4.055819 -4.109752
17 17 17_0 COMPLETED MBM 127.792519 -1.042798 4.220131
18 18 18_0 COMPLETED MBM 0.206041 3.618731 -1.755162
19 19 19_0 COMPLETED MBM 523.182209 4.490632 -5.000000
20 20 20_0 COMPLETED MBM 250.000000 -5.000000 -5.000000
21 21 21_0 COMPLETED MBM 530.000000 -5.000000 5.000000
22 22 22_0 COMPLETED MBM 476.270357 3.504528 -5.000000
23 23 23_0 COMPLETED MBM 463.847493 3.162337 5.000000
24 24 24_0 COMPLETED MBM 33.064328 4.126131 -2.757846
25 25 25_0 COMPLETED MBM 19.332266 2.233637 1.838400
26 26 26_0 COMPLETED MBM 11.655233 -3.225121 2.752523
27 27 27_0 COMPLETED MBM 34.690300 3.219664 -2.912540
28 28 28_0 COMPLETED MBM 160.787143 5.000000 -2.828056
29 29 29_0 COMPLETED MBM 87.946730 -2.613063 -1.452091
30 30 30_0 COMPLETED MBM 273.963916 -5.000000 -1.218155
31 31 31_0 COMPLETED MBM 12.117114 -3.721742 -2.691551
32 32 32_0 COMPLETED MBM 8.364971 3.010360 1.104547
33 33 33_0 COMPLETED MBM 2.412913 -2.535544 3.042677
34 34 34_0 COMPLETED MBM 69.854746 0.961734 1.984885
35 35 35_0 COMPLETED MBM 45.586512 -3.073538 1.824058
36 36 36_0 COMPLETED MBM 28.345886 -2.981361 -2.827050
37 37 37_0 COMPLETED MBM 321.633514 -4.973582 1.672803
38 38 38_0 COMPLETED MBM 2.264117 -3.720657 -3.476443
39 39 39_0 COMPLETED MBM 119.973746 -5.000000 -3.194673

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, x1 and x2 with 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.