Repository navigation
Remove and deprecate context manager for switching velocity representation - #496
flferretti wants to merge 18 commits into
Conversation
There was a problem hiding this comment.
Benchmark
Details
| Benchmark suite | Current: 132f760 | Previous: c28e89a | Ratio |
|---|---|---|---|
tests/test_benchmark.py::test_forward_dynamics_aba[1] |
319.2614265783487 iter/sec (stddev: 0.000007687928414904411) |
385.94492720843766 iter/sec (stddev: 0.000009463978323506126) |
1.21 |
tests/test_benchmark.py::test_forward_dynamics_aba[128] |
26.061866324206303 iter/sec (stddev: 0.00011850005770402863) |
29.216966653272625 iter/sec (stddev: 0.00011455086573428671) |
1.12 |
tests/test_benchmark.py::test_free_floating_bias_forces[1] |
297.2319063826794 iter/sec (stddev: 0.000010252393984526802) |
361.396251061539 iter/sec (stddev: 0.00000910574964681653) |
1.22 |
tests/test_benchmark.py::test_free_floating_bias_forces[128] |
14.566249466118304 iter/sec (stddev: 0.0003354849913413401) |
16.218942194940492 iter/sec (stddev: 0.00025096534945186314) |
1.11 |
tests/test_benchmark.py::test_forward_kinematics[1] |
364.948987035732 iter/sec (stddev: 0.000010465405339996125) |
452.4863643105723 iter/sec (stddev: 0.000008022285629396292) |
1.24 |
tests/test_benchmark.py::test_forward_kinematics[128] |
27.985786413362845 iter/sec (stddev: 0.00008688390795512073) |
31.765642438814933 iter/sec (stddev: 0.0002088457881717258) |
1.14 |
tests/test_benchmark.py::test_free_floating_mass_matrix[1] |
152.83158308217102 iter/sec (stddev: 0.000012938360417174908) |
181.58130216807277 iter/sec (stddev: 0.00005072371260792714) |
1.19 |
tests/test_benchmark.py::test_free_floating_mass_matrix[128] |
150.63494789138753 iter/sec (stddev: 0.000014898060859762702) |
175.24079377087364 iter/sec (stddev: 0.000018760096947039575) |
1.16 |
tests/test_benchmark.py::test_free_floating_jacobian[1] |
413.8739908587021 iter/sec (stddev: 0.000009812410856679114) |
525.7508803201982 iter/sec (stddev: 0.000006377672924636457) |
1.27 |
tests/test_benchmark.py::test_free_floating_jacobian[128] |
417.5550110080922 iter/sec (stddev: 0.000007741334773995725) |
534.2483568468638 iter/sec (stddev: 0.000006942445781767468) |
1.28 |
tests/test_benchmark.py::test_free_floating_jacobian_derivative[1] |
340.5652481854508 iter/sec (stddev: 0.000010220187569187532) |
410.0473494948492 iter/sec (stddev: 0.000012243950755069747) |
1.20 |
tests/test_benchmark.py::test_free_floating_jacobian_derivative[128] |
302.0503731539551 iter/sec (stddev: 0.00001896561229951185) |
302.58988317111164 iter/sec (stddev: 0.000015109621352982298) |
1.00 |
tests/test_benchmark.py::test_soft_contact_model[1] |
263.3831503704675 iter/sec (stddev: 0.000013667442949718066) |
349.9366267743607 iter/sec (stddev: 0.00000947480013200776) |
1.33 |
tests/test_benchmark.py::test_soft_contact_model[128] |
25.660711736857994 iter/sec (stddev: 0.00038516959783075624) |
29.951416599383442 iter/sec (stddev: 0.0001405258247109449) |
1.17 |
tests/test_benchmark.py::test_rigid_contact_model[1] |
47.315541190779996 iter/sec (stddev: 0.00036622850586332884) |
40.276241063183 iter/sec (stddev: 0.000024302278784552764) |
0.85 |
tests/test_benchmark.py::test_rigid_contact_model[128] |
0.7096774853548944 iter/sec (stddev: 0.0003874925270677735) |
0.7258859819172665 iter/sec (stddev: 0.0003607214923404956) |
1.02 |
tests/test_benchmark.py::test_relaxed_rigid_contact_model[1] |
98.56515506807776 iter/sec (stddev: 0.00014369177693839108) |
74.75017951811331 iter/sec (stddev: 0.00003167479964364776) |
0.76 |
tests/test_benchmark.py::test_relaxed_rigid_contact_model[128] |
5.071128280533731 iter/sec (stddev: 0.00036197841157675623) |
6.400062476314604 iter/sec (stddev: 0.00024891629896200675) |
1.26 |
tests/test_benchmark.py::test_simulation_step[1] |
87.4176223371017 iter/sec (stddev: 0.00001416886654168995) |
69.29459728383536 iter/sec (stddev: 0.00002754549281911007) |
0.79 |
tests/test_benchmark.py::test_simulation_step[128] |
4.471230938738151 iter/sec (stddev: 0.0006089090944558373) |
5.39599749835251 iter/sec (stddev: 0.000279412049524645) |
1.21 |
tests/test_benchmark.py::test_update_hw_parameters[1] |
101.39066404130952 iter/sec (stddev: 0.00004172880549589833) |
||
tests/test_benchmark.py::test_update_hw_parameters[128] |
101.49678889914968 iter/sec (stddev: 0.0000930788430776146) |
||
tests/test_benchmark.py::test_export_updated_model[1] |
3.4422759114776014 iter/sec (stddev: 0.006553000240783159) |
||
tests/test_benchmark.py::test_export_updated_model[128] |
0.018957285274988724 iter/sec (stddev: 0.5984209323189633) |
This comment was automatically generated by workflow using github-action-benchmark.
d9f152d to
132f760
Compare
|
CI failing due to brentyi/jax_dataclasses#7. They do not fail on Python 3.10 since the environment is using JAX v0.7.2 and the bug in on JAX > v0.8 |
c96b0b8 to
ba8ebc4
Compare
There was a problem hiding this comment.
Pull request overview
This pull request refactors the codebase to remove and deprecate the switch_velocity_representation context manager, replacing it with explicit input_representation and output_representation parameters throughout the API. The changes maintain backward compatibility through deprecation warnings and sensible defaults.
Changes:
- Deprecated the
switch_velocity_representationcontext manager with a clear deprecation warning - Added
output_representationparameter tobase_velocity()andgeneralized_velocity()methods inJaxSimModelData - Added
input_representationand/oroutput_representationparameters to numerous API functions across model, link, frame, contact, COM, ODE, and references modules - Updated all tests to use the new explicit parameter API instead of the context manager
- Updated example notebook to demonstrate the new API patterns
Reviewed changes
Copilot reviewed 22 out of 22 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
src/jaxsim/api/common.py |
Added deprecation warning to switch_velocity_representation context manager |
src/jaxsim/api/data.py |
Converted base_velocity and generalized_velocity from properties to methods accepting output_representation parameter; added input_representation to replace() |
src/jaxsim/api/references.py |
Added output_representation and input_representation parameters to link_forces() and apply_link_forces() |
src/jaxsim/api/model.py |
Added input_representation and output_representation parameters to multiple functions including jacobians, mass matrices, dynamics functions, and momenta computations |
src/jaxsim/api/ode.py |
Added output_representation parameter to system dynamics functions |
src/jaxsim/api/link.py |
Added input_representation parameter to jacobian() and jacobian_derivative() |
src/jaxsim/api/frame.py |
Added input_representation parameter to frame jacobian functions |
src/jaxsim/api/contact.py |
Added input_representation parameter to contact jacobian functions |
src/jaxsim/api/com.py |
Added output_representation parameter to centroidal momentum and related functions |
src/jaxsim/api/integrators.py |
Updated integrators to use new API with explicit representation parameters |
src/jaxsim/rbda/kinematic_constraints.py |
Replaced context manager usage with explicit parameters |
src/jaxsim/rbda/contacts/rigid.py |
Replaced context manager usage with explicit parameters |
src/jaxsim/rbda/contacts/relaxed_rigid.py |
Replaced context manager usage with explicit parameters |
tests/*.py |
Removed all context manager usage; updated tests to use new parameter-based API |
examples/jaxsim_as_multibody_dynamics_library.ipynb |
Updated to demonstrate new API patterns |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
545b3a7 to
18e00fd
Compare
18e00fd to
6e62fd7
Compare
|
Closing as stale |
This PR refactors the handling of velocity representations throughout the codebase, moving away from the deprecated
switch_velocity_representationcontext manager and instead encouraging the explicit use ofinput_representationandoutput_representationparameters in relevant API methods. The backward compatibility is maintained.Fixes https://github.com/gbionics/element_differentiable_simulators_for_codesign/issues/31
📚 Documentation preview 📚: https://jaxsim--496.org.readthedocs.build//496/