Coder Social home page Coder Social logo

desmondzhong / diff_sim_improve_grads Goto Github PK

View Code? Open in Web Editor NEW
4.0 3.0 0.0 305 KB

PyTorch and Taichi implementations of our paper on improving gradient computation

Home Page: https://desmondzhong.com/blog/2023-improving-gradient-computation/

License: Other

Python 100.00%
differentiable-programming dynamical-systems optimal-control pytorch taichi differentiable-simulation

diff_sim_improve_grads's Introduction


Improving Gradient Computation for Differentiable Physics Simulation with Contacts

Yaofeng Desmond Zhong, Jiequn Han, Biswadip Dey, Georgia Olympia Brikis | 2023

Conference Paper Blog Post

This repository contains Pytorch and Taichi implemenmtations to reproduce the optimal control tasks described in our paper.

We have a blog post explaining this work with interactive plots! Feel free to check it out!

Reproducibility

All experiments do not require GPUs.

To install all dependencies:

pip install -r requirements.txt
# or to install the exact versions of packages as done in this work. 
pip install -r requirements_freeze.txt

To run the optimal control tasks

# single collision task, pytorch implementation
python single_collision/single_torch.py

# single collision task, taichi implementation
python single_collision/single_taichi.py

# multiple collisions task, pytorch implementation
python multiple_collisions/multiple_torch.py

# multiple collisions task, taichi implementation
python multiple_collisions/multiple_taichi.py

Tasks

The goal of our optimal control tasks is to solve for the control sequence that minimize an objective. We can use differentiable simulation to calculate the gradients of the objective w.r.t. the control sequence and then use gradient descent to update control sequence iteratively.

Here the optimized trajectory of the single-collision task.

drawing

Here are he trajectories before and after optimization of the multiple-collision task. Notice that the number of collisions are different after optimization.

Before optimization After optimization
drawing drawing

Method

We find that, due to time discretization, the post-collision velocities of objects are not changing smoothly over the optimization iterations, which results in wrong gradient calculation. This is indicated by the difference between red and green arrows (penetration directions) in figure (a) abd (b) below. We propose to use continuous collision detection (CCD) and leverage collision direction, indicated by the brown arrow in (c) below, to compute the post-collision velocity. We show that after applying our technique, the optimization is able to converge to the analytical optimal solution for the two tasks considered. Check out our blog post for a more detailed and intuitive explanation.

(a) iteration $i$ (b) iteration $i+1$ (c) collision direction $\bar{n}$
drawing drawing drawing

Citation

If you find this work helpful, please consider starring this repo and citing our paper using the following Bibtex.

@article{zhong2023improving,
  title={Improving Gradient Computation for Differentiable Physics Simulation with Contacts},
  author={Zhong, Yaofeng Desmond and Han, Jiequn and Dey, Biswadip and Brikis, Georgia Olympia},
  journal={arXiv preprint arXiv:2305.00092},
  year={2023}
}

diff_sim_improve_grads's People

Contributors

desmondzhong avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.