Protocols for Optimization#
Bluesky Adaptive provides a set of protocols which enable users to define their own optimization workflows. These protocols are designed to be compatible with the Bluesky ecosystem, and are therefore compatible with the Bluesky RunEngine.
There are three main protocols:
bluesky_adaptive.protocols.Optimizer: A protocol for defining an optimizer. How to suggest points to evaluate and ingest outcomes to inform the optimization.bluesky_adaptive.protocols.EvaluationFunction: A protocol for transforming acquired data into measurable outcomes.bluesky_adaptive.protocols.AcquisitionPlan: An optional protocol for defining an acquisition plan. I.e. how to acquire data from the beamline.
The bluesky_adaptive.protocols.OptimizationProblem encapsulates all of these components into an immutable structure that can be used with specific optimization-focused
Bluesky plans. Immutability is important to ensure that the optimization problem is not modified after it has been created or used!
Note
For a full API reference, see Protocols.
Data Flow#
The data flow for a typical optimization workflow is as follows:
The optimizer suggests a sequence of mappings describing points to evaluate. When suggestions include
_idvalues used by Bluesky Adaptive optimization plans, those values must be unique within a batch and hashable.The acquisition plan acquires data and returns a uid.
Bluesky Adaptive passes that uid unchanged to the evaluation function, which transforms the acquired data into a sequence of outcome mappings. The suggestion sequence passed to the evaluator is optimizer-provided, not necessarily acquisition-ordered.
The optimizer ingests the outcomes to inform future suggestions.
The Bluesky RunEngine is used to execute each optimization workflow step using bluesky_adaptive.plans.optimize() and bluesky_adaptive.plans.optimize_step().
These plans are compatible with any NamedMovable or Flyable as a bluesky_adaptive.protocols.Actuator as well as Readable and Collectable as a bluesky_adaptive.protocols.Sensor. All of these are Bluesky protocols. For example, Ophyd signals can be used directly with Bluesky Adaptive since they implement both the NamedMovable and Readable protocols.
Furthermore, fly-scanning acquisition plans are supported with a custom bluesky_adaptive.protocols.AcquisitionPlan that uses actuators and sensors that implement the Flyable and Collectable protocols, respectively.
For more information on the differences between step-scanning and fly-scanning in Bluesky, see the explanation in ophyd-async.
Bluesky Adaptive optimizers and acquisition plans#
This protocol design allows you to pick and choose only the components you care about with regard to your optimization workflow. While Bluesky Adaptive provides a default optimizer and acquisition plan, you are free to implement your own!
Bluesky Adaptive provides built-in optimizers for common beamline optimization use cases, such as Bayesian optimization with Ax.
Similarly, Bluesky Adaptive provides bluesky_adaptive.plans.default_acquire() for run-owning acquisitions and bluesky_adaptive.plan_stubs.list_scan_in_run() for acquisition inside one optimization run.