brian-team / brian2

Brian is a free, open source simulator for spiking neural networks.
http://briansimulator.org
Other
924 stars 219 forks source link

Runtime error checking #499

Open thesamovar opened 9 years ago

thesamovar commented 9 years ago

More and more, we have features which could have associated runtime errors which we don't handle at the moment. For example, neuron indices in TimedArray, and potentially times that are not recorded in delayed variables (https://github.com/brian-team/brian2/issues/467#issuecomment-119553429). In the case of the former, this would typically raise an IndexError when running in numpy, or segfault when running in compiled mode. In either case it wouldn't be silent. However, for unrecorded times for delayed variables you would get silently incorrect behaviour. In addition, it's hard for the user to know what is going wrong when it just segfaults, so for all these cases having runtime error checking would be potentially beneficial. Since it would slow things down though, it should be made optional with a preference.

Issues for discussion:

I feel that the error checking preference should be set on by default.

We might also consider having switches for different types of error checking (e.g. you might want to check for errors in delays but not in indices if you were confident about the one but not the other).

We could also check for nan values or improbably large values in state variables to indicate to users that their differential equation solver was unstable since this is often a source of problems on the mailing list. This could be done every 100 timesteps or so to keep the computational cost down.

mstimberg commented 9 years ago

We should also have convenience functions (e.g. jinja2 macros?) that 1) do not include the error-checking code in the template if the respective preference is not set and 2) wrap the complexity of raising a Python exception from weave/cython, as well as whatever we want to do in standalone (just error message and exit, I guess)

thesamovar commented 9 years ago

Yep!