# Minimal refractory time

**URL:** <https://brian.discourse.group/t/minimal-refractory-time/1183>\
**Category:** Support\
**Created:** [30 March 2024 18:35 UTC](https://brian.discourse.group/t/minimal-refractory-time/1183 "2024-03-30T18:35:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![YannaelB](https://avatars.discourse-cdn.com/v4/letter/y/8c91f0/32.png) [@YannaelB](https://brian.discourse.group/u/YannaelB)\
**Post date:** [30 March 2024 18:35 UTC](https://brian.discourse.group/t/minimal-refractory-time/1183/1 "2024-03-30T18:35:26Z")

</div>

# Description of problem

I am working on modeling electronic neurons. The firing rates we are working on are far higher than for modeling biological neurons (around 300kHz).  
I want to add a noise throught the refractory time but I encounter a problem. It seems that there is a minimal value for the refractory time. However, I have not read any thing about it on any papers/research related to Brian2.

# Minimal code to reproduce problem

```python
from brian2 import *
from brian2 import clear_cache
from brian2 import device
device.reinit()
start_scope()

defaultclock.dt = 0.0001*us # a tiny tiny value in order to show that it is not because of the defaultclock that the refractory time doesn't work under 0.5us

duration = 10*us
threshold = 10*mV
tau = 5*us
eqs = '''
dv/dt = (not_refractory)*(v0 - v) / tau : volt 
v0 : volt
'''
group1 = NeuronGroup(1, eqs, threshold='v > threshold ', reset='v = 0*mV',
                    refractory=0.6*us, method='heun')
group2 = NeuronGroup(1, eqs, threshold='v > threshold ', reset='v = 0*mV',
                    refractory=0.4*us, method='heun')
group1.v = 0*mV
group1.v0 = '18*mV '
group2.v = 0*mV
group2.v0 = '18*mV'

v_monitor1 = StateMonitor(group1, 'v', record=True)  
v_monitor2 = StateMonitor(group2, 'v', record=True)  

run(duration, report='text', report_period = 60*second)

plot(v_monitor2.t/us, v_monitor2.v[0]/mV,label="refrac < 0.5us")
plot(v_monitor1.t/us, v_monitor1.v[0]/mV,label="refrac > 0.5us")
plt.axhline(y=threshold/mV, color='r', linestyle='--',label='threshold')
xlabel('Time (us)')
ylabel('Voltage (mV)')
legend()
show()

```

# What you have aready tried

Changing the defaultclock.dt

# Expected output (if relevant)

A refractory time \<0.5\*us

# Actual output (if relevant)

For a refractory time \<= 0.5\*us, their is no refractory at all.

 ![refrac](https://global.discourse-cdn.com/free1/uploads/brian/original/1X/dc1ef1c6ff60e512202b449d335579e8e4c467d5.png)

# Full traceback of error (if relevant)

---

<div class="post-metadata">

**Author:** ![mstimberg](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/mstimberg/32/11_2.png) [@mstimberg](https://brian.discourse.group/u/mstimberg)\
**Post date:** [8 April 2024 13:07 UTC](https://brian.discourse.group/t/minimal-refractory-time/1183/2 "2024-04-08T13:07:22Z")

</div>

Hi @YannaelB, sorry about the late reply, I was on vacation last week. This is indeed a bug in Brian, thanks for reporting it! By accident, one path of the code generation translated the given refractory period into a string, and implicitly assumed that the refractory period was not extremely small. It should be an easy fix, but until then there’s also a simple workaround: you can specify the refractory period as a quantity (as you did), or as a string. The bug I mentioned only applies to quantities, so you can declare it using a string instead:

```python
group1 = NeuronGroup(1, eqs, threshold='v > threshold ', reset='v = 0*mV',
                    refractory="0.6*us", method='heun')
group2 = NeuronGroup(1, eqs, threshold='v > threshold ', reset='v = 0*mV',
                    refractory="0.4*us", method='heun')

```

This will make it work correctly:  
 ![Figure_1](https://global.discourse-cdn.com/free1/uploads/brian/original/1X/8ad880cbec04fb1d1a58327209574c1922887cb0.png)

---

<div class="post-metadata">

**Author:** ![mstimberg](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/mstimberg/32/11_2.png) [@mstimberg](https://brian.discourse.group/u/mstimberg)\
**Post date:** [8 April 2024 14:33 UTC](https://brian.discourse.group/t/minimal-refractory-time/1183/3 "2024-04-08T14:33:50Z")

</div>

For reference, here’s the GitHub issue I just opened: [(Very) small refractory values get lost in code generation · Issue #1521 · brian-team/brian2 · GitHub](https://github.com/brian-team/brian2/issues/1521)

---

<div class="post-metadata">

**Author:** ![YannaelB](https://avatars.discourse-cdn.com/v4/letter/y/8c91f0/32.png) [@YannaelB](https://brian.discourse.group/u/YannaelB)\
**Post date:** [9 April 2024 08:16 UTC](https://brian.discourse.group/t/minimal-refractory-time/1183/4 "2024-04-09T08:16:01Z")

</div>

Thank you very much for your help

---

<div class="post-metadata">

**Author:** ![mstimberg](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/mstimberg/32/11_2.png) [@mstimberg](https://brian.discourse.group/u/mstimberg)\
**Post date:** [9 April 2024 08:48 UTC](https://brian.discourse.group/t/minimal-refractory-time/1183/5 "2024-04-09T08:48:40Z")

</div>

I’ve just merged the fix into the main branch of our repository, if you want you can therefore install the development version as explained in our documentation to get the fix: [Installation — Brian 2 2.6.0 documentation](https://brian2.readthedocs.io/en/stable/introduction/install.html#development-install) We will probably have a “proper” release fairly soon, though, so you might rather want to wait to update and use the workaround until then.

PS: Not that it matters any more, but the bug did not only lead to 0.4µs being interpreted as 0.0µs, but 0.6µs did not work correctly either – it was interpreted as 1µs 😊
