Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simulator refactor #366

Merged
merged 99 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
99 commits
Select commit Hold shift + click to select a range
a9008fe
erase integrators
younik Jan 20, 2025
a1a2b5f
fix import
younik Jan 20, 2025
f1dfca4
remotveintegrators
younik Jan 20, 2025
55f2d69
restore heun2 integrator
younik Jan 20, 2025
b0c9cf4
tentative change
younik Jan 20, 2025
1c1c7e3
adding quaternion integration from axis angle
CarlottaSartore Jan 20, 2025
e6ce21a
improve semi implicit euler and add velocity representation
CarlottaSartore Jan 20, 2025
da48411
tentative fix
younik Jan 21, 2025
ff93841
Pass link and joint forces to `js.ode.system_dynamics`
flferretti Jan 21, 2025
54640dd
fix tests but one
younik Jan 21, 2025
9fd2f87
Fix position derivative extraction in semi-implicit Euler
flferretti Jan 21, 2025
6073c3f
Remove `rigid.py`
xela-95 Jan 20, 2025
0b1d574
Remove `soft.py`
xela-95 Jan 20, 2025
ca66f8d
Remove `visco_elastic.py`
xela-95 Jan 20, 2025
82aac36
Remove commented note about default contact model in JaxSimModel
xela-95 Jan 20, 2025
a8c6b91
Update `jaxsim.rbda.contacts.__init__.py`
xela-95 Jan 20, 2025
ea874c2
Add `_hunt_crossley_contact_model` to initialize RelaxedRigidContacts
xela-95 Jan 20, 2025
a8d9e2a
Refactor `contact.py` to use only RelaxedRigidContacts
xela-95 Jan 20, 2025
8f2d9a2
Update `JaxSimModel` to use only RelaxedRigidContacts
xela-95 Jan 20, 2025
38a6d74
Update `JaxSimModelData` to use only RelaxedRigidContacts
xela-95 Jan 20, 2025
7d289a8
Refactor `ode.py` to simplify `system_dynamics` and `system_velocity_…
xela-95 Jan 20, 2025
a7fa83b
Remove unused soft contacts test and related parameters from automati…
xela-95 Jan 20, 2025
0285468
Refactor simulation tests to remove soft contacts and streamline cont…
xela-95 Jan 20, 2025
c611de0
Create `contact_model.py` to contain all functions related to contact…
xela-95 Jan 21, 2025
a32ccd4
Add `contact_model` __init__.py
xela-95 Jan 21, 2025
c0eb0e2
Remove `collidable_point_dynamics` function from contact module
xela-95 Jan 21, 2025
7ff8951
Remove `link_contact_forces` function from model API
xela-95 Jan 21, 2025
071ef2b
Remove compute_link_contact_forces and link_forces_from_contact_force…
xela-95 Jan 21, 2025
1436517
Update link_contact_forces reference to use contact_model module
xela-95 Jan 21, 2025
432e640
Remove collidable_point_forces function from contact.py
xela-95 Jan 21, 2025
566e450
Refactor `link_contact_forces` to compute contact forces in inertial …
xela-95 Jan 21, 2025
f3710ba
Refactor `link_forces_from_contact_forces` to work only in inertial
xela-95 Jan 21, 2025
b2efb84
Update docstring to clarify that computed contact forces are in inert…
xela-95 Jan 21, 2025
7d24d75
Refactor heun2_integration to remove aux_dict
xela-95 Jan 21, 2025
495538a
Refactor system_velocity_dynamics and system_dynamics to use inertial…
xela-95 Jan 21, 2025
42b28a1
Fix semi-implicit integrators
flferretti Jan 21, 2025
eadaaef
Fix pre-commit
flferretti Jan 21, 2025
25d5e59
Improve error message for incompatible PyTree structures
flferretti Jan 21, 2025
38179ea
Update AD test to include aux dict and fix gradient check modes
flferretti Jan 21, 2025
dea93ed
Remove unnecessary `VelRepr` switch from `rbda.contacts`
flferretti Jan 20, 2025
c0f3190
Use inertial-fixed representation in `system_dynamics`
flferretti Jan 20, 2025
cfec41f
Remove unnecessary `VelRepr` switch in `forward_dynamics_aba`
flferretti Jan 20, 2025
c1dc06b
remove ode_data
younik Jan 22, 2025
9067c39
add comments
younik Jan 22, 2025
77adda1
remove hashing
younik Jan 22, 2025
be2e05b
fix tests
younik Jan 22, 2025
0d18ca2
Enable cache in `JaxSimModelData` and extract W_v_L in FK
flferretti Jan 22, 2025
6bdeee0
Fix tests
flferretti Jan 23, 2025
10a4428
Fix `test_model_creation_and_reduction`
flferretti Jan 23, 2025
92ce742
Avoid extra call to contact Jacobian
flferretti Jan 23, 2025
af7dade
Remove leftover `jax.disable_jit()`
flferretti Jan 23, 2025
ee0e9b4
Use `JointType` instead of integers in motion subspaces
flferretti Jan 23, 2025
00e3283
Fix pre-commit
flferretti Jan 23, 2025
df9168d
Fix formatting in tests
flferretti Jan 23, 2025
8a9d9fd
Remove Heun's method integration function from integrators.py
xela-95 Jan 23, 2025
e3b5e1f
removed usage of reference
xela-95 Jan 23, 2025
366591b
Remove commented-out reference handling in system_velocity_dynamics
xela-95 Jan 23, 2025
ca74989
Add contact_params to JaxSimModel `build`
xela-95 Jan 23, 2025
a644e7d
Add jaxlie import to joint_model.py
xela-95 Jan 23, 2025
ece292e
Fix attribute access for base_transform in `semi_implicit_euler_integ…
xela-95 Jan 23, 2025
4cafd09
Update cached data in `test_automatic_differentiation`
xela-95 Jan 23, 2025
ca8a716
Refactor `collidable_points_pos_vel` to use cached link transforms an…
xela-95 Jan 23, 2025
6c65aa4
Refactor `collidable_point_kinematics` to use link transforms and vel…
xela-95 Jan 23, 2025
bb4a8d1
Add initialization for terrain contact forces in `system_velocity_dyn…
xela-95 Jan 23, 2025
ad7436b
Add `actuation_model.py` to compute resultant joint torques
xela-95 Jan 23, 2025
5be2a0b
Add `actuation_model` import to API module
xela-95 Jan 23, 2025
2d3b3ae
Refactor `system_velocity_dynamics` and `system_acceleration`
xela-95 Jan 23, 2025
e67247a
Rename `joint_force_references` to `joint_torques` in `RelaxedRigidCo…
xela-95 Jan 23, 2025
c1b61d3
Refactor `semi_implicit_euler_integration`
xela-95 Jan 23, 2025
ddee4f5
Refactor `step` function
xela-95 Jan 23, 2025
eebed29
Refactor `test_box_with_zero_gravity` to use only `jaxsim.VelRepr.Ine…
xela-95 Jan 23, 2025
094bd22
Rename `joint_force_references` to `joint_torques` in `link_contact_f…
xela-95 Jan 23, 2025
922a98c
Update `step` function changing order of torques and link forces comp…
xela-95 Jan 23, 2025
64852e4
Rename `link_forces` parameter to `link_forces_inertial` in `step` fu…
xela-95 Jan 24, 2025
b5b64c2
Add data.switch in `semi_implicit_euler_integration`
xela-95 Jan 24, 2025
c00643f
Refactor `link_contact_forces` function by removing unused kwargs and…
xela-95 Jan 24, 2025
871942c
Fix call to `link_contact_forces` in `step`
xela-95 Jan 24, 2025
3f93cd1
fix device transfers
younik Jan 23, 2025
bd0fefd
Disable exceptions by default
flferretti Jan 24, 2025
7c076f5
Change flag name to enable exceptions
flferretti Jan 24, 2025
18986e8
Enable exceptions in tests
flferretti Jan 24, 2025
7e6dd4d
Fix argument name in AD integration test
flferretti Jan 24, 2025
6066c43
Save `time_step` and reduced joint positions as float
flferretti Jan 24, 2025
27d33bd
Fix missing switch to mixed in RelaxedRigidContacts `compute_contact_…
xela-95 Jan 28, 2025
4445ba1
Update src/jaxsim/rbda/contacts/relaxed_rigid.py
xela-95 Jan 28, 2025
a1c5770
[Sprint] Set mixed as default representation in `data.build` (#361)
xela-95 Jan 31, 2025
9a99cd7
remove resets
younik Jan 29, 2025
3f6d50a
make attributes private + add properties
younik Jan 30, 2025
3580ad0
fix data replace representation
younik Jan 30, 2025
c74084c
double replace solution
younik Jan 31, 2025
b8d030b
add todo
younik Jan 31, 2025
68ce5ba
fix formatting
younik Jan 31, 2025
912c27b
fix override import
younik Jan 31, 2025
8dcf7ac
fix tests
younik Jan 31, 2025
9028994
add base_transform property
younik Feb 3, 2025
8148c37
[Sprint] Clean up readme (#365)
CarlottaSartore Feb 4, 2025
43fb8ec
update ci for work on ubuntu last
CarlottaSartore Feb 4, 2025
b788f1d
udpate ci
CarlottaSartore Feb 4, 2025
05bbe6e
fix optax version for issues with automatic differentiation tests
CarlottaSartore Feb 4, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .github/workflows/ci_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

package:
name: Package the project
runs-on: ubuntu-22.04
runs-on: ubuntu-latest

steps:

Expand Down Expand Up @@ -58,7 +58,7 @@ jobs:
fail-fast: false
matrix:
os:
- ubuntu-22.04
- ubuntu-latest
- macos-latest
- windows-latest
python:
Expand Down Expand Up @@ -124,11 +124,11 @@ jobs:
steps.changes.outputs.all == 'true')
run: |
sudo apt-get update
sudo apt-get install lsb-release wget gnupg
sudo wget https://packages.osrfoundation.org/gazebo.gpg -O /usr/share/keyrings/pkgs-osrf-archive-keyring.gpg
sudo apt-get install lsb-release gnupg
sudo curl https://packages.osrfoundation.org/gazebo.gpg --output /usr/share/keyrings/pkgs-osrf-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/pkgs-osrf-archive-keyring.gpg] http://packages.osrfoundation.org/gazebo/ubuntu-stable $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/gazebo-stable.list > /dev/null
sudo apt-get update
sudo apt-get install --no-install-recommends libsdformat13 gz-tools2
sudo apt-get install gz-ionic sdf

- name: Run the Python tests
if: |
Expand All @@ -144,7 +144,7 @@ jobs:
publish:
name: Publish to PyPI
needs: test
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
permissions:
id-token: write

Expand Down
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
<br/>
<table>
<tr>
<th><img src="https://github.com/user-attachments/assets/115b1c1c-6ae5-4c59-92e0-1be13ba954db" width="250"></th>
<th><img src="https://github.com/user-attachments/assets/f9661fae-9a85-41dd-9a58-218758ec8c9c" width="250"></th>
<th><img src="https://github.com/user-attachments/assets/ae8adadf-3bca-47b8-97ca-3a9273633d60" width="250"></th>
<th><img src="https://github.com/user-attachments/assets/f9661fae-9a85-41dd-9a58-218758ec8c9c" width="500"></th>
<th><img src="https://github.com/user-attachments/assets/62b88b9d-45ea-4d22-99d2-f24fc842dd29" width="500"></th>
</tr>
</table>
<br/>
Expand Down Expand Up @@ -51,15 +50,14 @@ model = js.model.reduce(model=full_model, considered_joints=joints)

ndof = model.dofs()
# Initialize data and simulation
data = js.data.JaxSimModelData.zero(model=model).reset_base_position(
base_position=jnp.array([0.0, 0.0, 1.0])
)
# Note that the default data representation is mixed velocity representation
data = js.data.JaxSimModelData.build(model=model,base_position=jnp.array([0.0, 0.0, 1.0]))
T = jnp.arange(start=0, stop=1.0, step=model.time_step)
tau = jnp.zeros(ndof)

# Simulate
for t in T:
data, _ = js.model.step(model=model, data=data, link_forces=None, joint_force_references=tau)
data = js.model.step(model=model, data=data, link_forces=None, joint_force_references=tau)

```

Expand Down
2 changes: 1 addition & 1 deletion docs/guide/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ The logging and exceptions configurations is controlled by the following environ

*Default:* ``DEBUG`` for development, ``WARNING`` for production.

- ``JAXSIM_DISABLE_EXCEPTIONS``: Disables the runtime checks and exceptions.
- ``JAXSIM_ENABLE_EXCEPTIONS``: Enables the runtime checks and exceptions. Note that enabling exceptions might lead to device-to-host transfer of data, increasing the computational time required.

*Default:* ``False``.

Expand Down
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ dependencies:
- jaxlib >= 0.4.26
- jaxlie >= 1.3.0
- jax-dataclasses >= 1.4.0
- optax >= 0.2.3
- optax == 0.2.3
- pptree
- qpax
- rod >= 0.3.3
Expand Down
62 changes: 9 additions & 53 deletions examples/jaxsim_as_multibody_dynamics_library.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,8 @@
"data = js.data.random_model_data(model=model)\n",
"\n",
"# Print the default state.\n",
"W_H_B, s = data.generalized_position()\n",
"ν = data.generalized_velocity()\n",
"W_H_B, s = data.generalized_position\n",
"ν = data.generalized_velocity\n",
"\n",
"print(f\"W_H_B: shape={W_H_B.shape}\\n{W_H_B}\\n\")\n",
"print(f\"s: shape={s.shape}\\n{s}\\n\")\n",
Expand Down Expand Up @@ -365,12 +365,6 @@
"# Compute its pose w.r.t. the world frame through forward kinematics.\n",
"W_H_L = js.link.transform(model=model, data=data, link_index=link_index)\n",
"\n",
"# Alternatively, the same transform can be extracted from the tensor of\n",
"# all link transforms.\n",
"assert jnp.allclose(\n",
" W_H_L, js.model.forward_kinematics(model=model, data=data)[link_index]\n",
")\n",
"\n",
"print(f\"Transform of '{link_name}': shape={W_H_L.shape}\\n{W_H_L}\")"
]
},
Expand Down Expand Up @@ -406,7 +400,7 @@
"with data.switch_velocity_representation(VelRepr.Body):\n",
"\n",
" # Body-fixed generalized velocity.\n",
" B_ν = data.generalized_velocity()\n",
" B_ν = data.generalized_velocity\n",
"\n",
" # Free-floating Jacobian accepting a body-fixed generalized velocity and\n",
" # returning an inertial-fixed link velocity.\n",
Expand Down Expand Up @@ -479,7 +473,7 @@
"with data.switch_velocity_representation(VelRepr.Body):\n",
"\n",
" # Body-fixed generalized velocity.\n",
" B_ν = data.generalized_velocity()\n",
" B_ν = data.generalized_velocity\n",
"\n",
" # Free-floating Jacobian accepting a body-fixed generalized velocity and\n",
" # returning an inertial-fixed link velocity.\n",
Expand Down Expand Up @@ -782,12 +776,11 @@
")\n",
"\n",
"# Compute the 3D gravity vector and the total mass of the robot.\n",
"W_g = data.gravity\n",
"m = js.model.total_mass(model=model)\n",
"\n",
"# The centroidal dynamics can be computed as follows.\n",
"G_ḣ = 0\n",
"G_ḣ += m * jnp.hstack([W_g, jnp.zeros(3)])\n",
"G_ḣ += m * jnp.hstack([0, 0, model.gravity, 0, 0, 0])\n",
"G_ḣ += jnp.einsum(\"c66,c6->6\", G_Xf_C, jnp.hstack([C_fl, jnp.zeros_like(C_fl)]))\n",
"print(f\"G_ḣ: shape={G_ḣ.shape}\")"
]
Expand Down Expand Up @@ -839,7 +832,7 @@
"):\n",
"\n",
" # Compute the mixed generalized velocity.\n",
" BW_ν = data.generalized_velocity()\n",
" BW_ν = data.generalized_velocity\n",
"\n",
" # Compute the mixed generalized acceleration.\n",
" BW_ν̇ = jnp.hstack(\n",
Expand Down Expand Up @@ -876,44 +869,7 @@
"W_p̈_C = 0\n",
"W_p̈_C += jnp.einsum(\"c3g,g->c3\", J̇l_WC, BW_ν)\n",
"W_p̈_C += jnp.einsum(\"c3g,g->c3\", Jl_WC, BW_ν̇)\n",
"print(f\"W_p̈_C: shape={W_p̈_C.shape}\")\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "rrSfxp8lh9YZ"
},
"source": [
"### Contact Forces\n",
"\n",
"To conclude, JaxSim also provides different contact models to compute the contact forces. However, these forces are mainly related to the usage of JaxSim as a simulator rather than as a multibody dynamics library. This use case is shown in more details in other examples.\n",
"\n",
"Here below we report the function to call to compute the contact forces using the default contact model stored in the `JaxSimModel`."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "Ot6HePB_twaE",
"outputId": "02a6abae-257e-45ee-e9de-6a607cdbeb9a"
},
"outputs": [],
"source": [
"print(f\"Active contact model: {type(model.contact_model)}\\n\")\n",
"\n",
"# Compute the contact forces.\n",
"W_f_C = js.contact.collidable_point_forces(\n",
" model=model,\n",
" data=data,\n",
" link_forces=references.link_forces(model=model, data=data),\n",
" joint_force_references=references.joint_force_references(model=model),\n",
")\n",
"print(f\"W_f_C: shape={W_f_C.shape}\")"
"print(f\"W_p̈_C: shape={W_p̈_C.shape}\")"
]
},
{
Expand Down Expand Up @@ -944,7 +900,7 @@
"toc_visible": true
},
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "comodo_jaxsim",
"language": "python",
"name": "python3"
},
Expand All @@ -958,7 +914,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.15"
"version": "3.12.8"
}
},
"nbformat": 4,
Expand Down
14 changes: 6 additions & 8 deletions examples/jaxsim_as_physics_engine.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"# Set environment variable to avoid GPU out of memory errors\n",
"%env XLA_PYTHON_CLIENT_MEM_PREALLOCATE=false\n",
"\n",
"\n",
"# ================\n",
"# Notebook imports\n",
"# ================\n",
Expand Down Expand Up @@ -148,9 +149,7 @@
"outputs": [],
"source": [
"# Create the data of a single model.\n",
"data_zero = js.data.JaxSimModelData.zero(model=model)\n",
"base_position = jnp.array([0.0, 0.0, 1.0])\n",
"data = data_zero.reset_base_position(base_position=base_position) # Note that the reset position returns the updated data object"
"data = js.data.JaxSimModelData.build(model=model, base_position=jnp.array([0.0, 0.0, 1.0]))"
]
},
{
Expand All @@ -175,7 +174,7 @@
"\n",
"# Simulate\n",
"for _t in T:\n",
" data, _ = js.model.step(\n",
" data = js.model.step(\n",
" model=model,\n",
" data=data,\n",
" link_forces=None,\n",
Expand Down Expand Up @@ -234,12 +233,11 @@
"# Then we have to create the vector of initial state\n",
"batch_size = 5\n",
"data_batch_t0 = jax.vmap(\n",
" lambda pos: data_zero.reset_base_position(base_position=pos)\n",
")(jnp.tile(jnp.array([0.0, 0.0, 1.0]), (batch_size, 1)))\n",
" lambda pos: js.data.JaxSimModelData.build(model=model, base_position=pos))(jnp.tile(jnp.array([0.0, 0.0, 1.0]), (batch_size, 1)))\n",
"\n",
"data = data_batch_t0\n",
"for _t in T:\n",
" data, _ = step_parallel(model, data)"
" data = step_parallel(model, data)"
]
}
],
Expand All @@ -266,7 +264,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.13.0"
"version": "3.13.1"
}
},
"nbformat": 4,
Expand Down
Loading