Callbacks#

OptimizationCallbackRouter#

class blop.callbacks.OptimizationCallbackRouter(callbacks)[source]#

Bases: object

Routes documents from optimization runs to a list of callbacks.

Acts as a Bluesky callback that filters documents by run_key, forwarding only those from "optimize" or "sample_suggestions" runs to the registered callbacks.

The router holds a reference to the provided list, so external mutations (e.g. callbacks.append(cb)) take effect on the next run.

Parameters:
callbackslist[CallbackBase]

A mutable list of callback instances. The router reads from this list at the start of each matching run.

OptimizationLogger#

class blop.callbacks.logger.OptimizationLogger(console=None, **kwargs)[source]#

Bases: CallbackBase

A Bluesky callback for displaying optimization progress to the console.

This callback provides structured, styled console output during optimization runs using the rich library. It listens for documents from the optimize plan and displays:

  • A header panel with optimizer configuration at run start

  • A formatted table of parameter and outcome values for each iteration

  • A compact inline summary of outcome statistics after each iteration

  • A full summary statistics table at run completion

Notes

Multiple consecutive optimization runs will accumulate iteration counts and statistics.

When n_points > 1, each iteration is displayed as a multi-row table showing the batch of points suggested together by the optimizer, with NaN-padded entries (from incomplete batches) filtered out.

start(doc)[source]#

Process the start document from the Bluesky run.

Logs the optimization setup observed from metadata.

descriptor(doc)[source]#

Cache data keys and group by their source.

event(doc)[source]#

Process an event document from a Bluesky run.

Logs what occurred in this event along with running stats.

stop(doc)[source]#

Handle the stop document of a Bluesky run.

Prints summary statistics of what has been observed so far.