ophyd-async 0.7.0a1__py3-none-any.whl → 0.8.0a3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. ophyd_async/_version.py +2 -2
  2. ophyd_async/core/__init__.py +30 -9
  3. ophyd_async/core/_detector.py +5 -10
  4. ophyd_async/core/_device.py +146 -67
  5. ophyd_async/core/_device_filler.py +269 -0
  6. ophyd_async/core/_device_save_loader.py +6 -7
  7. ophyd_async/core/_mock_signal_backend.py +32 -40
  8. ophyd_async/core/_mock_signal_utils.py +22 -16
  9. ophyd_async/core/_protocol.py +28 -8
  10. ophyd_async/core/_readable.py +133 -134
  11. ophyd_async/core/_signal.py +140 -152
  12. ophyd_async/core/_signal_backend.py +131 -64
  13. ophyd_async/core/_soft_signal_backend.py +125 -194
  14. ophyd_async/core/_status.py +22 -6
  15. ophyd_async/core/_table.py +97 -100
  16. ophyd_async/core/_utils.py +79 -18
  17. ophyd_async/epics/adaravis/_aravis_controller.py +2 -2
  18. ophyd_async/epics/adaravis/_aravis_io.py +8 -6
  19. ophyd_async/epics/adcore/_core_io.py +5 -7
  20. ophyd_async/epics/adcore/_hdf_writer.py +2 -2
  21. ophyd_async/epics/adcore/_single_trigger.py +4 -9
  22. ophyd_async/epics/adcore/_utils.py +15 -10
  23. ophyd_async/epics/adkinetix/__init__.py +2 -1
  24. ophyd_async/epics/adkinetix/_kinetix_controller.py +6 -3
  25. ophyd_async/epics/adkinetix/_kinetix_io.py +4 -5
  26. ophyd_async/epics/adpilatus/_pilatus_controller.py +2 -2
  27. ophyd_async/epics/adpilatus/_pilatus_io.py +3 -4
  28. ophyd_async/epics/adsimdetector/_sim_controller.py +2 -2
  29. ophyd_async/epics/advimba/__init__.py +4 -1
  30. ophyd_async/epics/advimba/_vimba_controller.py +6 -3
  31. ophyd_async/epics/advimba/_vimba_io.py +8 -9
  32. ophyd_async/epics/core/__init__.py +26 -0
  33. ophyd_async/epics/core/_aioca.py +323 -0
  34. ophyd_async/epics/core/_epics_connector.py +53 -0
  35. ophyd_async/epics/core/_epics_device.py +13 -0
  36. ophyd_async/epics/core/_p4p.py +382 -0
  37. ophyd_async/epics/core/_pvi_connector.py +92 -0
  38. ophyd_async/epics/core/_signal.py +171 -0
  39. ophyd_async/epics/core/_util.py +61 -0
  40. ophyd_async/epics/demo/_mover.py +4 -5
  41. ophyd_async/epics/demo/_sensor.py +14 -13
  42. ophyd_async/epics/eiger/_eiger.py +1 -2
  43. ophyd_async/epics/eiger/_eiger_controller.py +1 -1
  44. ophyd_async/epics/eiger/_eiger_io.py +3 -5
  45. ophyd_async/epics/eiger/_odin_io.py +5 -5
  46. ophyd_async/epics/motor.py +4 -5
  47. ophyd_async/epics/signal.py +11 -0
  48. ophyd_async/fastcs/core.py +9 -0
  49. ophyd_async/fastcs/panda/__init__.py +4 -4
  50. ophyd_async/fastcs/panda/_block.py +23 -11
  51. ophyd_async/fastcs/panda/_control.py +3 -5
  52. ophyd_async/fastcs/panda/_hdf_panda.py +5 -19
  53. ophyd_async/fastcs/panda/_table.py +29 -51
  54. ophyd_async/fastcs/panda/_trigger.py +8 -8
  55. ophyd_async/fastcs/panda/_writer.py +4 -7
  56. ophyd_async/plan_stubs/_ensure_connected.py +3 -1
  57. ophyd_async/plan_stubs/_fly.py +2 -2
  58. ophyd_async/plan_stubs/_nd_attributes.py +5 -4
  59. ophyd_async/py.typed +0 -0
  60. ophyd_async/sim/demo/_pattern_detector/_pattern_detector_controller.py +1 -2
  61. ophyd_async/sim/demo/_sim_motor.py +3 -4
  62. ophyd_async/tango/__init__.py +2 -4
  63. ophyd_async/tango/base_devices/_base_device.py +76 -144
  64. ophyd_async/tango/demo/_counter.py +8 -18
  65. ophyd_async/tango/demo/_mover.py +5 -6
  66. ophyd_async/tango/signal/__init__.py +2 -4
  67. ophyd_async/tango/signal/_signal.py +29 -50
  68. ophyd_async/tango/signal/_tango_transport.py +38 -40
  69. {ophyd_async-0.7.0a1.dist-info → ophyd_async-0.8.0a3.dist-info}/METADATA +8 -12
  70. ophyd_async-0.8.0a3.dist-info/RECORD +112 -0
  71. {ophyd_async-0.7.0a1.dist-info → ophyd_async-0.8.0a3.dist-info}/WHEEL +1 -1
  72. ophyd_async/epics/pvi/__init__.py +0 -3
  73. ophyd_async/epics/pvi/_pvi.py +0 -338
  74. ophyd_async/epics/signal/__init__.py +0 -21
  75. ophyd_async/epics/signal/_aioca.py +0 -378
  76. ophyd_async/epics/signal/_common.py +0 -57
  77. ophyd_async/epics/signal/_epics_transport.py +0 -34
  78. ophyd_async/epics/signal/_p4p.py +0 -518
  79. ophyd_async/epics/signal/_signal.py +0 -114
  80. ophyd_async-0.7.0a1.dist-info/RECORD +0 -108
  81. {ophyd_async-0.7.0a1.dist-info → ophyd_async-0.8.0a3.dist-info}/LICENSE +0 -0
  82. {ophyd_async-0.7.0a1.dist-info → ophyd_async-0.8.0a3.dist-info}/entry_points.txt +0 -0
  83. {ophyd_async-0.7.0a1.dist-info → ophyd_async-0.8.0a3.dist-info}/top_level.txt +0 -0
@@ -1,6 +1,8 @@
1
1
  import warnings
2
- from collections.abc import Callable, Generator, Sequence
2
+ from collections.abc import Awaitable, Callable, Generator, Sequence
3
3
  from contextlib import contextmanager
4
+ from enum import Enum
5
+ from typing import Any, cast
4
6
 
5
7
  from bluesky.protocols import HasHints, Hints, Reading
6
8
  from event_model import DataKey
@@ -11,11 +13,61 @@ from ._signal import SignalR
11
13
  from ._status import AsyncStatus
12
14
  from ._utils import merge_gathered_dicts
13
15
 
14
- ReadableChild = AsyncReadable | AsyncConfigurable | AsyncStageable | HasHints
15
- ReadableChildWrapper = (
16
- Callable[[ReadableChild], ReadableChild]
17
- | type["ConfigSignal"]
18
- | type["HintedSignal"]
16
+
17
+ class StandardReadableFormat(Enum):
18
+ """Declare how a `Device` should contribute to the `StandardReadable` verbs."""
19
+
20
+ #: Detect which verbs the child supports and contribute to:
21
+ #:
22
+ #: - ``read()``, ``describe()`` if it is `bluesky.protocols.Readable`
23
+ #: - ``read_configuration()``, ``describe_configuration()`` if it is
24
+ #: `bluesky.protocols.Configurable`
25
+ #: - ``stage()``, ``unstage()`` if it is `bluesky.protocols.Stageable`
26
+ #: - ``hints`` if it `bluesky.protocols.HasHints`
27
+ CHILD = "CHILD"
28
+ #: Contribute the `Signal` value to ``read_configuration()`` and
29
+ #: ``describe_configuration()``
30
+ CONFIG_SIGNAL = "CONFIG_SIGNAL"
31
+ #: Contribute the monitored `Signal` value to ``read()`` and ``describe()``` and
32
+ #: put the signal name in ``hints``
33
+ HINTED_SIGNAL = "HINTED_SIGNAL"
34
+ #: Contribute the uncached `Signal` value to ``read()`` and ``describe()```
35
+ UNCACHED_SIGNAL = "UNCACHED_SIGNAL"
36
+ #: Contribute the uncached `Signal` value to ``read()`` and ``describe()``` and
37
+ #: put the signal name in ``hints``
38
+ HINTED_UNCACHED_SIGNAL = "HINTED_UNCACHED_SIGNAL"
39
+
40
+ def __call__(self, parent: Device, child: Device):
41
+ if not isinstance(parent, StandardReadable):
42
+ raise TypeError(f"Expected parent to be StandardReadable, got {parent}")
43
+ parent.add_readables([child], self)
44
+
45
+
46
+ # Back compat
47
+ class _WarningMatcher:
48
+ def __init__(self, name: str, target: StandardReadableFormat):
49
+ self._name = name
50
+ self._target = target
51
+
52
+ def __eq__(self, value: object) -> bool:
53
+ warnings.warn(
54
+ DeprecationWarning(
55
+ f"Use `StandardReadableFormat.{self._target.name}` "
56
+ f"instead of `{self._name}`"
57
+ ),
58
+ stacklevel=2,
59
+ )
60
+ return value == self._target
61
+
62
+
63
+ def _compat_format(name: str, target: StandardReadableFormat) -> StandardReadableFormat:
64
+ return cast(StandardReadableFormat, _WarningMatcher(name, target))
65
+
66
+
67
+ ConfigSignal = _compat_format("ConfigSignal", StandardReadableFormat.CONFIG_SIGNAL)
68
+ HintedSignal: Any = _compat_format("HintedSignal", StandardReadableFormat.HINTED_SIGNAL)
69
+ HintedSignal.uncached = _compat_format(
70
+ "HintedSignal.uncached", StandardReadableFormat.HINTED_UNCACHED_SIGNAL
19
71
  )
20
72
 
21
73
 
@@ -31,38 +83,13 @@ class StandardReadable(
31
83
 
32
84
  # These must be immutable types to avoid accidental sharing between
33
85
  # different instances of the class
34
- _readables: tuple[AsyncReadable, ...] = ()
35
- _configurables: tuple[AsyncConfigurable, ...] = ()
86
+ _describe_config_funcs: tuple[Callable[[], Awaitable[dict[str, DataKey]]], ...] = ()
87
+ _read_config_funcs: tuple[Callable[[], Awaitable[dict[str, Reading]]], ...] = ()
88
+ _describe_funcs: tuple[Callable[[], Awaitable[dict[str, DataKey]]], ...] = ()
89
+ _read_funcs: tuple[Callable[[], Awaitable[dict[str, Reading]]], ...] = ()
36
90
  _stageables: tuple[AsyncStageable, ...] = ()
37
91
  _has_hints: tuple[HasHints, ...] = ()
38
92
 
39
- def set_readable_signals(
40
- self,
41
- read: Sequence[SignalR] = (),
42
- config: Sequence[SignalR] = (),
43
- read_uncached: Sequence[SignalR] = (),
44
- ):
45
- """
46
- Parameters
47
- ----------
48
- read:
49
- Signals to make up :meth:`~StandardReadable.read`
50
- conf:
51
- Signals to make up :meth:`~StandardReadable.read_configuration`
52
- read_uncached:
53
- Signals to make up :meth:`~StandardReadable.read` that won't be cached
54
- """
55
- warnings.warn(
56
- DeprecationWarning(
57
- "Migrate to `add_children_as_readables` context manager or "
58
- "`add_readables` method"
59
- ),
60
- stacklevel=2,
61
- )
62
- self.add_readables(read, wrapper=HintedSignal)
63
- self.add_readables(config, wrapper=ConfigSignal)
64
- self.add_readables(read_uncached, wrapper=HintedSignal.uncached)
65
-
66
93
  @AsyncStatus.wrap
67
94
  async def stage(self) -> None:
68
95
  for sig in self._stageables:
@@ -75,19 +102,17 @@ class StandardReadable(
75
102
 
76
103
  async def describe_configuration(self) -> dict[str, DataKey]:
77
104
  return await merge_gathered_dicts(
78
- [sig.describe_configuration() for sig in self._configurables]
105
+ [func() for func in self._describe_config_funcs]
79
106
  )
80
107
 
81
108
  async def read_configuration(self) -> dict[str, Reading]:
82
- return await merge_gathered_dicts(
83
- [sig.read_configuration() for sig in self._configurables]
84
- )
109
+ return await merge_gathered_dicts([func() for func in self._read_config_funcs])
85
110
 
86
111
  async def describe(self) -> dict[str, DataKey]:
87
- return await merge_gathered_dicts([sig.describe() for sig in self._readables])
112
+ return await merge_gathered_dicts([func() for func in self._describe_funcs])
88
113
 
89
114
  async def read(self) -> dict[str, Reading]:
90
- return await merge_gathered_dicts([sig.read() for sig in self._readables])
115
+ return await merge_gathered_dicts([func() for func in self._read_funcs])
91
116
 
92
117
  @property
93
118
  def hints(self) -> Hints:
@@ -127,135 +152,109 @@ class StandardReadable(
127
152
  @contextmanager
128
153
  def add_children_as_readables(
129
154
  self,
130
- wrapper: ReadableChildWrapper | None = None,
155
+ format: StandardReadableFormat = StandardReadableFormat.CHILD,
131
156
  ) -> Generator[None, None, None]:
132
- """Context manager to wrap adding Devices
157
+ """Context manager that calls `add_readables` on child Devices added within.
133
158
 
134
- Add Devices to this class instance inside the Context Manager to automatically
135
- add them to the correct fields, based on the Device's interfaces.
136
-
137
- The provided wrapper class will be applied to all Devices and can be used to
138
- specify their behaviour.
139
-
140
- Parameters
141
- ----------
142
- wrapper:
143
- Wrapper class to apply to all Devices created inside the context manager.
144
-
145
- See Also
146
- --------
147
- :func:`~StandardReadable.add_readables`
148
- :class:`ConfigSignal`
149
- :class:`HintedSignal`
150
- :meth:`HintedSignal.uncached`
159
+ Scans ``self.children()`` on entry and exit to context manager, and calls
160
+ `add_readables` on any that are added with the provided
161
+ `StandardReadableFormat`.
151
162
  """
152
163
 
153
- dict_copy = self.__dict__.copy()
164
+ dict_copy = dict(self.children())
154
165
 
155
166
  yield
156
167
 
157
168
  # Set symmetric difference operator gives all newly added keys
158
- new_keys = dict_copy.keys() ^ self.__dict__.keys()
159
- new_values = [self.__dict__[key] for key in new_keys]
169
+ new_dict = dict(self.children())
170
+ new_keys = dict_copy.keys() ^ new_dict.keys()
171
+ new_values = [new_dict[key] for key in new_keys]
160
172
 
161
173
  flattened_values = []
162
174
  for value in new_values:
163
175
  if isinstance(value, DeviceVector):
164
- children = value.children()
165
- flattened_values.extend([x[1] for x in children])
176
+ flattened_values.extend(value.values())
166
177
  else:
167
178
  flattened_values.append(value)
168
179
 
169
180
  new_devices = list(filter(lambda x: isinstance(x, Device), flattened_values))
170
- self.add_readables(new_devices, wrapper)
181
+ self.add_readables(new_devices, format)
171
182
 
172
183
  def add_readables(
173
184
  self,
174
- devices: Sequence[ReadableChild],
175
- wrapper: ReadableChildWrapper | None = None,
185
+ devices: Sequence[Device],
186
+ format: StandardReadableFormat = StandardReadableFormat.CHILD,
176
187
  ) -> None:
177
- """Add the given devices to the lists of known Devices
188
+ """Add devices to contribute to various bluesky verbs.
178
189
 
179
- Add the provided Devices to the relevant fields, based on the Signal's
180
- interfaces.
190
+ Use output from the given devices to contribute to the verbs of the following
191
+ interfaces:
181
192
 
182
- The provided wrapper class will be applied to all Devices and can be used to
183
- specify their behaviour.
193
+ - `bluesky.protocols.Readable`
194
+ - `bluesky.protocols.Configurable`
195
+ - `bluesky.protocols.Stageable`
196
+ - `bluesky.protocols.HasHints`
184
197
 
185
198
  Parameters
186
199
  ----------
187
200
  devices:
188
201
  The devices to be added
189
- wrapper:
190
- Wrapper class to apply to all Devices created inside the context manager.
191
-
192
- See Also
193
- --------
194
- :func:`~StandardReadable.add_children_as_readables`
195
- :class:`ConfigSignal`
196
- :class:`HintedSignal`
197
- :meth:`HintedSignal.uncached`
202
+ format:
203
+ Determines which of the devices functions are added to which verb as per the
204
+ `StandardReadableFormat` documentation
198
205
  """
199
206
 
200
- for readable in devices:
201
- obj = readable
202
- if wrapper:
203
- obj = wrapper(readable)
204
-
205
- if isinstance(obj, AsyncReadable):
206
- self._readables += (obj,)
207
-
208
- if isinstance(obj, AsyncConfigurable):
209
- self._configurables += (obj,)
210
-
211
- if isinstance(obj, AsyncStageable):
212
- self._stageables += (obj,)
213
-
214
- if isinstance(obj, HasHints):
215
- self._has_hints += (obj,)
216
-
217
-
218
- class ConfigSignal(AsyncConfigurable):
219
- def __init__(self, signal: ReadableChild) -> None:
220
- assert isinstance(signal, SignalR), f"Expected signal, got {signal}"
207
+ for device in devices:
208
+ match format:
209
+ case StandardReadableFormat.CHILD:
210
+ if isinstance(device, AsyncConfigurable):
211
+ self._describe_config_funcs += (device.describe_configuration,)
212
+ self._read_config_funcs += (device.read_configuration,)
213
+ if isinstance(device, AsyncReadable):
214
+ self._describe_funcs += (device.describe,)
215
+ self._read_funcs += (device.read,)
216
+ if isinstance(device, AsyncStageable):
217
+ self._stageables += (device,)
218
+ if isinstance(device, HasHints):
219
+ self._has_hints += (device,)
220
+ case StandardReadableFormat.CONFIG_SIGNAL:
221
+ assert isinstance(device, SignalR), f"{device} is not a SignalR"
222
+ self._describe_config_funcs += (device.describe,)
223
+ self._read_config_funcs += (device.read,)
224
+ case StandardReadableFormat.HINTED_SIGNAL:
225
+ assert isinstance(device, SignalR), f"{device} is not a SignalR"
226
+ self._describe_funcs += (device.describe,)
227
+ self._read_funcs += (device.read,)
228
+ self._stageables += (device,)
229
+ self._has_hints += (_HintsFromName(device),)
230
+ case StandardReadableFormat.UNCACHED_SIGNAL:
231
+ assert isinstance(device, SignalR), f"{device} is not a SignalR"
232
+ self._describe_funcs += (device.describe,)
233
+ self._read_funcs += (_UncachedRead(device),)
234
+ case StandardReadableFormat.HINTED_UNCACHED_SIGNAL:
235
+ assert isinstance(device, SignalR), f"{device} is not a SignalR"
236
+ self._describe_funcs += (device.describe,)
237
+ self._read_funcs += (_UncachedRead(device),)
238
+ self._has_hints += (_HintsFromName(device),)
239
+
240
+
241
+ class _UncachedRead:
242
+ def __init__(self, signal: SignalR) -> None:
221
243
  self.signal = signal
222
244
 
223
- async def read_configuration(self) -> dict[str, Reading]:
224
- return await self.signal.read()
225
-
226
- async def describe_configuration(self) -> dict[str, DataKey]:
227
- return await self.signal.describe()
228
-
229
- @property
230
- def name(self) -> str:
231
- return self.signal.name
245
+ async def __call__(self) -> dict[str, Reading]:
246
+ return await self.signal.read(cached=False)
232
247
 
233
248
 
234
- class HintedSignal(HasHints, AsyncReadable):
235
- def __init__(self, signal: ReadableChild, allow_cache: bool = True) -> None:
236
- assert isinstance(signal, SignalR), f"Expected signal, got {signal}"
237
- self.signal = signal
238
- self.cached = None if allow_cache else allow_cache
239
- if allow_cache:
240
- self.stage = signal.stage
241
- self.unstage = signal.unstage
242
-
243
- async def read(self) -> dict[str, Reading]:
244
- return await self.signal.read(cached=self.cached)
245
-
246
- async def describe(self) -> dict[str, DataKey]:
247
- return await self.signal.describe()
249
+ class _HintsFromName(HasHints):
250
+ def __init__(self, device: Device) -> None:
251
+ self.device = device
248
252
 
249
253
  @property
250
254
  def name(self) -> str:
251
- return self.signal.name
255
+ return self.device.name
252
256
 
253
257
  @property
254
258
  def hints(self) -> Hints:
255
- if self.signal.name == "":
256
- return {"fields": []}
257
- return {"fields": [self.signal.name]}
258
-
259
- @classmethod
260
- def uncached(cls, signal: ReadableChild) -> "HintedSignal":
261
- return cls(signal, allow_cache=False)
259
+ fields = [self.name] if self.name else []
260
+ return {"fields": fields}