Your first Scipy optimization with Bluesky Adaptive#

In this tutorial, you will learn the three core concepts of Bluesky Adaptive: 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 bluesky_adaptive.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. Bluesky Adaptive 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    9b299d9b-f678-4d29-9697-c0f2bf18ab9f                                                                 │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ 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 ──────────────────────────────────────────────
('9b299d9b-f678-4d29-9697-c0f2bf18ab9f',
 '8721a7e4-c049-4717-a6fd-3451e9e4884e',
 '1ac8e15e-75b4-4b76-bd2e-4a0bef85b468',
 'bb9d4e05-dc62-4a95-b14e-84930473bca8',
 '2eef323a-6e39-480e-abe4-e0b351f4eaaf',
 '8993833e-6599-4225-8d13-dd6c8eacc127',
 'a17e0bcf-2070-4bb7-aa8c-d53a1ce1cbca',
 '9baa8e8a-0d0d-4f25-8cf5-ad40c008f371',
 'a9381a7c-7f66-427c-831e-1c81a266ea6f',
 '9c355c6c-a0f8-43ef-a9bf-8b9423e69e38',
 'a3ca9f39-f03e-42fa-a21c-f29fdf4ccd86')

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    8fde87bc-6280-430b-a9ef-87025048661f                                                                 │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Suggestion ID              ┃ x1                         ┃ x2                        ┃ himmelblau_2d             ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
└────────────────────────────┴────────────────────────────┴───────────────────────────┴───────────────────────────┘
┃                            ┃                            ┃                           ┃                           ┃
┃ 0                          ┃                          0 ┃                         0 ┃                       170 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 1                          ┃                   -1.45058 ┃                  -1.45058 ┃                   147.325 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 2                          ┃                   -1.22555 ┃                  -1.22555 ┃                   160.201 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 3                          ┃                   -1.33003 ┃                  -1.22555 ┃                   155.962 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
/home/runner/work/bluesky-adaptive/bluesky-adaptive/.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                          ┃                   -1.33003 ┃                   -4.1982 ┃                   266.738 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
──────────────────────────────────────────────── Iteration 5 / 20 ─────────────────────────────────────────────────
  himmelblau_2d  min: 147.325  max: 266.738  mean: 180.045
  (5 pts sampled)
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────
┃                            ┃                            ┃                           ┃                           ┃
┃ 5                          ┃                   -1.45058 ┃                  -1.45058 ┃                   147.325 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 6                          ┃                   -1.35058 ┃                  -1.45058 ┃                    151.94 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 7                          ┃                   -1.45058 ┃                  -1.35058 ┃                   148.899 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 8                          ┃                         -5 ┃                        -5 ┃                       250 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 10                         ┃                       -4.9 ┃                        -5 ┃                    235.77 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
──────────────────────────────────────────────── Iteration 9 / 20 ─────────────────────────────────────────────────
  himmelblau_2d  min: 147.325  max: 266.738  mean: 183.416
  (10 pts sampled)
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────
┃                            ┃                            ┃                           ┃                           ┃
┃ 9                          ┃                         -5 ┃                      -4.9 ┃                    227.05 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 11                         ┃                   -3.06698 ┃                  -3.06698 ┃                   22.1578 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 12                         ┃                   -3.06698 ┃                  -2.96698 ┃                    22.397 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 13                         ┃                   -2.96698 ┃                  -3.06698 ┃                   28.0242 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 14                         ┃                   -3.77839 ┃                  -3.77839 ┃                   12.4869 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
──────────────────────────────────────────────── Iteration 12 / 20 ────────────────────────────────────────────────
  himmelblau_2d  min: 12.4869  max: 266.738  mean: 143.085
  (15 pts sampled)
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────
┃                            ┃                            ┃                           ┃                           ┃
┃ 15                         ┃                   -3.67839 ┃                  -3.77839 ┃                   14.5014 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 16                         ┃                   -3.77839 ┃                  -3.67839 ┃                   7.73602 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 17                         ┃                   -4.83504 ┃                  -2.33691 ┃                   141.442 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 18                         ┃                   -4.83504 ┃                  -2.23691 ┃                     149.5 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 19                         ┃                   -4.73504 ┃                  -2.33691 ┃                   121.875 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
──────────────────────────────────────────────── Iteration 15 / 20 ────────────────────────────────────────────────
  himmelblau_2d  min: 7.73602  max: 266.738  mean: 129.067
  (20 pts sampled)
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────
┃                            ┃                            ┃                           ┃                           ┃
┃ 20                         ┃                   -3.97897 ┃                  -3.50475 ┃                   3.46335 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 21                         ┃                   -3.87897 ┃                  -3.50475 ┃                    2.2654 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 22                         ┃                   -3.97897 ┃                  -3.40475 ┃                    2.4139 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 23                         ┃                   -3.34109 ┃                  -2.93846 ┃                   10.6161 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 24                         ┃                   -3.24109 ┃                  -2.93846 ┃                    14.372 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
──────────────────────────────────────────────── Iteration 19 / 20 ────────────────────────────────────────────────
  himmelblau_2d  min: 2.2654  max: 266.738  mean: 104.578
  (25 pts sampled)
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────
┃                            ┃                            ┃                           ┃                           ┃
┃ 25                         ┃                   -3.34109 ┃                  -2.83846 ┃                   12.3765 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 26                         ┃                   -3.75482 ┃                  -3.30575 ┃                  0.072873 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩

                             Summary Statistics                              
┏━━━━━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━┓
┃ Name          ┃ Type    ┃      Min ┃     Max ┃     Mean ┃     Std ┃ Count ┃
┡━━━━━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━┩
│ x1            │ param   │       -5 │       0 │ -3.13867 │ 1.43737 │    27 │
│ x2            │ param   │       -5 │       0 │  -2.8494 │ 1.26487 │    27 │
│ himmelblau_2d │ outcome │ 0.072873 │ 266.738 │   97.293 │ 90.4417 │    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/616257c02ca95c6c3d38b79310890d7781aab7d624c9464ac6421674d9557cef.png

Seeing the sample history

data
iteration suggestion_ids x2 x1 acquisition_uid himmelblau_2d
time
1.793050e+09 0 0 0.000000 0.000000 34b9765b-455c-4fc0-91e6-bc67fa3a30fc 170.000000
1.793050e+09 1 1 -1.450582 -1.450582 f7619190-a24e-4b69-a14f-19f29e6eb554 147.324608
1.793050e+09 2 2 -1.225555 -1.225555 bb06c34f-6741-4353-a105-23000213c94e 160.201352
1.793050e+09 3 3 -1.225555 -1.330029 eb549714-ae79-449f-b152-507480360628 155.962222
1.793050e+09 4 4 -4.198197 -1.330029 8677bc68-5cf2-4e5c-84d4-e8b28c14a8ea 266.737897
1.793050e+09 5 5 -1.450582 -1.450582 83883022-0d33-4583-b9ae-abe12e403902 147.324608
1.793050e+09 6 6 -1.450582 -1.350582 2c336447-6d5f-40b1-ae4d-03c5ed8ad2a2 151.940182
1.793050e+09 6 7 -1.350582 -1.450582 2c336447-6d5f-40b1-ae4d-03c5ed8ad2a2 148.899251
1.793050e+09 7 8 -5.000000 -5.000000 c8df5901-e367-4331-87c2-4647a8728460 250.000000
1.793050e+09 8 10 -5.000000 -4.900000 d47dfaac-57f5-4357-bace-2ec947ad8f67 235.770100
1.793050e+09 8 9 -4.900000 -5.000000 d47dfaac-57f5-4357-bace-2ec947ad8f67 227.050100
1.793050e+09 9 11 -3.066978 -3.066978 fe904a09-353f-4912-9a99-105e10e3e34c 22.157844
1.793050e+09 10 12 -2.966978 -3.066978 e24839a0-5cc5-437e-9da1-10564cb64dfa 22.397041
1.793050e+09 10 13 -3.066978 -2.966978 e24839a0-5cc5-437e-9da1-10564cb64dfa 28.024206
1.793050e+09 11 14 -3.778386 -3.778386 78bd4773-1fb7-4101-8f18-5ce0a86ac5d3 12.486905
1.793050e+09 12 15 -3.778386 -3.678386 075849e1-7bc7-4cdf-bed0-1e3c06157a4b 14.501437
1.793050e+09 12 16 -3.678386 -3.778386 075849e1-7bc7-4cdf-bed0-1e3c06157a4b 7.736019
1.793050e+09 13 17 -2.336910 -4.835040 c93b59fb-37ea-4fe5-97a4-e1192506f1df 141.442263
1.793050e+09 14 18 -2.236910 -4.835040 94b37190-0bd6-4760-abd9-dc5a28691383 149.500209
1.793050e+09 14 19 -2.336910 -4.735040 94b37190-0bd6-4760-abd9-dc5a28691383 121.875275
1.793050e+09 15 20 -3.504746 -3.978975 fdf129ec-0648-4891-970b-6f5263f21d7e 3.463352
1.793050e+09 16 21 -3.504746 -3.878975 76ea998b-d427-4746-9032-f1e34446fee7 2.265404
1.793050e+09 16 22 -3.404746 -3.978975 76ea998b-d427-4746-9032-f1e34446fee7 2.413897
1.793050e+09 17 23 -2.938459 -3.341090 27356e88-ba32-479a-8df5-9f8236aeb015 10.616147
1.793050e+09 18 24 -2.938459 -3.241090 92f4f986-c290-4904-933c-e79562dd9d18 14.371958
1.793050e+09 18 25 -2.838459 -3.341090 92f4f986-c290-4904-933c-e79562dd9d18 12.376479
1.793050e+09 19 26 -3.305747 -3.754815 95cbd0fb-c105-4dc6-ad60-af82b97b814e 0.072873
print(agent.get_best_points())
[22, {'x1': np.float64(-3.7548153874739545), 'x2': np.float64(-3.305746617949284)}, {'himmelblau_2d': np.float64(3.463352404930271)}]

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 Bluesky Adaptive:

  • 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.