techlist.io

Cython

1 posts

OpenAI2017-06-272 min readCurated summary

Faster physics in Python

# Faster Physics in Python: Open-Sourcing mujoco-py 1.50 OpenAI released a major version of mujoco-py, its Python 3 bindings for the MuJoCo physics engine, to support its deep learning robotics research. The release adds efficient parallel simulation, GPU-accelerated headless rendering, direct access to MuJoCo's internals, and support for MuJoCo 1.50 features such as its improved contact solver. Together these changes make batched simulation several times faster and let robotics teams generate large volumes of synthetic training data. ## Batched Simulation with MjSimPool - Trajectory optimization and reinforcement learning methods such as LQR, PI2, and TRPO benefit from running many simulations at once. - mujoco-py uses OpenMP for data parallelism, and Cython and NumPy for direct-access memory management. - Naive use of the new MjSimPool interface is about 400% faster than the previous version. - It is still about 180% faster than an optimized multiprocessing setup achieving the same parallelism. - Most of the gain comes from reduced access times to MuJoCo data structures. ## GPU-Accelerated Texture Randomization - OpenAI uses domain randomization across many projects, and headless GPU rendering provides about a 40x speedup over CPU rendering. - This yields hundreds of synthetic frames per second. - Randomizing a robot's textures during training helps it recognize its own body when transferring from simulation to the real world. ## Virtual Reality Support - The API is sufficient for VR interaction without additional C++ code. - The team ported MuJoCo's C++ VR example to Python using mujoco-py. - The example works with an HTC Vive setup. The support is experimental but has been used internally for some time. ## API and Usage - The `MjSim` class is the simplest entry point. It wraps the model and data, steps the simulation, and renders camera sensor images. - Models are loaded with `load_model_from_path`, and state is read through attributes such as `sim.data.qpos`. - Advanced users can access the MuJoCo C structs and functions directly. The README and full documentation cover these interfaces. ## Conclusion For teams running large-scale robotics simulation or training with synthetic data, mujoco-py 1.50 offers substantial performance gains. MjSimPool is the recommended starting point for batched workloads, and the included examples (`simpool.py`, `disco_fetch.py`) show how to use it.