Brax - A Differentiable Physics Engine for Large Scale Rigid Body Simulation

C. Daniel Freeman, Erik Frey, Anton Raichuk, Sertan Girgin, Igor Mordatch, Olivier BachemNeurIPS 2021

TL;DR

Brax is a new, open-source, differentiable physics engine built in JAX, designed for high-performance, large-scale rigid body simulations on accelerators. It aims to bridge the gap between simulation and reinforcement learning (RL) by enabling faster training, new optimization techniques, and seamless integration with RL algorithms.

What Problem Does This Paper Address?

Reinforcement learning (RL) has made significant strides in controlling physically simulated agents, but training these agents remains prohibitively expensive and slow. This is largely due to the computational demands of physics simulations and the inefficiencies in how RL algorithms interact with them. Current simulation engines often run on CPUs while RL algorithms run on GPUs/TPUs, leading to communication bottlenecks. Furthermore, the lack of differentiability in many engines limits the optimization methods that can be used, forcing reliance on slower, model-free approaches. This inaccessibility, both in terms of computational cost and algorithmic flexibility, hinders research progress.

Methods

Brax tackles these challenges with several key innovations:

  • JAX-based Physics Engine: Brax is written entirely in JAX, a high-performance numerical computation library that leverages automatic differentiation and XLA (Accelerated Linear Algebra) for efficient compilation and execution on accelerators like GPUs and TPUs.
  • Device-Parallelism and Auto-Vectorization: The engine is designed from the ground up to exploit parallelism across multiple accelerators and vectorize computations within a single device. This allows for simulating thousands of independent environments concurrently.
  • Differentiable Simulation: Brax provides gradients for the environment's state, opening the door to gradient-based optimization methods beyond traditional RL, such as directly optimizing physics parameters or using differentiable physics for planning.
  • Integrated RL Algorithms: The paper presents reimplementations of popular RL algorithms (PPO, SAC, ES, APG) in JAX that compile and run alongside the Brax environments on the same accelerator. This co-location eliminates data transfer bottlenecks and allows for end-to-end jitted training loops.
  • ProtoBuf Environment Specification: A flexible ProtoBuf format is used to define physics scenes, allowing for rich and complex environments to be constructed.

Datasets

The paper introduces a suite of environments inspired by existing reinforcement learning benchmarks, including:

  • MuJoCo-likes: Recreations of Ant, Halfcheetah, and Humanoid environments.
  • Grasp: A dexterous manipulation task involving picking up and moving a ball.
  • Fetch: A goal-directed locomotion task.

These environments are designed to be used with the bundled RL algorithms and are available for interactive training in Colab notebooks.

Key Insights and Ideas

  • The Power of Co-location: By running the physics engine and RL algorithms on the same accelerator and compiling them together, Brax achieves dramatic speedups (100-1000x) compared to traditional CPU-based simulation setups. This is a fundamental shift in how RL experiments can be conducted.
  • Differentiability Unlocks New Possibilities: The ability to backpropagate through the physics simulation opens up avenues for more sophisticated control and optimization techniques, moving beyond purely model-free RL.
  • Scalability is Key: The design for large-scale parallelism on accelerators is crucial for tackling the sample complexity of modern RL problems, making research more accessible and affordable.
  • Bridging the Gap: Brax effectively bridges the gap between the simulation and learning components, allowing for faster iteration, debugging, and ultimately, more efficient RL research.

Key Results

  • Massive Speedups: Brax can achieve millions of simulation steps per second on a single accelerator for simple environments like Ant, and scales to hundreds of millions of steps per second across multiple accelerators.
  • Rapid Policy Training: Performant policies for many of the bundled environments can be trained in seconds to minutes on a standard accelerator. For example, training the Ant environment with Brax's PPO takes seconds, compared to nearly half an hour for a standard PPO implementation.
  • Qualitative Similarity: Brax's MuJoCo-like environments demonstrate qualitatively similar training curves and performance to their MuJoCo counterparts when using standard RL algorithms.
  • Improved Simulation Quality: Brax exhibits competitive linear momentum conservation and superior angular momentum conservation compared to other engines.

Limitations and Future Work

  • Spring Joints Brittleness: The reliance on spring constraints for joints can lead to instabilities that require careful tuning of damping, mass, inertia, and step sizes. Featherstone-style methods are suggested for future work.
  • Naive Collision Detection: The current implementation uses quadratically-scaling, naive collision detection, which may become a bottleneck for highly complex scenes with many colliders. More advanced collision physics are planned.
  • JIT Compilation Times: While JAX's JIT compilation is a strength, it can sometimes lead to significant compilation times, especially for complex environments and learning algorithms.
  • Algorithm Maturity: While PPO and SAC are well-tested, other bundled algorithms like APG and ES require further exploration and testing.
  • Social Impact Considerations: The authors acknowledge the potential for faster engines to increase compute expenditure and the dual-use nature of robotics control technology. They also note the commitment to renewable energy sources for their data centers.
  • Future Work: The authors plan to investigate Featherstone methods for joints, more advanced collision physics, and further leverage the differentiability of the engine for more advanced algorithms. They also aim to bring closer parity with MuJoCo's environments and explore sim-to-real transfer.

Summary updated

BibTeX
@inproceedings{freeman2021brax,
  author = {C. Daniel Freeman and Erik Frey and Anton Raichuk and Sertan Girgin and Igor Mordatch and Olivier Bachem},
  title = {{Brax - A Differentiable Physics Engine for Large Scale Rigid Body Simulation}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2021},
  url = {https://openreview.net/forum?id=VdvDlnnjzIN},
}
Figure