When defining variables that are used in the neuron group differential equations or in the synaptic parameters (so basically any of the equations that are assigned in quotations), it is straightforward to assign them to a variable name and, for example, sweep over different values of that variable.
However, if the neuron group or synaptic connections are defined within a function and that function is called from another file, I have been unable to pass parameter values into that function for assignment in these equations. In fact, I cannot even be assign values within the function and then use them in these string-equations.
I am guessing the issue has to do with how Brian uses namespaces, but nonetheless I have not come across any working solutions.
Note, that I have basically made a function that generates different population/synapse configurations so that I can sweep over different combinations and would therefore like to be able to pass in different parameters into this function and then into NeuronGroup and Synapses Brian functions.
KeyError: ‘The identifier “U” could not be resolved.’
Thanks, that makes things indeed clearer. The problem in this code is that Brian is resolving external variables at the point where net.run is called – “X” needs to be visible there (in your example code it kind of is actually, but it refers to an unknown variable X which I guess in your real code is replaced by a concrete value for example).
There are at least two ways to deal with this:
You can have a group-specific namespace in the synapses that you create in generate_population, i.e. they carry their own interpretation of external variables: