New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1-timestep difference when running certain simulations in standalone mode #695

Closed
mstimberg opened this Issue May 10, 2016 · 0 comments

Comments

Projects
None yet
1 participant
@mstimberg
Member

mstimberg commented May 10, 2016

The following code will run for 250 time steps in runtime mode but for 251 steps in standalone:

from brian2 import *
#set_device('cpp_standalone')
defaultclock.dt = 20.000000000020002*us
G = NeuronGroup(1, 'v:1')
mon = StateMonitor(G, 'v', record=True)
run(defaultclock.dt*250)
print len(mon.t)

The example may look contrived, but @romainbrette stumbled across this in a real use case, the weird dt value was of course not specified manually but taken from the difference between two time stamps in a file.

The reason for this issue is actually quite simple: we insert the desired runtime as a string into the standalone code, using default string formatting which does not preserve the full precision. We should instead force the use of the repr representation:

dt_float = float(20.000000000020002*us)
print('{t}'.format(t=250*dt_float))
print('{t!r}'.format(t=250*dt_float))
0.00500000000001
0.0050000000000050004

I had a quick check and it seems for other constants we are already using the conversion via repr, so they should be fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment