taichi-dev / difftaichi

10 differentiable physical simulators built with Taichi differentiable programming (DiffTaichi, ICLR 2020)
2.47k stars 260 forks source link

Remove redundant lines in mass_spring.py clear_states() #30

Closed ehannigan closed 4 years ago

ehannigan commented 4 years ago

As I was playing around with mass_spring.py, I got confused by clear_states(). I was curious why only some of the variable gradients were being cleared. I dug into the TaiChi code and found that with Tape(loss) seems to clear all the variable gradients automatically, so there is no need to clear them in clear_states(). The only thing clear_states() needs to do is reset v_inc.

This shouldn't change how mass_spring.py runs at all (Although I cannot guarantee this because it seems that mass_spring.py is non deterministic and I get a slightly different result each time I run it). This edit should only help reduce confusion for new users.

However, if I have misunderstood clear_states(), let me know. I'm still pretty new to TaiChi.

ehannigan commented 4 years ago

This is a response to the question I asked in issue #29

ehannigan commented 4 years ago

No worries, managing TaiChi has got to be very time consuming. I learned a lot digging through TaiChi to figure out where gradients were cleared.