kinfer 0.5.1__cp312-cp312-macosx_11_0_arm64.whl → 0.5.4__cp312-cp312-macosx_11_0_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.
- kinfer/rust/Cargo.toml +1 -0
- kinfer/rust/src/logger.rs +6 -0
- kinfer/rust/src/model.rs +20 -3
- kinfer/rust/src/types.rs +10 -0
- kinfer/rust_bindings/src/lib.rs +78 -23
- kinfer/rust_bindings.cpython-312-darwin.so +0 -0
- {kinfer-0.5.1.dist-info → kinfer-0.5.4.dist-info}/METADATA +6 -1
- {kinfer-0.5.1.dist-info → kinfer-0.5.4.dist-info}/RECORD +11 -11
- {kinfer-0.5.1.dist-info → kinfer-0.5.4.dist-info}/WHEEL +0 -0
- {kinfer-0.5.1.dist-info → kinfer-0.5.4.dist-info}/licenses/LICENSE +0 -0
- {kinfer-0.5.1.dist-info → kinfer-0.5.4.dist-info}/top_level.txt +0 -0
kinfer/rust/Cargo.toml
CHANGED
kinfer/rust/src/logger.rs
CHANGED
@@ -16,6 +16,8 @@ struct NdjsonStep<'a> {
|
|
16
16
|
t_us: u64,
|
17
17
|
joint_angles: Option<&'a [f32]>,
|
18
18
|
joint_vels: Option<&'a [f32]>,
|
19
|
+
initial_heading: Option<&'a [f32]>,
|
20
|
+
quaternion: Option<&'a [f32]>,
|
19
21
|
projected_g: Option<&'a [f32]>,
|
20
22
|
accel: Option<&'a [f32]>,
|
21
23
|
gyro: Option<&'a [f32]>,
|
@@ -88,6 +90,8 @@ impl StepLogger {
|
|
88
90
|
&self,
|
89
91
|
joint_angles: Option<&[f32]>,
|
90
92
|
joint_vels: Option<&[f32]>,
|
93
|
+
initial_heading: Option<&[f32]>,
|
94
|
+
quaternion: Option<&[f32]>,
|
91
95
|
projected_g: Option<&[f32]>,
|
92
96
|
accel: Option<&[f32]>,
|
93
97
|
gyro: Option<&[f32]>,
|
@@ -99,6 +103,8 @@ impl StepLogger {
|
|
99
103
|
t_us: Self::now_us() as u64,
|
100
104
|
joint_angles,
|
101
105
|
joint_vels,
|
106
|
+
initial_heading,
|
107
|
+
quaternion,
|
102
108
|
projected_g,
|
103
109
|
accel,
|
104
110
|
gyro,
|
kinfer/rust/src/model.rs
CHANGED
@@ -129,9 +129,12 @@ impl ModelRunner {
|
|
129
129
|
std::fs::create_dir_all(log_dir_path)?;
|
130
130
|
}
|
131
131
|
|
132
|
-
//
|
133
|
-
let
|
134
|
-
|
132
|
+
// Use uuid if found, otherwise timestamp
|
133
|
+
let log_name = std::env::var("KINFER_LOG_UUID").unwrap_or_else(|_| {
|
134
|
+
chrono::Utc::now().format("%Y-%m-%d_%H-%M-%S").to_string()
|
135
|
+
});
|
136
|
+
|
137
|
+
let log_file_path = log_dir_path.join(format!("{}.ndjson", log_name));
|
135
138
|
|
136
139
|
Some(StepLogger::new(log_file_path).map(Arc::new)?)
|
137
140
|
} else {
|
@@ -241,6 +244,12 @@ impl ModelRunner {
|
|
241
244
|
"joint_angular_velocities" => {
|
242
245
|
input_types.push(InputType::JointAngularVelocities);
|
243
246
|
}
|
247
|
+
"initial_heading" => {
|
248
|
+
input_types.push(InputType::InitialHeading);
|
249
|
+
}
|
250
|
+
"quaternion" => {
|
251
|
+
input_types.push(InputType::Quaternion);
|
252
|
+
}
|
244
253
|
"projected_gravity" => {
|
245
254
|
input_types.push(InputType::ProjectedGravity);
|
246
255
|
}
|
@@ -296,6 +305,12 @@ impl ModelRunner {
|
|
296
305
|
let joint_vels_opt = inputs
|
297
306
|
.get(&InputType::JointAngularVelocities)
|
298
307
|
.map(|a| a.as_slice().unwrap());
|
308
|
+
let initial_heading_opt = inputs
|
309
|
+
.get(&InputType::InitialHeading)
|
310
|
+
.map(|a| a.as_slice().unwrap());
|
311
|
+
let quaternion_opt = inputs
|
312
|
+
.get(&InputType::Quaternion)
|
313
|
+
.map(|a| a.as_slice().unwrap());
|
299
314
|
let projected_g_opt = inputs
|
300
315
|
.get(&InputType::ProjectedGravity)
|
301
316
|
.map(|a| a.as_slice().unwrap());
|
@@ -313,6 +328,8 @@ impl ModelRunner {
|
|
313
328
|
lg.log_step(
|
314
329
|
joint_angles_opt,
|
315
330
|
joint_vels_opt,
|
331
|
+
initial_heading_opt,
|
332
|
+
quaternion_opt,
|
316
333
|
projected_g_opt,
|
317
334
|
accel_opt,
|
318
335
|
gyro_opt,
|
kinfer/rust/src/types.rs
CHANGED
@@ -22,6 +22,8 @@ impl ModelMetadata {
|
|
22
22
|
pub enum InputType {
|
23
23
|
JointAngles,
|
24
24
|
JointAngularVelocities,
|
25
|
+
InitialHeading,
|
26
|
+
Quaternion,
|
25
27
|
ProjectedGravity,
|
26
28
|
Accelerometer,
|
27
29
|
Gyroscope,
|
@@ -35,6 +37,8 @@ impl InputType {
|
|
35
37
|
match self {
|
36
38
|
InputType::JointAngles => "joint_angles",
|
37
39
|
InputType::JointAngularVelocities => "joint_angular_velocities",
|
40
|
+
InputType::InitialHeading => "initial_heading",
|
41
|
+
InputType::Quaternion => "quaternion",
|
38
42
|
InputType::ProjectedGravity => "projected_gravity",
|
39
43
|
InputType::Accelerometer => "accelerometer",
|
40
44
|
InputType::Gyroscope => "gyroscope",
|
@@ -48,6 +52,8 @@ impl InputType {
|
|
48
52
|
match self {
|
49
53
|
InputType::JointAngles => vec![metadata.joint_names.len()],
|
50
54
|
InputType::JointAngularVelocities => vec![metadata.joint_names.len()],
|
55
|
+
InputType::InitialHeading => vec![1],
|
56
|
+
InputType::Quaternion => vec![4],
|
51
57
|
InputType::ProjectedGravity => vec![3],
|
52
58
|
InputType::Accelerometer => vec![3],
|
53
59
|
InputType::Gyroscope => vec![3],
|
@@ -61,6 +67,8 @@ impl InputType {
|
|
61
67
|
match name {
|
62
68
|
"joint_angles" => Ok(InputType::JointAngles),
|
63
69
|
"joint_angular_velocities" => Ok(InputType::JointAngularVelocities),
|
70
|
+
"initial_heading" => Ok(InputType::InitialHeading),
|
71
|
+
"quaternion" => Ok(InputType::Quaternion),
|
64
72
|
"projected_gravity" => Ok(InputType::ProjectedGravity),
|
65
73
|
"accelerometer" => Ok(InputType::Accelerometer),
|
66
74
|
"gyroscope" => Ok(InputType::Gyroscope),
|
@@ -75,6 +83,8 @@ impl InputType {
|
|
75
83
|
vec![
|
76
84
|
"joint_angles",
|
77
85
|
"joint_angular_velocities",
|
86
|
+
"initial_heading",
|
87
|
+
"quaternion",
|
78
88
|
"projected_gravity",
|
79
89
|
"accelerometer",
|
80
90
|
"gyroscope",
|
kinfer/rust_bindings/src/lib.rs
CHANGED
@@ -17,6 +17,19 @@ use std::sync::Mutex;
|
|
17
17
|
|
18
18
|
type StepResult = (Py<PyArrayDyn<f32>>, Py<PyArrayDyn<f32>>);
|
19
19
|
|
20
|
+
// Custom error type for Send/Sync compatibility
|
21
|
+
#[derive(Debug)]
|
22
|
+
struct SendError(String);
|
23
|
+
|
24
|
+
unsafe impl Send for SendError {}
|
25
|
+
unsafe impl Sync for SendError {}
|
26
|
+
|
27
|
+
impl std::fmt::Display for SendError {
|
28
|
+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
29
|
+
write!(f, "{}", self.0)
|
30
|
+
}
|
31
|
+
}
|
32
|
+
|
20
33
|
#[pyfunction]
|
21
34
|
#[gen_stub_pyfunction]
|
22
35
|
fn get_version() -> String {
|
@@ -204,9 +217,15 @@ impl ModelProviderABC {
|
|
204
217
|
metadata: PyModelMetadata,
|
205
218
|
) -> PyResult<()> {
|
206
219
|
let n = action.len()?;
|
207
|
-
|
220
|
+
if metadata.joint_names.len() != n {
|
221
|
+
return Err(PyErr::new::<pyo3::exceptions::PyValueError, _>(format!(
|
222
|
+
"Expected {} joints, got {} action elements",
|
223
|
+
metadata.joint_names.len(),
|
224
|
+
n
|
225
|
+
)));
|
226
|
+
}
|
208
227
|
Err(PyNotImplementedError::new_err(format!(
|
209
|
-
"Must override take_action with {} action",
|
228
|
+
"Must override take_action with {} action elements",
|
210
229
|
n
|
211
230
|
)))
|
212
231
|
}
|
@@ -286,6 +305,7 @@ impl ModelProvider for PyModelProvider {
|
|
286
305
|
#[derive(Clone)]
|
287
306
|
struct PyModelRunner {
|
288
307
|
runner: Arc<ModelRunner>,
|
308
|
+
runtime: Arc<tokio::runtime::Runtime>,
|
289
309
|
}
|
290
310
|
|
291
311
|
#[gen_stub_pymethods]
|
@@ -295,7 +315,11 @@ impl PyModelRunner {
|
|
295
315
|
fn __new__(model_path: String, provider: Py<ModelProviderABC>) -> PyResult<Self> {
|
296
316
|
let input_provider = Arc::new(PyModelProvider::__new__(provider));
|
297
317
|
|
298
|
-
|
318
|
+
// Create a single runtime to be reused for all operations
|
319
|
+
let runtime = Arc::new(tokio::runtime::Runtime::new()
|
320
|
+
.map_err(|e| PyErr::new::<pyo3::exceptions::PyRuntimeError, _>(e.to_string()))?);
|
321
|
+
|
322
|
+
let runner = runtime.block_on(async {
|
299
323
|
ModelRunner::new(model_path, input_provider)
|
300
324
|
.await
|
301
325
|
.map_err(|e| PyErr::new::<pyo3::exceptions::PyRuntimeError, _>(e.to_string()))
|
@@ -303,17 +327,27 @@ impl PyModelRunner {
|
|
303
327
|
|
304
328
|
Ok(Self {
|
305
329
|
runner: Arc::new(runner),
|
330
|
+
runtime,
|
306
331
|
})
|
307
332
|
}
|
308
333
|
|
334
|
+
// Reuse runtime and release GIL
|
309
335
|
fn init(&self) -> PyResult<Py<PyArrayDyn<f32>>> {
|
310
336
|
let runner = self.runner.clone();
|
311
|
-
let
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
337
|
+
let runtime = self.runtime.clone();
|
338
|
+
|
339
|
+
let result = Python::with_gil(|py| {
|
340
|
+
// Release GIL during async operation
|
341
|
+
py.allow_threads(|| {
|
342
|
+
runtime.block_on(async {
|
343
|
+
runner
|
344
|
+
.init()
|
345
|
+
.await
|
346
|
+
.map_err(|e| SendError(e.to_string()))
|
347
|
+
})
|
348
|
+
})
|
349
|
+
})
|
350
|
+
.map_err(|e| PyErr::new::<pyo3::exceptions::PyRuntimeError, _>(e.0))?;
|
317
351
|
|
318
352
|
Python::with_gil(|py| {
|
319
353
|
let array = numpy::PyArray::from_array(py, &result);
|
@@ -321,20 +355,31 @@ impl PyModelRunner {
|
|
321
355
|
})
|
322
356
|
}
|
323
357
|
|
358
|
+
// Reuse runtime and release GIL
|
324
359
|
fn step(&self, carry: Py<PyArrayDyn<f32>>) -> PyResult<StepResult> {
|
325
360
|
let runner = self.runner.clone();
|
361
|
+
let runtime = self.runtime.clone();
|
362
|
+
|
363
|
+
// Extract the carry array from Python with GIL
|
326
364
|
let carry_array = Python::with_gil(|py| -> PyResult<Array<f32, IxDyn>> {
|
327
365
|
let carry_array = carry.bind(py);
|
328
366
|
Ok(carry_array.to_owned_array())
|
329
367
|
})?;
|
330
368
|
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
.
|
335
|
-
|
336
|
-
|
369
|
+
// Release GIL during computation
|
370
|
+
let result = Python::with_gil(|py| {
|
371
|
+
py.allow_threads(|| {
|
372
|
+
runtime.block_on(async {
|
373
|
+
runner
|
374
|
+
.step(carry_array)
|
375
|
+
.await
|
376
|
+
.map_err(|e| SendError(e.to_string()))
|
377
|
+
})
|
378
|
+
})
|
379
|
+
})
|
380
|
+
.map_err(|e| PyErr::new::<pyo3::exceptions::PyRuntimeError, _>(e.0))?;
|
337
381
|
|
382
|
+
// Reacquire the GIL to convert results back to Python objects
|
338
383
|
Python::with_gil(|py| {
|
339
384
|
let (output, carry) = result;
|
340
385
|
let output_array = numpy::PyArray::from_array(py, &output);
|
@@ -343,19 +388,29 @@ impl PyModelRunner {
|
|
343
388
|
})
|
344
389
|
}
|
345
390
|
|
391
|
+
// Reuse runtime and release GIL
|
346
392
|
fn take_action(&self, action: Py<PyArrayDyn<f32>>) -> PyResult<()> {
|
347
393
|
let runner = self.runner.clone();
|
394
|
+
let runtime = self.runtime.clone();
|
395
|
+
|
396
|
+
// Extract action data with GIL
|
348
397
|
let action_array = Python::with_gil(|py| -> PyResult<Array<f32, IxDyn>> {
|
349
398
|
let action_array = action.bind(py);
|
350
399
|
Ok(action_array.to_owned_array())
|
351
400
|
})?;
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
.
|
357
|
-
|
358
|
-
|
401
|
+
|
402
|
+
// Release GIL during computation
|
403
|
+
Python::with_gil(|py| {
|
404
|
+
py.allow_threads(|| {
|
405
|
+
runtime.block_on(async {
|
406
|
+
runner
|
407
|
+
.take_action(action_array)
|
408
|
+
.await
|
409
|
+
.map_err(|e| SendError(e.to_string()))
|
410
|
+
})
|
411
|
+
})
|
412
|
+
})
|
413
|
+
.map_err(|e| PyErr::new::<pyo3::exceptions::PyRuntimeError, _>(e.0))?;
|
359
414
|
|
360
415
|
Ok(())
|
361
416
|
}
|
@@ -428,4 +483,4 @@ fn rust_bindings(m: &Bound<PyModule>) -> PyResult<()> {
|
|
428
483
|
Ok(())
|
429
484
|
}
|
430
485
|
|
431
|
-
define_stub_info_gatherer!(stub_info);
|
486
|
+
define_stub_info_gatherer!(stub_info);
|
Binary file
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: kinfer
|
3
|
-
Version: 0.5.
|
3
|
+
Version: 0.5.4
|
4
4
|
Summary: Tool to make it easier to run a model on a real robot
|
5
5
|
Home-page: https://github.com/kscalelabs/kinfer.git
|
6
6
|
Author: K-Scale Labs
|
@@ -56,3 +56,8 @@ Dynamic: summary
|
|
56
56
|
This package is designed to support running real-time robotics models.
|
57
57
|
|
58
58
|
For more information, see the documentation [here](https://docs.kscale.dev/docs/k-infer).
|
59
|
+
|
60
|
+
To enable logging, set your log path in the environment variable `KINFER_LOG_PATH`. For example,
|
61
|
+
```
|
62
|
+
export KINFER_LOG_PATH=/home/dpsh/kinfer-logs
|
63
|
+
```
|
@@ -2,13 +2,13 @@ kinfer/requirements.txt,sha256=e8RzCNVZGJ9Jb874Eom0psUCOqp0wGf8LJZ86ysto0w,127
|
|
2
2
|
kinfer/__init__.py,sha256=i5da6ND827Cgn8PFKzDCmEBk14ptQasLa_9fdof4Y9c,398
|
3
3
|
kinfer/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
4
4
|
kinfer/rust_bindings.pyi,sha256=lPGHMDsydr4Ue-CNHRjQtJWmq5sE5daVN8PbxJgOZY4,2048
|
5
|
-
kinfer/rust_bindings.cpython-312-darwin.so,sha256=
|
6
|
-
kinfer/rust/Cargo.toml,sha256=
|
5
|
+
kinfer/rust_bindings.cpython-312-darwin.so,sha256=5Thj3t4xz9-85MJ8ckTmb9yZ6C7_NIg5OQCgEuy2vbk,2069520
|
6
|
+
kinfer/rust/Cargo.toml,sha256=NoWaLluRJHV6mOCeVXk8q8Pb4028Z3ZPqLspBMHAPTQ,703
|
7
7
|
kinfer/rust/src/runtime.rs,sha256=7BRZmyMoV6FvYs2_XnLk0DFrxt7qgz35loCUJRSsuxM,3448
|
8
|
-
kinfer/rust/src/logger.rs,sha256=
|
9
|
-
kinfer/rust/src/types.rs,sha256=
|
8
|
+
kinfer/rust/src/logger.rs,sha256=5Uvv60zp6HV4zmaD9bA1vENDtE19uYrRzA-xRY26bl8,4124
|
9
|
+
kinfer/rust/src/types.rs,sha256=wNLlXXmGmcE7uF4tKuZ7ChRy9-PI-JWq2iuh7diQS_g,3187
|
10
10
|
kinfer/rust/src/lib.rs,sha256=25LuAdONp9c3lI0_g2kAf73yrtzbYc9GtJjm1zl9IwU,120
|
11
|
-
kinfer/rust/src/model.rs,sha256=
|
11
|
+
kinfer/rust/src/model.rs,sha256=WluovJlgKSrAlAOkKlhhiVnD-OhN9E6xznZRPn2LFFI,12176
|
12
12
|
kinfer/scripts/plot_ndjson.py,sha256=eg-wwuDLRDcuVdr1Jc5W4yeJG5Bf--UjaK6kk9XoC4w,6179
|
13
13
|
kinfer/export/serialize.py,sha256=QjsvTn7cIRroZXXONXQUrEd1tR69oLrszojuKoK-Xuk,3208
|
14
14
|
kinfer/export/__init__.py,sha256=6a8cClA2H3AAjAhY6ucmxEnfCRZ30FDn2L7SArCu7nY,56
|
@@ -17,10 +17,10 @@ kinfer/export/pytorch.py,sha256=nRo9TKClRhPcLJQDR3oHNCbTYjf_3gLBxGfzZBScPxc,1303
|
|
17
17
|
kinfer/rust_bindings/Cargo.toml,sha256=i1RGB9VNd9Q4FJ6gGwjZJQYo8DBBvpVWf3GJ95EfVgM,637
|
18
18
|
kinfer/rust_bindings/pyproject.toml,sha256=jLcJuHCnQRh9HWR_R7a9qLHwj6LMBgnHyeKK_DruO1Y,135
|
19
19
|
kinfer/rust_bindings/rust_bindings.pyi,sha256=lPGHMDsydr4Ue-CNHRjQtJWmq5sE5daVN8PbxJgOZY4,2048
|
20
|
-
kinfer/rust_bindings/src/lib.rs,sha256=
|
20
|
+
kinfer/rust_bindings/src/lib.rs,sha256=f5TBqP6tYmb3vXQiisCsxAPB37_mtoaZSFvc_FlOeKY,14473
|
21
21
|
kinfer/rust_bindings/src/bin/stub_gen.rs,sha256=hhoVGnaSfazbSfj5a4x6mPicGPOgWQAfsDmiPej0B6Y,133
|
22
|
-
kinfer-0.5.
|
23
|
-
kinfer-0.5.
|
24
|
-
kinfer-0.5.
|
25
|
-
kinfer-0.5.
|
26
|
-
kinfer-0.5.
|
22
|
+
kinfer-0.5.4.dist-info/RECORD,,
|
23
|
+
kinfer-0.5.4.dist-info/WHEEL,sha256=V1loQ6TpxABu1APUg0MoTRBOzSKT5xVc3skizX-ovCU,136
|
24
|
+
kinfer-0.5.4.dist-info/top_level.txt,sha256=6mY_t3PYr3Dm0dpqMk80uSnArbvGfCFkxOh1QWtgDEo,7
|
25
|
+
kinfer-0.5.4.dist-info/METADATA,sha256=Da03N1PNxRcIrOj0ub_N19j9v8n0siXLjxW5ZCtsiOQ,1983
|
26
|
+
kinfer-0.5.4.dist-info/licenses/LICENSE,sha256=Qw-Z0XTwS-diSW91e_jLeBPX9zZbAatOJTBLdPHPaC0,1069
|
File without changes
|
File without changes
|
File without changes
|