
Enabling fluid simulation
Since Isaac Lab's support for fluid simulation in reinforcement learning (RL) is currently limited, we need to make some modifications to enable fluid simulation during RL training. To the best of our knowledge (by 11/2024), no one has yet proposed a complete solution for conducting fluid simulation in Isaac Lab. The implementation steps are as follows:
- Run simulation with cpu mode using
--device cpu
. After extensive testing, we found that fluid motion is visible in the GUI only when Isaac Sim is running in CPU mode, regardless of whether thefabric
extension is enabled. Additionally, it is possible to retrieve the positions and velocities of fluid particles using Python code in this configuration. - When running RL in CPU mode, some parts of the
rsl_rl
code may not function correctly. To address this, you need to add the following line to line 114 of theon_policy_runner.py
file located inrsl_rl\rsl_rl\runners
: - When running Isaac Lab in headless mode, the simulator settings differ from those in GUI mode, which prevents us from retrieving the positions of fluid particles.
To resolve this, modify lines 213-214 in the file
IsaacLab\source\apps\isaaclab.python.headless.kit
as follows: - The Manager-based workflow does not support fluid creation and reset, so we use the Direct workflow instead. Examples of the Direct workflow can be found in the directory:
The Code
This is a sample code of RL training with fluid simulation:
Sample code of RL training with fluid simulation
The Code Explained
This section covers the implementation of fluid simulation in Isaac Lab.
In Isaac Lab, when creating a scene, we typically only need to create one env, and the other envs are duplicated by Isaac Lab based on the first one. However, since Isaac Lab does not support duplicating particle objects, we need to create individual particle objects for each env.
We use particleUtils.add_physx_particle_system
to create the particle system and the CreateMdlMaterialPrim
command to bind the physical and surface materials of the particles.
It is important to note that the CreateAndBindMdlMaterialFromLibrary
command is not available in headless mode, so we need to use the CreateMdlMaterialPrim
command instead.
Next, we configure the physical properties of the particle system.
We use particleUtils.add_physx_particleset_points
to create a particle set, which belongs to the particle system and contains the actual particles.
In an RL environment, only one particle system is needed, but a separate particle set must be created for each environment.
Currently, there doesn't seem to be a direct way to retrieve the positions and velocities of particles from Isaac Lab's backend.
As a workaround, we use the UsdGeom
Points API to obtain the particle states. This is also why it's necessary to enable UpdateToUsd
and UpdateParticlesToUsd
.
Directly converting particle states into tensors is very slow, significantly impacting RL training efficiency. However, converting them into NumPy arrays is much faster. Therefore, we convert the particle positions into a NumPy array and record the minimum value along the z-axis for each group of particles, as this is the only data we need.