You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support scanspec deserialization in plans with pydantic #118
That way, when the plan parameters are send in JSON form, they can be parsed and validated by pydantic and we don't have to worry. However, what happens when your plan doesn't take a simple dictionary, list or primitive? What happens if it takes, say, a detector as an argument?
defmy_plan(a: int, b: Readable) ->Plan:
...
We don't want to pass the whole Ophyd object as JSON because it has state. We need to pass a reference to it that we know the worker understands. At the moment we pass its name according to the worker's BlueskyContext, so we want some intermediary process to perform that lookup when needed. Before pydantic we used apischema, which had an ideal feature for this called conversions.
I have written a similar feature of blueapi to work with pydantic called type validators: source tests
so that our dynamically generated pydantic model can look roughly like this:
Activity
callumforrester commentedon Apr 19, 2023
Some background:
The bluesky worker takes the parameters of a plan and internally creates a pydantic model for future validation e.g.
That way, when the plan parameters are send in JSON form, they can be parsed and validated by pydantic and we don't have to worry. However, what happens when your plan doesn't take a simple dictionary, list or primitive? What happens if it takes, say, a detector as an argument?
We don't want to pass the whole Ophyd object as JSON because it has state. We need to pass a reference to it that we know the worker understands. At the moment we pass its name according to the worker's
BlueskyContext, so we want some intermediary process to perform that lookup when needed. Before pydantic we used apischema, which had an ideal feature for this called conversions.I have written a similar feature of blueapi to work with pydantic called type validators:
source
tests
so that our dynamically generated pydantic model can look roughly like this:
Which is all well and good, but what about the
Readabletype being placed at various type levels? For example:The code also copes with all of the above, as seen in the tests. The only thing left to do is make it work with scanspecs.
The following already works
In the plan, you can access a scanspec object where the axes are strings, which is helpful, but ideally you want them to be motors, so we need
This is the last remaining case.