dora-rs 0.3.12__cp37-abi3-macosx_14_5_arm64.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.

Potentially problematic release.


This version of dora-rs might be problematic. Click here for more details.

dora/__init__.py ADDED
@@ -0,0 +1,42 @@
1
+ """
2
+ # dora-rs.
3
+
4
+ This is the dora python client for interacting with dora dataflow.
5
+ You can install it via:
6
+ ```bash
7
+ pip install dora-rs
8
+ ```.
9
+ """
10
+
11
+ from enum import Enum
12
+
13
+ from .dora import *
14
+ from .dora import (
15
+ Node,
16
+ Ros2Context,
17
+ Ros2Durability,
18
+ Ros2Liveliness,
19
+ Ros2Node,
20
+ Ros2NodeOptions,
21
+ Ros2Publisher,
22
+ Ros2QosPolicies,
23
+ Ros2Subscription,
24
+ Ros2Topic,
25
+ __author__,
26
+ __version__,
27
+ start_runtime,
28
+ )
29
+
30
+
31
+ class DoraStatus(Enum):
32
+ """Dora status to indicate if operator `on_input` loop should be stopped.
33
+
34
+ Args:
35
+ Enum (u8): Status signaling to dora operator to
36
+ stop or continue the operator.
37
+
38
+ """
39
+
40
+ CONTINUE = 0
41
+ STOP = 1
42
+ STOP_ALL = 2
dora/__init__.pyi ADDED
@@ -0,0 +1,335 @@
1
+ import typing
2
+
3
+ import pyarrow
4
+
5
+ import dora
6
+
7
+ @typing.final
8
+ class Enum:
9
+ """Generic enumeration.
10
+
11
+ Derive from this class to define new enumerations.
12
+ """
13
+
14
+ __members__: mappingproxy = ...
15
+
16
+ @typing.final
17
+ class Node:
18
+ """The custom node API lets you integrate `dora` into your application.
19
+
20
+ It allows you to retrieve input and send output in any fashion you want.
21
+
22
+ Use with:
23
+
24
+ ```python
25
+ from dora import Node
26
+
27
+ node = Node()
28
+ ```
29
+ """
30
+
31
+ def __init__(self, node_id: str=None) -> None:
32
+ """Use the custom node API to embed `dora` into your application.
33
+
34
+ It allows you to retrieve input and send output in any fashion you want.
35
+
36
+ Use with:
37
+
38
+ ```python
39
+ from dora import Node
40
+
41
+ node = Node()
42
+ ```
43
+ """
44
+
45
+ def dataflow_descriptor(self) -> dict:
46
+ """Return the full dataflow descriptor that this node is part of.
47
+
48
+ This method returns the parsed dataflow YAML file.
49
+ """
50
+
51
+ def dataflow_id(self) -> str:
52
+ """Return the dataflow id."""
53
+
54
+ def merge_external_events(self, subscription: dora.Ros2Subscription) -> None:
55
+ """Merge an external event stream with dora main loop.
56
+
57
+ This currently only work with ROS2.
58
+ """
59
+
60
+ def next(self, timeout: float=None) -> dict:
61
+ """`.next()` gives you the next input that the node has received.
62
+
63
+ It blocks until the next event becomes available.
64
+ You can use timeout in seconds to return if no input is available.
65
+ It will return `None` when all senders has been dropped.
66
+
67
+ ```python
68
+ event = node.next()
69
+ ```
70
+
71
+ You can also iterate over the event stream with a loop
72
+
73
+ ```python
74
+ for event in node:
75
+ match event["type"]:
76
+ case "INPUT":
77
+ match event["id"]:
78
+ case "image":
79
+ ```
80
+ """
81
+
82
+ def send_output(self, output_id: str, data: pyarrow.Array, metadata: dict=None) -> None:
83
+ """`send_output` send data from the node.
84
+
85
+ ```python
86
+ Args:
87
+ output_id: str,
88
+ data: pyarrow.Array,
89
+ metadata: Option[Dict],
90
+ ```
91
+
92
+ ex:
93
+
94
+ ```python
95
+ node.send_output("string", b"string", {"open_telemetry_context": "7632e76"})
96
+ ```
97
+ """
98
+
99
+ def __iter__(self) -> typing.Any:
100
+ """Implement iter(self)."""
101
+
102
+ def __next__(self) -> typing.Any:
103
+ """Implement next(self)."""
104
+
105
+ @typing.final
106
+ class Ros2Context:
107
+ """ROS2 Context holding all messages definition for receiving and sending messages to ROS2.
108
+
109
+ By default, Ros2Context will use env `AMENT_PREFIX_PATH` to search for message definition.
110
+
111
+ AMENT_PREFIX_PATH folder structure should be the following:
112
+
113
+ - For messages: <namespace>/msg/<name>.msg
114
+ - For services: <namespace>/srv/<name>.srv
115
+
116
+ You can also use `ros_paths` if you don't want to use env variable.
117
+
118
+ warning::
119
+ dora Ros2 bridge functionality is considered **unstable**. It may be changed
120
+ at any point without it being considered a breaking change.
121
+
122
+ ```python
123
+ context = Ros2Context()
124
+ ```
125
+ """
126
+
127
+ def __init__(self, ros_paths: list[str]=None) -> None:
128
+ """ROS2 Context holding all messages definition for receiving and sending messages to ROS2.
129
+
130
+ By default, Ros2Context will use env `AMENT_PREFIX_PATH` to search for message definition.
131
+
132
+ AMENT_PREFIX_PATH folder structure should be the following:
133
+
134
+ - For messages: <namespace>/msg/<name>.msg
135
+ - For services: <namespace>/srv/<name>.srv
136
+
137
+ You can also use `ros_paths` if you don't want to use env variable.
138
+
139
+ warning::
140
+ dora Ros2 bridge functionality is considered **unstable**. It may be changed
141
+ at any point without it being considered a breaking change.
142
+
143
+ ```python
144
+ context = Ros2Context()
145
+ ```
146
+ """
147
+
148
+ def new_node(self, name: str, namespace: str, options: dora.Ros2NodeOptions) -> dora.Ros2Node:
149
+ """Create a new ROS2 node.
150
+
151
+ ```python
152
+ ros2_node = ros2_context.new_node(
153
+ "turtle_teleop",
154
+ "/ros2_demo",
155
+ Ros2NodeOptions(rosout=True),
156
+ )
157
+ ```
158
+
159
+ warning::
160
+ dora Ros2 bridge functionality is considered **unstable**. It may be changed
161
+ at any point without it being considered a breaking change.
162
+ """
163
+
164
+ @typing.final
165
+ class Ros2Durability:
166
+ """DDS 2.2.3.4 DURABILITY."""
167
+
168
+ def __eq__(self, value: object) -> bool:
169
+ """Return self==value."""
170
+
171
+ def __ge__(self, value: typing.Any) -> bool:
172
+ """Return self>=value."""
173
+
174
+ def __gt__(self, value: typing.Any) -> bool:
175
+ """Return self>value."""
176
+
177
+ def __int__(self) -> None:
178
+ """int(self)."""
179
+
180
+ def __le__(self, value: typing.Any) -> bool:
181
+ """Return self<=value."""
182
+
183
+ def __lt__(self, value: typing.Any) -> bool:
184
+ """Return self<value."""
185
+
186
+ def __ne__(self, value: object) -> bool:
187
+ """Return self!=value."""
188
+
189
+ Persistent: Ros2Durability = ...
190
+ Transient: Ros2Durability = ...
191
+ TransientLocal: Ros2Durability = ...
192
+ Volatile: Ros2Durability = ...
193
+
194
+ @typing.final
195
+ class Ros2Liveliness:
196
+ """DDS 2.2.3.11 LIVELINESS."""
197
+
198
+ def __eq__(self, value: object) -> bool:
199
+ """Return self==value."""
200
+
201
+ def __ge__(self, value: typing.Any) -> bool:
202
+ """Return self>=value."""
203
+
204
+ def __gt__(self, value: typing.Any) -> bool:
205
+ """Return self>value."""
206
+
207
+ def __int__(self) -> None:
208
+ """int(self)."""
209
+
210
+ def __le__(self, value: typing.Any) -> bool:
211
+ """Return self<=value."""
212
+
213
+ def __lt__(self, value: typing.Any) -> bool:
214
+ """Return self<value."""
215
+
216
+ def __ne__(self, value: object) -> bool:
217
+ """Return self!=value."""
218
+
219
+ Automatic: Ros2Liveliness = ...
220
+ ManualByParticipant: Ros2Liveliness = ...
221
+ ManualByTopic: Ros2Liveliness = ...
222
+
223
+ @typing.final
224
+ class Ros2Node:
225
+ """ROS2 Node.
226
+
227
+ warnings::
228
+ - dora Ros2 bridge functionality is considered **unstable**. It may be changed
229
+ at any point without it being considered a breaking change.
230
+ - There's a known issue about ROS2 nodes not being discoverable by ROS2
231
+ See: https://github.com/jhelovuo/ros2-client/issues/4
232
+ """
233
+
234
+ def create_publisher(self, topic: dora.Ros2Topic, qos: dora.Ros2QosPolicies=None) -> dora.Ros2Publisher:
235
+ """Create a ROS2 publisher.
236
+
237
+ ```python
238
+ pose_publisher = ros2_node.create_publisher(turtle_pose_topic)
239
+ ```
240
+ warnings:
241
+ - dora Ros2 bridge functionality is considered **unstable**. It may be changed
242
+ at any point without it being considered a breaking change.
243
+ """
244
+
245
+ def create_subscription(self, topic: dora.Ros2Topic, qos: dora.Ros2QosPolicies=None) -> dora.Ros2Subscription:
246
+ """Create a ROS2 subscription.
247
+
248
+ ```python
249
+ pose_reader = ros2_node.create_subscription(turtle_pose_topic)
250
+ ```
251
+
252
+ Warnings:
253
+ - dora Ros2 bridge functionality is considered **unstable**. It may be changed
254
+ at any point without it being considered a breaking change.
255
+
256
+ """
257
+
258
+ def create_topic(self, name: str, message_type: str, qos: dora.Ros2QosPolicies) -> dora.Ros2Topic:
259
+ """Create a ROS2 topic to connect to.
260
+
261
+ ```python
262
+ turtle_twist_topic = ros2_node.create_topic(
263
+ "/turtle1/cmd_vel", "geometry_msgs/Twist", topic_qos
264
+ )
265
+ ```
266
+ """
267
+
268
+ @typing.final
269
+ class Ros2NodeOptions:
270
+ """ROS2 Node Options."""
271
+
272
+ def __init__(self, rosout: bool=None) -> None:
273
+ """ROS2 Node Options."""
274
+
275
+ @typing.final
276
+ class Ros2Publisher:
277
+ """ROS2 Publisher.
278
+
279
+ Warnings:
280
+ - dora Ros2 bridge functionality is considered **unstable**. It may be changed
281
+ at any point without it being considered a breaking change.
282
+
283
+ """
284
+
285
+ def publish(self, data: pyarrow.Array) -> None:
286
+ """Publish a message into ROS2 topic.
287
+
288
+ Remember that the data format should respect the structure of the ROS2 message using an arrow Structure.
289
+
290
+ ex:
291
+ ```python
292
+ gripper_command.publish(
293
+ pa.array(
294
+ [
295
+ {
296
+ "name": "gripper",
297
+ "cmd": np.float32(5),
298
+ }
299
+ ]
300
+ ),
301
+ )
302
+ ```
303
+ """
304
+
305
+ @typing.final
306
+ class Ros2QosPolicies:
307
+ """ROS2 QoS Policy."""
308
+
309
+ def __init__(self, durability: dora.Ros2Durability=None, liveliness: dora.Ros2Liveliness=None, reliable: bool=None, keep_all: bool=None, lease_duration: float=None, max_blocking_time: float=None, keep_last: int=None) -> dora.Ros2QoSPolicies:
310
+ """ROS2 QoS Policy."""
311
+
312
+ @typing.final
313
+ class Ros2Subscription:
314
+ """ROS2 Subscription.
315
+
316
+ Warnings:
317
+ - dora Ros2 bridge functionality is considered **unstable**. It may be changed
318
+ at any point without it being considered a breaking change.
319
+
320
+ """
321
+
322
+ def next(self):...
323
+
324
+ @typing.final
325
+ class Ros2Topic:
326
+ """ROS2 Topic.
327
+
328
+ Warnings:
329
+ - dora Ros2 bridge functionality is considered **unstable**. It may be changed
330
+ at any point without it being considered a breaking change.
331
+
332
+ """
333
+
334
+ def start_runtime() -> None:
335
+ """Start a runtime for Operators."""
dora/cuda.py ADDED
@@ -0,0 +1,94 @@
1
+ """TODO: Add docstring."""
2
+
3
+ import pyarrow as pa
4
+
5
+ # Make sure to install torch with cuda
6
+ import torch
7
+ from numba.cuda import to_device
8
+
9
+ # Make sure to install numba with cuda
10
+ from numba.cuda.cudadrv.devicearray import DeviceNDArray
11
+ from numba.cuda.cudadrv.devices import get_context
12
+ from numba.cuda.cudadrv.driver import IpcHandle
13
+
14
+
15
+ import json
16
+
17
+ from contextlib import contextmanager
18
+ from typing import ContextManager
19
+
20
+
21
+ def torch_to_ipc_buffer(tensor: torch.TensorType) -> tuple[pa.array, dict]:
22
+ """Convert a Pytorch tensor into a pyarrow buffer containing the IPC handle
23
+ and its metadata.
24
+
25
+ Example Use:
26
+ ```python
27
+ torch_tensor = torch.tensor(random_data, dtype=torch.int64, device="cuda")
28
+ ipc_buffer, metadata = torch_to_ipc_buffer(torch_tensor)
29
+ node.send_output("latency", ipc_buffer, metadata)
30
+ ```
31
+ """
32
+ device_arr = to_device(tensor)
33
+ ipch = get_context().get_ipc_handle(device_arr.gpu_data)
34
+ _, handle, size, source_info, offset = ipch.__reduce__()[1]
35
+ metadata = {
36
+ "shape": device_arr.shape,
37
+ "strides": device_arr.strides,
38
+ "dtype": device_arr.dtype.str,
39
+ "size": size,
40
+ "offset": offset,
41
+ "source_info": json.dumps(source_info),
42
+ }
43
+ return pa.array(handle, pa.int8()), metadata
44
+
45
+
46
+ def ipc_buffer_to_ipc_handle(handle_buffer: pa.array, metadata: dict) -> IpcHandle:
47
+ """Convert a buffer containing a serialized handler into cuda IPC Handle.
48
+
49
+ example use:
50
+ ```python
51
+ from dora.cuda import ipc_buffer_to_ipc_handle, open_ipc_handle
52
+
53
+ event = node.next()
54
+
55
+ ipc_handle = ipc_buffer_to_ipc_handle(event["value"], event["metadata"])
56
+ with open_ipc_handle(ipc_handle, event["metadata"]) as tensor:
57
+ pass
58
+ ```
59
+ """
60
+ handle = handle_buffer.to_pylist()
61
+ return IpcHandle._rebuild(
62
+ handle,
63
+ metadata["size"],
64
+ json.loads(metadata["source_info"]),
65
+ metadata["offset"],
66
+ )
67
+
68
+
69
+ @contextmanager
70
+ def open_ipc_handle(
71
+ ipc_handle: IpcHandle, metadata: dict
72
+ ) -> ContextManager[torch.TensorType]:
73
+ """Open a CUDA IPC handle and return a Pytorch tensor.
74
+
75
+ example use:
76
+ ```python
77
+ from dora.cuda import ipc_buffer_to_ipc_handle, open_ipc_handle
78
+
79
+ event = node.next()
80
+
81
+ ipc_handle = ipc_buffer_to_ipc_handle(event["value"], event["metadata"])
82
+ with open_ipc_handle(ipc_handle, event["metadata"]) as tensor:
83
+ pass
84
+ ```
85
+ """
86
+ shape = metadata["shape"]
87
+ strides = metadata["strides"]
88
+ dtype = metadata["dtype"]
89
+ try:
90
+ buffer = ipc_handle.open(get_context())
91
+ device_arr = DeviceNDArray(shape, strides, dtype, gpu_data=buffer)
92
+ yield torch.as_tensor(device_arr, device="cuda")
93
+ finally:
94
+ ipc_handle.close()
dora/dora.abi3.so ADDED
Binary file
@@ -0,0 +1,30 @@
1
+ Metadata-Version: 2.4
2
+ Name: dora-rs
3
+ Version: 0.3.12
4
+ Requires-Dist: pyarrow
5
+ Summary: `dora` goal is to be a low latency, composable, and distributed data flow.
6
+ License: MIT
7
+ Requires-Python: >=3.7
8
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
9
+ Project-URL: Source Code, https://github.com/dora-rs/dora/
10
+
11
+ This crate corresponds to the Node API for Dora.
12
+
13
+ ## Building
14
+
15
+ To build the Python module for development:
16
+
17
+ ```bash
18
+ uv venv --seed -p 3.11
19
+ uv pip install -e .
20
+ ```
21
+
22
+ ## Type hinting
23
+
24
+ Type hinting requires to run a second step
25
+
26
+ ```bash
27
+ python generate_stubs.py dora dora/__init__.pyi
28
+ maturin develop
29
+ ```
30
+
@@ -0,0 +1,7 @@
1
+ dora/__init__.py,sha256=mogA09uYFBIwnBnnMfeQtD52ZJbVbWmWo1h70GZj2aU,709
2
+ dora/__init__.pyi,sha256=-jnLcWmFIi8ygYv44-VeYmq4e4I9a5zBHdz5q2Kae-E,9148
3
+ dora/cuda.py,sha256=tsp76SLAeR1gOXoQTTMv4oVHFoSzkXeevEQG41U9xFU,2736
4
+ dora/dora.abi3.so,sha256=NQxlWApQUyX8Vcsnp-b9e94OvIJRqbFeqkUOWOAcn8w,42400832
5
+ dora_rs-0.3.12.dist-info/METADATA,sha256=2Qkm4dNw_2tbfmDk1fxY8l73P33gVA2VtxVZWPTPtjU,625
6
+ dora_rs-0.3.12.dist-info/WHEEL,sha256=_L8nY6bR6hMZmGooZOPKShAbqQfdn4XB7b1iH-rupRI,102
7
+ dora_rs-0.3.12.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: maturin (1.9.0)
3
+ Root-Is-Purelib: false
4
+ Tag: cp37-abi3-macosx_14_5_arm64