Issue with running the model

Description of problem

I’m getting the difficult to debug error when I try to run the code included below. The error message is not very informative.

Minimal code to reproduce problem


tau_e=5 * ms # excitatory synaptic time constant
tau_i=10 * ms # inhibitory synaptic time constant
tau_Ia = 1000*ms # adaptation current

tau_ref = 2 * ms, # refractory time 
SFA = 0.1 * nS, # conductance adaptation
Vr=-60 * mV # resting potential
VT=-35 * mV # spike threshold 

DeltaT=1 * mV
g_l = 5 * nS # leak conductance 
E_l = -60 * mV
E_e = 0 * mV # excitatory synaptic potential
E_i = -75 * mV  # inhibitory synaptic potential
E_Ia = -90*mV
C_m = 100 * pF   # capacitance 


start_scope()

eqs = '''
    dv/dt = (g_l*(E_l-v) + g_e*(E_e-v) - g_i*(E_i-v) - g_Ia*(E_Ia-v))/C_m    : volt (unless refractory)
    dg_e/dt = -g_e/tau_e  : siemens
    dg_i/dt = -g_i/tau_i  : siemens
    dg_Ia/dt = -g_Ia/tau_Ia : siemens
    '''

G = NeuronGroup(10,
                eqs,
                threshold='v > VT',
                reset='''v = Vr; g_Ia-=SFA''',
                refractory = tau_ref)
G.v = -30 * mV

M = StateMonitor(G, 'v', record=True)

run(duration = 100*ms)

plot(M.t/ms, M.v[0])
xlabel('Time (ms)')
ylabel('v')

What you have aready tried

I tried to use Equations.

Full traceback of error (if relevant)

File ~/anaconda3/envs/brian/lib/python3.10/re.py:240, in findall(pattern, string, flags)
    233 """Return a list of all non-overlapping matches in the string.
    234 
    235 If one or more capturing groups are present in the pattern, return
   (...)
    238 
    239 Empty matches are included in the result."""
--> 240 return _compile(pattern, flags).findall(string)

TypeError: expected string or bytes-like object

The above exception was the direct cause of the following exception:

BrianObjectException                      Traceback (most recent call last)
Input In [69], in <module>
     33 G.v = -60 * mV
     35 M = StateMonitor(G, 'v', record=True)
---> 37 run(duration = 100*ms)
     39 plot(M.t/ms, M.v[0])
     40 xlabel('Time (ms)')

File ~/anaconda3/envs/brian/lib/python3.10/site-packages/brian2/units/fundamentalunits.py:2428, in check_units.<locals>.do_check_units.<locals>.new_f(*args, **kwds)
   2421             error_message = (f"Function '{f.__name__}' "
   2422                              f"expected a quantitity with unit "
   2423                              f"{unit} for argument '{k}' but got "
   2424                              f"'{value}'")
   2425             raise DimensionMismatchError(error_message,
   2426                                          get_dimensions(newkeyset[k]))
-> 2428 result = f(*args, **kwds)
   2429 if 'result' in au:
   2430     if isinstance(au['result'], Callable) and au['result'] != bool:

File ~/anaconda3/envs/brian/lib/python3.10/site-packages/brian2/core/magic.py:373, in run(duration, report, report_period, namespace, profile, level)
    310 @check_units(duration=second, report_period=second)
    311 def run(duration, report=None, report_period=10*second, namespace=None,
    312         profile=None, level=0):
    313     """
    314     run(duration, report=None, report_period=10*second, namespace=None, level=0)
    315     
   (...)
    371         intended use. See `MagicNetwork` for more details.
    372     """
--> 373     return magic_network.run(duration, report=report, report_period=report_period,
    374                              namespace=namespace, profile=profile, level=2+level)

File ~/anaconda3/envs/brian/lib/python3.10/site-packages/brian2/core/magic.py:230, in MagicNetwork.run(self, duration, report, report_period, namespace, profile, level)
    227 def run(self, duration, report=None, report_period=10*second,
    228         namespace=None, profile=None, level=0):
    229     self._update_magic_objects(level=level+1)
--> 230     Network.run(self, duration, report=report, report_period=report_period,
    231                 namespace=namespace, profile=profile, level=level+1)

File ~/anaconda3/envs/brian/lib/python3.10/site-packages/brian2/core/base.py:293, in device_override.<locals>.device_override_decorator.<locals>.device_override_decorated_function(*args, **kwds)
    291     return getattr(curdev, name)(*args, **kwds)
    292 else:
--> 293     return func(*args, **kwds)

File ~/anaconda3/envs/brian/lib/python3.10/site-packages/brian2/units/fundamentalunits.py:2428, in check_units.<locals>.do_check_units.<locals>.new_f(*args, **kwds)
   2421             error_message = (f"Function '{f.__name__}' "
   2422                              f"expected a quantitity with unit "
   2423                              f"{unit} for argument '{k}' but got "
   2424                              f"'{value}'")
   2425             raise DimensionMismatchError(error_message,
   2426                                          get_dimensions(newkeyset[k]))
-> 2428 result = f(*args, **kwds)
   2429 if 'result' in au:
   2430     if isinstance(au['result'], Callable) and au['result'] != bool:

File ~/anaconda3/envs/brian/lib/python3.10/site-packages/brian2/core/network.py:1006, in Network.run(self, duration, report, report_period, namespace, profile, level)
   1003 if namespace is None:
   1004     namespace = get_local_namespace(level=level+3)
-> 1006 self.before_run(namespace)
   1008 if len(all_objects) == 0:
   1009     return  # TODO: raise an error? warning?

File ~/anaconda3/envs/brian/lib/python3.10/site-packages/brian2/core/base.py:293, in device_override.<locals>.device_override_decorator.<locals>.device_override_decorated_function(*args, **kwds)
    291     return getattr(curdev, name)(*args, **kwds)
    292 else:
--> 293     return func(*args, **kwds)

File ~/anaconda3/envs/brian/lib/python3.10/site-packages/brian2/core/network.py:894, in Network.before_run(self, run_namespace)
    892             obj.before_run(run_namespace)
    893         except Exception as ex:
--> 894             raise BrianObjectException("An error occurred when preparing an object.", obj) from ex
    896 # Check that no object has been run as part of another network before
    897 for obj in all_objects:

BrianObjectException: Error encountered with object named 'neurongroup_17_stateupdater'.
Object was created here (most recent call only, full details in debug log):
  File '/var/folders/zt/s4rb4_kj4pnbmcqw7xyw52hw0000gn/T/ipykernel_88701/1728005146.py', line 28, in <module>
    G = NeuronGroup(10,

Clearly I made a mistake somewhere, not sure where?

Hi. This error message is indeed not very helpful… The problem is the definition of tau_ref (and SFA which would have raised an error later):

Both variables have a comma on the right-hand side, the variable tau_ref is therefore a tuple (2*ms, ) instead of a Quantity. For the refractory period, Brian tries to treat everything that is not a Quantity as a string expression, which leads to the error message.

1 Like

Oh, of course, thank you @mstimberg . Too much c&p, too little coffee today :wink:

1 Like