# Issue with running the model

**URL:** <https://brian.discourse.group/t/issue-with-running-the-model/604>\
**Category:** Support\
**Created:** [8 February 2022 13:14 UTC](https://brian.discourse.group/t/issue-with-running-the-model/604 "2022-02-08T13:14:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dokato](https://avatars.discourse-cdn.com/v4/letter/d/f1d935/32.png) [@dokato](https://brian.discourse.group/u/dokato)\
**Post date:** [8 February 2022 13:14 UTC](https://brian.discourse.group/t/issue-with-running-the-model/604/1 "2022-02-08T13:14:01Z")

</div>

# 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

```auto

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)

```auto
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?

---

<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 February 2022 13:33 UTC](https://brian.discourse.group/t/issue-with-running-the-model/604/2 "2022-02-08T13:33:31Z")

</div>

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):

> [@dokato](#):
>
> ```auto
> tau_ref = 2 * ms, # refractory time 
> SFA = 0.1 * nS, # conductance adaptation
> 
> ```

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.

---

<div class="post-metadata">

**Author:** ![dokato](https://avatars.discourse-cdn.com/v4/letter/d/f1d935/32.png) [@dokato](https://brian.discourse.group/u/dokato)\
**Post date:** [8 February 2022 14:25 UTC](https://brian.discourse.group/t/issue-with-running-the-model/604/3 "2022-02-08T14:25:49Z")

</div>

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