taichi-dev/difftaichi

[MassSpring] Potentially incorrect index

Closed this issue · 4 comments

https://github.com/yuanming-hu/difftaichi/blob/ac72580d8e4ae7b36b6e8ecc72e0ab51670d6a9f/examples/mass_spring.py#L114

It seems that it should actually be v[t, j] instead of v[t, i]. Since j is for objects, i is for hidden layers; v was allocated with respect to the total number of objects.
https://github.com/yuanming-hu/difftaichi/blob/ac72580d8e4ae7b36b6e8ecc72e0ab51670d6a9f/examples/mass_spring.py#L74

I was kinda surprised that it works, but actually, all of the velocities are put into the input several times:

  • the number of hidden units is larger than the number of objects
  • when index is out of range for a tensor, it start cycling (note that matrix indices work okay v[t, i][3] will fail)

Nice catch! Running this script in debug mode I got

[E 05/29/20 19:29:40.506] [program.cpp:check_runtime_error@322] Assertion failure: Accessing Tensor of Size [4096, 
20] with indices (0, 20)

These scripts were written when Taichi doesn't really support debug mode...

Thank you very much for pointing this out! I'm checking other scripts. and will make an update soon.

I fixed indices. I believe the optimizations will converge better with this bug fixed (although I haven't got a chance to confirm quantitatively). Note that most tasks here are pretty simple so it may work even with the wrong indices...

Thanks again for pointing this out!

Great job! Thanks for the library and examples, it's of great potential.