etaler / Etaler

A flexable HTM (Hierarchical Temporal Memory) framework with full GPU support.
BSD 3-Clause "New" or "Revised" License
89 stars 14 forks source link

Granularize error/pre/post-condition checking machenisim #133

Closed marty1885 closed 4 years ago

marty1885 commented 4 years ago

For now, there's three ways to check if an error (or function pre/post condition violation) occurs.

  1. if(some condition) { throw EtError("bla, bla, bla..."); }
  2. et_assert(some condition)
  3. checkProperties(tensor, )

Which is kinda not enough. if(...) throw; is okay for simple conditions but doesn't generate a stack trace even if we want to. et_assert just abort the entire program (including cling if using PyEtaler or ROOT) leading to a bad interactive experience. And checkProperties only works for tensors.

So I purpose the following:

  1. We reserve if..... throw; for simple cases
  2. checkProperties is still used for tensor checking
  3. et_assert is for absolutely worst, non-recoverable errors like OOM or internal state mess-ups
  4. a new et_check is used for ordinary condition checking. If the check fails, it throws an EtError and optionally generates a stack trace.
  5. We need a way to generate stack traces pragmatically. It also would be nice to be able to detect the present of cling and use cling for traces when available.

Even tho the C++ standard committee is against using exceptions for programming errors (dtype/shape/backend mismatch is our cases). We consider these user errors - the developers are our users and exceptions gives us a better experiences under an interactive environment. However depending on how contracts are implemented in C++23, it might be a good idea to replace some of the checks with it in the future.

Related to #93

marty1885 commented 4 years ago

Fixed by #140