Skip to content
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

(Very) small refractory values get lost in code generation #1521

Closed
mstimberg opened this issue Apr 8, 2024 · 0 comments · Fixed by #1522
Closed

(Very) small refractory values get lost in code generation #1521

mstimberg opened this issue Apr 8, 2024 · 0 comments · Fixed by #1522

Comments

@mstimberg
Copy link
Member

As mentioned on the discussion forum, very small refractory values are not handled correctly, since they are converted into code with Python's f format specifier which defaults to 6 significant digits:

>>> from brian2 import us
>>> f"{1*us:f}"
'0.000001'
>>> f"{0.6*us:f}"
'0.000001'
>>> f"{0.4*us:f}"
'0.000000'

This is of course rarely relevant (note that above the refractory period is < 1 microsecond), but still, it is unnecessary. I think I introduced this bug at some point when I modernized the code base to use format strings instead of the former % or .format syntax.

This issue is only triggered when you provide a Quantity as the refractory argument, not when you use a string directly:

group1 = NeuronGroup(..., refractory=0.4*us)    # WRONG: uses 0 as refractory period
group2 = NeuronGroup(..., refractory="0.4*us")  # WORKS
@mstimberg mstimberg self-assigned this Apr 8, 2024
mstimberg added a commit that referenced this issue Apr 8, 2024
This specifier defaults to 6 significant digits, truncating extremely small refractory times

Fixes (Very) small refractory values get lost in code generation #1521
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants
@mstimberg and others