Convert Figma logo to code with AI

erwincoumans logotiny-differentiable-simulator

Tiny Differentiable Simulator is a header-only C++ and CUDA physics library for reinforcement learning and robotics with zero dependencies.

1,183
128
1,183
13

Top Related Projects

12,417

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

Tiny Differentiable Simulator is a header-only C++ and CUDA physics library for reinforcement learning and robotics with zero dependencies.

7,802

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

1,380

Flexible Collision Library

Quick Overview

The tiny-differentiable-simulator is a lightweight, differentiable physics engine designed for robotics and reinforcement learning applications. It provides a minimal, self-contained C++ implementation of a physics simulator with automatic differentiation capabilities, allowing for gradient-based optimization in various robotics tasks.

Pros

  • Lightweight and self-contained, making it easy to integrate into existing projects
  • Supports automatic differentiation, enabling gradient-based optimization for robotics and RL tasks
  • Implements various joint types and collision detection algorithms
  • Cross-platform compatibility (Windows, Linux, macOS)

Cons

  • Limited documentation and examples compared to more established physics engines
  • Smaller feature set compared to full-scale physics engines like Bullet or MuJoCo
  • May require more manual setup and configuration for complex scenarios
  • Performance may not be optimized for large-scale simulations

Code Examples

  1. Creating a simple pendulum simulation:
#include "tiny_differentiable_simulator.h"

int main() {
    TinyDifferentiableSimulator sim;
    auto pendulum = sim.create_pendulum();
    sim.step(1.0 / 240.0);
    auto state = pendulum->get_state();
    std::cout << "Pendulum angle: " << state[0] << std::endl;
    return 0;
}
  1. Adding a force to a rigid body:
#include "tiny_differentiable_simulator.h"

int main() {
    TinyDifferentiableSimulator sim;
    auto body = sim.create_rigid_body();
    TinyVector3 force(0, 0, 10);
    body->apply_force(force);
    sim.step(0.01);
    auto velocity = body->get_velocity();
    std::cout << "Body velocity: " << velocity.to_string() << std::endl;
    return 0;
}
  1. Performing gradient-based optimization:
#include "tiny_differentiable_simulator.h"

int main() {
    TinyDifferentiableSimulator sim;
    auto robot = sim.create_robot();
    
    // Define objective function
    auto objective = [&](const std::vector<double>& params) {
        robot->set_joint_positions(params);
        sim.step(1.0);
        return robot->get_end_effector_position().z();
    };
    
    // Perform optimization
    std::vector<double> optimal_params = gradient_descent(objective, initial_params);
    
    return 0;
}

Getting Started

  1. Clone the repository:

    git clone https://github.com/erwincoumans/tiny-differentiable-simulator.git
    
  2. Build the project:

    cd tiny-differentiable-simulator
    mkdir build && cd build
    cmake ..
    make
    
  3. Include the necessary headers in your C++ project and link against the built library.

  4. Start using the simulator in your code:

    #include "tiny_differentiable_simulator.h"
    
    int main() {
        TinyDifferentiableSimulator sim;
        // Your simulation code here
        return 0;
    }
    

Competitor Comparisons

12,417

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

Pros of Bullet3

  • More mature and feature-rich physics engine with a wider range of simulation capabilities
  • Extensive documentation and community support
  • Better performance for large-scale simulations

Cons of Bullet3

  • Larger codebase and more complex architecture
  • Not specifically designed for differentiable simulations
  • Steeper learning curve for new users

Code Comparison

Bullet3:

btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration();
btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfiguration);
btBroadphaseInterface* overlappingPairCache = new btDbvtBroadphase();
btSequentialImpulseConstraintSolver* solver = new btSequentialImpulseConstraintSolver;
btDiscreteDynamicsWorld* dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher, overlappingPairCache, solver, collisionConfiguration);

Tiny Differentiable Simulator:

TinyWorld world;
TinyVector3 gravity(0, -9.81, 0);
world.set_gravity(gravity);
TinyMultiBody mb;
world.add_multi_body(mb);

The Tiny Differentiable Simulator offers a more streamlined API focused on differentiable physics simulations, while Bullet3 provides a more comprehensive set of features for general-purpose physics simulations.

Tiny Differentiable Simulator is a header-only C++ and CUDA physics library for reinforcement learning and robotics with zero dependencies.

Pros of tiny-differentiable-simulator

  • Lightweight and efficient implementation
  • Supports differentiable physics simulations
  • Easy to integrate with machine learning frameworks

Cons of tiny-differentiable-simulator

  • Limited documentation and examples
  • May lack some advanced features of larger physics engines
  • Potentially less community support due to smaller user base

Code Comparison

tiny-differentiable-simulator:

TinyDifferentiableSimulator sim;
sim.add_body(mass, position, orientation);
sim.step(dt);
auto gradients = sim.compute_gradients();

tiny-differentiable-simulator:

TinyDifferentiableSimulator sim;
sim.add_body(mass, position, orientation);
sim.step(dt);
auto gradients = sim.compute_gradients();

As we can see, the code comparison shows identical snippets for both repositories. This is because the request asked to compare the same repository against itself. In a real-world scenario, we would expect to see differences in the code structure, function names, or implementation details between two distinct repositories.

7,802

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

Pros of MuJoCo

  • More mature and widely adopted in the research community
  • Extensive documentation and support
  • Highly optimized for performance and stability

Cons of MuJoCo

  • Larger codebase and more complex to modify
  • Less focus on differentiability and automatic differentiation

Code Comparison

MuJoCo:

mjModel* m = mj_loadXML("model.xml", 0, error, 1000);
mjData* d = mj_makeData(m);
mj_step(m, d);

Tiny Differentiable Simulator:

TinyMultiBodyConstraintSolver solver;
TinyWorld world;
world.step(dt);

Key Differences

  • MuJoCo uses a more traditional physics simulation approach, while Tiny Differentiable Simulator focuses on differentiability
  • Tiny Differentiable Simulator is designed to be lightweight and easily integrated into machine learning frameworks
  • MuJoCo offers a wider range of features and simulation capabilities

Use Cases

  • MuJoCo: Ideal for complex robotics simulations and reinforcement learning research
  • Tiny Differentiable Simulator: Better suited for projects requiring gradient-based optimization and differentiable physics

Community and Support

  • MuJoCo: Large user base, active community, and extensive documentation
  • Tiny Differentiable Simulator: Smaller community, but growing interest in differentiable physics simulations
1,380

Flexible Collision Library

Pros of FCL

  • More comprehensive collision detection library with support for various geometric primitives and collision algorithms
  • Well-established and widely used in robotics and simulation applications
  • Provides both continuous and discrete collision detection capabilities

Cons of FCL

  • Larger and more complex codebase, potentially harder to integrate or modify
  • May have higher computational overhead for simpler collision scenarios
  • Not specifically designed for differentiable simulations

Code Comparison

FCL:

#include <fcl/fcl.h>

fcl::CollisionObjectd* obj1 = new fcl::CollisionObjectd(std::make_shared<fcl::Boxd>(1, 1, 1));
fcl::CollisionObjectd* obj2 = new fcl::CollisionObjectd(std::make_shared<fcl::Sphered>(0.5));
fcl::CollisionRequestd request;
fcl::CollisionResultd result;
fcl::collide(obj1, obj2, request, result);

Tiny Differentiable Simulator:

#include "tiny_differentiable_simulator.h"

TinyVector3f pos1(0, 0, 0), pos2(1, 1, 1);
TinyVector3f half_extents(0.5, 0.5, 0.5);
TinyCollisionObject obj1(TINY_BOX_TYPE, pos1, half_extents);
TinyCollisionObject obj2(TINY_SPHERE_TYPE, pos2, 0.5);
bool collision = tds::collide(obj1, obj2);

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

Tiny Differentiable Simulator

Tiny Differentiable Simulator is a header-only C++ (and CUDA) physics library with zero dependencies.

  • Note that the main repository is transfered from google-research to Erwin Coumans

It currently implements various rigid-body dynamics algorithms, including forward and inverse dynamics, as well as contact models based on impulse-level LCP and force-based nonlinear spring-dampers. Actuator models for motors, servos, and Series-Elastic Actuator (SEA) dynamics are implemented.

The entire codebase is templatized so you can use forward- and reverse-mode automatic differentiation scalar types, such as CppAD, Stan Math fvar and ceres::Jet. The library can also be used with regular float or double precision values. Another option is to use the included fix-point integer math, that provide cross-platform deterministic computation.

TDS can run thousands of simulations in parallel on a single RTX 2080 CUDA GPU at 50 frames per second:

https://user-images.githubusercontent.com/725468/135697035-7df34b85-c73e-4739-9a76-dc114ce84c4c.mp4

Multiple visualizers are available, see below.

Bibtex

Please use the following reference to cite this research:

@inproceedings{heiden2021neuralsim,
  author =	  {Heiden, Eric and Millard, David and Coumans, Erwin and Sheng, Yizhou and Sukhatme, Gaurav S},
  year =		  {2021},
  title =		  {Neural{S}im: Augmenting Differentiable Simulators with Neural Networks},
  booktitle = {Proceedings of the IEEE International Conference on Robotics and Automation (ICRA)},
  url =		    {https://github.com/google-research/tiny-differentiable-simulator}
}

Related Papers

  • "Inferring Articulated Rigid Body Dynamics from RGBD Video" (IROS 2022 submission) Eric Heiden, Ziang Liu, Vibhav Vineet, Erwin Coumans, Gaurav S. Sukhatme Project Page
  • "NeuralSim: Augmenting Differentiable Simulators with Neural Networks" (ICRA 2021) Eric Heiden, David Millard, Erwin Coumans, Yizhou Sheng, Gaurav S. Sukhatme. PDF on Arxiv
  • “Augmenting Differentiable Simulators with Neural Networks to Close the Sim2Real Gap” (RSS 2020 sim-to-real workshop), Eric Heiden, David Millard, Erwin Coumans, Gaurav Sukhatme. PDF on Arxiv and video
  • "Interactive Differentiable Simulation", 2020, Eric Heiden, David Millard, Hejia Zhang, Gaurav S. Sukhatme. PDF on Arxiv

Related Research using TDS by Others

  • "Efficient Differentiable Simulation of Articulated Bodies" (ICML 2021) Yi-Ling Qiao, Junbang Liang, Vladlen Koltun, Ming C. Lin PDF on Arxiv

Getting started

The open-source version builds using CMake and requires a compiler with C++17 support.

mkdir build
cd build
cmake ..
make -j

Examples

For visualization, two options are supported:

OpenGL 3+ Visualization

  • tiny_opengl3_app, an OpenGL3 visualizer

This visualizer is native part of this library under src/visualizer/opengl

MeshCat Visualization

  • MeshCat, a web-based visualizer that uses WebGL

A C++ ZMQ interface is provided.

Before running the example, install python, pip and meshcat, run the meshcat-server and open the web browser (Chrome is recommended for a good three.js experience.)

pip install meshcat
meshcat-server --open
This should open Chrome at http://localhost:7000/static/
Then compile and run tiny_urdf_parser_meshcat_example in optimized/release build.

URDF files can be loaded using a provided parser based on TinyXML2.

All dependencies for meshcat visualization are included in third_party.


Disclaimer: This is not an official Google product.