Demonstrating “Bring Your Own Beamline” simulation with XRT#

In this tutorial we’ll show a simulation optimization workflow by loading arbitrary XRT setups using xml/json. By the end, you should be able to go to XRT qook/glow and build your beamline from there to export and drop in to Bluesky Adaptive. Or if you are lucky enough for an XRT model to be already built for you, export to xml and load in Bluesky Adaptive.

Some Environment Setup#

note, like all other demos you need the bluesky_adaptive_sim subpackage to run

import logging
import warnings

import matplotlib.pyplot as plt
import numpy as np
from bluesky.callbacks.best_effort import BestEffortCallback

# Import simulation devices (requires: pip install -e sim/)
from bluesky.run_engine import RunEngine
from bluesky.utils import ProgressBarManager
from bluesky_tiled_plugins import TiledWriter
from tiled.client import from_uri  # type: ignore[import-untyped]
from tiled.client.container import Container
from tiled.server import SimpleTiledServer

from bluesky_adaptive.ax import Agent, Objective, RangeDOF
from bluesky_adaptive.protocols import EvaluationFunction
from bluesky_adaptive_sim.backends import XRTBackend
from bluesky_adaptive_sim.devices.xrt import infer_detectors, infer_variables

# Suppress noisy logs from httpx and dependency deprecation warnings
logging.getLogger("httpx").setLevel(logging.WARNING)
warnings.filterwarnings("ignore", category=FutureWarning)

# Enable interactive plotting
plt.ion()

DETECTOR_STORAGE = "/tmp/bluesky-adaptive/sim"
/home/runner/work/bluesky-adaptive/bluesky-adaptive/.pixi/envs/docs/lib/python3.13/site-packages/torch/jit/_script.py:1491: FutureWarning: `torch.jit.script` is deprecated. Please switch to `torch.compile` or `torch.export`.
  warnings.warn(
[INFO 10-26 21:33:09] ax.storage.sqa_store.with_db_settings_base: Ax SQL storage initialized with SQLAlchemy 2.0.55
fileName = r"toroid_focus.xml"
beam = XRTBackend(file=fileName)
dets = infer_detectors(beam)
motors = infer_variables(beam, filter_for=None)
created inferred variable toroid_focus:screen01:center:z of float type as value is None or auto.
                Be careful when setting this variable as the type is guessed as float by default.

A small view of the inferred motors#

for name, element in motors.items():
    print(name)
    for nm, motor in element.items():
        print(f"{nm} : {motor}")
bendingMagnet01
B0 : <InferredVariable::toroid_focus:bendingMagnet01:B0=<class 'float'>:1.0>
rho : <InferredVariable::toroid_focus:bendingMagnet01:rho=<class 'float'>:10.00692285594456>
toroidMirror01
R : <InferredVariable::toroid_focus:toroidMirror01:R=<class 'float'>:152982.84327559808>
r : <InferredVariable::toroid_focus:toroidMirror01:r=<class 'float'>:1162.0765699687756>
screen01
center:x : <InferredVariable::toroid_focus:screen01:center:x=<class 'int'>:0>
center:y : <InferredVariable::toroid_focus:screen01:center:y=<class 'int'>:30000>
center:z : <InferredVariable::toroid_focus:screen01:center:z=<class 'float'>:auto>
x:x : <InferredVariable::toroid_focus:screen01:x:x=<class 'float'>:1.0>
x:y : <InferredVariable::toroid_focus:screen01:x:y=<class 'float'>:-0.0>
x:z : <InferredVariable::toroid_focus:screen01:x:z=<class 'float'>:0.0>
z:x : <InferredVariable::toroid_focus:screen01:z:x=<class 'float'>:0.0>
z:y : <InferredVariable::toroid_focus:screen01:z:y=<class 'float'>:0.0>
z:z : <InferredVariable::toroid_focus:screen01:z:z=<class 'float'>:1.0>

Another glimpse into the inferred detectors#

for name, det in dets.items():
    print(f"{name} : {det}")
bendingMagnet01 : <bluesky_adaptive_sim.devices.xrt.auto_element.InferredDetector object at 0x7f1bdcf03620>
toroidMirror01 : <bluesky_adaptive_sim.devices.xrt.auto_element.InferredDetector object at 0x7f1bdcee7250>
screen01 : <bluesky_adaptive_sim.devices.xrt.auto_element.InferredDetector object at 0x7f1bdcee7390>

Setting up an optimization#

toro_R = motors["toroidMirror01"]["R"]
toro_R.alias = "big_r"
toro_r = motors["toroidMirror01"]["r"]

screen = dets["screen01"]
screen.set_primary()


VERTICAL_BOUNDS = (toro_R.val - 15000, toro_R.val + 15000)
HORIZONTAL_BOUNDS = (toro_r.val - 500, toro_r.val + 500)
# Define DOFs using mirror radius signals
dofs = [
    RangeDOF(actuator=toro_R, bounds=VERTICAL_BOUNDS, parameter_type="float"),
    RangeDOF(actuator=toro_r, bounds=HORIZONTAL_BOUNDS, parameter_type="float"),
]
tiled_server = SimpleTiledServer()
tiled_client = from_uri(tiled_server.uri)
tiled_writer = TiledWriter(tiled_client)

RE = RunEngine({})
bec = BestEffortCallback()

# Send all metadata/data captured to the BestEffortCallback.
# RE.subscribe(bec)
RE.waiting_hook = ProgressBarManager()

tiled_client = from_uri(tiled_server.uri)
tiled_writer = TiledWriter(tiled_client)
RE.subscribe(tiled_writer)
0
# Single objective: minimize the geometric-mean FWHM
objectives = [
    Objective(name="fwhm", minimize=True),
]
from collections.abc import Mapping, Sequence

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

    def _fwhm_from_profile(self, profile: np.ndarray) -> float:
        """Compute FWHM from a 1D marginal profile.

        Finds the half-maximum crossing points with sub-pixel interpolation.
        Returns a large value if the beam is too dim or fills the entire detector.
        """
        peak = profile.max()
        if peak == 0:
            return float(len(profile))  # No signal — return detector width as penalty

        half_max = peak / 2.0
        above = profile >= half_max
        if not above.any():
            return float(len(profile))

        indices = np.where(above)[0]
        left_idx = indices[0]
        right_idx = indices[-1]

        # Sub-pixel interpolation at left crossing
        if left_idx > 0:
            left = left_idx - 1 + (half_max - profile[left_idx - 1]) / (profile[left_idx] - profile[left_idx - 1])
        else:
            left = 0.0

        # Sub-pixel interpolation at right crossing
        if right_idx < len(profile) - 1:
            right = right_idx + (half_max - profile[right_idx]) / (profile[right_idx + 1] - profile[right_idx])
        else:
            right = float(len(profile) - 1)

        return right - left

    def _compute_stats(self, image: np.ndarray) -> tuple[float, float]:
        """Compute FWHM and integrated intensity from a beam image.

        Returns
        -------
        fwhm : float
            Geometric mean of the horizontal and vertical FWHM (in pixels).
        intensity : float
            Total integrated intensity (sum of all pixel values).
        """
        gray = image.squeeze().astype(np.float64)
        if gray.ndim == 3:
            gray = gray.mean(axis=-1)

        # Integrated intensity (total flux on detector)
        intensity = gray.sum()

        if intensity == 0:
            return 400.0, 0.0  # No beam — return max FWHM penalty

        # Marginal profiles: project onto each axis
        x_profile = gray.sum(axis=0)  # sum along Y rows -> X profile
        y_profile = gray.sum(axis=1)  # sum along X cols -> Y profile

        fwhm_x = self._fwhm_from_profile(x_profile)
        fwhm_y = self._fwhm_from_profile(y_profile)

        # Geometric mean FWHM — targets a small, round spot
        fwhm = np.sqrt(fwhm_x * fwhm_y)

        return float(fwhm), float(intensity)

    def __call__(self, uid: str, suggestions: Sequence[Mapping]) -> Sequence[Mapping]:
        outcomes = []
        run = self.tiled_client[uid]

        # Read beam images from detector
        images = run[f"primary/{screen.name}"].read()

        # These IDs, not positions in suggestions, are ordered to match acquired images.
        acquisition_order = run.metadata["start"]["blop_acquisition_order"]

        # Compute statistics from each image
        for idx, suggestion_id in enumerate(acquisition_order):
            image = images[idx]
            fwhm, intensity = self._compute_stats(image)

            outcome = {
                "_id": suggestion_id,
                "fwhm": fwhm,
                # "intensity": intensity,
            }
            outcomes.append(outcome)
        return outcomes
agent = Agent(
    sensors=[screen],
    dofs=dofs,
    objectives=objectives,
    evaluation_function=DetectorEvaluation(tiled_client),
    name="xrt-bluesky-adaptive-demo",
    description="A demo of the Bluesky Adaptive agent with XRT simulated beamline",
)
# Run 1 iteration with a batch of 10 points for initial exploration
RE(agent.optimize(1, n_points=10))
╭───────────────────────────────────────────────── Optimization ──────────────────────────────────────────────────╮
│ Optimizer  AxOptimizer                                                                                          │
│ Actuators  big_r, toroid_focus:toroidMirror01:r                                                                 │
│ Sensors    screen01                                                                                             │
│ Iterations 1  Points/iter 10                                                                                    │
│ Run UID    5ae472ff-b4d8-47e3-8809-2a8bc17edb54                                                                 │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
125837 rays of 500000
251340 rays of 500000
376910 rays of 500000
502013 rays of 500000
screen01
center:
[0.0, 30000.0, 1763.2606473439778]
[INFO 10-26 21:33:13] ax.api.client: GenerationStrategy(name='Center+Sobol+MBM:fast', nodes=[CenterGenerationNode(next_node_name='Sobol', use_existing_trials_for_initialization=True), GenerationNode(name='Sobol', generator_specs=[GeneratorSpec(generator_enum=Sobol, generator_key_override=None)], transition_criteria=[MinTrials(transition_to='MBM'), MinTrials(transition_to='MBM')], suggested_experiment_status=ExperimentStatus.INITIALIZATION, pausing_criteria=[MaxTrialsAwaitingData(threshold=5)]), GenerationNode(name='MBM', generator_specs=[GeneratorSpec(generator_enum=BoTorch, generator_key_override=None)], transition_criteria=None, suggested_experiment_status=ExperimentStatus.OPTIMIZATION, pausing_criteria=None)]) chosen based on user input and problem structure.
[INFO 10-26 21:33:13] ax.api.client: Generated new trial 0 with parameters {'big_r': 152982.843276, 'toroid_focus:toroidMirror01:r': 1162.07657} using GenerationNode CenterOfSearchSpace.
[INFO 10-26 21:33:13] ax.api.client: Generated new trial 1 with parameters {'big_r': 164835.244175, 'toroid_focus:toroidMirror01:r': 719.265427} using GenerationNode Sobol.
[INFO 10-26 21:33:13] ax.api.client: Generated new trial 2 with parameters {'big_r': 148586.104512, 'toroid_focus:toroidMirror01:r': 1164.781627} using GenerationNode Sobol.
[INFO 10-26 21:33:13] ax.api.client: Generated new trial 3 with parameters {'big_r': 143000.561287, 'toroid_focus:toroidMirror01:r': 1004.001832} using GenerationNode Sobol.
[INFO 10-26 21:33:13] ax.api.client: Generated new trial 4 with parameters {'big_r': 155506.731579, 'toroid_focus:toroidMirror01:r': 1512.09432} using GenerationNode Sobol.
[INFO 10-26 21:33:13] ax.api.client: Generated new trial 5 with parameters {'big_r': 157007.518522, 'toroid_focus:toroidMirror01:r': 1141.313411} using GenerationNode Sobol.
[INFO 10-26 21:33:13] ax.api.client: Generated new trial 6 with parameters {'big_r': 141381.656955, 'toroid_focus:toroidMirror01:r': 1618.099702} using GenerationNode Sobol.
[INFO 10-26 21:33:13] ax.api.client: Generated new trial 7 with parameters {'big_r': 150834.387289, 'toroid_focus:toroidMirror01:r': 800.820935} using GenerationNode Sobol.
[INFO 10-26 21:33:13] ax.api.client: Generated new trial 8 with parameters {'big_r': 162703.218338, 'toroid_focus:toroidMirror01:r': 1340.152996} using GenerationNode Sobol.
[INFO 10-26 21:33:13] ax.api.client: Generated new trial 9 with parameters {'big_r': 161797.210909, 'toroid_focus:toroidMirror01:r': 971.39891} using GenerationNode Sobol.
[INFO 10-26 21:33:29] ax.api.client: Trial 0 marked COMPLETED.
[INFO 10-26 21:33:29] ax.api.client: Trial 7 marked COMPLETED.
[INFO 10-26 21:33:29] ax.api.client: Trial 2 marked COMPLETED.
[INFO 10-26 21:33:29] ax.api.client: Trial 3 marked COMPLETED.
[INFO 10-26 21:33:29] ax.api.client: Trial 6 marked COMPLETED.
[INFO 10-26 21:33:29] ax.api.client: Trial 4 marked COMPLETED.
[INFO 10-26 21:33:29] ax.api.client: Trial 5 marked COMPLETED.
[INFO 10-26 21:33:29] ax.api.client: Trial 9 marked COMPLETED.
[INFO 10-26 21:33:29] ax.api.client: Trial 8 marked COMPLETED.
[INFO 10-26 21:33:29] ax.api.client: Trial 1 marked COMPLETED.
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Suggestion ID              ┃ big_r                      ┃ toroid_focus:toroidMirro… ┃ fwhm                      ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
└────────────────────────────┴────────────────────────────┴───────────────────────────┴───────────────────────────┘
┃                            ┃                            ┃                           ┃                           ┃
┃ 0                          ┃                     152983 ┃                   1162.08 ┃                   42.9368 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 1                          ┃                     164835 ┃                   719.265 ┃                   57.1487 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 2                          ┃                     148586 ┃                   1164.78 ┃                   17.2131 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 3                          ┃                     143001 ┃                      1004 ┃                   13.2838 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 4                          ┃                     155507 ┃                   1512.09 ┃                   87.8352 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
───────────────────────────────────────────────── Iteration 1 / 1 ─────────────────────────────────────────────────
  fwhm  min: 13.2838  max: 87.8352  mean: 43.6835
  (5 pts sampled)
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────
┃                            ┃                            ┃                           ┃                           ┃
┃ 5                          ┃                     157008 ┃                   1141.31 ┃                   63.2594 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 6                          ┃                     141382 ┃                    1618.1 ┃                   12.6431 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 7                          ┃                     150834 ┃                   800.821 ┃                   21.8392 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 8                          ┃                     162703 ┃                   1340.15 ┃                   64.3163 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 9                          ┃                     161797 ┃                   971.399 ┃                   13.8384 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
───────────────────────────────────────────────── Iteration 1 / 1 ─────────────────────────────────────────────────
  fwhm  min: 12.6431  max: 87.8352  mean: 39.4314
  (10 pts sampled)
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────

                                    Summary Statistics                                     
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━┳━━━━━━━┓
┃ Name                          ┃ Type    ┃     Min ┃     Max ┃    Mean ┃     Std ┃ Count ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━╇━━━━━━━┩
│ big_r                         │ param   │  141382 │  164835 │  153864 │ 8066.74 │    10 │
│ toroid_focus:toroidMirror01:r │ param   │ 719.265 │  1618.1 │  1143.4 │  288.11 │    10 │
│ fwhm                          │ outcome │ 12.6431 │ 87.8352 │ 39.4314 │ 27.3163 │    10 │
└───────────────────────────────┴─────────┴─────────┴─────────┴─────────┴─────────┴───────┘
────────────────────────────────────────────── Optimization Complete ──────────────────────────────────────────────
('5ae472ff-b4d8-47e3-8809-2a8bc17edb54',
 '725d5119-436d-48a4-9c65-9db406cd6388')
# Run more iterations
RE(agent.optimize(5, n_points=5))
╭───────────────────────────────────────────────── Optimization ──────────────────────────────────────────────────╮
│ Optimizer  AxOptimizer                                                                                          │
│ Actuators  big_r, toroid_focus:toroidMirror01:r                                                                 │
│ Sensors    screen01                                                                                             │
│ Iterations 5 more (1 completed, 6 total)  Points/iter 5                                                         │
│ Run UID    4e2b2ace-17ba-4aa1-8854-1c37cf1ee530                                                                 │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
[INFO 10-26 21:33:32] ax.api.client: Generated new trial 10 with parameters {'big_r': 142689.161193, 'toroid_focus:toroidMirror01:r': 1122.159068} using GenerationNode MBM.
[INFO 10-26 21:33:32] ax.api.client: Generated new trial 11 with parameters {'big_r': 149465.50809, 'toroid_focus:toroidMirror01:r': 962.475131} using GenerationNode MBM.
[INFO 10-26 21:33:32] ax.api.client: Generated new trial 12 with parameters {'big_r': 167982.843276, 'toroid_focus:toroidMirror01:r': 967.287443} using GenerationNode MBM.
[INFO 10-26 21:33:32] ax.api.client: Generated new trial 13 with parameters {'big_r': 137982.843276, 'toroid_focus:toroidMirror01:r': 1507.522638} using GenerationNode MBM.
[INFO 10-26 21:33:32] ax.api.client: Generated new trial 14 with parameters {'big_r': 157508.709995, 'toroid_focus:toroidMirror01:r': 896.371154} using GenerationNode MBM.
[INFO 10-26 21:33:39] ax.api.client: Trial 12 marked COMPLETED.
[INFO 10-26 21:33:39] ax.api.client: Trial 14 marked COMPLETED.
[INFO 10-26 21:33:39] ax.api.client: Trial 11 marked COMPLETED.
[INFO 10-26 21:33:39] ax.api.client: Trial 10 marked COMPLETED.
[INFO 10-26 21:33:39] ax.api.client: Trial 13 marked COMPLETED.
[INFO 10-26 21:33:42] ax.api.client: Generated new trial 15 with parameters {'big_r': 159699.008757, 'toroid_focus:toroidMirror01:r': 806.643501} using GenerationNode MBM.
[INFO 10-26 21:33:42] ax.api.client: Generated new trial 16 with parameters {'big_r': 142891.836849, 'toroid_focus:toroidMirror01:r': 1405.193679} using GenerationNode MBM.
[INFO 10-26 21:33:42] ax.api.client: Generated new trial 17 with parameters {'big_r': 138259.516477, 'toroid_focus:toroidMirror01:r': 1047.820379} using GenerationNode MBM.
[INFO 10-26 21:33:42] ax.api.client: Generated new trial 18 with parameters {'big_r': 157223.650794, 'toroid_focus:toroidMirror01:r': 662.07657} using GenerationNode MBM.
[INFO 10-26 21:33:42] ax.api.client: Generated new trial 19 with parameters {'big_r': 146077.976641, 'toroid_focus:toroidMirror01:r': 1662.07657} using GenerationNode MBM.
[INFO 10-26 21:33:49] ax.api.client: Trial 17 marked COMPLETED.
[INFO 10-26 21:33:49] ax.api.client: Trial 16 marked COMPLETED.
[INFO 10-26 21:33:49] ax.api.client: Trial 19 marked COMPLETED.
[INFO 10-26 21:33:49] ax.api.client: Trial 18 marked COMPLETED.
[INFO 10-26 21:33:49] ax.api.client: Trial 15 marked COMPLETED.
[INFO 10-26 21:33:52] ax.api.client: Generated new trial 20 with parameters {'big_r': 138158.211795, 'toroid_focus:toroidMirror01:r': 662.07657} using GenerationNode MBM.
[INFO 10-26 21:33:52] ax.api.client: Generated new trial 21 with parameters {'big_r': 140254.913288, 'toroid_focus:toroidMirror01:r': 1272.93296} using GenerationNode MBM.
[INFO 10-26 21:33:52] ax.api.client: Generated new trial 22 with parameters {'big_r': 144901.307217, 'toroid_focus:toroidMirror01:r': 1149.215589} using GenerationNode MBM.
[INFO 10-26 21:33:52] ax.api.client: Generated new trial 23 with parameters {'big_r': 144113.334838, 'toroid_focus:toroidMirror01:r': 662.07657} using GenerationNode MBM.
[INFO 10-26 21:33:52] ax.api.client: Generated new trial 24 with parameters {'big_r': 137982.843276, 'toroid_focus:toroidMirror01:r': 1662.07657} using GenerationNode MBM.
[INFO 10-26 21:33:59] ax.api.client: Trial 22 marked COMPLETED.
[INFO 10-26 21:33:59] ax.api.client: Trial 23 marked COMPLETED.
[INFO 10-26 21:33:59] ax.api.client: Trial 21 marked COMPLETED.
[INFO 10-26 21:33:59] ax.api.client: Trial 20 marked COMPLETED.
[INFO 10-26 21:33:59] ax.api.client: Trial 24 marked COMPLETED.
[INFO 10-26 21:34:02] ax.api.client: Generated new trial 25 with parameters {'big_r': 141523.897386, 'toroid_focus:toroidMirror01:r': 1232.141072} using GenerationNode MBM.
[INFO 10-26 21:34:02] ax.api.client: Generated new trial 26 with parameters {'big_r': 141301.177114, 'toroid_focus:toroidMirror01:r': 1328.516563} using GenerationNode MBM.
[INFO 10-26 21:34:02] ax.api.client: Generated new trial 27 with parameters {'big_r': 141256.26375, 'toroid_focus:toroidMirror01:r': 1183.164817} using GenerationNode MBM.
[INFO 10-26 21:34:02] ax.api.client: Generated new trial 28 with parameters {'big_r': 146354.890031, 'toroid_focus:toroidMirror01:r': 925.741591} using GenerationNode MBM.
[INFO 10-26 21:34:02] ax.api.client: Generated new trial 29 with parameters {'big_r': 167982.843276, 'toroid_focus:toroidMirror01:r': 1662.07657} using GenerationNode MBM.
[INFO 10-26 21:34:09] ax.api.client: Trial 27 marked COMPLETED.
[INFO 10-26 21:34:09] ax.api.client: Trial 26 marked COMPLETED.
[INFO 10-26 21:34:09] ax.api.client: Trial 25 marked COMPLETED.
[INFO 10-26 21:34:09] ax.api.client: Trial 28 marked COMPLETED.
[INFO 10-26 21:34:09] ax.api.client: Trial 29 marked COMPLETED.
[INFO 10-26 21:34:14] ax.api.client: Generated new trial 30 with parameters {'big_r': 142130.018125, 'toroid_focus:toroidMirror01:r': 1217.563831} using GenerationNode MBM.
[INFO 10-26 21:34:14] ax.api.client: Generated new trial 31 with parameters {'big_r': 141281.909499, 'toroid_focus:toroidMirror01:r': 1471.509719} using GenerationNode MBM.
[INFO 10-26 21:34:14] ax.api.client: Generated new trial 32 with parameters {'big_r': 141412.704689, 'toroid_focus:toroidMirror01:r': 1120.752333} using GenerationNode MBM.
[INFO 10-26 21:34:14] ax.api.client: Generated new trial 33 with parameters {'big_r': 141178.454707, 'toroid_focus:toroidMirror01:r': 852.553947} using GenerationNode MBM.
[INFO 10-26 21:34:14] ax.api.client: Generated new trial 34 with parameters {'big_r': 150858.200734, 'toroid_focus:toroidMirror01:r': 1662.07657} using GenerationNode MBM.
[INFO 10-26 21:34:21] ax.api.client: Trial 34 marked COMPLETED.
[INFO 10-26 21:34:21] ax.api.client: Trial 30 marked COMPLETED.
[INFO 10-26 21:34:21] ax.api.client: Trial 31 marked COMPLETED.
[INFO 10-26 21:34:21] ax.api.client: Trial 32 marked COMPLETED.
[INFO 10-26 21:34:21] ax.api.client: Trial 33 marked COMPLETED.
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Suggestion ID              ┃ big_r                      ┃ toroid_focus:toroidMirro… ┃ fwhm                      ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
└────────────────────────────┴────────────────────────────┴───────────────────────────┴───────────────────────────┘
┃                            ┃                            ┃                           ┃                           ┃
┃ 10                         ┃                     142689 ┃                   1122.16 ┃                   10.9796 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 11                         ┃                     149466 ┃                   962.475 ┃                   16.7898 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 12                         ┃                     167983 ┃                   967.287 ┃                     60.46 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 13                         ┃                     137983 ┃                   1507.52 ┃                   18.6362 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 14                         ┃                     157509 ┃                   896.371 ┃                   17.6537 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
───────────────────────────────────────────────── Iteration 2 / 6 ─────────────────────────────────────────────────
  fwhm  min: 10.9796  max: 87.8352  mean: 34.5889
  (15 pts sampled)
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────
┃                            ┃                            ┃                           ┃                           ┃
┃ 15                         ┃                     159699 ┃                   806.644 ┃                   17.2852 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 16                         ┃                     142892 ┃                   1405.19 ┃                   12.4495 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 17                         ┃                     138260 ┃                   1047.82 ┃                   18.9019 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 18                         ┃                     157224 ┃                   662.077 ┃                   22.8728 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 19                         ┃                     146078 ┃                   1662.08 ┃                   19.9711 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
───────────────────────────────────────────────── Iteration 3 / 6 ─────────────────────────────────────────────────
  fwhm  min: 10.9796  max: 87.8352  mean: 30.5157
  (20 pts sampled)
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────
┃                            ┃                            ┃                           ┃                           ┃
┃ 20                         ┃                     138158 ┃                   662.077 ┃                   21.9576 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 21                         ┃                     140255 ┃                   1272.93 ┃                   10.9381 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 22                         ┃                     144901 ┃                   1149.22 ┃                   13.5038 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 23                         ┃                     144113 ┃                   662.077 ┃                   19.2227 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 24                         ┃                     137983 ┃                   1662.08 ┃                   17.5734 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
───────────────────────────────────────────────── Iteration 4 / 6 ─────────────────────────────────────────────────
  fwhm  min: 10.9381  max: 87.8352  mean: 27.7404
  (25 pts sampled)
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────
┃                            ┃                            ┃                           ┃                           ┃
┃ 25                         ┃                     141524 ┃                   1232.14 ┃                   12.3215 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 26                         ┃                     141301 ┃                   1328.52 ┃                    10.395 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 27                         ┃                     141256 ┃                   1183.16 ┃                   8.85722 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 28                         ┃                     146355 ┃                   925.742 ┃                   18.0816 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 29                         ┃                     167983 ┃                   1662.08 ┃                   62.5288 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
───────────────────────────────────────────────── Iteration 5 / 6 ─────────────────────────────────────────────────
  fwhm  min: 8.85722  max: 87.8352  mean: 26.8564
  (30 pts sampled)
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────
┃                            ┃                            ┃                           ┃                           ┃
┃ 30                         ┃                     142130 ┃                   1217.56 ┃                   9.93424 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 31                         ┃                     141282 ┃                   1471.51 ┃                   9.85023 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 32                         ┃                     141413 ┃                   1120.75 ┃                   11.5321 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 33                         ┃                     141178 ┃                   852.554 ┃                   15.7832 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
┃                            ┃                            ┃                           ┃                           ┃
┃ 34                         ┃                     150858 ┃                   1662.08 ┃                   52.1889 ┃
┡────────────────────────────╇────────────────────────────╇───────────────────────────╇───────────────────────────┩
───────────────────────────────────────────────── Iteration 6 / 6 ─────────────────────────────────────────────────
  fwhm  min: 8.85722  max: 87.8352  mean: 25.8566
  (35 pts sampled)
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────

                                    Summary Statistics                                     
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━┳━━━━━━━┓
┃ Name                          ┃ Type    ┃     Min ┃     Max ┃    Mean ┃     Std ┃ Count ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━╇━━━━━━━┩
│ big_r                         │ param   │  137983 │  167983 │  148546 │ 9203.52 │    35 │
│ toroid_focus:toroidMirror01:r │ param   │ 662.077 │ 1662.08 │ 1158.23 │ 309.912 │    35 │
│ fwhm                          │ outcome │ 8.85722 │ 87.8352 │ 25.8566 │ 20.7599 │    35 │
└───────────────────────────────┴─────────┴─────────┴─────────┴─────────┴─────────┴───────┘
────────────────────────────────────────────── Optimization Complete ──────────────────────────────────────────────
('4e2b2ace-17ba-4aa1-8854-1c37cf1ee530',
 'd43b0ddf-bac1-473c-aa50-ef54f5263a57',
 '9256cf46-9ba2-4f08-adc7-0f0160ec24d2',
 '27d057ed-d31e-4f40-9e26-afde0664cf04',
 'b44e854c-36f5-42ab-ae3e-3dc97c4794a6',
 'a251bc14-d74c-46d2-a015-30c75661710a')
_ = agent.ax_client.compute_analyses()
[ERROR 10-26 21:34:22] ax.core.experiment: Encountered ValueError Data to attach is empty. while attaching results. Proceeding and returning results fetched without attaching.
[ERROR 10-26 21:34:22] ax.core.experiment: Encountered ValueError Data to attach is empty. while attaching results. Proceeding and returning results fetched without attaching.
[ERROR 10-26 21:34:22] ax.core.experiment: Encountered ValueError Data to attach is empty. while attaching results. Proceeding and returning results fetched without attaching.
[ERROR 10-26 21:34:22] ax.core.experiment: Encountered ValueError Data to attach is empty. while attaching results. Proceeding and returning results fetched without attaching.
[ERROR 10-26 21:34:23] ax.core.experiment: Encountered ValueError Data to attach is empty. while attaching results. Proceeding and returning results fetched without attaching.
[ERROR 10-26 21:34:23] ax.core.experiment: Encountered ValueError Data to attach is empty. while attaching results. Proceeding and returning results fetched without attaching.
[ERROR 10-26 21:34:23] ax.core.experiment: Encountered ValueError Data to attach is empty. while attaching results. Proceeding and returning results fetched without attaching.
Overview of the Entire Optimization Process

This analysis provides an overview of the entire optimization process. It includes visualizations of the results obtained so far, insights into the parameter and metric relationships learned by the Ax model, diagnostics such as model fit, and health checks to assess the overall health of the experiment.

Results Analysis

Result Analyses provide a high-level overview of the results of the optimization process so far with respect to the metrics specified in experiment design.

Metric Effects: Predicted and observed effects for all arms in the experiment

These pair of plots visualize the metric effects for each arm, with the Ax model predictions on the left and the raw observed data on the right. The predicted effects apply shrinkage for noise and adjust for non-stationarity in the data, so they are more representative of the reproducible effects that will manifest in a long-term validation experiment.

Metric Effects Pair for fwhm

Modeled Arm Effects on fwhm
Modeled effects on fwhm. This plot visualizes predictions of the true metric changes for each arm based on Ax's model. This is the expected delta you would expect if you (re-)ran that arm. This plot helps in anticipating the outcomes and performance of arms based on the model's predictions. Note, flat predictions across arms indicate that the model predicts that there is no effect, meaning if you were to re-run the experiment, the delta you would see would be small and fall within the confidence interval indicated in the plot.
Observed Arm Effects on fwhm
Observed effects on fwhm. This plot visualizes the effects from previously-run arms on a specific metric, providing insights into their performance. This plot allows one to compare and contrast the effectiveness of different arms, highlighting which configurations have yielded the most favorable outcomes.
Utility Progression
Shows the best fwhm value achieved so far across completed trials (objective is to minimize). The x-axis shows trial index. Only completed or early-stopped trials with complete metric data are included, so there may be gaps if some trials failed, were abandoned, or have incomplete data. The y-axis shows cumulative best utility. Only improvements are plotted, so flat segments indicate trials that didn't surpass the previous best. Infeasible trials (violating outcome constraints) don't contribute to the improvements.
Best Trial for Experiment
Displays the trial with the best objective value based on raw observations. This reflects actual measured performance during execution. This trial achieved the optimal objective value and represents the recommended configuration for your optimization goal. Only considering COMPLETED trials.
trial_index arm_name trial_status generation_node fwhm big_r toroid_focus:toroidMirror01:r
0 27 27_0 COMPLETED MBM 8.857221 141256.26375 1183.164817
Summary for xrt-bluesky-adaptive-demo
High-level summary of the `Trial`-s in this `Experiment`
trial_index arm_name trial_status generation_node fwhm big_r toroid_focus:toroidMirror01:r
0 0 0_0 COMPLETED CenterOfSearchSpace 42.936815 152982.843276 1162.076570
1 1 1_0 COMPLETED Sobol 57.148699 164835.244175 719.265427
2 2 2_0 COMPLETED Sobol 17.213111 148586.104512 1164.781627
3 3 3_0 COMPLETED Sobol 13.283751 143000.561287 1004.001832
4 4 4_0 COMPLETED Sobol 87.835217 155506.731579 1512.094320
5 5 5_0 COMPLETED Sobol 63.259396 157007.518522 1141.313411
6 6 6_0 COMPLETED Sobol 12.643062 141381.656955 1618.099702
7 7 7_0 COMPLETED Sobol 21.839207 150834.387289 800.820935
8 8 8_0 COMPLETED Sobol 64.316255 162703.218338 1340.152996
9 9 9_0 COMPLETED Sobol 13.838444 161797.210909 971.398910
10 10 10_0 COMPLETED MBM 10.979559 142689.161193 1122.159068
11 11 11_0 COMPLETED MBM 16.789817 149465.508090 962.475131
12 12 12_0 COMPLETED MBM 60.460013 167982.843276 967.287443
13 13 13_0 COMPLETED MBM 18.636185 137982.843276 1507.522638
14 14 14_0 COMPLETED MBM 17.653740 157508.709995 896.371154
15 15 15_0 COMPLETED MBM 17.285183 159699.008757 806.643501
16 16 16_0 COMPLETED MBM 12.449500 142891.836849 1405.193679
17 17 17_0 COMPLETED MBM 18.901870 138259.516477 1047.820379
18 18 18_0 COMPLETED MBM 22.872811 157223.650794 662.076570
19 19 19_0 COMPLETED MBM 19.971134 146077.976641 1662.076570
20 20 20_0 COMPLETED MBM 21.957640 138158.211795 662.076570
21 21 21_0 COMPLETED MBM 10.938084 140254.913288 1272.932960
22 22 22_0 COMPLETED MBM 13.503781 144901.307217 1149.215589
23 23 23_0 COMPLETED MBM 19.222663 144113.334838 662.076570
24 24 24_0 COMPLETED MBM 17.573355 137982.843276 1662.076570
25 25 25_0 COMPLETED MBM 12.321519 141523.897386 1232.141072
26 26 26_0 COMPLETED MBM 10.395006 141301.177114 1328.516563
27 27 27_0 COMPLETED MBM 8.857221 141256.263750 1183.164817
28 28 28_0 COMPLETED MBM 18.081559 146354.890031 925.741591
29 29 29_0 COMPLETED MBM 62.528804 167982.843276 1662.076570
30 30 30_0 COMPLETED MBM 9.934243 142130.018125 1217.563831
31 31 31_0 COMPLETED MBM 9.850233 141281.909499 1471.509719
32 32 32_0 COMPLETED MBM 11.532145 141412.704689 1120.752333
33 33 33_0 COMPLETED MBM 15.783227 141178.454707 852.553947
34 34 34_0 COMPLETED MBM 52.188926 150858.200734 1662.076570
Insights Analysis

Insight Analyses display information to help understand the underlying experiment i.e parameter and metric relationships learned by the Ax model.Use this information to better understand your experiment space and users.

Top Surfaces Analysis: Parameter sensitivity, slice, and contour plots

The top surfaces analysis displays three analyses in one. First, it shows parameter sensitivities, which shows the sensitivity of the metrics in the experiment to the most important parameters. Subsetting to only the most important parameters, it then shows slice plots and contour plots for each metric in the experiment, displaying the relationship between the metric and the most important parameters.

Sensitivity Analysis for fwhm
Understand how each parameter affects fwhm according to a second-order sensitivity analysis.
Slice Plots: Metric effects by parameter value

These plots show the relationship between a metric and a parameter. They show the predicted values of the metric on the y-axis as a function of the parameter on the x-axis while keeping all other parameters fixed at their status_quo value (if available), best trial value, or the center of the search space.

fwhm vs. big_r
The slice plot provides a one-dimensional view of predicted outcomes for fwhm as a function of a single parameter, while keeping all other parameters fixed at their best trial value (Arm 25_0). This visualization helps in understanding the sensitivity and impact of changes in the selected parameter on the predicted metric outcomes.
fwhm vs. toroid_focus:toroidMirror01:r
The slice plot provides a one-dimensional view of predicted outcomes for fwhm as a function of a single parameter, while keeping all other parameters fixed at their best trial value (Arm 25_0). This visualization helps in understanding the sensitivity and impact of changes in the selected parameter on the predicted metric outcomes.
Contour Plots: Metric effects by parameter values

These plots show the relationship between a metric and two parameters. They show the predicted values of the metric (indicated by color) as a function of the two parameters on the x- and y-axes while keeping all other parameters fixed at their status_quo value (if available), best trial value, or the center of the search space.

fwhm (Mean) vs. big_r, toroid_focus:toroidMirror01:r
The contour plot visualizes the predicted outcomes for fwhm across a two-dimensional parameter space, with other parameters held fixed at their best trial value (Arm 25_0). This plot helps in identifying regions of optimal performance and understanding how changes in the selected parameters influence the predicted outcomes. Contour lines represent levels of constant predicted values, providing insights into the gradient and potential optima within the parameter space.
Diagnostic Analysis

Diagnostic Analyses provide information about the optimization process and the quality of the model fit. You can use this information to understand if the experimental design should be adjusted to improve optimization quality.

Cross Validation: Assessing model fit

Cross-validation plots display the model fit for each metric in the experiment. The model is trained on a subset of the data and then predicts the outcome for the remaining subset. The plots show the predicted outcome for the validation set on the y-axis against its actual value on the x-axis. Points that align closely with the dotted diagonal line indicate a strong model fit, signifying accurate predictions. Additionally, the plots include confidence intervals that provide insight into the noise in observations and the uncertainty in model predictions.

NOTE: A horizontal, flat line of predictions indicates that the model has not picked up on sufficient signal in the data, and instead is just predicting the mean.

Cross Validation for fwhm (R² = 0.76)
The cross-validation plot displays the model fit for each metric in the experiment. It employs a leave-one-out approach, where the model is trained on all data except one sample, which is used for validation. The plot shows the predicted outcome for the validation set on the y-axis against its actual value on the x-axis. Points that align closely with the dotted diagonal line indicate a strong model fit, signifying accurate predictions. Additionally, the plot includes 95% confidence intervals that provide insight into the noise in observations and the uncertainty in model predictions. A horizontal, flat line of predictions indicates that the model has not picked up on sufficient signal in the data, and instead is just predicting the mean.
Summary of model fits
R² (coefficient of determination) measures how well the model predicts each metric. Higher values indicate better model fit. Metrics with R² >= 0.1 are highlighted in green.
Generation Strategy Graph
GenerationStrategy: Center+Sobol+MBM:fast Visualize the structure of a GenerationStrategy as a directed graph. Each node represents a GenerationNode in the strategy, and edges represent transitions between nodes based on TransitionCriterion. Edge labels show the criterion class names that trigger the transition.
b'\n\n\n\n\n\nGenerationStrategy\n\n\n\nCenterOfSearchSpace\n\nCenterOfSearchSpace\n()\n\n\n\nSobol\n\nSobol\n\n\n\nCenterOfSearchSpace->Sobol\n\n\nAutoTransitionAfterGen\n\n\n\nMBM\n\nMBM\n(BoTorch)\n\n\n\nSobol->MBM\n\n\nMinTrials(5)\nMinTrials(2)\n\n\n\n'
Health Checks

Comprehensive health checks designed to identify potential issues in the Ax experiment. These checks cover areas such as metric fetching, search space configuration, and candidate generation, with the aim of flagging areas where user intervention may be necessary to ensure the experiment's robustness and success.

Baseline Improvement Healthcheck
All 1 objective(s) improved over baseline. **Metric `fwhm` improved 79.37%** from `42.94` in arm `'0_0'` to `8.86` in arm `'27_0'`. **Note:** Using the first trial's first arm ('0_0') as the baseline since no explicit baseline was provided.
Metric Status Details
0 fwhm Improved **Metric `fwhm` improved 79.37%** from `42.94` in arm `'0_0'` to `8.86` in arm `'27_0'`.
agent.ax_client.summarize()
trial_index arm_name trial_status generation_node fwhm big_r toroid_focus:toroidMirror01:r
0 0 0_0 COMPLETED CenterOfSearchSpace 42.936815 152982.843276 1162.076570
1 1 1_0 COMPLETED Sobol 57.148699 164835.244175 719.265427
2 2 2_0 COMPLETED Sobol 17.213111 148586.104512 1164.781627
3 3 3_0 COMPLETED Sobol 13.283751 143000.561287 1004.001832
4 4 4_0 COMPLETED Sobol 87.835217 155506.731579 1512.094320
5 5 5_0 COMPLETED Sobol 63.259396 157007.518522 1141.313411
6 6 6_0 COMPLETED Sobol 12.643062 141381.656955 1618.099702
7 7 7_0 COMPLETED Sobol 21.839207 150834.387289 800.820935
8 8 8_0 COMPLETED Sobol 64.316255 162703.218338 1340.152996
9 9 9_0 COMPLETED Sobol 13.838444 161797.210909 971.398910
10 10 10_0 COMPLETED MBM 10.979559 142689.161193 1122.159068
11 11 11_0 COMPLETED MBM 16.789817 149465.508090 962.475131
12 12 12_0 COMPLETED MBM 60.460013 167982.843276 967.287443
13 13 13_0 COMPLETED MBM 18.636185 137982.843276 1507.522638
14 14 14_0 COMPLETED MBM 17.653740 157508.709995 896.371154
15 15 15_0 COMPLETED MBM 17.285183 159699.008757 806.643501
16 16 16_0 COMPLETED MBM 12.449500 142891.836849 1405.193679
17 17 17_0 COMPLETED MBM 18.901870 138259.516477 1047.820379
18 18 18_0 COMPLETED MBM 22.872811 157223.650794 662.076570
19 19 19_0 COMPLETED MBM 19.971134 146077.976641 1662.076570
20 20 20_0 COMPLETED MBM 21.957640 138158.211795 662.076570
21 21 21_0 COMPLETED MBM 10.938084 140254.913288 1272.932960
22 22 22_0 COMPLETED MBM 13.503781 144901.307217 1149.215589
23 23 23_0 COMPLETED MBM 19.222663 144113.334838 662.076570
24 24 24_0 COMPLETED MBM 17.573355 137982.843276 1662.076570
25 25 25_0 COMPLETED MBM 12.321519 141523.897386 1232.141072
26 26 26_0 COMPLETED MBM 10.395006 141301.177114 1328.516563
27 27 27_0 COMPLETED MBM 8.857221 141256.263750 1183.164817
28 28 28_0 COMPLETED MBM 18.081559 146354.890031 925.741591
29 29 29_0 COMPLETED MBM 62.528804 167982.843276 1662.076570
30 30 30_0 COMPLETED MBM 9.934243 142130.018125 1217.563831
31 31 31_0 COMPLETED MBM 9.850233 141281.909499 1471.509719
32 32 32_0 COMPLETED MBM 11.532145 141412.704689 1120.752333
33 33 33_0 COMPLETED MBM 15.783227 141178.454707 852.553947
34 34 34_0 COMPLETED MBM 52.188926 150858.200734 1662.076570
optimal_parameters, metrics, _, _ = agent.ax_client.get_best_parameterization(use_model_predictions=False)
optimal_parameters
{'big_r': 141256.26374972126,
 'toroid_focus:toroidMirror01:r': 1183.164817337457}
from bluesky.plans import list_scan

uid = RE(
    list_scan(
        [screen],
        toro_r,
        [optimal_parameters[toro_r.name]],
        toro_R,
        [optimal_parameters[toro_R.name]],
    )
)
image = tiled_client[uid[0]][f"primary/{screen.name}"].read().squeeze()
plt.imshow(image)
plt.colorbar()
plt.title("Optimized toroid Mirror Beam")
plt.show()