Repository navigation
added Exception handling for devices - #550
Conversation
| devices = make_all_devices(fake_beamline) | ||
| assert not devices | ||
| assert not devices[0] | ||
| for exception in devices[1]: |
There was a problem hiding this comment.
I just had a look at this, the device fake_beamlines don't create exceptions so I will need to add some devices in the fake_beamline that raises a exception when it does not connect
There was a problem hiding this comment.
I think we need the following test cases:
- All devices pass
- All devices fail
- Mixture
If you have to make a few small fake beamline modules to cover those then go for it
callumforrester
left a comment
There was a problem hiding this comment.
LGTM! Just the tests and a couple of nitpicks
| devices = make_all_devices(i03, fake_with_ophyd_sim=True) | ||
| assert len(beamline_utils.ACTIVE_DEVICES) == len(devices.keys()) | ||
| assert len(beamline_utils.ACTIVE_DEVICES) == len(devices[0].keys()) |
There was a problem hiding this comment.
Nit: You could instead have
devices, exceptions = make_all_devices(i03, fake_with_ophyd_sim=True)
assert len(beamline_utils.ACTIVE_DEVICES) == len(devices.keys()) and len(exceptions) == 0...which is more readable, ditto for the other tests
| devices = make_all_devices(fake_beamline) | ||
| assert not devices | ||
| assert not devices[0] | ||
| for exception in devices[1]: |
There was a problem hiding this comment.
I think we need the following test cases:
- All devices pass
- All devices fail
- Mixture
If you have to make a few small fake beamline modules to cover those then go for it
| ) -> Dict[str, AnyDevice]: | ||
| ) -> Tuple[Dict[str, AnyDevice], Dict[str, Exception]]: | ||
| devices: dict[str, AnyDevice] = {} | ||
| exception_devices: dict[str, Exception] = {} |
There was a problem hiding this comment.
Nit: I think this makes more sense
| exception_devices: dict[str, Exception] = {} | |
| device_exceptions: dict[str, Exception] = {} |
| all_devices = { | ||
| device.name: device | ||
| for device in devices.values() | ||
| if not isinstance(device, Exception) |
There was a problem hiding this comment.
I don't think you need this line
dcf7556 to
2301b48
Compare
|
I'm taking over this PR in @ZohebShaikh's absence |
3aaad38 to
a2b7316
Compare
DiamondJoseph
left a comment
There was a problem hiding this comment.
Overall looks good just some edge cases and minor optimisations
| device | ||
| for device, device_dependencies in dependencies.items() | ||
| if device not in devices.keys() | ||
| if (device not in devices.keys() and device not in exceptions.keys()) |
There was a problem hiding this comment.
nit:
| if (device not in devices.keys() and device not in exceptions.keys()) | |
| if device not in devices and device not in exceptions |
a in dict == a in dict.keys()
| for _, device in make_all_devices(i03, fake_with_ophyd_sim=True).items() | ||
| ] | ||
| devices, _ = make_all_devices(i03, fake_with_ophyd_sim=True) | ||
| return [id(device) for _, device in devices.items()] |
There was a problem hiding this comment.
| return [id(device) for _, device in devices.items()] | |
| return [id(device) for device in devices.values()] |
The view on the values should be sorted the same as items() or keys() (order of insertion)
| devices, _ = make_all_devices(i03, fake_with_ophyd_sim=True) | ||
| return [id(device) for _, device in devices.items()] | ||
|
|
||
| ids_1 = [_make_devices_and_get_id()] |
There was a problem hiding this comment.
unrelated to the change, but this is list[list[id]] ?
There was a problem hiding this comment.
Yes, could be simplified, separate "good first issue"?
| @@ -0,0 +1,21 @@ | |||
| from bluesky.protocols import Readable | |||
There was a problem hiding this comment.
nit:
"rasie" in filename
| def device_a() -> Readable: | ||
| raise DestroyedError | ||
|
|
||
|
|
||
| def device_b() -> EpicsMotor: | ||
| raise DisconnectedError | ||
|
|
||
|
|
||
| def device_c() -> Cryo: | ||
| raise UnknownStatusFailure |
There was a problem hiding this comment.
Currently one Protocol, 2 ophyd devices, add an ophyd-async device class?
There was a problem hiding this comment.
Given that we are moving in the direction of exclusive ophyd-async (and therefore hopefully dodal's handling of ophyd devices can go away one day) I might just make it ophyd-async exclusively
There was a problem hiding this comment.
I'd prefer to see both tested until there are no ophyd devices, given they are different execution paths
There was a problem hiding this comment.
Have reverted cryostream
d74afb7 to
da4e441
Compare
DominicOram
left a comment
There was a problem hiding this comment.
Ta, I think mostly just need to fix the cli
| def make_all_devices( | ||
| module: str | ModuleType | None = None, include_skipped: bool = False, **kwargs | ||
| ) -> Dict[str, AnyDevice]: | ||
| ) -> Tuple[Dict[str, AnyDevice], Dict[str, Exception]]: |
There was a problem hiding this comment.
Must: This breaks connect with the error:
Traceback (most recent call last):
File "/scratch/ffv81422/hyperion/hyperion/.venv/bin/dodal", line 8, in <module>
sys.exit(main())
^^^^^^
File "/scratch/ffv81422/hyperion/hyperion/.venv/lib/python3.11/site-packages/click/core.py", line 1130, in __call__
return self.main(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/scratch/ffv81422/hyperion/hyperion/.venv/lib/python3.11/site-packages/click/core.py", line 1055, in main
rv = self.invoke(ctx)
^^^^^^^^^^^^^^^^
File "/scratch/ffv81422/hyperion/hyperion/.venv/lib/python3.11/site-packages/click/core.py", line 1657, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/scratch/ffv81422/hyperion/hyperion/.venv/lib/python3.11/site-packages/click/core.py", line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/scratch/ffv81422/hyperion/hyperion/.venv/lib/python3.11/site-packages/click/core.py", line 760, in invoke
return __callback(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/scratch/ffv81422/hyperion/dodal/src/dodal/cli.py", line 62, in connect
print("\n".join([f"\t{key}" for key in devices.keys()]))
^^^^^^^^^^^^
AttributeError: 'tuple' object has no attribute 'keys'There was a problem hiding this comment.
Good spot, concerning that this didn't make any tests fail, I'll investigate
da4e441 to
ff43ad9
Compare
91a0098 to
f23ec12
Compare
DominicOram
left a comment
There was a problem hiding this comment.
Great, thank you, happy for this to be merged now but if you want to do the dataclass change then that's fine too
f3f29dc to
b02f6c1
Compare
closes #444 With PR for dodal at DiamondLightSource/dodal#550 --------- Co-authored-by: Callum Forrester <[email protected]>
closes DiamondLightSource/blueapi#444
The main change in this PR is that
make_all_devicesreturns tuple of(all_devices, exception_devices)Instructions to reviewer on how to test:
device-resiliencein dodalpip install -e ../dodal[dev]pip install -e .[dev]Checks for reviewer