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    4f373d70-a7ab-429f-a6d0-436324480758                                                                 │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ 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 ──────────────────────────────────────────────
('6b6589cc-ebdb-43f8-b509-4b6d51d67cb1',
 'e3d707c7-47fd-4e97-89c6-6246841795bf',
 'f75fbda7-a440-46ca-a055-4e42dc57db20',
 '84fd1aca-68c8-4bac-98a5-4cb8c7cc3123',
 '83d10f4a-2dfe-4776-b899-3bb6e95288e5',
 '77427320-f481-43f8-b76c-e3fbcf498e9d',
 'f2890bc4-38da-4616-ab65-7e6b73d4f33e',
 '9d30a266-485d-468c-bac3-7b389cf562df',
 '59f8bec3-852f-45e6-aef2-327ae70e4b96',
 'fdc6cc44-50a5-4b8b-9427-9c284dc2fad7')

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",
)
# Store the agent's optimization runs in Tiled to view the results below
agent.subscribe(tiled_writer)
RE(agent.optimize(20, n_points=2))
╭───────────────────────────────────────────────── Optimization ──────────────────────────────────────────────────╮
│ Optimizer  InteractiveOptimizer                                                                                 │
│ Actuators  x1, x2                                                                                               │
│ Sensors    N/A                                                                                                  │
│ Iterations 20  Points/iter 2                                                                                    │
│ Run UID    ee38910b-ec1a-4f13-9fa1-34baa42cd0ba                                                                 │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Suggestion ID              ┃ x1                         ┃ x2                        ┃ himmelblau_2d             ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
└────────────────────────────┴────────────────────────────┴───────────────────────────┴───────────────────────────┘
┃                            ┃                            ┃                           ┃                           ┃
┃ 0                          ┃                          0 ┃                         0 ┃                       170 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 1                          ┃                    2.32108 ┃                   2.32108 ┃                    11.336 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 2                          ┃                   -3.94762 ┃                  -3.94762 ┃                   21.8975 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 3                          ┃                   -3.90082 ┃                  -3.94762 ┃                   22.0013 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
/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                          ┃                   -3.90082 ┃                  -4.12728 ┃                   37.6293 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
──────────────────────────────────────────────── Iteration 5 / 20 ─────────────────────────────────────────────────
  himmelblau_2d  min: 11.336  max: 170  mean: 52.5728
  (5 pts sampled)
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────
┃                            ┃                            ┃                           ┃                           ┃
┃ 5                          ┃                    2.32108 ┃                   2.32108 ┃                    11.336 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 6                          ┃                    2.42108 ┃                   2.32108 ┃                   8.59077 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 7                          ┃                    2.32108 ┃                   2.42108 ┃                   11.5845 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 8                          ┃                          5 ┃                  -0.16434 ┃                   195.318 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 9                          ┃                        4.9 ┃                  -0.16434 ┃                   169.308 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
──────────────────────────────────────────────── Iteration 9 / 20 ─────────────────────────────────────────────────
  himmelblau_2d  min: 8.59077  max: 195.318  mean: 65.9002
  (10 pts sampled)
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────
┃                            ┃                            ┃                           ┃                           ┃
┃ 10                         ┃                          5 ┃                -0.0643404 ┃                   198.186 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 11                         ┃                    2.86881 ┃                   1.81291 ┃                    1.6291 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 12                         ┃                    2.96881 ┃                   1.81291 ┃                  0.693646 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 13                         ┃                    2.86881 ┃                   1.91291 ┃                  0.957197 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 14                         ┃                    3.11043 ┃                   2.10226 ┃                  0.884582 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
──────────────────────────────────────────────── Iteration 12 / 20 ────────────────────────────────────────────────
  himmelblau_2d  min: 0.693646  max: 198.186  mean: 57.4235
  (15 pts sampled)
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────
┃                            ┃                            ┃                           ┃                           ┃
┃ 15                         ┃                    3.21043 ┃                   2.10226 ┃                    2.3824 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 16                         ┃                    3.11043 ┃                   2.20226 ┃                   1.69148 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 17                         ┃                    2.96882 ┃                   1.93267 ┃                  0.151842 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 18                         ┃                    3.06882 ┃                   1.93267 ┃                  0.161117 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 19                         ┃                    2.96882 ┃                   2.03267 ┃                 0.0336627 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
──────────────────────────────────────────────── Iteration 15 / 20 ────────────────────────────────────────────────
  himmelblau_2d  min: 0.0336627  max: 198.186  mean: 43.2886
  (20 pts sampled)
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────
┃                            ┃                            ┃                           ┃                           ┃
┃ 20                         ┃                    2.95337 ┃                   1.98291 ┃                  0.100008 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 21                         ┃                    3.05337 ┃                   1.98291 ┃                 0.0938313 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 22                         ┃                    2.95337 ┃                   2.08291 ┃                  0.123108 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 23                         ┃                     2.9565 ┃                   1.97436 ┃                  0.102219 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 24                         ┃                     2.9565 ┃                   2.07436 ┃                  0.101462 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
──────────────────────────────────────────────── Iteration 19 / 20 ────────────────────────────────────────────────
  himmelblau_2d  min: 0.0336627  max: 198.186  mean: 34.6517
  (25 pts sampled)
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────
┃                            ┃                            ┃                           ┃                           ┃
┃ 25                         ┃                     3.0565 ┃                   1.97436 ┃                  0.102267 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 26                         ┃                    2.95371 ┃                   1.98197 ┃                  0.100152 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩

                             Summary Statistics                              
┏━━━━━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━┳━━━━━━━┓
┃ Name          ┃ Type    ┃       Min ┃     Max ┃    Mean ┃     Std ┃ Count ┃
┡━━━━━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━╇━━━━━━━┩
│ x1            │ param   │  -3.94762 │       5 │ 2.24306 │  2.4059 │    27 │
│ x2            │ param   │  -4.12728 │ 2.42108 │ 1.06911 │ 1.99206 │    27 │
│ himmelblau_2d │ outcome │ 0.0336627 │ 198.186 │ 32.0924 │ 65.0569 │    27 │
└───────────────┴─────────┴───────────┴─────────┴─────────┴─────────┴───────┘
────────────────────────────────────────────── Optimization Complete ──────────────────────────────────────────────
('a2dee2d9-1417-4782-aa8f-a81dd87df2da',
 '96a17e6f-ef85-45f6-a5c1-fe8d3164e4d2',
 '15b639e0-8744-427f-8b34-52a1ab5b79bc',
 'bb303e52-64e5-4ba8-a139-49bc38785566',
 '6adc69d4-5e0e-4278-9917-9df78d61d998',
 '17005edd-66e2-478d-b2dc-dfbfb34172b1',
 '9a05298e-2359-4f60-8278-52afe2f9bd52',
 'a20802a9-ba0d-4d6f-ac82-2aa0a6c1676b',
 'd00c325a-126f-4951-b7bc-2ae53df0ba14',
 '2013f9ad-5b86-45f6-b10c-038b3ca9dd1e',
 '0d95906b-9f22-4bf0-973e-c37bf8d40a3c',
 '767d9a46-7b4b-4a5b-9270-bfc8a8fdb787',
 '2ff36aa3-d132-4e9d-a563-98f5251df17d',
 '6715e87b-1b10-45fd-8966-46136f209273',
 '979fbbd4-2a07-4a94-b48a-72f22e435ac1',
 '848369d6-c42c-4266-97f8-3ab19bf0b8cd',
 'bf3aa335-6209-418c-a686-1e165f982634',
 '696675da-e67d-4aa9-9886-ce68d6c109b5',
 'a6eec652-1bb5-4b83-824a-3820890ede92',
 '22673dfc-9951-4459-82bb-4bc43005a0a4')

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
from tiled.queries import Key

res_client = tiled_client.search(Key("start.bluesky-adaptive.optimization_uid") == agent.optimization_uid).values().first()
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/332b1a90fe9e6eb5c5196c2d4a0b4393a53623a158146dc111120b09e43c48e4.png

Seeing the sample history

data
adaptive_iteration adaptive_suggestion_id x2 himmelblau_2d adaptive_acquisition_uid x1
time
1.795125e+09 0 0 0.000000 170.000000 a2dee2d9-1417-4782-aa8f-a81dd87df2da 0.000000
1.795125e+09 1 1 2.321081 11.335959 96a17e6f-ef85-45f6-a5c1-fe8d3164e4d2 2.321081
1.795125e+09 2 2 -3.947615 21.897526 15b639e0-8744-427f-8b34-52a1ab5b79bc -3.947615
1.795125e+09 3 3 -3.947615 22.001314 bb303e52-64e5-4ba8-a139-49bc38785566 -3.900815
1.795125e+09 4 4 -4.127280 37.629328 6adc69d4-5e0e-4278-9917-9df78d61d998 -3.900815
1.795125e+09 5 5 2.321081 11.335959 17005edd-66e2-478d-b2dc-dfbfb34172b1 2.321081
1.795125e+09 6 6 2.321081 8.590772 9a05298e-2359-4f60-8278-52afe2f9bd52 2.421081
1.795125e+09 6 7 2.421081 11.584501 9a05298e-2359-4f60-8278-52afe2f9bd52 2.321081
1.795125e+09 7 8 -0.164340 195.318176 a20802a9-ba0d-4d6f-ac82-2aa0a6c1676b 5.000000
1.795125e+09 8 9 -0.164340 169.308268 d00c325a-126f-4951-b7bc-2ae53df0ba14 4.900000
1.795125e+09 8 10 -0.064340 198.186068 d00c325a-126f-4951-b7bc-2ae53df0ba14 5.000000
1.795125e+09 9 11 1.812912 1.629100 2013f9ad-5b86-45f6-b10c-038b3ca9dd1e 2.868813
1.795125e+09 10 12 1.812912 0.693646 0d95906b-9f22-4bf0-973e-c37bf8d40a3c 2.968813
1.795125e+09 10 13 1.912912 0.957197 0d95906b-9f22-4bf0-973e-c37bf8d40a3c 2.868813
1.795125e+09 11 14 2.102256 0.884582 767d9a46-7b4b-4a5b-9270-bfc8a8fdb787 3.110430
1.795125e+09 12 15 2.102256 2.382396 2ff36aa3-d132-4e9d-a563-98f5251df17d 3.210430
1.795125e+09 12 16 2.202256 1.691478 2ff36aa3-d132-4e9d-a563-98f5251df17d 3.110430
1.795125e+09 13 17 1.932669 0.151842 6715e87b-1b10-45fd-8966-46136f209273 2.968816
1.795125e+09 14 18 1.932669 0.161117 979fbbd4-2a07-4a94-b48a-72f22e435ac1 3.068816
1.795125e+09 14 19 2.032669 0.033663 979fbbd4-2a07-4a94-b48a-72f22e435ac1 2.968816
1.795125e+09 15 20 1.982911 0.100008 848369d6-c42c-4266-97f8-3ab19bf0b8cd 2.953368
1.795125e+09 16 21 1.982911 0.093831 bf3aa335-6209-418c-a686-1e165f982634 3.053368
1.795125e+09 16 22 2.082911 0.123108 bf3aa335-6209-418c-a686-1e165f982634 2.953368
1.795125e+09 17 23 1.974363 0.102219 696675da-e67d-4aa9-9886-ce68d6c109b5 2.956500
1.795125e+09 18 24 2.074363 0.101462 a6eec652-1bb5-4b83-824a-3820890ede92 2.956500
1.795125e+09 18 25 1.974363 0.102267 a6eec652-1bb5-4b83-824a-3820890ede92 3.056500
1.795125e+09 19 26 1.981968 0.100152 22673dfc-9951-4459-82bb-4bc43005a0a4 2.953713
print(agent.get_best_points())
[22, {'x1': np.float64(2.9537134913359173), 'x2': np.float64(1.9819675732309907)}, {'himmelblau_2d': np.float64(0.1000077443221453)}]

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.