Description of problem
I am trying to simulate the model from Klaus Wimmer’s 2015 paper (Dynamics of sensory integration in a hierarchical network explains choice probabilities in cortical area MT) in Brian2. The model simulation code is publicly available but I am having issues translating it into Brian2.
First, the simulation code appears to be nested in an if statement, but the first line of the if statement (defaultclock.reinit()) throws up an error stating that there is ’ No attribute with name reinit’. Additionally, the penultimate line throws an error stating that Network’ object has no attribute ‘prepare’.
Minimal code to reproduce problem
if __name__ == '__main__':
# initialize
defaultclock.reinit()
net = Network(Dgroups.values(), Sgroups.values(), Dconnections.values(), Sconnections.values(),
Dnetfunctions, update_input, C_SE1_DE1, C_SE2_DE2, C_DE1_SE1, C_DE2_SE2,
S_DE1, S_DE2, S_SE1, S_SE2, R_DE1, R_DE2, R_SE1, R_SE2)
net.prepare()
What you have aready tried
I removed the if statement and the net.prepare line, but the code throws up another error relating to a parameter that was defined earlier.
Expected output (if relevant)
Actual output (if relevant)
Full traceback of error (if relevant)
defaultclock.reinit()
throws out this error:
KeyError Traceback (most recent call last)
File ~/Library/Python/3.11/lib/python/site-packages/brian2/groups/group.py:351, in VariableOwner.state(self, name, use_units, level)
350 try:
--> 351 var = self.variables[name]
352 except KeyError as exc:
File ~/Library/Python/3.11/lib/python/site-packages/brian2/core/variables.py:1455, in Variables.__getitem__(self, item)
1454 def __getitem__(self, item):
-> 1455 return self._variables[item]
KeyError: 'reinit'
The above exception was the direct cause of the following exception:
KeyError Traceback (most recent call last)
File ~/Library/Python/3.11/lib/python/site-packages/brian2/groups/group.py:387, in VariableOwner.__getattr__(self, name)
386 use_units = True
--> 387 return self.state(name, use_units)
389 except KeyError:
File ~/Library/Python/3.11/lib/python/site-packages/brian2/groups/group.py:353, in VariableOwner.state(self, name, use_units, level)
352 except KeyError as exc:
--> 353 raise KeyError(f"State variable {name} not found.") from exc
355 if use_units:
KeyError: 'State variable reinit not found.'
During handling of the above exception, another exception occurred:
AttributeError Traceback (most recent call last)
Cell In[22], line 1
----> 1 defaultclock.reinit()
File ~/Library/Python/3.11/lib/python/site-packages/brian2/core/clocks.py:201, in DefaultClockProxy.__getattr__(self, name)
199 return True
200 from brian2.devices.device import active_device
--> 201 return getattr(active_device.defaultclock, name)
File ~/Library/Python/3.11/lib/python/site-packages/brian2/groups/group.py:390, in VariableOwner.__getattr__(self, name)
387 return self.state(name, use_units)
389 except KeyError:
--> 390 raise AttributeError(f"No attribute with name {name}")
AttributeError: No attribute with name reinit
net.prepare throws up this error: AttributeError Traceback (most recent call last)
Cell In[23], line 166
162 # construct network
163 net = Network(Dgroups.values(), Sgroups.values(), Dconnections.values(), Sconnections.values(),
164 Dnetfunctions, update_input, C_SE1_DE1, C_SE2_DE2, C_DE1_SE1, C_DE2_SE2,
165 S_DE1, S_DE2, S_SE1, S_SE2, R_DE1, R_DE2, R_SE1, R_SE2)
--> 166 net.prepare()
167 net.run(runtime)
AttributeError: 'Network' object has no attribute 'prepare'
The code without the if statement and net.prepare throws up this error: KeyError Traceback (most recent call last)
File ~/Library/Python/3.11/lib/python/site-packages/brian2/core/network.py:892, in Network.before_run(self, run_namespace)
891 try:
--> 892 obj.before_run(run_namespace)
893 except Exception as ex:
File ~/Library/Python/3.11/lib/python/site-packages/brian2/groups/neurongroup.py:878, in NeuronGroup.before_run(self, run_namespace)
876 def before_run(self, run_namespace=None):
877 # Check units
--> 878 self.equations.check_units(self, run_namespace=run_namespace)
879 # Check that subexpressions that refer to stateful functions are labeled
880 # as "constant over dt"
File ~/Library/Python/3.11/lib/python/site-packages/brian2/equations/equations.py:1018, in Equations.check_units(self, group, run_namespace)
1016 external -= set(all_variables.keys())
-> 1018 resolved_namespace = group.resolve_all(external, run_namespace,
1019 user_identifiers=external) # all variables are user defined
1021 all_variables.update(resolved_namespace)
File ~/Library/Python/3.11/lib/python/site-packages/brian2/groups/group.py:731, in Group.resolve_all(self, identifiers, run_namespace, user_identifiers, additional_variables)
730 for identifier in identifiers:
--> 731 resolved[identifier] = self._resolve(identifier,
732 user_identifier=identifier in user_identifiers,
733 additional_variables=additional_variables,
734 run_namespace=run_namespace)
735 return resolved
File ~/Library/Python/3.11/lib/python/site-packages/brian2/groups/group.py:691, in Group._resolve(self, identifier, run_namespace, user_identifier, additional_variables)
689 # We did not find the name internally, try to resolve it in the external
690 # namespace
--> 691 return self._resolve_external(identifier, run_namespace=run_namespace)
File ~/Library/Python/3.11/lib/python/site-packages/brian2/groups/group.py:814, in Group._resolve_external(self, identifier, run_namespace, user_identifier, internal_variable)
813 error_msg = f'The identifier "{identifier}" could not be resolved.'
--> 814 raise KeyError(error_msg)
816 elif len(matches) > 1:
817 # Possibly, all matches refer to the same object
KeyError: 'The identifier "tau_GABA" could not be resolved.'
The above exception was the direct cause of the following exception:
BrianObjectException Traceback (most recent call last)
Cell In[24], line 167
163 net = Network(Dgroups.values(), Sgroups.values(), Dconnections.values(), Sconnections.values(),
164 Dnetfunctions, update_input, C_SE1_DE1, C_SE2_DE2, C_DE1_SE1, C_DE2_SE2,
165 S_DE1, S_DE2, S_SE1, S_SE2, R_DE1, R_DE2, R_SE1, R_SE2)
166 #net.prepare()
--> 167 net.run(runtime)
File ~/Library/Python/3.11/lib/python/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 ~/Library/Python/3.11/lib/python/site-packages/brian2/units/fundamentalunits.py:2462, in check_units.<locals>.do_check_units.<locals>.new_f(*args, **kwds)
2455 error_message = (f"Function '{f.__name__}' "
2456 f"expected a quantitity with unit "
2457 f"{unit} for argument '{k}' but got "
2458 f"'{value}'")
2459 raise DimensionMismatchError(error_message,
2460 get_dimensions(newkeyset[k]))
-> 2462 result = f(*args, **kwds)
2463 if 'result' in au:
2464 if isinstance(au['result'], Callable) and au['result'] != bool:
File ~/Library/Python/3.11/lib/python/site-packages/brian2/core/network.py:1007, in Network.run(self, duration, report, report_period, namespace, profile, level)
1004 if namespace is None:
1005 namespace = get_local_namespace(level=level+3)
-> 1007 self.before_run(namespace)
1009 if len(all_objects) == 0:
1010 return # TODO: raise an error? warning?
File ~/Library/Python/3.11/lib/python/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 ~/Library/Python/3.11/lib/python/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_6'.
Object was created here (most recent call only, full details in debug log):
File '/var/folders/5_/t7fh3bc53l33rdmffzzqhdf4nb8xt0/T/ipykernel_84865/9675799.py', line 86, in make_integration_circuit
decisionE = NeuronGroup(NE, model=eqsE, threshold=Vt, reset=Vr, refractory=tau_refE)
An error occurred when preparing an object. (See above for original error message and traceback.)