Taichi: NAN check and throw exception on debug mode

Created on 25 Aug 2020  路  3Comments  路  Source: taichi-dev/taichi

Concisely describe the proposed feature
I found it's hard to locate where the first NAN was calculated when I use Taichi to write MPM simulation code, once a NAN exist, the calculation iterations will spread it to everywhere. It seems Taichi hasn't included NAN judge function and because of parallelism and numbers of particles, locate the problem is still challenging for me.

Describe the solution you'd like (if any)
Add library functions like insan(), isinf().
Throw reasonable exception information in debug mode when encountered NAN.

Additional comments
My Macbook system version is OS X 10.11.6, for some reasons it can't update but have enough calculation resources, could Taichi support OS X 10.11.6 next time? :P

feature request

Most helpful comment

For the isnan and isinf, consider install taichi_glsl, an extension library:

pip install taichi_glsl

or simply define one yourself:

@ti.func
def isnan(x):
    return not (x >= 0 or x <= 0)

For the throw exception when NAN detected on debug mode, use the assert statement with ts.isnan:

import taichi as ti
import taichi_glsl as ts

ti.init(debug=True)  # `assert` only works in debug mode

@ti.kernel
def substep():
  ...
  assert not ts.isnan(x), "some message"   # insert this statement to some critical points
  ...

For the OS X 10.11.6, sorry about the trouble, @yuanming-hu would you mind help to support taichi on 10.11.6?

All 3 comments

For the isnan and isinf, consider install taichi_glsl, an extension library:

pip install taichi_glsl

or simply define one yourself:

@ti.func
def isnan(x):
    return not (x >= 0 or x <= 0)

For the throw exception when NAN detected on debug mode, use the assert statement with ts.isnan:

import taichi as ti
import taichi_glsl as ts

ti.init(debug=True)  # `assert` only works in debug mode

@ti.kernel
def substep():
  ...
  assert not ts.isnan(x), "some message"   # insert this statement to some critical points
  ...

For the OS X 10.11.6, sorry about the trouble, @yuanming-hu would you mind help to support taichi on 10.11.6?

It works. Thanks! : )

Glad that this issue has been resolved.

For the OS X 10.11.6, sorry about the trouble, @yuanming-hu would you mind help to support taichi on 10.11.6?

Sorry, but we have to prioritize on supporting OS X 10.14+...

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Xayahp picture Xayahp  路  3Comments

liaopeiyuan picture liaopeiyuan  路  3Comments

archibate picture archibate  路  4Comments

archibate picture archibate  路  3Comments

kigawas picture kigawas  路  4Comments