Evaluation#
per_suggestion#
- bluesky_adaptive.evaluation.per_suggestion(evaluate, fetch)[source]#
Build an evaluation function from a function of one suggestion’s data.
The evaluation function applies
evaluateto each value offetch(uid)and sets the outcome’s"_id"to its key.- Parameters:
- evaluateCallable[[_TData], Mapping[str, Any]]
Returns the outcome of one suggestion’s data.
- fetchCallable[[TUid], Mapping[Any, _TData]]
Returns each suggestion’s data keyed by suggestion ID, e.g.
RunEventBuffer.pop.
- Returns:
- EvaluationFunction[TUid]
The evaluation function.
Examples
>>> from bluesky_adaptive.evaluation import per_suggestion >>> def score(data): ... return {"objective": 10 * data["x"]} >>> evaluation_function = per_suggestion(score, lambda uid: {"a": {"x": 1.0}, "b": {"x": 2.0}}) >>> evaluation_function("run-uid", []) [{'objective': 10.0, '_id': 'a'}, {'objective': 20.0, '_id': 'b'}]
RunEventBuffer#
- class bluesky_adaptive.evaluation.documents.RunEventBuffer[source]#
Bases:
CallbackBaseBuffer the
"primary"event data of acquisition runs by suggestion ID.Subscribe with
RE.subscribe(buffer)and passpop()toper_suggestion(). Buffers runs that recordstart["bluesky-adaptive"]["acquisition_order"], such as fromdefault_acquire(), pairing the n-th event with the n-th suggestion ID.- pop(uid)[source]#
Remove a buffered run and return its event data keyed by suggestion ID.
- Parameters:
- uidstr
Run UID returned by the acquisition plan.
- Returns:
- dict[Hashable, dict[str, Any]]
Event data keyed by suggestion ID, in acquisition order.
- Raises:
- KeyError
If the run is not buffered.
- ValueError
If the number of
"primary"events differs from the number of suggestion IDs.
TiledRunPoller#
- class bluesky_adaptive.evaluation.tiled.TiledRunPoller(client, *, poll_interval=0.5, timeout=60.0)[source]#
Bases:
objectPoll Tiled for a stopped acquisition run and return its
"primary"data by suggestion ID.Pass an instance to
per_suggestion(). Every call polls Tiled until the run has a stop document, so the run’s documents may reach Tiled after the acquisition plan returns, e.g. through a separateTiledWriterservice. Reads runs that recordstart["bluesky-adaptive"]["acquisition_order"], such as fromdefault_acquire(), pairing the n-th"primary"row with the n-th suggestion ID.- Parameters:
- clientContainer
Tiled container keyed by run UID that a
TiledWriterwrites to, e.g.tiled.client.from_uri(...)or aCatalogOfBlueskyRuns.- poll_intervalfloat, optional
Seconds between polls. Default is 0.5.
- timeoutfloat | None, optional
Seconds to wait for the run’s stop document before raising
TimeoutError, orNoneto wait indefinitely. Default is 60.
- Raises:
- ValueError
If
poll_intervalis not positive ortimeoutis negative.
- __call__(uid)[source]#
Wait for a run to stop and return its
"primary"data keyed by suggestion ID.- Parameters:
- uidstr
Run UID returned by the acquisition plan.
- Returns:
- dict[Hashable, dict[str, Any]]
Each
"primary"row as a mapping of data key to value, keyed by suggestion ID in acquisition order.
- Raises:
- TimeoutError
If the run has no stop document in Tiled within
timeoutseconds.- KeyError
If the run does not record its acquisition order.
- ValueError
If the number of
"primary"rows differs from the number of suggestion IDs.