Your first Scipy 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

from bluesky.protocols import HasHints, HasParent, Hints, NamedMovable, Readable, Status
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

from blop.scipy import SCP, ScipyCFG, Objective, RangeDOF, Scipy

# Suppress noisy logs from httpx 
logging.getLogger("httpx").setLevel(logging.WARNING)
# 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 uid returned by the acquisition plan and the suggestions that were tried. This tutorial uses the default acquisition plan, so the uid is a Bluesky run UID and blop_acquisition_order associates measurements with outcomes.

from collections.abc import Mapping, Sequence

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

    def __call__(self, uid: str, suggestions: Sequence[Mapping]) -> Sequence[Mapping]:
        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()

        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 = Scipy.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(10))
╭───────────────────────────────────────────────── Optimization ──────────────────────────────────────────────────╮
│ Optimizer  InteractiveOptimizer                                                                                 │
│ Actuators  x1, x2                                                                                               │
│ Sensors    N/A                                                                                                  │
│ Iterations 10                                                                                                   │
│ Run UID    372d6c9e-9fec-4e44-9852-fe8d45e370f7                                                                 │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Suggestion ID              ┃ x1                         ┃ x2                        ┃ himmelblau_2d             ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
└────────────────────────────┴────────────────────────────┴───────────────────────────┴───────────────────────────┘
┃                            ┃                            ┃                           ┃                           ┃
┃ 0                          ┃                          0 ┃                         0 ┃                       170 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 1                          ┃                      1e-08 ┃                         0 ┃                       170 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 2                          ┃                          0 ┃                     1e-08 ┃                       170 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 3                          ┃                          5 ┃                         5 ┃                       890 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 4                          ┃                          5 ┃                         5 ┃                       890 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
──────────────────────────────────────────────── Iteration 5 / 10 ─────────────────────────────────────────────────
  himmelblau_2d  min: 170  max: 890  mean: 458
  (5 pts sampled)
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────
┃                            ┃                            ┃                           ┃                           ┃
┃ 5                          ┃                          5 ┃                         5 ┃                       890 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 6                          ┃                    1.51545 ┃                   1.51545 ┃                   61.8302 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 7                          ┃                    1.51545 ┃                   1.51545 ┃                   61.8302 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 8                          ┃                    1.51545 ┃                   1.51545 ┃                   61.8302 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 9                          ┃                    3.25772 ┃                   3.25772 ┃                   55.4432 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
──────────────────────────────────────────────── Iteration 10 / 10 ────────────────────────────────────────────────
  himmelblau_2d  min: 55.4432  max: 890  mean: 342.093
  (10 pts sampled)
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────

                          Summary Statistics                           
┏━━━━━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━┳━━━━━┳━━━━━━━━━┳━━━━━━━━━┳━━━━━━━┓
┃ Name          ┃ Type    ┃     Min ┃ Max ┃    Mean ┃     Std ┃ Count ┃
┡━━━━━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━╇━━━━━╇━━━━━━━━━╇━━━━━━━━━╇━━━━━━━┩
│ x1            │ param   │       0 │   5 │ 2.28041 │ 2.12132 │    10 │
│ x2            │ param   │       0 │   5 │ 2.28041 │ 2.12132 │    10 │
│ himmelblau_2d │ outcome │ 55.4432 │ 890 │ 342.093 │ 381.119 │    10 │
└───────────────┴─────────┴─────────┴─────┴─────────┴─────────┴───────┘
────────────────────────────────────────────── Optimization Complete ──────────────────────────────────────────────
('372d6c9e-9fec-4e44-9852-fe8d45e370f7',
 '62edcbff-4717-4e7b-9b25-fb98a29f5d5e',
 'a940c3a7-5e75-4d7b-9e24-048c9cb037a7',
 '5f182d5e-fb01-4485-a970-db486d36b114',
 '90807876-e67e-484a-9793-94ac00cf919e',
 '24775f47-fad6-45be-a1c0-9b5f5372a219',
 '03f2864f-e2d6-42c9-b578-e5d7af9133d8',
 '180d0704-2050-4583-b387-f43064851be0',
 'e5080eac-33ed-4bab-b29d-cdddecd44cef',
 '44352bd3-a30c-411b-844d-0bcc4b168f76',
 '364bfc13-f7b8-4b93-a0a6-702c7ac87dc7')

Configuring the optimization#

Sometimes a default Agent optimization may not do all that you’d like. We expose a configuration object called ScipyCFG and a pure scipy interface so that the classic parameters of scipy minimize can be tweaked (and some multipoint sampling can be used).

config = ScipyCFG(dofs=dofs, objective=objectives[0], optimizer=SCP.DUAL_ANNEALING, threads=4, max_iter=2, eps=0.1)
agent = Scipy(
    sensors=sensors,
    config=config,
    evaluation_function=Himmelblau2DEvaluation(tiled_client=tiled_client),
    name="test_experiment",
)
res_uid = RE(agent.optimize(20, n_points=2))
╭───────────────────────────────────────────────── Optimization ──────────────────────────────────────────────────╮
│ Optimizer  InteractiveOptimizer                                                                                 │
│ Actuators  x1, x2                                                                                               │
│ Sensors    N/A                                                                                                  │
│ Iterations 20  Points/iter 2                                                                                    │
│ Run UID    fa552c9d-dfe5-4a2f-8202-4966dbd4875a                                                                 │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Suggestion ID              ┃ x1                         ┃ x2                        ┃ himmelblau_2d             ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
└────────────────────────────┴────────────────────────────┴───────────────────────────┴───────────────────────────┘
┃                            ┃                            ┃                           ┃                           ┃
┃ 0                          ┃                          0 ┃                         0 ┃                       170 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 1                          ┃                   -1.88937 ┃                  -1.88937 ┃                   115.155 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 2                          ┃                   -2.60401 ┃                  -2.60401 ┃                   54.5254 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 3                          ┃                   -2.44437 ┃                  -2.60401 ┃                    65.297 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
/home/runner/work/blop/blop/.pixi/envs/docs/lib/python3.13/site-packages/scipy/optimize/_dual_annealing.py:434: OptimizeWarning: Unknown solver options: max_iter
  mres = self.minimizer(self.func_wrapper.fun, x, **self.kwargs)
┃                            ┃                            ┃                           ┃                           ┃
┃ 4                          ┃                   -2.44437 ┃                   1.70306 ┃                   53.8593 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
──────────────────────────────────────────────── Iteration 5 / 20 ─────────────────────────────────────────────────
  himmelblau_2d  min: 53.8593  max: 170  mean: 91.7673
  (5 pts sampled)
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────
┃                            ┃                            ┃                           ┃                           ┃
┃ 5                          ┃                   -2.44437 ┃                   1.70306 ┃                   53.8593 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 6                          ┃                   -2.34437 ┃                   1.70306 ┃                   55.9715 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 7                          ┃                   -2.44437 ┃                   1.80306 ┃                    48.739 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 8                          ┃                         -5 ┃                         5 ┃                       530 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 10                         ┃                       -4.9 ┃                         5 ┃                    495.97 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
──────────────────────────────────────────────── Iteration 9 / 20 ─────────────────────────────────────────────────
  himmelblau_2d  min: 48.739  max: 530  mean: 164.338
  (10 pts sampled)
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────
┃                            ┃                            ┃                           ┃                           ┃
┃ 9                          ┃                         -5 ┃                       4.9 ┃                    501.45 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 11                         ┃                   -3.04451 ┃                   2.47729 ┃                   15.8261 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 12                         ┃                   -3.04451 ┃                   2.57729 ┃                   12.2906 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 13                         ┃                   -2.94451 ┃                   2.47729 ┃                   14.5193 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 14                         ┃                   -2.93955 ┃                   3.93606 ┃                   33.3232 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
──────────────────────────────────────────────── Iteration 12 / 20 ────────────────────────────────────────────────
  himmelblau_2d  min: 12.2906  max: 530  mean: 148.052
  (15 pts sampled)
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────
┃                            ┃                            ┃                           ┃                           ┃
┃ 15                         ┃                   -2.93955 ┃                   4.03606 ┃                   43.1381 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 16                         ┃                   -2.83955 ┃                   3.93606 ┃                   32.9551 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 17                         ┃                   -2.99958 ┃                   3.10175 ┃                   1.35175 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 18                         ┃                   -2.99958 ┃                   3.20175 ┃                   1.50148 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 19                         ┃                   -2.89958 ┃                   3.10175 ┃                  0.337094 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
──────────────────────────────────────────────── Iteration 15 / 20 ────────────────────────────────────────────────
  himmelblau_2d  min: 0.337094  max: 530  mean: 115.003
  (20 pts sampled)
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────
┃                            ┃                            ┃                           ┃                           ┃
┃ 20                         ┃                   -2.83987 ┃                   3.07609 ┃                  0.162411 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 21                         ┃                   -2.73987 ┃                   3.07609 ┃                  0.250943 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 22                         ┃                   -2.83987 ┃                   3.17609 ┃                  0.119396 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 23                         ┃                   -2.85252 ┃                   3.08277 ┃                  0.170087 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 24                         ┃                   -2.85252 ┃                   3.18277 ┃                  0.179172 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
──────────────────────────────────────────────── Iteration 19 / 20 ────────────────────────────────────────────────
  himmelblau_2d  min: 0.119396  max: 530  mean: 92.0381
  (25 pts sampled)
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────
┃                            ┃                            ┃                           ┃                           ┃
┃ 25                         ┃                   -2.75252 ┃                   3.08277 ┃                   0.17822 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 26                         ┃                   -2.84187 ┃                   3.07714 ┃                   0.16269 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩

                            Summary Statistics                            
┏━━━━━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━┳━━━━━┳━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━┓
┃ Name          ┃ Type    ┃      Min ┃ Max ┃     Mean ┃      Std ┃ Count ┃
┡━━━━━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━╇━━━━━╇━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━┩
│ x1            │ param   │       -5 │   0 │ -2.88464 │ 0.952822 │    27 │
│ x2            │ param   │ -2.60401 │   5 │  2.41903 │  2.04186 │    27 │
│ himmelblau_2d │ outcome │ 0.119396 │ 530 │   85.233 │  157.819 │    27 │
└───────────────┴─────────┴──────────┴─────┴──────────┴──────────┴───────┘
────────────────────────────────────────────── Optimization Complete ──────────────────────────────────────────────

Viewing the results#

Scipy is a local optimizer so it doesn’t have internal point tracking, but we can to grab it from our datastore.

import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

res_client = tiled_client[res_uid[0]]
data = res_client["primary"].read().to_dataframe()

fig, ax = plt.subplots(figsize=(12, 8))

xb, yb = np.random.uniform(-5, 5, (2, 1000))
ax.tripcolor(xb, yb, (xb**2 + yb - 11) ** 2 + (xb + yb**2 - 7) ** 2, shading="gouraud")

ps = ax.scatter(data.x1, data.x2, marker='+', c=range(len(data.x1)), cmap="plasma", s=50)
plt.colorbar(ps).set_label("sample index")
plt.title("Visualizing Scipy's traversal of Himmelblau")
Text(0.5, 1.0, "Visualizing Scipy's traversal of Himmelblau")
../_images/57598844cf1ef60b6d3a08e4903f9a8f5fc4d0ea2818d26b75fbfb9348177891.png

Seeing the sample history

data
suggestion_ids iteration x2 acquisition_uid x1 himmelblau_2d
time
1.793112e+09 0 0 0.000000 1b7e1d70-7d0e-4ab3-96dd-02daafc5e939 0.000000 170.000000
1.793112e+09 1 1 -1.889366 fc7e801a-e3bb-48a3-984b-dd53ea90e8b7 -1.889366 115.154907
1.793112e+09 2 2 -2.604010 84811c68-4cbd-4e1a-a4fd-0abf8f5a8e44 -2.604010 54.525362
1.793112e+09 3 3 -2.604010 0c312c40-e201-4a46-b914-2a0979079944 -2.444368 65.297044
1.793112e+09 4 4 1.703056 883f4ed5-6724-41ac-8369-ad91dfb9efb5 -2.444368 53.859297
1.793112e+09 5 5 1.703056 c920848a-214f-4eb5-a590-17b64d149173 -2.444368 53.859297
1.793112e+09 6 6 1.703056 aa37d60a-dab3-409f-a8cc-1e913a328dd8 -2.344368 55.971470
1.793112e+09 7 6 1.803056 aa37d60a-dab3-409f-a8cc-1e913a328dd8 -2.444368 48.739046
1.793112e+09 8 7 5.000000 05cc2c29-2ee9-450e-b9b5-1a4cbb0f6250 -5.000000 530.000000
1.793112e+09 10 8 5.000000 5c40a042-d96e-425b-8e77-f04c4c098301 -4.900000 495.970100
1.793112e+09 9 8 4.900000 5c40a042-d96e-425b-8e77-f04c4c098301 -5.000000 501.450100
1.793112e+09 11 9 2.477287 5b83a911-66b0-4a79-9d39-693fd168e89c -3.044515 15.826092
1.793112e+09 12 10 2.577287 a24fa941-db70-4309-9cee-e359c00b99e7 -3.044515 12.290638
1.793112e+09 13 10 2.477287 a24fa941-db70-4309-9cee-e359c00b99e7 -2.944515 14.519273
1.793112e+09 14 11 3.936063 0acb1ad5-387e-4eb0-a5b0-b98cb3e19af3 -2.939547 33.323216
1.793112e+09 15 12 4.036063 122f7f19-0ad2-4a74-8eb6-6ad0bb667638 -2.939547 43.138076
1.793112e+09 16 12 3.936063 122f7f19-0ad2-4a74-8eb6-6ad0bb667638 -2.839547 32.955081
1.793112e+09 17 13 3.101750 ee3439d3-a90e-4edf-bceb-51c0311178da -2.999581 1.351750
1.793112e+09 18 14 3.201750 32fdf018-8df5-4937-8009-b03ea57ba281 -2.999581 1.501478
1.793112e+09 19 14 3.101750 32fdf018-8df5-4937-8009-b03ea57ba281 -2.899581 0.337094
1.793112e+09 20 15 3.076088 0ce2a876-723b-4c1d-8b69-a9badfda523e -2.839870 0.162411
1.793112e+09 21 16 3.076088 c3c257b4-c6eb-4478-990f-5074031c45ca -2.739870 0.250943
1.793112e+09 22 16 3.176088 c3c257b4-c6eb-4478-990f-5074031c45ca -2.839870 0.119396
1.793112e+09 23 17 3.082768 19fd5732-fe95-4247-80db-c2030d43fff3 -2.852521 0.170087
1.793112e+09 24 18 3.182768 6200c481-7e4f-4c70-b90e-0cbee48b6fbb -2.852521 0.179172
1.793112e+09 25 18 3.082768 6200c481-7e4f-4c70-b90e-0cbee48b6fbb -2.752521 0.178220
1.793112e+09 26 19 3.077144 4cfa58e0-3922-4e53-8ac9-9c6d763a510b -2.841869 0.162690
print(agent.get_best_points())
[22, {'x1': np.float64(-2.841869406009054), 'x2': np.float64(3.077144110395579)}, {'himmelblau_2d': np.float64(0.16241084288483515)}]

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.