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
As a user of BlueAPI I would like to not have to specify my devices everytime I call a particular plan e.g.
definitialise_detector(det: Eiger):
...
Should be able to be called from BlueAPI with no arguments specified as BlueAPI should already have all the devices and be able to use its existing Eiger.
With ophyd-async calling connect only when required, the only [required] side effect is creating light weight Signals without backends. Any device that needs to e.g. read from the filesystem should do that on first connect.
I'd much rather have 3 or 4 than 2 or 5.
RE: 5 I really really want to avoid re-inventing the Finder: once we re-introduce the idea that you can get anything anywhere in your plan, the signature of every plan is degenerate, and it's a race to the bottom of not knowing what was available/required at the start of your plan and not able to pass any overrides so you simultaneously have N plans for the same scan with each of N devices, and none of them have the device as an argument...
RE: 3 it would give us a hook to ensure the device is connected too, at the start of the scan. But it also means there is an inconsistency between running the scan with blueapi and from a terminal.
With ophyd-async calling connect only when required, the only [required] side effect is creating light weight Signals without backends. Any device that needs to e.g. read from the filesystem should do that on first connect.
I still think doing this on import is bad:
Devices are going to be written by a number of people, including potentially scientists. I think it's unrealistic to enforce no work on initialisation (not just touching filesystem, it's more generally anything that we would ideally want to mock out) and to expect this to continue to be enforced over ~20 years rather than falling into the old pattern of just not doing testing
The consequence of factories now not being connected by default is a degradation of the jupyter notebook way of working. It is expected by a scientist that calling a factory will give them a device that is connected and is a gotcha to then have to call connect on it.
From discussion with @DominicOram and @DiamondJoseph:
We agree that (potential) import side effects are bad, so discourage 1. We want to encourage injecting all devices into plans rather than retrieving them halfway through, so discourage 5.
There is some disagreement over just how terrible a thing having tens of defaulted arguments for complex plans would be. It's messy, but explicit e.g.
@DiamondJoseph and I had previously envisioned inject only being used to specify per-beamline defaults, but @DominicOram is interested in using it to make plans reusable between beamlines, making 4. difficult as it ties a plan to a beamline.
We want to keep plan logic and device instantiation separate
Scientists can ignore a decorator more easily than a default argument
A decorator can also be used to signify that something is a plan that blueapi should export, however we should be careful not to reinvent the existing @bluesky.plan decorator.
We could have something like this, where we have a shared set of constants for device names...
# Devices@device_factory()defeiger() ->Eiger:
returnEiger(name=MY_EXPERIMENT_DEFINITION.main_detector)
# Plan@export(inject={"eiger": MY_EXPERIMENT_DEFINITION.main_detector}) # This should shout at you if there is no parameter called "eiger" on importdefmy_plan(eiger: Eiger) ->MsgGenerator:
...
Activity
DominicOram commentedon Oct 29, 2024
My personal preference is 3. I think it is more readable as "this is just a blueAPI thing I can ignore generally" and it is beamline independent.
DiamondJoseph commentedon Nov 5, 2024
I prefer 1; or some version of it that linting is happy with e.g.
With ophyd-async calling connect only when required, the only [required] side effect is creating light weight Signals without backends. Any device that needs to e.g. read from the filesystem should do that on first connect.
I'd much rather have 3 or 4 than 2 or 5.
RE: 5 I really really want to avoid re-inventing the Finder: once we re-introduce the idea that you can get anything anywhere in your plan, the signature of every plan is degenerate, and it's a race to the bottom of not knowing what was available/required at the start of your plan and not able to pass any overrides so you simultaneously have N plans for the same scan with each of N devices, and none of them have the device as an argument...
RE: 3 it would give us a hook to ensure the device is connected too, at the start of the scan. But it also means there is an inconsistency between running the scan with blueapi and from a terminal.
DominicOram commentedon Nov 5, 2024
I still think doing this on import is bad:
callumforrester commentedon Nov 14, 2024
From discussion with @DominicOram and @DiamondJoseph:
We agree that (potential) import side effects are bad, so discourage 1. We want to encourage injecting all devices into plans rather than retrieving them halfway through, so discourage 5.
There is some disagreement over just how terrible a thing having tens of defaulted arguments for complex plans would be. It's messy, but explicit e.g.
@DiamondJoseph and I had previously envisioned
injectonly being used to specify per-beamline defaults, but @DominicOram is interested in using it to make plans reusable between beamlines, making 4. difficult as it ties a plan to a beamline.The current, boilerplate-heavy solution would be:
We discussed using composites to satisfy this e.g.
callumforrester commentedon Nov 14, 2024
callumforrester commentedon Nov 14, 2024
We are favouring 3. because:
@bluesky.plandecorator.We could have something like this, where we have a shared set of constants for device names...
callumforrester commentedon Nov 14, 2024
Thinking about how a composite device would work:
...can we think of a nicer way?
Do we want something like this? Composite is defined as a device.
tpoliaw commentedon Jun 25, 2025
Now that (I think?) it is working with Pydantic 2, do we still need changes to the
injectmechanism or can this be left as it is?