-
Couldn't load subscription status.
- Fork 6
feat: Support for dataclasses as composite types #1242
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rtuck99
wants to merge
5
commits into
main
Choose a base branch
from
506_composite_devices_with_dataclasses
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+152
−25
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1162236
Support for dataclasses as composite types
rtuck99 42486d5
Update to documentation
rtuck99 7bac9fb
Fix unit test build with example code modules
rtuck99 27be0b5
Make code coverage happy
rtuck99 015ecae
Fix plan schema for composites
rtuck99 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import pydantic | ||
| from tests.unit_tests.code_examples.device_module import BimorphMirror | ||
|
|
||
|
|
||
| @pydantic.dataclasses.dataclass(config={"arbitrary_types_allowed": True}) | ||
| class MyDeviceComposite: | ||
| oav: BimorphMirror | ||
| # More devices here.... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| from bluesky.utils import MsgGenerator | ||
| from dodal.common import inject | ||
| from tests.unit_tests.code_examples.device_composite import MyDeviceComposite | ||
|
|
||
|
|
||
| def my_plan( | ||
| parameter_one: int, | ||
| parameter_two: str, | ||
| my_necessary_devices: MyDeviceComposite = inject(""), | ||
| ) -> MsgGenerator[None]: | ||
| # logic goes here | ||
| ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't agree that it is preferable- if you require overriding one device you must override the whole Composite.
I just think it's an alternative option that may be useful quite often, depending on how a specific beamline operates.
I'll look through the code change later, but I am admitting upfront that I am opinionated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. Perhaps I should rephrase that to reflect the difference between UDC and non-UDC use cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure it's a
UDCvs.non-UDCthing. It's just if you have loads of devices it's cleaner to use a composite. If you have a couple it's cleaner not toThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's number but flexibility
the json for the former if I wanted to scan theta/y instead of x/y:
{"xy": {"x": "theta", "y": "y"}}compared to the latter:
{"x": "theta"}The more devices I have in my BaseModel, the more verbose my plan signature would become if I don't use one, but the more duplicates I need to have in my JSON if I want to replace one of them.
If I'm always scanning x, y or I have multiple plans that all need x, y then a composite is neater. I'd prefer to define a specific device like a Stage to enforce a meaning to the relationship between x and y, but it's not always possible.
Or we support multiple levels of injection:
{"xy": {"x": "theta"}}Creating a new MyComposite with x=
theta, y=inject("y")which findsyto pass in as thexyargument?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The way that I see it, if you are writing a plan which is intended to be consumed directly by scientists, for commissioning or one-off scripts explicitly inject the individual devices in the parameters, since that provides more flexibility over device selection. But I think most of those will probably not be called via
blueapi.There may be a use case with blueapi for individual device injection for things such as UI components if there are multiple similar devices e.g. slits, mirrors etc. and we want to provide direct control / monitoring over them for commissioning purposes. (although currently this functionality is mainly provided by the EDM)
If you have a plan that is intended to support a single frequently invoked high-level plan that will be called from a client application such as the hyperion supervisor, or GDA, then it's better to have a composite, because you almost certainly don't want or need the flexibility to inject different devices - client applications probably don't want to have to know about a beamline's specific configuration or what the naming of devices is, they just want to run a plan with whatever experimental parameters it requires.
If there's a choice of different devices for some section of the plan, the plan probably has to do other things that are bespoke for each device. For example, on i03, we can run with the panda or the zebra, but the initialisation and tear down code is different for each, so there would be no benefit to injecting only one device or the other.