Convert Figma logo to code with AI

google-deepmind logomujoco

Multi-Joint dynamics with Contact. A general purpose physics simulator.

7,805
777
7,805
92

Top Related Projects

Google DeepMind's software stack for physics-based simulation and Reinforcement Learning environments, using MuJoCo.

12,540

Bullet Physics SDK: real-time collision detection and multi-physics simulation for VR, games, visual effects, robotics, machine learning etc.

34,643

A toolkit for developing and comparing reinforcement learning algorithms.

MuJoCo is a physics engine for detailed, efficient rigid body simulations with contacts. mujoco-py allows using MuJoCo from Python 3.

Quick Overview

MuJoCo (Multi-Joint dynamics with Contact) is an advanced physics engine developed by Google DeepMind. It is designed for robotics, biomechanics, and machine learning research, offering fast and accurate simulation of complex dynamical systems with contacts.

Pros

  • High performance and accuracy in simulating complex physical interactions
  • Extensive support for various joint types and constraints
  • Seamless integration with machine learning frameworks like TensorFlow and PyTorch
  • Active development and support from Google DeepMind

Cons

  • Steep learning curve for beginners due to its complexity
  • Limited documentation compared to some other physics engines
  • Primarily focused on research applications, which may limit its use in some commercial projects
  • Requires a license for commercial use

Code Examples

  1. Creating a simple MuJoCo model:
import mujoco

model = mujoco.MjModel.from_xml_string("""
<mujoco>
  <worldbody>
    <light diffuse=".5 .5 .5" pos="0 0 3" dir="0 0 -1"/>
    <geom type="plane" size="1 1 0.1" rgba=".9 .9 .9 1"/>
    <body pos="0 0 1">
      <joint type="free"/>
      <geom type="sphere" size="0.1" rgba="1 0 0 1"/>
    </body>
  </worldbody>
</mujoco>
""")
  1. Simulating the model:
data = mujoco.MjData(model)
while data.time < 1.0:
    mujoco.mj_step(model, data)
    print(f"Time: {data.time:.2f}, Position: {data.qpos[:3]}")
  1. Rendering the simulation:
viewer = mujoco.viewer.launch_passive(model, data)
for _ in range(100):
    mujoco.mj_step(model, data)
    viewer.sync()
viewer.close()

Getting Started

  1. Install MuJoCo:

    pip install mujoco
    
  2. Create a simple model and simulate:

    import mujoco
    
    model = mujoco.MjModel.from_xml_string('<mujoco><worldbody><light diffuse=".5 .5 .5" pos="0 0 3" dir="0 0 -1"/><geom type="plane" size="1 1 0.1" rgba=".9 .9 .9 1"/><body pos="0 0 1"><joint type="free"/><geom type="sphere" size="0.1" rgba="1 0 0 1"/></body></worldbody></mujoco>')
    data = mujoco.MjData(model)
    
    for _ in range(100):
        mujoco.mj_step(model, data)
        print(f"Time: {data.time:.2f}, Position: {data.qpos[:3]}")
    
  3. For more advanced usage, refer to the official documentation and examples in the GitHub repository.

Competitor Comparisons

Google DeepMind's software stack for physics-based simulation and Reinforcement Learning environments, using MuJoCo.

Pros of dm_control

  • Higher-level API for building complex control tasks and environments
  • Includes a suite of pre-built tasks and domains for reinforcement learning research
  • Better integration with DeepMind's machine learning ecosystem

Cons of dm_control

  • More specialized for reinforcement learning, less flexible for general robotics simulations
  • Steeper learning curve for users not familiar with DeepMind's tools and conventions
  • Potentially slower performance due to additional abstraction layers

Code Comparison

dm_control:

from dm_control import suite
env = suite.load(domain_name="cartpole", task_name="swingup")
timestep = env.reset()
action = env.action_spec().generate_value()
next_timestep = env.step(action)

MuJoCo:

import mujoco
model = mujoco.MjModel.from_xml_path("cartpole.xml")
data = mujoco.MjData(model)
mujoco.mj_step(model, data)

dm_control builds upon MuJoCo, offering a more structured approach for reinforcement learning tasks, while MuJoCo provides lower-level control for physics simulations. The choice between them depends on the specific requirements of the project and the user's familiarity with each library.

12,540

Bullet Physics SDK: real-time collision detection and multi-physics simulation for VR, games, visual effects, robotics, machine learning etc.

Pros of Bullet

  • Open-source and free for commercial use
  • Supports a wide range of platforms and programming languages
  • Extensive documentation and active community support

Cons of Bullet

  • Less accurate for certain types of simulations compared to MuJoCo
  • May require more manual tuning and optimization for complex scenarios
  • Slower performance in some cases, especially for large-scale simulations

Code Comparison

MuJoCo example:

import mujoco
model = mujoco.load_model_from_path("model.xml")
data = mujoco.MjData(model)
mujoco.mj_step(model, data)

Bullet example:

import pybullet as p
p.connect(p.DIRECT)
robot = p.loadURDF("robot.urdf")
p.stepSimulation()

Both libraries offer Python bindings for ease of use, but MuJoCo's API is generally more concise and focused on physics simulation. Bullet provides a broader range of functionality, including rendering and collision detection, which can be beneficial for some applications but may require more setup code.

34,643

A toolkit for developing and comparing reinforcement learning algorithms.

Pros of Gym

  • Broader scope, supporting various environments beyond physics simulations
  • More extensive documentation and community support
  • Easier to set up and use for beginners in reinforcement learning

Cons of Gym

  • Less specialized for physics-based simulations
  • May have lower performance for complex physics tasks
  • Fewer built-in advanced features for detailed physics modeling

Code Comparison

MuJoCo example:

import mujoco
model = mujoco.load_model_from_path("model.xml")
sim = mujoco.MjSim(model)
sim.step()

Gym example:

import gym
env = gym.make('CartPole-v1')
observation = env.reset()
action = env.action_space.sample()
observation, reward, done, info = env.step(action)

MuJoCo focuses on low-level physics simulation, while Gym provides a higher-level interface for reinforcement learning environments. MuJoCo offers more control over physics parameters, while Gym emphasizes ease of use and standardization across different environments. MuJoCo is better suited for detailed physics simulations, while Gym is more versatile for general reinforcement learning tasks.

MuJoCo is a physics engine for detailed, efficient rigid body simulations with contacts. mujoco-py allows using MuJoCo from Python 3.

Pros of mujoco-py

  • More established and widely used in the reinforcement learning community
  • Extensive documentation and community support
  • Better integration with OpenAI Gym environments

Cons of mujoco-py

  • Requires a separate MuJoCo installation and license
  • Less frequently updated compared to mujoco
  • Limited to Python bindings

Code Comparison

mujoco-py:

import mujoco_py
import os
model = mujoco_py.load_model_from_path("model.xml")
sim = mujoco_py.MjSim(model)

mujoco:

import mujoco
import os
model = mujoco.MjModel.from_xml_path("model.xml")
data = mujoco.MjData(model)

The main difference in the code is the import statement and the way the model and simulation are initialized. mujoco-py uses mujoco_py.load_model_from_path() and mujoco_py.MjSim(), while mujoco uses mujoco.MjModel.from_xml_path() and mujoco.MjData(). The mujoco library provides a more direct interface to the MuJoCo physics engine, while mujoco-py acts as a Python wrapper around the C API.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

MuJoCo

MuJoCo stands for Multi-Joint dynamics with Contact. It is a general purpose physics engine that aims to facilitate research and development in robotics, biomechanics, graphics and animation, machine learning, and other areas which demand fast and accurate simulation of articulated structures interacting with their environment.

This repository is maintained by Google DeepMind.

MuJoCo has a C API and is intended for researchers and developers. The runtime simulation module is tuned to maximize performance and operates on low-level data structures that are preallocated by the built-in XML compiler. The library includes interactive visualization with a native GUI, rendered in OpenGL. MuJoCo further exposes a large number of utility functions for computing physics-related quantities.

We also provide Python bindings and a plug-in for the Unity game engine.

Documentation

MuJoCo's documentation can be found at mujoco.readthedocs.io. Upcoming features due for the next release can be found in the changelog in the latest branch.

Getting Started

There are two easy ways to get started with MuJoCo:

  1. Run simulate on your machine. This video shows a screen capture of simulate, MuJoCo's native interactive viewer. Follow the steps described in the Getting Started section of the documentation to get simulate running on your machine.

  2. Explore our online IPython notebooks. If you are a Python user, you might want to start with our tutorial notebooks running on Google Colab:

  • The introductory tutorial teaches MuJoCo basics: Open In Colab
  • The LQR tutorial synthesizes a linear-quadratic controller, balancing a humanoid on one leg: Open In Colab
  • The least-squares tutorial explains how to use the Python-based nonlinear least-squares solver: Open In Colab
  • The MJX tutorial provides usage examples of MuJoCo XLA, a branch of MuJoCo written in JAX: Open In Colab
  • The differentiable physics tutorial trains locomotion policies with analytical gradients automatically derived from MuJoCo's physics step: Open In Colab

Installation

Prebuilt binaries

Versioned releases are available as precompiled binaries from the GitHub releases page, built for Linux (x86-64 and AArch64), Windows (x86-64 only), and macOS (universal). This is the recommended way to use the software.

Building from source

Users who wish to build MuJoCo from source should consult the build from source section of the documentation. However, please note that the commit at the tip of the main branch may be unstable.

Python (>= 3.8)

The native Python bindings, which come pre-packaged with a copy of MuJoCo, can be installed from PyPI via:

pip install mujoco

Note that Pre-built Linux wheels target manylinux2014, see here for compatible distributions. For more information such as building the bindings from source, see the Python bindings section of the documentation.

Contributing

We welcome community engagement: questions, requests for help, bug reports and feature requests. To read more about bug reports, feature requests and more ambitious contributions, please see our contributors guide and style guide.

Asking Questions

Questions and requests for help are welcome as a GitHub "Asking for Help" Discussion and should focus on a specific problem or question.

Bug reports and feature requests

GitHub Issues are reserved for bug reports, feature requests and other development-related subjects.

Related software

MuJoCo forms the backbone of many environment packages, but these are too many to list here individually. Below we focus on bindings and converters.

Bindings

These packages give users of various languages access to MuJoCo functionality:

First-party bindings:

Third-party bindings:

Converters

  • OpenSim: MyoConverter converts OpenSim models to MJCF.
  • SDFormat: gz-mujoco is a two-way SDFormat <-> MJCF conversion tool.
  • OBJ: obj2mjcf a script for converting composite OBJ files into a loadable MJCF model.

Citation

If you use MuJoCo for published research, please cite:

@inproceedings{todorov2012mujoco,
  title={MuJoCo: A physics engine for model-based control},
  author={Todorov, Emanuel and Erez, Tom and Tassa, Yuval},
  booktitle={2012 IEEE/RSJ International Conference on Intelligent Robots and Systems},
  pages={5026--5033},
  year={2012},
  organization={IEEE},
  doi={10.1109/IROS.2012.6386109}
}

License and Disclaimer

Copyright 2021 DeepMind Technologies Limited.

Box collision code (engine_collision_box.c) is Copyright 2016 Svetoslav Kolev.

ReStructuredText documents, images, and videos in the doc directory are made available under the terms of the Creative Commons Attribution 4.0 (CC BY 4.0) license. You may obtain a copy of the License at https://creativecommons.org/licenses/by/4.0/legalcode.

Source code is licensed under the Apache License, Version 2.0. You may obtain a copy of the License at https://www.apache.org/licenses/LICENSE-2.0.

This is not an officially supported Google product.