brian-team / brian2genn

Brian 2 frontend to the GeNN simulator
http://brian2genn.readthedocs.io/
GNU General Public License v2.0
47 stars 16 forks source link

Better implementation of _timestep function #81

Closed tnowotny closed 5 years ago

tnowotny commented 5 years ago

Hi @mstimberg, I notice you implemented the Brian 2 _timestep function to derive an integer timestep from the global variable t as

return (int64_t)((t + 1e-3*dt)/dt);

Is there a particular reason why not return the GeNN intrinsic integer timestep

return iT;

(maybe you didn't know of its existence but I thought I'd ask before changing your solution)?

tnowotny commented 5 years ago

Hum ... was just about to make a pull request for this but while it gives more precise timestep information and is more efficient, I could see problems as t and dt is passed to the function, a user could in principle pass in completely different t and dt into the function than is currently used int he simulation. I guess it would be quite dangerous to change is actually. So I guess we leave it as is.

mstimberg commented 5 years ago

It is unfortunately a bit more complicated than that. The main expression where we use the timestep function is when checking whether a neuron is refractory. The expression we use is something like:

bool not_refractory = _timestep(t - lastspike, dt) >= _timestep(0.005, dt);

(where the 0.005 stands for a refractory time of 5ms). We could certainly implement this in a more efficient way, but I think it would be better to do this for Brian in general and not only for Brian2GeNN. For example, we could not only have a lastspike variable, but also an integer variable steps_since_last_spike that we can then directly compare.

And yes, in principle a user could use the timestep for something else, even though I don't see many use cases.