XRT KB Mirror Demo#
For ophyd beamline setup see:
https://github.com/NSLS-II/blop/blob/main/src/blop/sim/xrt_beamline.py
https://github.com/NSLS-II/blop/blob/main/src/blop/sim/xrt_kb_model.py
The picture below displays beam from geometric source propagating through a pair of toroidal mirrors focusing the beam on screen. Simulation of a KB setup.

import logging
import matplotlib.pyplot as plt
from tiled.client.container import Container
from bluesky.callbacks import best_effort
from bluesky.callbacks.tiled_writer import TiledWriter
from bluesky.run_engine import RunEngine
from tiled.client import from_uri # type: ignore[import-untyped]
from tiled.server import SimpleTiledServer
from blop.ax import Agent, RangeDOF, Objective
from blop.sim.xrt_beamline import TiledBeamline
from blop.protocols import EvaluationFunction
# Suppress noisy logs from httpx
logging.getLogger("httpx").setLevel(logging.WARNING)
DETECTOR_STORAGE = "/tmp/blop/sim"
[WARNING 12-08 20:35:00] ax.service.utils.with_db_settings_base: Ax currently requires a sqlalchemy version below 2.0. This will be addressed in a future release. Disabling SQL storage in Ax for now, if you would like to use SQL storage please install Ax with mysql extras via `pip install ax-platform[mysql]`.
tiled_server = SimpleTiledServer(readable_storage=[DETECTOR_STORAGE])
tiled_client = from_uri(tiled_server.uri)
tiled_writer = TiledWriter(tiled_client)
bec = best_effort.BestEffortCallback()
bec.disable_plots()
RE = RunEngine({})
RE.subscribe(bec)
RE.subscribe(tiled_writer)
2025-12-08 20:35:03.675 INFO: Subprocess stdout:
2025-12-08 20:35:03.676 INFO: Subprocess stderr: Database sqlite+aiosqlite:////tmp/tmp965wbfkb/catalog.db is new. Creating tables.
Database initialized.
Tiled version 0.2.2
2025-12-08 20:35:04.101 INFO: Tiled version 0.2.2
2025-12-08 20:35:04.106 INFO: Context impl SQLiteImpl.
2025-12-08 20:35:04.107 INFO: Will assume non-transactional DDL.
1
plt.ion()
h_opt = 0
dh = 5
R1, dR1 = 40000, 10000
R2, dR2 = 20000, 10000
beamline = TiledBeamline(name="bl")
dofs = [
RangeDOF(movable=beamline.kbv_dsv, bounds=(R1 - dR1, R1 + dR1), parameter_type="float"),
RangeDOF(movable=beamline.kbh_dsh, bounds=(R2 - dR2, R2 + dR2), parameter_type="float"),
]
objectives = [
Objective(name="bl_det_sum", minimize=False),
Objective(name="bl_det_wid_x", minimize=True),
Objective(name="bl_det_wid_y", minimize=True),
]
class DetectorEvaluation(EvaluationFunction):
def __init__(self, tiled_client: Container):
self.tiled_client = tiled_client
def __call__(self, uid: str, suggestions: list[dict]) -> list[dict]:
outcomes = []
run = self.tiled_client[uid]
bl_det_sum = run["primary/bl_det_sum"].read()
bl_det_wid_x = run["primary/bl_det_wid_x"].read()
bl_det_wid_y = run["primary/bl_det_wid_y"].read()
# These ids are stored in the start document's metadata when
# using the `blop.plans.default_acquire` plan.
# You may want to store them differently in your experiment when writing
# your a custom acquisiton plan.
suggestion_ids = run.metadata["start"]["blop_suggestion_ids"]
for idx, sid in enumerate(suggestion_ids):
outcome = {
"_id": sid,
"bl_det_sum": bl_det_sum[idx],
"bl_det_wid_x": bl_det_wid_x[idx],
"bl_det_wid_y": bl_det_wid_y[idx],
}
outcomes.append(outcome)
return outcomes
agent = Agent(
readables=[beamline.det],
dofs=dofs,
objectives=objectives,
evaluation=DetectorEvaluation(tiled_client),
name="xrt-blop-demo",
description="A demo of the Blop agent with XRT simulated beamline",
experiment_type="demo",
)
# Number of iterations can be increased to be more specific
RE(agent.optimize(30))
Transient Scan ID: 1 Time: 2025-12-08 20:35:04
Persistent Unique Scan ID: '503f646c-533d-436e-be71-d60453e61f77'
ToroidMirror2
center:
[0, 11000, np.float64(176.32497705083168)]
New stream: 'primary'
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
| seq_num | time | bl_kbv_dsv | bl_kbh_dsh | bl_det_sum | bl_det_cen_x | bl_det_cen_y | bl_det_wid_x | bl_det_wid_y |
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
| 1 | 20:35:04.5 | 40000.000 | 20000.000 | 22086.016 | 201.918 | 145.244 | 18.929 | 39.964 |
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
generator list_scan ['503f646c'] (scan num: 1)
Transient Scan ID: 2 Time: 2025-12-08 20:35:05
Persistent Unique Scan ID: '9b5b480e-c536-45af-b997-3c2ac9a2261a'
New stream: 'primary'
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
| seq_num | time | bl_kbv_dsv | bl_kbh_dsh | bl_det_sum | bl_det_cen_x | bl_det_cen_y | bl_det_wid_x | bl_det_wid_y |
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
| 1 | 20:35:05.3 | 30860.564 | 27700.797 | 977.354 | 224.171 | 161.908 | 228.392 | 123.217 |
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
generator list_scan ['9b5b480e'] (scan num: 2)
Transient Scan ID: 3 Time: 2025-12-08 20:35:05
Persistent Unique Scan ID: 'b040a628-b36b-431b-9a49-1c5e5f2f3078'
New stream: 'primary'
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
| seq_num | time | bl_kbv_dsv | bl_kbh_dsh | bl_det_sum | bl_det_cen_x | bl_det_cen_y | bl_det_wid_x | bl_det_wid_y |
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
| 1 | 20:35:06.0 | 44489.435 | 10476.807 | 32.724 | 238.800 | 170.267 | 310.800 | 58.933 |
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
generator list_scan ['b040a628'] (scan num: 3)
Transient Scan ID: 4 Time: 2025-12-08 20:35:06
Persistent Unique Scan ID: 'd1623312-66e1-4569-9ae2-963a7eae0eca'
New stream: 'primary'
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
| seq_num | time | bl_kbv_dsv | bl_kbh_dsh | bl_det_sum | bl_det_cen_x | bl_det_cen_y | bl_det_wid_x | bl_det_wid_y |
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
| 1 | 20:35:06.6 | 46611.224 | 24416.544 | 5621.816 | 208.819 | 152.292 | 105.429 | 96.317 |
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
generator list_scan ['d1623312'] (scan num: 4)
Transient Scan ID: 5 Time: 2025-12-08 20:35:07
Persistent Unique Scan ID: '061e1316-80ee-41ec-b32e-c95faf9d1437'
New stream: 'primary'
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
| seq_num | time | bl_kbv_dsv | bl_kbh_dsh | bl_det_sum | bl_det_cen_x | bl_det_cen_y | bl_det_wid_x | bl_det_wid_y |
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
| 1 | 20:35:07.3 | 38040.379 | 17188.642 | 4962.618 | 222.793 | 146.002 | 200.653 | 21.655 |
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
generator list_scan ['061e1316'] (scan num: 5)
Transient Scan ID: 6 Time: 2025-12-08 20:35:11
Persistent Unique Scan ID: '5a7d8a4f-5d0d-489d-9991-f2526f22da1b'
New stream: 'primary'
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
| seq_num | time | bl_kbv_dsv | bl_kbh_dsh | bl_det_sum | bl_det_cen_x | bl_det_cen_y | bl_det_wid_x | bl_det_wid_y |
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
| 1 | 20:35:11.3 | 40438.496 | 19020.284 | 19127.281 | 210.082 | 149.602 | 73.089 | 37.321 |
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
generator list_scan ['5a7d8a4f'] (scan num: 6)
Transient Scan ID: 7 Time: 2025-12-08 20:35:15
Persistent Unique Scan ID: 'd46471a7-197f-4f6e-852b-cf0a85f7a835'
New stream: 'primary'
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
| seq_num | time | bl_kbv_dsv | bl_kbh_dsh | bl_det_sum | bl_det_cen_x | bl_det_cen_y | bl_det_wid_x | bl_det_wid_y |
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
| 1 | 20:35:15.7 | 34748.488 | 19165.975 | 17551.019 | 205.402 | 149.400 | 71.131 | 56.278 |
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
generator list_scan ['d46471a7'] (scan num: 7)
Transient Scan ID: 8 Time: 2025-12-08 20:35:19
Persistent Unique Scan ID: 'e95f2ed3-495e-4fb3-a312-cf13b6a8f2d1'
New stream: 'primary'
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
| seq_num | time | bl_kbv_dsv | bl_kbh_dsh | bl_det_sum | bl_det_cen_x | bl_det_cen_y | bl_det_wid_x | bl_det_wid_y |
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
| 1 | 20:35:19.4 | 38545.321 | 19256.627 | 22534.793 | 205.625 | 146.967 | 69.042 | 22.001 |
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
generator list_scan ['e95f2ed3'] (scan num: 8)
Transient Scan ID: 9 Time: 2025-12-08 20:35:23
Persistent Unique Scan ID: 'd7ac463b-f171-4db4-953b-d9637af1af3f'
New stream: 'primary'
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
| seq_num | time | bl_kbv_dsv | bl_kbh_dsh | bl_det_sum | bl_det_cen_x | bl_det_cen_y | bl_det_wid_x | bl_det_wid_y |
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
| 1 | 20:35:23.2 | 37887.594 | 20416.176 | 23664.953 | 194.750 | 147.305 | 14.733 | 18.009 |
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
generator list_scan ['d7ac463b'] (scan num: 9)
Transient Scan ID: 10 Time: 2025-12-08 20:35:27
Persistent Unique Scan ID: 'a5af5e0a-734d-4c75-b3ff-b05a7b7cc81a'
New stream: 'primary'
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
| seq_num | time | bl_kbv_dsv | bl_kbh_dsh | bl_det_sum | bl_det_cen_x | bl_det_cen_y | bl_det_wid_x | bl_det_wid_y |
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
| 1 | 20:35:27.1 | 37478.653 | 20711.323 | 23687.479 | 193.318 | 150.386 | 14.190 | 19.717 |
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
generator list_scan ['a5af5e0a'] (scan num: 10)
Transient Scan ID: 11 Time: 2025-12-08 20:35:32
Persistent Unique Scan ID: 'cf8a389c-e0f9-4cd7-b354-9443710739f8'
New stream: 'primary'
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
| seq_num | time | bl_kbv_dsv | bl_kbh_dsh | bl_det_sum | bl_det_cen_x | bl_det_cen_y | bl_det_wid_x | bl_det_wid_y |
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
| 1 | 20:35:32.1 | 37410.658 | 20561.506 | 23614.474 | 193.500 | 149.050 | 13.700 | 20.080 |
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
generator list_scan ['cf8a389c'] (scan num: 11)
Transient Scan ID: 12 Time: 2025-12-08 20:35:37
Persistent Unique Scan ID: '641d5b60-039d-4674-8db6-009012e79bb9'
New stream: 'primary'
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
| seq_num | time | bl_kbv_dsv | bl_kbh_dsh | bl_det_sum | bl_det_cen_x | bl_det_cen_y | bl_det_wid_x | bl_det_wid_y |
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
| 1 | 20:35:37.6 | 37864.268 | 21247.962 | 23764.322 | 197.750 | 153.065 | 19.491 | 18.303 |
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
generator list_scan ['641d5b60'] (scan num: 12)
Transient Scan ID: 13 Time: 2025-12-08 20:35:42
Persistent Unique Scan ID: '8d64ef6a-06de-41e0-9db2-47fd16f45d04'
New stream: 'primary'
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
| seq_num | time | bl_kbv_dsv | bl_kbh_dsh | bl_det_sum | bl_det_cen_x | bl_det_cen_y | bl_det_wid_x | bl_det_wid_y |
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
| 1 | 20:35:42.9 | 37932.355 | 20953.698 | 23752.912 | 194.905 | 151.426 | 14.549 | 17.907 |
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
generator list_scan ['8d64ef6a'] (scan num: 13)
Transient Scan ID: 14 Time: 2025-12-08 20:35:49
Persistent Unique Scan ID: 'e7f52949-3fc4-49c1-b2b9-7ada1f7458ff'
New stream: 'primary'
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
| seq_num | time | bl_kbv_dsv | bl_kbh_dsh | bl_det_sum | bl_det_cen_x | bl_det_cen_y | bl_det_wid_x | bl_det_wid_y |
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
| 1 | 20:35:49.3 | 37949.776 | 20658.388 | 23669.900 | 193.382 | 148.962 | 14.218 | 17.725 |
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
generator list_scan ['e7f52949'] (scan num: 14)
Transient Scan ID: 15 Time: 2025-12-08 20:35:55
Persistent Unique Scan ID: '7c812e02-780a-4aaa-b1c2-d7ea61a5389b'
New stream: 'primary'
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
| seq_num | time | bl_kbv_dsv | bl_kbh_dsh | bl_det_sum | bl_det_cen_x | bl_det_cen_y | bl_det_wid_x | bl_det_wid_y |
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
| 1 | 20:35:55.2 | 37795.742 | 21097.962 | 23753.491 | 195.372 | 152.150 | 17.534 | 19.359 |
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
generator list_scan ['7c812e02'] (scan num: 15)
Transient Scan ID: 16 Time: 2025-12-08 20:36:03
Persistent Unique Scan ID: 'c0007016-1bde-4587-a9be-07c03e1ce044'
New stream: 'primary'
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
| seq_num | time | bl_kbv_dsv | bl_kbh_dsh | bl_det_sum | bl_det_cen_x | bl_det_cen_y | bl_det_wid_x | bl_det_wid_y |
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
| 1 | 20:36:03.1 | 37431.283 | 21128.781 | 23459.896 | 196.330 | 153.558 | 17.105 | 20.283 |
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
generator list_scan ['c0007016'] (scan num: 16)
Transient Scan ID: 17 Time: 2025-12-08 20:36:11
Persistent Unique Scan ID: 'cde60b91-beee-4404-a641-79439e0f90c3'
New stream: 'primary'
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
| seq_num | time | bl_kbv_dsv | bl_kbh_dsh | bl_det_sum | bl_det_cen_x | bl_det_cen_y | bl_det_wid_x | bl_det_wid_y |
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
| 1 | 20:36:11.1 | 37926.954 | 20513.728 | 23701.885 | 194.275 | 147.955 | 13.719 | 17.791 |
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
generator list_scan ['cde60b91'] (scan num: 17)
Transient Scan ID: 18 Time: 2025-12-08 20:36:21
Persistent Unique Scan ID: '86ad5908-af74-494a-b224-493bde73e6c0'
New stream: 'primary'
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
| seq_num | time | bl_kbv_dsv | bl_kbh_dsh | bl_det_sum | bl_det_cen_x | bl_det_cen_y | bl_det_wid_x | bl_det_wid_y |
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
| 1 | 20:36:22.0 | 38009.592 | 20712.071 | 23816.798 | 193.538 | 149.550 | 14.070 | 18.590 |
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
generator list_scan ['86ad5908'] (scan num: 18)
Transient Scan ID: 19 Time: 2025-12-08 20:36:33
Persistent Unique Scan ID: '24ed2a8b-3f12-462f-a42a-c78ba111e196'
New stream: 'primary'
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
| seq_num | time | bl_kbv_dsv | bl_kbh_dsh | bl_det_sum | bl_det_cen_x | bl_det_cen_y | bl_det_wid_x | bl_det_wid_y |
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
| 1 | 20:36:34.1 | 41621.378 | 21369.101 | 19289.254 | 200.716 | 157.372 | 20.575 | 62.614 |
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
generator list_scan ['24ed2a8b'] (scan num: 19)
Transient Scan ID: 20 Time: 2025-12-08 20:36:42
Persistent Unique Scan ID: '99d9b60f-ea34-4767-bb10-efe0482ef13e'
New stream: 'primary'
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
| seq_num | time | bl_kbv_dsv | bl_kbh_dsh | bl_det_sum | bl_det_cen_x | bl_det_cen_y | bl_det_wid_x | bl_det_wid_y |
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
| 1 | 20:36:42.2 | 37868.356 | 20589.351 | 23774.008 | 193.938 | 148.615 | 13.563 | 17.840 |
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
generator list_scan ['99d9b60f'] (scan num: 20)
Transient Scan ID: 21 Time: 2025-12-08 20:36:49
Persistent Unique Scan ID: '754924a5-9767-4972-b957-1592998ec3c0'
New stream: 'primary'
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
| seq_num | time | bl_kbv_dsv | bl_kbh_dsh | bl_det_sum | bl_det_cen_x | bl_det_cen_y | bl_det_wid_x | bl_det_wid_y |
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
| 1 | 20:36:49.7 | 37990.736 | 20458.930 | 23774.987 | 194.556 | 147.374 | 13.842 | 17.693 |
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
generator list_scan ['754924a5'] (scan num: 21)
Transient Scan ID: 22 Time: 2025-12-08 20:36:59
Persistent Unique Scan ID: '59e34bb0-7b5d-4fdc-b3c2-2004560430ff'
New stream: 'primary'
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
| seq_num | time | bl_kbv_dsv | bl_kbh_dsh | bl_det_sum | bl_det_cen_x | bl_det_cen_y | bl_det_wid_x | bl_det_wid_y |
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
| 1 | 20:36:59.7 | 37871.993 | 20479.126 | 23672.930 | 194.299 | 147.851 | 14.126 | 18.243 |
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
generator list_scan ['59e34bb0'] (scan num: 22)
Transient Scan ID: 23 Time: 2025-12-08 20:37:08
Persistent Unique Scan ID: '7e8d920d-8136-48c7-b403-6be9cd155a34'
New stream: 'primary'
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
| seq_num | time | bl_kbv_dsv | bl_kbh_dsh | bl_det_sum | bl_det_cen_x | bl_det_cen_y | bl_det_wid_x | bl_det_wid_y |
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
| 1 | 20:37:09.1 | 37899.702 | 20782.238 | 23804.868 | 193.750 | 150.057 | 13.900 | 17.595 |
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
generator list_scan ['7e8d920d'] (scan num: 23)
Transient Scan ID: 24 Time: 2025-12-08 20:37:23
Persistent Unique Scan ID: '7138f135-5275-41f2-bf2d-f7036e03e573'
New stream: 'primary'
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
| seq_num | time | bl_kbv_dsv | bl_kbh_dsh | bl_det_sum | bl_det_cen_x | bl_det_cen_y | bl_det_wid_x | bl_det_wid_y |
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
| 1 | 20:37:23.5 | 37913.413 | 20629.646 | 23882.577 | 193.799 | 149.100 | 13.486 | 18.211 |
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
generator list_scan ['7138f135'] (scan num: 24)
Transient Scan ID: 25 Time: 2025-12-08 20:37:40
Persistent Unique Scan ID: '8b613fd4-6374-43c5-8a8d-cb4924507691'
New stream: 'primary'
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
| seq_num | time | bl_kbv_dsv | bl_kbh_dsh | bl_det_sum | bl_det_cen_x | bl_det_cen_y | bl_det_wid_x | bl_det_wid_y |
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
| 1 | 20:37:40.2 | 37949.328 | 20821.286 | 23663.665 | 193.714 | 150.583 | 14.536 | 18.792 |
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
generator list_scan ['8b613fd4'] (scan num: 25)
Transient Scan ID: 26 Time: 2025-12-08 20:37:57
Persistent Unique Scan ID: '991d8e0d-1f7c-4123-9c99-0988048cbf29'
New stream: 'primary'
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
| seq_num | time | bl_kbv_dsv | bl_kbh_dsh | bl_det_sum | bl_det_cen_x | bl_det_cen_y | bl_det_wid_x | bl_det_wid_y |
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
| 1 | 20:37:58.0 | 37990.976 | 20552.025 | 23626.579 | 193.845 | 148.365 | 13.555 | 17.248 |
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
generator list_scan ['991d8e0d'] (scan num: 26)
Transient Scan ID: 27 Time: 2025-12-08 20:38:07
Persistent Unique Scan ID: 'b8e58229-2783-4e64-a54f-1bbf91715c84'
New stream: 'primary'
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
| seq_num | time | bl_kbv_dsv | bl_kbh_dsh | bl_det_sum | bl_det_cen_x | bl_det_cen_y | bl_det_wid_x | bl_det_wid_y |
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
| 1 | 20:38:07.9 | 37862.568 | 20536.853 | 23775.659 | 193.958 | 147.907 | 14.225 | 17.768 |
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
generator list_scan ['b8e58229'] (scan num: 27)
Transient Scan ID: 28 Time: 2025-12-08 20:38:15
Persistent Unique Scan ID: 'b19aebd8-fca0-445a-9f38-e8815b6ad5e6'
New stream: 'primary'
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
| seq_num | time | bl_kbv_dsv | bl_kbh_dsh | bl_det_sum | bl_det_cen_x | bl_det_cen_y | bl_det_wid_x | bl_det_wid_y |
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
| 1 | 20:38:15.5 | 38007.452 | 20628.149 | 23765.749 | 193.960 | 148.819 | 13.781 | 17.988 |
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
generator list_scan ['b19aebd8'] (scan num: 28)
Transient Scan ID: 29 Time: 2025-12-08 20:38:32
Persistent Unique Scan ID: '387d4ad3-f7a7-4c0a-ba94-f87b91aa945f'
New stream: 'primary'
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
| seq_num | time | bl_kbv_dsv | bl_kbh_dsh | bl_det_sum | bl_det_cen_x | bl_det_cen_y | bl_det_wid_x | bl_det_wid_y |
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
| 1 | 20:38:32.1 | 37889.464 | 20705.533 | 23731.654 | 193.842 | 149.371 | 13.424 | 17.588 |
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
generator list_scan ['387d4ad3'] (scan num: 29)
Transient Scan ID: 30 Time: 2025-12-08 20:38:52
Persistent Unique Scan ID: '57aa9c4a-6d4d-4e74-948b-922a2f031f2e'
New stream: 'primary'
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
| seq_num | time | bl_kbv_dsv | bl_kbh_dsh | bl_det_sum | bl_det_cen_x | bl_det_cen_y | bl_det_wid_x | bl_det_wid_y |
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
| 1 | 20:38:52.2 | 37961.825 | 20486.672 | 23855.809 | 194.259 | 147.815 | 14.343 | 17.569 |
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
generator list_scan ['57aa9c4a'] (scan num: 30)
2025-12-08 20:35:04.396 INFO: Executing plan <generator object Agent.optimize at 0x7f10c9aba5e0>
2025-12-08 20:35:04.398 INFO: Change state on <bluesky.run_engine.RunEngine object at 0x7f10c9acf740> from 'idle' -> 'running'
/home/runner/work/blop/blop/.pixi/envs/docs/lib/python3.12/site-packages/linear_operator/utils/cholesky.py:40: NumericalWarning: A not p.d., added jitter of 1.0e-08 to the diagonal
warnings.warn(
/home/runner/work/blop/blop/.pixi/envs/docs/lib/python3.12/site-packages/linear_operator/utils/cholesky.py:40: NumericalWarning: A not p.d., added jitter of 1.0e-08 to the diagonal
warnings.warn(
/home/runner/work/blop/blop/.pixi/envs/docs/lib/python3.12/site-packages/botorch/optim/optimize.py:677: RuntimeWarning: Optimization failed in `gen_candidates_scipy` with the following warning(s):
[NumericalWarning('A not p.d., added jitter of 1.0e-08 to the diagonal'), NumericalWarning('A not p.d., added jitter of 1.0e-08 to the diagonal'), OptimizationWarning('Optimization failed within `scipy.optimize.minimize` with status 2 and message ABNORMAL: .'), NumericalWarning('A not p.d., added jitter of 1.0e-08 to the diagonal'), NumericalWarning('A not p.d., added jitter of 1.0e-08 to the diagonal')]
Trying again with a new set of initial conditions.
return _optimize_acqf_batch(opt_inputs=opt_inputs)
/home/runner/work/blop/blop/.pixi/envs/docs/lib/python3.12/site-packages/linear_operator/utils/cholesky.py:40: NumericalWarning: A not p.d., added jitter of 1.0e-08 to the diagonal
warnings.warn(
/home/runner/work/blop/blop/.pixi/envs/docs/lib/python3.12/site-packages/linear_operator/utils/cholesky.py:40: NumericalWarning: A not p.d., added jitter of 1.0e-08 to the diagonal
warnings.warn(
/home/runner/work/blop/blop/.pixi/envs/docs/lib/python3.12/site-packages/botorch/optim/optimize.py:677: RuntimeWarning: Optimization failed in `gen_candidates_scipy` with the following warning(s):
[OptimizationWarning('Optimization failed within `scipy.optimize.minimize` with status 2 and message ABNORMAL: .')]
Trying again with a new set of initial conditions.
return _optimize_acqf_batch(opt_inputs=opt_inputs)
/home/runner/work/blop/blop/.pixi/envs/docs/lib/python3.12/site-packages/linear_operator/utils/cholesky.py:40: NumericalWarning: A not p.d., added jitter of 1.0e-08 to the diagonal
warnings.warn(
/home/runner/work/blop/blop/.pixi/envs/docs/lib/python3.12/site-packages/botorch/optim/optimize.py:677: RuntimeWarning: Optimization failed in `gen_candidates_scipy` with the following warning(s):
[NumericalWarning('A not p.d., added jitter of 1.0e-08 to the diagonal'), NumericalWarning('A not p.d., added jitter of 1.0e-07 to the diagonal'), NumericalWarning('A not p.d., added jitter of 1.0e-06 to the diagonal'), NumericalWarning('A not p.d., added jitter of 1.0e-08 to the diagonal'), NumericalWarning('A not p.d., added jitter of 1.0e-07 to the diagonal'), OptimizationWarning('Optimization failed within `scipy.optimize.minimize` with status 2 and message ABNORMAL: .'), NumericalWarning('A not p.d., added jitter of 1.0e-08 to the diagonal'), NumericalWarning('A not p.d., added jitter of 1.0e-08 to the diagonal'), NumericalWarning('A not p.d., added jitter of 1.0e-07 to the diagonal'), NumericalWarning('A not p.d., added jitter of 1.0e-06 to the diagonal'), OptimizationWarning('Optimization failed within `scipy.optimize.minimize` with status 2 and message ABNORMAL: .'), NumericalWarning('A not p.d., added jitter of 1.0e-08 to the diagonal'), NumericalWarning('A not p.d., added jitter of 1.0e-08 to the diagonal')]
Trying again with a new set of initial conditions.
return _optimize_acqf_batch(opt_inputs=opt_inputs)
/home/runner/work/blop/blop/.pixi/envs/docs/lib/python3.12/site-packages/botorch/optim/optimize.py:677: RuntimeWarning: Optimization failed on the second try, after generating a new set of initial conditions.
return _optimize_acqf_batch(opt_inputs=opt_inputs)
/home/runner/work/blop/blop/.pixi/envs/docs/lib/python3.12/site-packages/linear_operator/utils/cholesky.py:40: NumericalWarning: A not p.d., added jitter of 1.0e-08 to the diagonal
warnings.warn(
/home/runner/work/blop/blop/.pixi/envs/docs/lib/python3.12/site-packages/linear_operator/utils/cholesky.py:40: NumericalWarning: A not p.d., added jitter of 1.0e-07 to the diagonal
warnings.warn(
/home/runner/work/blop/blop/.pixi/envs/docs/lib/python3.12/site-packages/linear_operator/utils/cholesky.py:40: NumericalWarning: A not p.d., added jitter of 1.0e-06 to the diagonal
warnings.warn(
/home/runner/work/blop/blop/.pixi/envs/docs/lib/python3.12/site-packages/linear_operator/utils/cholesky.py:40: NumericalWarning: A not p.d., added jitter of 1.0e-08 to the diagonal
warnings.warn(
/home/runner/work/blop/blop/.pixi/envs/docs/lib/python3.12/site-packages/linear_operator/utils/cholesky.py:40: NumericalWarning: A not p.d., added jitter of 1.0e-08 to the diagonal
warnings.warn(
/home/runner/work/blop/blop/.pixi/envs/docs/lib/python3.12/site-packages/linear_operator/utils/cholesky.py:40: NumericalWarning: A not p.d., added jitter of 1.0e-08 to the diagonal
warnings.warn(
/home/runner/work/blop/blop/.pixi/envs/docs/lib/python3.12/site-packages/botorch/optim/optimize.py:677: RuntimeWarning: Optimization failed in `gen_candidates_scipy` with the following warning(s):
[NumericalWarning('A not p.d., added jitter of 1.0e-08 to the diagonal'), OptimizationWarning('Optimization failed within `scipy.optimize.minimize` with status 2 and message ABNORMAL: .'), NumericalWarning('A not p.d., added jitter of 1.0e-08 to the diagonal'), OptimizationWarning('Optimization failed within `scipy.optimize.minimize` with status 2 and message ABNORMAL: .'), NumericalWarning('A not p.d., added jitter of 1.0e-08 to the diagonal'), NumericalWarning('A not p.d., added jitter of 1.0e-08 to the diagonal'), NumericalWarning('A not p.d., added jitter of 1.0e-08 to the diagonal')]
Trying again with a new set of initial conditions.
return _optimize_acqf_batch(opt_inputs=opt_inputs)
/home/runner/work/blop/blop/.pixi/envs/docs/lib/python3.12/site-packages/botorch/optim/optimize.py:677: RuntimeWarning: Optimization failed on the second try, after generating a new set of initial conditions.
return _optimize_acqf_batch(opt_inputs=opt_inputs)
/home/runner/work/blop/blop/.pixi/envs/docs/lib/python3.12/site-packages/linear_operator/utils/cholesky.py:40: NumericalWarning: A not p.d., added jitter of 1.0e-08 to the diagonal
warnings.warn(
/home/runner/work/blop/blop/.pixi/envs/docs/lib/python3.12/site-packages/linear_operator/utils/cholesky.py:40: NumericalWarning: A not p.d., added jitter of 1.0e-08 to the diagonal
warnings.warn(
/home/runner/work/blop/blop/.pixi/envs/docs/lib/python3.12/site-packages/botorch/optim/optimize.py:677: RuntimeWarning: Optimization failed in `gen_candidates_scipy` with the following warning(s):
[NumericalWarning('A not p.d., added jitter of 1.0e-08 to the diagonal'), NumericalWarning('A not p.d., added jitter of 1.0e-08 to the diagonal'), NumericalWarning('A not p.d., added jitter of 1.0e-07 to the diagonal'), NumericalWarning('A not p.d., added jitter of 1.0e-08 to the diagonal'), OptimizationWarning('Optimization failed within `scipy.optimize.minimize` with status 2 and message ABNORMAL: .'), NumericalWarning('A not p.d., added jitter of 1.0e-08 to the diagonal'), NumericalWarning('A not p.d., added jitter of 1.0e-08 to the diagonal'), NumericalWarning('A not p.d., added jitter of 1.0e-07 to the diagonal'), NumericalWarning('A not p.d., added jitter of 1.0e-06 to the diagonal'), NumericalWarning('A not p.d., added jitter of 1.0e-05 to the diagonal'), OptimizationWarning('Optimization failed within `scipy.optimize.minimize` with status 2 and message ABNORMAL: .'), NumericalWarning('A not p.d., added jitter of 1.0e-08 to the diagonal')]
Trying again with a new set of initial conditions.
return _optimize_acqf_batch(opt_inputs=opt_inputs)
/home/runner/work/blop/blop/.pixi/envs/docs/lib/python3.12/site-packages/botorch/optim/optimize.py:677: RuntimeWarning: Optimization failed on the second try, after generating a new set of initial conditions.
return _optimize_acqf_batch(opt_inputs=opt_inputs)
/home/runner/work/blop/blop/.pixi/envs/docs/lib/python3.12/site-packages/linear_operator/utils/cholesky.py:40: NumericalWarning: A not p.d., added jitter of 1.0e-08 to the diagonal
warnings.warn(
2025-12-08 20:38:52.743 INFO: Change state on <bluesky.run_engine.RunEngine object at 0x7f10c9acf740> from 'running' -> 'idle'
2025-12-08 20:38:52.743 INFO: Cleaned up from plan <generator object Agent.optimize at 0x7f10c9aba5e0>
('503f646c-533d-436e-be71-d60453e61f77',
'9b5b480e-c536-45af-b997-3c2ac9a2261a',
'b040a628-b36b-431b-9a49-1c5e5f2f3078',
'd1623312-66e1-4569-9ae2-963a7eae0eca',
'061e1316-80ee-41ec-b32e-c95faf9d1437',
'5a7d8a4f-5d0d-489d-9991-f2526f22da1b',
'd46471a7-197f-4f6e-852b-cf0a85f7a835',
'e95f2ed3-495e-4fb3-a312-cf13b6a8f2d1',
'd7ac463b-f171-4db4-953b-d9637af1af3f',
'a5af5e0a-734d-4c75-b3ff-b05a7b7cc81a',
'cf8a389c-e0f9-4cd7-b354-9443710739f8',
'641d5b60-039d-4674-8db6-009012e79bb9',
'8d64ef6a-06de-41e0-9db2-47fd16f45d04',
'e7f52949-3fc4-49c1-b2b9-7ada1f7458ff',
'7c812e02-780a-4aaa-b1c2-d7ea61a5389b',
'c0007016-1bde-4587-a9be-07c03e1ce044',
'cde60b91-beee-4404-a641-79439e0f90c3',
'86ad5908-af74-494a-b224-493bde73e6c0',
'24ed2a8b-3f12-462f-a42a-c78ba111e196',
'99d9b60f-ea34-4767-bb10-efe0482ef13e',
'754924a5-9767-4972-b957-1592998ec3c0',
'59e34bb0-7b5d-4fdc-b3c2-2004560430ff',
'7e8d920d-8136-48c7-b403-6be9cd155a34',
'7138f135-5275-41f2-bf2d-f7036e03e573',
'8b613fd4-6374-43c5-8a8d-cb4924507691',
'991d8e0d-1f7c-4123-9c99-0988048cbf29',
'b8e58229-2783-4e64-a54f-1bbf91715c84',
'b19aebd8-fca0-445a-9f38-e8815b6ad5e6',
'387d4ad3-f7a7-4c0a-ba94-f87b91aa945f',
'57aa9c4a-6d4d-4e74-948b-922a2f031f2e')
_ = agent.plot_objective(x_dof_name="bl_kbh_dsh", y_dof_name="bl_kbv_dsv", objective_name="bl_det_sum")
The contour plot visualizes the predicted outcomes for bl_det_sum across a two-dimensional parameter space, with other parameters held fixed at their status_quo value (or mean value if status_quo is unavailable). 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.
Visualizing the optimal beam#
Below we get the optimal parameters, move the motors to their optimal positions, and observe the resulting beam.
optimal_parameters = next(iter(agent.ax_client.get_pareto_frontier()))[0]
optimal_parameters
[INFO 12-08 20:38:55] ax.service.utils.best_point: Using inferred objective thresholds: [ObjectiveThreshold(bl_det_sum >= 23743.490873982868), ObjectiveThreshold(bl_det_wid_x <= 14.107692799984811), ObjectiveThreshold(bl_det_wid_y <= 18.139251884602157)], as objective thresholds were not specified as part of the optimization configuration on the experiment.
{'bl_kbv_dsv': 37961.82534980681, 'bl_kbh_dsh': 20486.672486020747}
from bluesky.plans import list_scan
scan_motor_params = []
for motor in [beamline.kbv_dsv, beamline.kbh_dsh]:
scan_motor_params.append(motor)
scan_motor_params.append([optimal_parameters[motor.name]])
uid = RE(list_scan([beamline.det], *scan_motor_params))
Transient Scan ID: 31 Time: 2025-12-08 20:38:55
Persistent Unique Scan ID: '8c3a526c-4a08-47cf-9b55-c1d5eaeb043c'
New stream: 'primary'
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
| seq_num | time | bl_kbv_dsv | bl_kbh_dsh | bl_det_sum | bl_det_cen_x | bl_det_cen_y | bl_det_wid_x | bl_det_wid_y |
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
| 1 | 20:38:55.4 | 37961.825 | 20486.672 | 23822.965 | 194.362 | 147.997 | 13.694 | 17.878 |
+-----------+------------+------------+------------+------------+--------------+--------------+--------------+--------------+
generator list_scan ['8c3a526c'] (scan num: 31)
2025-12-08 20:38:55.320 INFO: Executing plan <generator object list_scan at 0x7f10989e59c0>
2025-12-08 20:38:55.321 INFO: Change state on <bluesky.run_engine.RunEngine object at 0x7f10c9acf740> from 'idle' -> 'running'
2025-12-08 20:38:55.723 INFO: Change state on <bluesky.run_engine.RunEngine object at 0x7f10c9acf740> from 'running' -> 'idle'
2025-12-08 20:38:55.723 INFO: Cleaned up from plan <generator object list_scan at 0x7f10989e59c0>