imt-ring 1.6.24__tar.gz → 1.6.26__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
Files changed (119) hide show
  1. {imt_ring-1.6.24 → imt_ring-1.6.26}/PKG-INFO +1 -1
  2. {imt_ring-1.6.24 → imt_ring-1.6.26}/pyproject.toml +1 -1
  3. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/imt_ring.egg-info/PKG-INFO +1 -1
  4. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/ml/ml_utils.py +97 -0
  5. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/ml/train.py +2 -2
  6. {imt_ring-1.6.24 → imt_ring-1.6.26}/readme.md +0 -0
  7. {imt_ring-1.6.24 → imt_ring-1.6.26}/setup.cfg +0 -0
  8. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/imt_ring.egg-info/SOURCES.txt +0 -0
  9. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/imt_ring.egg-info/dependency_links.txt +0 -0
  10. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/imt_ring.egg-info/requires.txt +0 -0
  11. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/imt_ring.egg-info/top_level.txt +0 -0
  12. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/__init__.py +0 -0
  13. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/algebra.py +0 -0
  14. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/algorithms/__init__.py +0 -0
  15. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/algorithms/_random.py +0 -0
  16. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/algorithms/custom_joints/__init__.py +0 -0
  17. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/algorithms/custom_joints/rr_imp_joint.py +0 -0
  18. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/algorithms/custom_joints/rr_joint.py +0 -0
  19. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/algorithms/custom_joints/rsaddle_joint.py +0 -0
  20. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/algorithms/custom_joints/suntay.py +0 -0
  21. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/algorithms/dynamics.py +0 -0
  22. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/algorithms/generator/__init__.py +0 -0
  23. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/algorithms/generator/base.py +0 -0
  24. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/algorithms/generator/batch.py +0 -0
  25. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/algorithms/generator/finalize_fns.py +0 -0
  26. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/algorithms/generator/motion_artifacts.py +0 -0
  27. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/algorithms/generator/pd_control.py +0 -0
  28. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/algorithms/generator/setup_fns.py +0 -0
  29. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/algorithms/generator/types.py +0 -0
  30. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/algorithms/jcalc.py +0 -0
  31. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/algorithms/kinematics.py +0 -0
  32. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/algorithms/sensors.py +0 -0
  33. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/base.py +0 -0
  34. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/io/__init__.py +0 -0
  35. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/io/examples/branched.xml +0 -0
  36. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/io/examples/exclude/knee_trans_dof.xml +0 -0
  37. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/io/examples/exclude/standard_sys.xml +0 -0
  38. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/io/examples/exclude/standard_sys_rr_imp.xml +0 -0
  39. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/io/examples/inv_pendulum.xml +0 -0
  40. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/io/examples/knee_flexible_imus.xml +0 -0
  41. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/io/examples/spherical_stiff.xml +0 -0
  42. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/io/examples/symmetric.xml +0 -0
  43. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/io/examples/test_all_1.xml +0 -0
  44. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/io/examples/test_all_2.xml +0 -0
  45. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/io/examples/test_ang0_pos0.xml +0 -0
  46. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/io/examples/test_control.xml +0 -0
  47. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/io/examples/test_double_pendulum.xml +0 -0
  48. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/io/examples/test_free.xml +0 -0
  49. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/io/examples/test_kinematics.xml +0 -0
  50. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/io/examples/test_morph_system/four_seg_seg1.xml +0 -0
  51. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/io/examples/test_morph_system/four_seg_seg3.xml +0 -0
  52. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/io/examples/test_randomize_position.xml +0 -0
  53. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/io/examples/test_sensors.xml +0 -0
  54. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/io/examples/test_three_seg_seg2.xml +0 -0
  55. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/io/examples.py +0 -0
  56. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/io/test_examples.py +0 -0
  57. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/io/xml/__init__.py +0 -0
  58. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/io/xml/abstract.py +0 -0
  59. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/io/xml/from_xml.py +0 -0
  60. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/io/xml/test_from_xml.py +0 -0
  61. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/io/xml/test_to_xml.py +0 -0
  62. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/io/xml/to_xml.py +0 -0
  63. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/maths.py +0 -0
  64. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/ml/__init__.py +0 -0
  65. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/ml/base.py +0 -0
  66. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/ml/callbacks.py +0 -0
  67. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/ml/optimizer.py +0 -0
  68. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/ml/params/0x13e3518065c21cd8.pickle +0 -0
  69. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/ml/params/0x1d76628065a71e0f.pickle +0 -0
  70. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/ml/ringnet.py +0 -0
  71. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/ml/rnno_v1.py +0 -0
  72. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/ml/training_loop.py +0 -0
  73. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/rendering/__init__.py +0 -0
  74. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/rendering/base_render.py +0 -0
  75. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/rendering/mujoco_render.py +0 -0
  76. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/rendering/vispy_render.py +0 -0
  77. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/rendering/vispy_visuals.py +0 -0
  78. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/sim2real/__init__.py +0 -0
  79. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/sim2real/sim2real.py +0 -0
  80. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/spatial.py +0 -0
  81. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/sys_composer/__init__.py +0 -0
  82. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/sys_composer/delete_sys.py +0 -0
  83. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/sys_composer/inject_sys.py +0 -0
  84. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/sys_composer/morph_sys.py +0 -0
  85. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/utils/__init__.py +0 -0
  86. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/utils/backend.py +0 -0
  87. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/utils/batchsize.py +0 -0
  88. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/utils/colab.py +0 -0
  89. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/utils/dataloader.py +0 -0
  90. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/utils/dataloader_torch.py +0 -0
  91. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/utils/hdf5.py +0 -0
  92. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/utils/normalizer.py +0 -0
  93. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/utils/path.py +0 -0
  94. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/utils/randomize_sys.py +0 -0
  95. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/utils/register_gym_envs/__init__.py +0 -0
  96. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/utils/register_gym_envs/saddle.py +0 -0
  97. {imt_ring-1.6.24 → imt_ring-1.6.26}/src/ring/utils/utils.py +0 -0
  98. {imt_ring-1.6.24 → imt_ring-1.6.26}/tests/test_algebra.py +0 -0
  99. {imt_ring-1.6.24 → imt_ring-1.6.26}/tests/test_base.py +0 -0
  100. {imt_ring-1.6.24 → imt_ring-1.6.26}/tests/test_custom_joints.py +0 -0
  101. {imt_ring-1.6.24 → imt_ring-1.6.26}/tests/test_dynamics.py +0 -0
  102. {imt_ring-1.6.24 → imt_ring-1.6.26}/tests/test_generator.py +0 -0
  103. {imt_ring-1.6.24 → imt_ring-1.6.26}/tests/test_jcalc.py +0 -0
  104. {imt_ring-1.6.24 → imt_ring-1.6.26}/tests/test_jit.py +0 -0
  105. {imt_ring-1.6.24 → imt_ring-1.6.26}/tests/test_kinematics.py +0 -0
  106. {imt_ring-1.6.24 → imt_ring-1.6.26}/tests/test_maths.py +0 -0
  107. {imt_ring-1.6.24 → imt_ring-1.6.26}/tests/test_ml_utils.py +0 -0
  108. {imt_ring-1.6.24 → imt_ring-1.6.26}/tests/test_motion_artifacts.py +0 -0
  109. {imt_ring-1.6.24 → imt_ring-1.6.26}/tests/test_pd_control.py +0 -0
  110. {imt_ring-1.6.24 → imt_ring-1.6.26}/tests/test_quickstart_example.py +0 -0
  111. {imt_ring-1.6.24 → imt_ring-1.6.26}/tests/test_random.py +0 -0
  112. {imt_ring-1.6.24 → imt_ring-1.6.26}/tests/test_randomize.py +0 -0
  113. {imt_ring-1.6.24 → imt_ring-1.6.26}/tests/test_rcmg.py +0 -0
  114. {imt_ring-1.6.24 → imt_ring-1.6.26}/tests/test_render.py +0 -0
  115. {imt_ring-1.6.24 → imt_ring-1.6.26}/tests/test_sensors.py +0 -0
  116. {imt_ring-1.6.24 → imt_ring-1.6.26}/tests/test_sim2real.py +0 -0
  117. {imt_ring-1.6.24 → imt_ring-1.6.26}/tests/test_sys_composer.py +0 -0
  118. {imt_ring-1.6.24 → imt_ring-1.6.26}/tests/test_train.py +0 -0
  119. {imt_ring-1.6.24 → imt_ring-1.6.26}/tests/test_utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: imt-ring
3
- Version: 1.6.24
3
+ Version: 1.6.26
4
4
  Summary: RING: Recurrent Inertial Graph-based Estimator
5
5
  Author-email: Simon Bachhuber <simon.bachhuber@fau.de>
6
6
  Project-URL: Homepage, https://github.com/SimiPixel/ring
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "imt-ring"
7
- version = "1.6.24"
7
+ version = "1.6.26"
8
8
  authors = [
9
9
  { name="Simon Bachhuber", email="simon.bachhuber@fau.de" },
10
10
  ]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: imt-ring
3
- Version: 1.6.24
3
+ Version: 1.6.26
4
4
  Summary: RING: Recurrent Inertial Graph-based Estimator
5
5
  Author-email: Simon Bachhuber <simon.bachhuber@fau.de>
6
6
  Project-URL: Homepage, https://github.com/SimiPixel/ring
@@ -243,5 +243,102 @@ def save_model_tf(jax_func, path: str, *input, validate: bool = True):
243
243
  )
244
244
 
245
245
 
246
+ def to_onnx(
247
+ fn,
248
+ output_path,
249
+ *args: tuple[np.ndarray],
250
+ in_args_names: Optional[list[str]] = None,
251
+ out_args_names: Optional[list[str]] = None,
252
+ validate: bool = False,
253
+ ):
254
+ """
255
+ Converts a JAX function to ONNX format, with optional input/output renaming and validation.
256
+
257
+ Args:
258
+ fn (callable): The JAX function to be converted.
259
+ output_path (str): Path where the ONNX model will be saved.
260
+ *args (tuple[np.ndarray]): Input arguments for the JAX function.
261
+ in_args_names (Optional[list[str]]): Names for the ONNX model's input tensors. Defaults to None.
262
+ out_args_names (Optional[list[str]]): Names for the ONNX model's output tensors. Defaults to None.
263
+ validate (bool): Whether to validate the ONNX model against the JAX function's outputs. Defaults to False.
264
+
265
+ Raises:
266
+ AssertionError: If the number of provided names does not match the number of inputs/outputs.
267
+ AssertionError: If the ONNX model's outputs do not match the JAX function's outputs within tolerance.
268
+ ValueError: If any error occurs during ONNX conversion, saving, or validation.
269
+
270
+ Notes:
271
+ - The function uses `jax2tf` to convert the JAX function to TensorFlow format,
272
+ and `tf2onnx` for ONNX conversion.
273
+ - Input and output tensor names in the ONNX model can be renamed using `sor4onnx.rename`.
274
+ - Validation compares outputs of the JAX function and the ONNX model using ONNX Runtime.
275
+
276
+ Example:
277
+ ```
278
+ import jax.numpy as jnp
279
+
280
+ def my_fn(x, y):
281
+ return x + y, x * y
282
+
283
+ x = jnp.array([1, 2, 3])
284
+ y = jnp.array([4, 5, 6])
285
+
286
+ to_onnx(
287
+ my_fn,
288
+ "model.onnx",
289
+ x, y,
290
+ in_args_names=["input1", "input2"],
291
+ out_args_names=["sum", "product"],
292
+ validate=True,
293
+ )
294
+ ```
295
+ """ # noqa: E501
296
+ import jax.experimental.jax2tf as jax2tf
297
+ import tensorflow as tf
298
+ import tf2onnx
299
+
300
+ tf_fn = tf.function(jax2tf.convert(fn, enable_xla=False))
301
+ tf_args = [tf.TensorSpec(np.shape(x), np.result_type(x)) for x in args]
302
+ tf2onnx.convert.from_function(
303
+ tf_fn, input_signature=tf_args, output_path=output_path
304
+ )
305
+
306
+ if in_args_names is not None or out_args_names is not None:
307
+ import onnx
308
+ from sor4onnx import rename
309
+
310
+ model = onnx.load(output_path)
311
+
312
+ if in_args_names is not None:
313
+ old_names = [inp.name for inp in model.graph.input]
314
+ assert len(old_names) == len(in_args_names)
315
+ for old_name, new_name in zip(old_names, in_args_names):
316
+ model = rename([old_name, new_name], None, model, None, mode="inputs")
317
+
318
+ if out_args_names is not None:
319
+ old_names = [out.name for out in model.graph.output]
320
+ assert len(old_names) == len(out_args_names)
321
+ for old_name, new_name in zip(old_names, out_args_names):
322
+ model = rename([old_name, new_name], None, model, None, mode="outputs")
323
+
324
+ onnx.save(model, output_path)
325
+
326
+ if validate:
327
+ import onnxruntime as ort
328
+
329
+ output_jax = fn(*args)
330
+ session = ort.InferenceSession(output_path)
331
+ input_names = [inp.name for inp in session.get_inputs()]
332
+ output_onnx = session.run(
333
+ None, {name: np.array(arg) for name, arg in zip(input_names, args)}
334
+ )
335
+
336
+ for o1, o2 in zip(output_jax, output_onnx):
337
+ assert np.allclose(o1, o2, atol=1e-5, rtol=1e-5)
338
+
339
+ if out_args_names is not None:
340
+ assert [out.name for out in session.get_outputs()] == out_args_names
341
+
342
+
246
343
  def _unknown_link_names(N: int):
247
344
  return [f"link{i}" for i in range(N)]
@@ -45,7 +45,7 @@ def _build_step_fn(
45
45
 
46
46
  @partial(jax.value_and_grad, has_aux=True)
47
47
  def loss_fn(params, state, X, y):
48
- yhat, state = filter.apply(params=params, state=state, X=X)
48
+ yhat, state = filter.apply(params=params, state=state, X=X, y=y)
49
49
  # this vmap maps along batch-axis, not time-axis
50
50
  # time-axis is handled by `metric_fn`
51
51
  pipe = lambda q, qhat: jnp.mean(jax.vmap(metric_fn)(q, qhat))
@@ -261,7 +261,7 @@ def _build_eval_fn(
261
261
  """Build function that evaluates the filter performance."""
262
262
 
263
263
  def eval_fn(params, state, X, y):
264
- yhat, _ = filter.apply(params=params, state=state, X=X)
264
+ yhat, _ = filter.apply(params=params, state=state, X=X, y=y)
265
265
 
266
266
  y = _arr_to_dict(y, link_names)
267
267
  yhat = _arr_to_dict(yhat, link_names)
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes