Taichi: A Brand New Programming Language, “Frozen” in 99 Lines of Code FineReport | BI Reporting and Dashboard Software

Taichi: A Brand New Programming Language, “Frozen” in 99 Lines of Code

Original source from https://mp.weixin.qq.com/s/H7YAcOTjM1RSEU4HpQRkkA

For code details, please click the taichi_mpm project link at the end of the text.

What is Taichi?

With only 99 lines of code, you can also have the magic of snow and ice like Princess Aisha in “Frozen”.
Although you cannot arbitrarily create magic in the real world, it can be implemented in the virtual world of computers.

Maybe you don’t know that sometimes special effects in movies and animations that last for just one second may require a high-performance computer to perform calculations for a week, which costs surprisingly.

“Frozen” has no real person, but the budget is as high as 150 million US dollars, and every second of the lens is burning. It is unimaginable for most people to use computers to make CG effects.

However, recently an MIT PhD from China has developed a new CG special effects programming language, Taichi, which has greatly reduced the threshold.

(White: snow; red: jelly; blue: water)

A simple physical scene can be rendered in just a few minutes on an ordinary PC. It is 188 times faster than TensorFlow and 13.4 times faster than PyTorch, and the code length is only one-tenth of other methods.

Installing it is as easy as TensorFlow, and it’s almost the same:

import taichi as ti

88 Lines of Code to Simulate a Real Physical Environment

As Hu said, 99 lines of code are short, but the technical story behind it is long.

The beginning of the story is the Material Point Method.

MPM is a popular method for simulating continuous media in the field of film and television special effects, and Disney’s “Frozen” also uses this technology.

But in the early days, MPM was running very slowly. For example, in the movie “Frozen”, the scene of Anna going cross the snow. It is said to run on the cluster for a whole week.

In order to improve the running speed and performance of MPM, Yuanming. Hu invested in the research of Moving Least Squares MPM (MLS-MPM) during the summer vacation of his senior year.

Yuanming.Hu’s inspiration was to use the moving least-squares method to unify the two discretizations of the affine velocity field in APIC (The Affine Particle-In-Cell Method) and the deformation gradient update in MPM.

Under the guidance of Professor Jiang of the University of Pennsylvania, Hu and others completed the study of the moving least squares material point method (MLS-MPM), which not only realized the new discretization of the stress divergence but also made the MPM run faster. It also doubled and successfully simulated various new phenomena that MPM had not previously supported.

Such as material cutting:

Two-way coupling of rigid bodies:

This result was finally published at SIGGRAPH 2018.

In order to further prove the simplicity of MLS-MPM, Hu implemented the MLS-MPM demo with 88 lines of C ++ code. (For code details, please click the taichi_mpm project link at the end of the text).

This 88-line version later became a necessary reference implementation for getting started with MPM.


Later, Mr. Hu pushed the work one step further and proposed DiffTaichi, differentiable programming, which was included in ICLR 2020.

In the code in this article, Hu created 10 different physical simulators and benchmarked their performance against existing benchmarks.

Differentiable programming in Taichi can effectively optimize the neural network controller through brute force gradient descent without using reinforcement learning.

Most of the 10 differentiable simulators can be implemented in 2-3 hours, and most do not require a GPU. In these examples, elastomers, rigid bodies, fluids, refraction of light, and elastic collisions, there are common physical environments.

The first example is a differentiable elastic object simulator. After our actual measurement, it can also run on the 2017 version of the 13-inch MacBook Pro, and it takes less than ten minutes to complete the optimization:



Not only 2D, more complex 3D elastomers can also be simulated:

There is also a differentiable 3D fluid simulator. After 450 steps of gradient descent iteration, it is very realistic:

DiffTaichi can simulate the render of water refraction of light. After an image is rendered, it can even fool the image classifier. After testing, VGG16 treated the squirrel picture with water ripple as a goldfish, and the probability was 99.91%.

In the simulation environment of reinforcement learning, rigid body robots are common, DiffTaichi can also simulate:

DiffTaichi can also simulate complex scenes with multiple objects, such as billiards:

The simulator written in Taichi language greatly simplifies the code. The differentiable elastic object simulator uses only 110 lines of code, while the direct writing in CUDA requires 490 lines.

At the same time, Taichi’s speed is very fast, there is almost no loss compared to the CUDA version, it is 188 times faster than TensorFlow, and 13.4 times faster than PyTorch.


Moreover, the neural network controller generally only needs tens of iterations to complete the optimization.


Yuanming.Hu Zhihu:




Tai Chi Project:


taichi_mpm project:



Related Posts

© All Right Reserved