dora-rs 0.3.9rc2__cp37-abi3-musllinux_1_2_armv7l.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
+ This is the dora python client for interacting with dora dataflow.
4
+ You can install it via:
5
+ ```bash
6
+ pip install dora-rs
7
+ ```
8
+ """
9
+
10
+ from enum import Enum
11
+
12
+ from .dora import *
13
+ from .dora import (
14
+ Node,
15
+ Ros2Context,
16
+ Ros2Durability,
17
+ Ros2Liveliness,
18
+ Ros2Node,
19
+ Ros2NodeOptions,
20
+ Ros2Publisher,
21
+ Ros2QosPolicies,
22
+ Ros2Subscription,
23
+ Ros2Topic,
24
+ __author__,
25
+ __version__,
26
+ start_runtime,
27
+ )
28
+
29
+
30
+ class DoraStatus(Enum):
31
+ """Dora status to indicate if operator `on_input` loop
32
+ 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,311 @@
1
+ import dora
2
+ import pyarrow
3
+ import typing
4
+
5
+ @typing.final
6
+ class Enum:
7
+ """Generic enumeration.
8
+
9
+ Derive from this class to define new enumerations."""
10
+ __members__: mappingproxy = ...
11
+
12
+ @typing.final
13
+ class Node:
14
+ """The custom node API lets you integrate `dora` into your application.
15
+ It allows you to retrieve input and send output in any fashion you want.
16
+
17
+ Use with:
18
+
19
+ ```python
20
+ from dora import Node
21
+
22
+ node = Node()
23
+ ```"""
24
+
25
+ def __init__(self, node_id: str=None) -> None:
26
+ """The custom node API lets you integrate `dora` into your application.
27
+ It allows you to retrieve input and send output in any fashion you want.
28
+
29
+ Use with:
30
+
31
+ ```python
32
+ from dora import Node
33
+
34
+ node = Node()
35
+ ```"""
36
+
37
+ def dataflow_descriptor(self) -> dict:
38
+ """Returns the full dataflow descriptor that this node is part of.
39
+
40
+ This method returns the parsed dataflow YAML file."""
41
+
42
+ def dataflow_id(self) -> str:
43
+ """Returns the dataflow id."""
44
+
45
+ def merge_external_events(self, subscription: dora.Ros2Subscription) -> None:
46
+ """Merge an external event stream with dora main loop.
47
+ This currently only work with ROS2."""
48
+
49
+ def next(self, timeout: float=None) -> dict:
50
+ """`.next()` gives you the next input that the node has received.
51
+ It blocks until the next event becomes available.
52
+ You can use timeout in seconds to return if no input is available.
53
+ It will return `None` when all senders has been dropped.
54
+
55
+ ```python
56
+ event = node.next()
57
+ ```
58
+
59
+ You can also iterate over the event stream with a loop
60
+
61
+ ```python
62
+ for event in node:
63
+ match event["type"]:
64
+ case "INPUT":
65
+ match event["id"]:
66
+ case "image":
67
+ ```"""
68
+
69
+ def send_output(self, output_id: str, data: pyarrow.Array, metadata: dict=None) -> None:
70
+ """`send_output` send data from the node.
71
+
72
+ ```python
73
+ Args:
74
+ output_id: str,
75
+ data: pyarrow.Array,
76
+ metadata: Option[Dict],
77
+ ```
78
+
79
+ ex:
80
+
81
+ ```python
82
+ node.send_output("string", b"string", {"open_telemetry_context": "7632e76"})
83
+ ```"""
84
+
85
+ def __iter__(self) -> typing.Any:
86
+ """Implement iter(self)."""
87
+
88
+ def __next__(self) -> typing.Any:
89
+ """Implement next(self)."""
90
+
91
+ @typing.final
92
+ class Ros2Context:
93
+ """ROS2 Context holding all messages definition for receiving and sending messages to ROS2.
94
+
95
+ By default, Ros2Context will use env `AMENT_PREFIX_PATH` to search for message definition.
96
+
97
+ AMENT_PREFIX_PATH folder structure should be the following:
98
+
99
+ - For messages: <namespace>/msg/<name>.msg
100
+ - For services: <namespace>/srv/<name>.srv
101
+
102
+ You can also use `ros_paths` if you don't want to use env variable.
103
+
104
+ warning::
105
+ dora Ros2 bridge functionality is considered **unstable**. It may be changed
106
+ at any point without it being considered a breaking change.
107
+
108
+ ```python
109
+ context = Ros2Context()
110
+ ```"""
111
+
112
+ def __init__(self, ros_paths: typing.List[str]=None) -> None:
113
+ """ROS2 Context holding all messages definition for receiving and sending messages to ROS2.
114
+
115
+ By default, Ros2Context will use env `AMENT_PREFIX_PATH` to search for message definition.
116
+
117
+ AMENT_PREFIX_PATH folder structure should be the following:
118
+
119
+ - For messages: <namespace>/msg/<name>.msg
120
+ - For services: <namespace>/srv/<name>.srv
121
+
122
+ You can also use `ros_paths` if you don't want to use env variable.
123
+
124
+ warning::
125
+ dora Ros2 bridge functionality is considered **unstable**. It may be changed
126
+ at any point without it being considered a breaking change.
127
+
128
+ ```python
129
+ context = Ros2Context()
130
+ ```"""
131
+
132
+ def new_node(self, name: str, namespace: str, options: dora.Ros2NodeOptions) -> dora.Ros2Node:
133
+ """Create a new ROS2 node
134
+
135
+ ```python
136
+ ros2_node = ros2_context.new_node(
137
+ "turtle_teleop",
138
+ "/ros2_demo",
139
+ Ros2NodeOptions(rosout=True),
140
+ )
141
+ ```
142
+
143
+ warning::
144
+ dora Ros2 bridge functionality is considered **unstable**. It may be changed
145
+ at any point without it being considered a breaking change."""
146
+
147
+ @typing.final
148
+ class Ros2Durability:
149
+ """DDS 2.2.3.4 DURABILITY"""
150
+
151
+ def __eq__(self, value: typing.Any) -> bool:
152
+ """Return self==value."""
153
+
154
+ def __ge__(self, value: typing.Any) -> bool:
155
+ """Return self>=value."""
156
+
157
+ def __gt__(self, value: typing.Any) -> bool:
158
+ """Return self>value."""
159
+
160
+ def __int__(self) -> None:
161
+ """int(self)"""
162
+
163
+ def __le__(self, value: typing.Any) -> bool:
164
+ """Return self<=value."""
165
+
166
+ def __lt__(self, value: typing.Any) -> bool:
167
+ """Return self<value."""
168
+
169
+ def __ne__(self, value: typing.Any) -> bool:
170
+ """Return self!=value."""
171
+
172
+ def __repr__(self) -> str:
173
+ """Return repr(self)."""
174
+ Persistent: Ros2Durability = ...
175
+ Transient: Ros2Durability = ...
176
+ TransientLocal: Ros2Durability = ...
177
+ Volatile: Ros2Durability = ...
178
+
179
+ @typing.final
180
+ class Ros2Liveliness:
181
+ """DDS 2.2.3.11 LIVELINESS"""
182
+
183
+ def __eq__(self, value: typing.Any) -> bool:
184
+ """Return self==value."""
185
+
186
+ def __ge__(self, value: typing.Any) -> bool:
187
+ """Return self>=value."""
188
+
189
+ def __gt__(self, value: typing.Any) -> bool:
190
+ """Return self>value."""
191
+
192
+ def __int__(self) -> None:
193
+ """int(self)"""
194
+
195
+ def __le__(self, value: typing.Any) -> bool:
196
+ """Return self<=value."""
197
+
198
+ def __lt__(self, value: typing.Any) -> bool:
199
+ """Return self<value."""
200
+
201
+ def __ne__(self, value: typing.Any) -> bool:
202
+ """Return self!=value."""
203
+
204
+ def __repr__(self) -> str:
205
+ """Return repr(self)."""
206
+ Automatic: Ros2Liveliness = ...
207
+ ManualByParticipant: Ros2Liveliness = ...
208
+ ManualByTopic: Ros2Liveliness = ...
209
+
210
+ @typing.final
211
+ class Ros2Node:
212
+ """ROS2 Node
213
+
214
+ warnings::
215
+ - dora Ros2 bridge functionality is considered **unstable**. It may be changed
216
+ at any point without it being considered a breaking change.
217
+ - There's a known issue about ROS2 nodes not being discoverable by ROS2
218
+ See: https://github.com/jhelovuo/ros2-client/issues/4"""
219
+
220
+ def create_publisher(self, topic: dora.Ros2Topic, qos: dora.Ros2QosPolicies=None) -> dora.Ros2Publisher:
221
+ """Create a ROS2 publisher
222
+
223
+ ```python
224
+ pose_publisher = ros2_node.create_publisher(turtle_pose_topic)
225
+ ```
226
+ warnings:
227
+ - dora Ros2 bridge functionality is considered **unstable**. It may be changed
228
+ at any point without it being considered a breaking change."""
229
+
230
+ def create_subscription(self, topic: dora.Ros2Topic, qos: dora.Ros2QosPolicies=None) -> dora.Ros2Subscription:
231
+ """Create a ROS2 subscription
232
+
233
+ ```python
234
+ pose_reader = ros2_node.create_subscription(turtle_pose_topic)
235
+ ```
236
+
237
+ warnings:
238
+ - dora Ros2 bridge functionality is considered **unstable**. It may be changed
239
+ at any point without it being considered a breaking change."""
240
+
241
+ def create_topic(self, name: str, message_type: str, qos: dora.Ros2QosPolicies) -> dora.Ros2Topic:
242
+ """Create a ROS2 topic to connect to.
243
+
244
+ ```python
245
+ turtle_twist_topic = ros2_node.create_topic(
246
+ "/turtle1/cmd_vel", "geometry_msgs/Twist", topic_qos
247
+ )
248
+ ```"""
249
+
250
+ @typing.final
251
+ class Ros2NodeOptions:
252
+ """ROS2 Node Options"""
253
+
254
+ def __init__(self, rosout: bool=None) -> None:
255
+ """ROS2 Node Options"""
256
+
257
+ @typing.final
258
+ class Ros2Publisher:
259
+ """ROS2 Publisher
260
+
261
+ warnings:
262
+ - dora Ros2 bridge functionality is considered **unstable**. It may be changed
263
+ at any point without it being considered a breaking change."""
264
+
265
+ def publish(self, data: pyarrow.Array) -> None:
266
+ """Publish a message into ROS2 topic.
267
+
268
+ Remember that the data format should respect the structure of the ROS2 message using an arrow Structure.
269
+
270
+ ex:
271
+ ```python
272
+ gripper_command.publish(
273
+ pa.array(
274
+ [
275
+ {
276
+ "name": "gripper",
277
+ "cmd": np.float32(5),
278
+ }
279
+ ]
280
+ ),
281
+ )
282
+ ```"""
283
+
284
+ @typing.final
285
+ class Ros2QosPolicies:
286
+ """ROS2 QoS Policy"""
287
+
288
+ 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:
289
+ """ROS2 QoS Policy"""
290
+
291
+ @typing.final
292
+ class Ros2Subscription:
293
+ """ROS2 Subscription
294
+
295
+
296
+ warnings:
297
+ - dora Ros2 bridge functionality is considered **unstable**. It may be changed
298
+ at any point without it being considered a breaking change."""
299
+
300
+ def next(self):...
301
+
302
+ @typing.final
303
+ class Ros2Topic:
304
+ """ROS2 Topic
305
+
306
+ warnings:
307
+ - dora Ros2 bridge functionality is considered **unstable**. It may be changed
308
+ at any point without it being considered a breaking change."""
309
+
310
+ def start_runtime() -> None:
311
+ """Start a runtime for Operators"""
dora/cuda.py ADDED
@@ -0,0 +1,100 @@
1
+ import pyarrow as pa
2
+
3
+ # Make sure to install torch with cuda
4
+ import torch
5
+ from numba.cuda import to_device
6
+
7
+ # Make sure to install numba with cuda
8
+ from numba.cuda.cudadrv.devicearray import DeviceNDArray
9
+
10
+ # To install pyarrow.cuda, run `conda install pyarrow "arrow-cpp-proc=*=cuda" -c conda-forge`
11
+ from pyarrow import cuda
12
+
13
+
14
+ def torch_to_ipc_buffer(tensor: torch.TensorType) -> tuple[pa.array, dict]:
15
+ """Converts a Pytorch tensor into a pyarrow buffer containing the IPC handle and its metadata.
16
+
17
+ Example Use:
18
+ ```python
19
+ torch_tensor = torch.tensor(random_data, dtype=torch.int64, device="cuda")
20
+ ipc_buffer, metadata = torch_to_ipc_buffer(torch_tensor)
21
+ node.send_output("latency", ipc_buffer, metadata)
22
+ ```
23
+ """
24
+ device_arr = to_device(tensor)
25
+ cuda_buf = pa.cuda.CudaBuffer.from_numba(device_arr.gpu_data)
26
+ handle_buffer = cuda_buf.export_for_ipc().serialize()
27
+ metadata = {
28
+ "shape": device_arr.shape,
29
+ "strides": device_arr.strides,
30
+ "dtype": device_arr.dtype.str,
31
+ }
32
+ return pa.array(handle_buffer, type=pa.uint8()), metadata
33
+
34
+
35
+ def ipc_buffer_to_ipc_handle(handle_buffer: pa.array) -> cuda.IpcMemHandle:
36
+ """Converts a buffer containing a serialized handler into cuda IPC MemHandle.
37
+
38
+ example use:
39
+ ```python
40
+
41
+ import pyarrow as pa
42
+ from dora.cuda import ipc_buffer_to_ipc_handle, cudabuffer_to_torch
43
+
44
+ ctx = pa.cuda.context()
45
+ event = node.next()
46
+
47
+ ipc_handle = ipc_buffer_to_ipc_handle(event["value"])
48
+ cudabuffer = ctx.open_ipc_buffer(ipc_handle)
49
+ torch_tensor = cudabuffer_to_torch(cudabuffer, event["metadata"]) # on cuda
50
+ ```
51
+ """
52
+ handle_buffer = handle_buffer.buffers()[1]
53
+ ipc_handle = pa.cuda.IpcMemHandle.from_buffer(handle_buffer)
54
+ return ipc_handle
55
+
56
+
57
+ def cudabuffer_to_numba(buffer: cuda.CudaBuffer, metadata: dict) -> DeviceNDArray:
58
+ """Converts a pyarrow CUDA buffer to numba.
59
+
60
+ example use:
61
+ ```python
62
+
63
+ import pyarrow as pa
64
+ from dora.cuda import ipc_buffer_to_ipc_handle, cudabuffer_to_torch
65
+
66
+ ctx = pa.cuda.context()
67
+ event = node.next()
68
+
69
+ ipc_handle = ipc_buffer_to_ipc_handle(event["value"])
70
+ cudabuffer = ctx.open_ipc_buffer(ipc_handle)
71
+ numba_tensor = cudabuffer_to_numbda(cudabuffer, event["metadata"])
72
+ ```
73
+ """
74
+ shape = metadata["shape"]
75
+ strides = metadata["strides"]
76
+ dtype = metadata["dtype"]
77
+ device_arr = DeviceNDArray(shape, strides, dtype, gpu_data=buffer.to_numba())
78
+ return device_arr
79
+
80
+
81
+ def cudabuffer_to_torch(buffer: cuda.CudaBuffer, metadata: dict) -> torch.Tensor:
82
+ """Converts a pyarrow CUDA buffer to a torch tensor.
83
+
84
+ example use:
85
+ ```python
86
+
87
+ import pyarrow as pa
88
+ from dora.cuda import ipc_buffer_to_ipc_handle, cudabuffer_to_torch
89
+
90
+ ctx = pa.cuda.context()
91
+ event = node.next()
92
+
93
+ ipc_handle = ipc_buffer_to_ipc_handle(event["value"])
94
+ cudabuffer = ctx.open_ipc_buffer(ipc_handle)
95
+ torch_tensor = cudabuffer_to_torch(cudabuffer, event["metadata"]) # on cuda
96
+ ```
97
+ """
98
+ device_arr = cudabuffer_to_numba(buffer, metadata)
99
+ torch_tensor = torch.as_tensor(device_arr, device="cuda")
100
+ return torch_tensor
dora/dora.abi3.so ADDED
Binary file
Binary file
@@ -0,0 +1,32 @@
1
+ Metadata-Version: 2.4
2
+ Name: dora-rs
3
+ Version: 0.3.9rc2
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
+ python -m venv .env
19
+ source .env/bin/activate
20
+ pip install maturin
21
+ maturin develop
22
+ ```
23
+
24
+ ## Type hinting
25
+
26
+ Type hinting requires to run a second step
27
+
28
+ ```bash
29
+ python generate_stubs.py dora dora/__init__.pyi
30
+ maturin develop
31
+ ```
32
+
@@ -0,0 +1,8 @@
1
+ dora_rs-0.3.9rc2.dist-info/METADATA,sha256=4aDA44TmaXVAckYLSoztWKfjJtjue7vcoC9RWTnXLhg,665
2
+ dora_rs-0.3.9rc2.dist-info/WHEEL,sha256=_rxC7VyJxGZeonyKlCWBCllzF0Zu2ip4bWvmnNh7jMg,105
3
+ dora.libs/libgcc_s-5b5488a6.so.1,sha256=HGKUsVmTeNAxEdSy7Ua5Vh_I9FN3RCbPWzvZ7H_TrwE,2749061
4
+ dora/__init__.py,sha256=x3SdgwncpcHNnvLdsSc8Jrj1BBEC2uZVOCMYULyTrvo,711
5
+ dora/__init__.pyi,sha256=MZfafEGo1F_Al2RLrD36_cGRfFgOYY8Qa1_14bFYcf0,8342
6
+ dora/cuda.py,sha256=KuB-J8cykDkcbLjeSYWt4oz5lbkrKOUycUh3o1hfJRA,3161
7
+ dora/dora.abi3.so,sha256=2DpTmhHlheLfdLtk66dCyLMkddQtRYI5dztYL5Y5fqk,21184405
8
+ dora_rs-0.3.9rc2.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: maturin (1.8.1)
3
+ Root-Is-Purelib: false
4
+ Tag: cp37-abi3-musllinux_1_2_armv7l