Description of problem
Hello, I always appreciate using Brian2.
Recently, I’ve been refining my code to enable the configuration of Brian2 objects through a separate script, in addition to the main script responsible for creating these objects in the lists with for loops.
But when I run the simulation the warning messages pop out and indicate that there is a conflict between internal variables and run namespace values.
The warning message for the first type is as follows (for the list ‘neurongroups’ which contains about 15 neurons) :
WARNING The name "timestep" refers to different objects in different namespaces used for resolving names in the context of group "neurongroup_1".
Will use the object from the functions namespace with the value <Function>,
but the name also refers to a variable in the run namespace with value '100. * usecond'. [brian2.groups.group.Group.resolve.resolution_conflict]
The second type mentions the variable ‘t’ for a poison group and synapses :
WARNING 't' is an internal variable of group 'poissongroup', but also exists in the run namespace with the value 3. The internal variable will be used. [brian2.groups.group.Group.resolve.resolution_conflict]
WARNING 't' is an internal variable of group 'synapses_10', but also exists in the run namespace with the value 3. The internal variable will be used. [brian2.groups.group.Group.resolve.resolution_conflict]
And the last ones are about the variable ‘gmax’ :
WARNING 'gmax' is an internal variable of group 'synapses_20', but also exists in the run namespace with the value 250. * psiemens. The internal variable will be used. [brian2.groups.group.Group.resolve.resolution_conflict]
I found it difficult to grasp the situation accurately.
First of all, what are the functions namespace and the run namespace, and why would an internal variable also exist in there? I looked into the Brian2 documentation about the ‘Namespaces’ but I couldn’t get a clear idea of the namespaces. :
Brian2 docs about Namespaces
Since I haven’t provided to the Network.run
I guess this problem has something to do with the lines around the point where the run function is called.
My code around those lines was:
net = Network(collect())
net.add(neurongroups, input_layers, input_synapses, intrinsic_syns_inh, intrinsic_syns_exc, neurongroups_ii, neurongroups_exc, intrinsic_synapses, fw_sources, fw_targets, forward_synapses, bw_sources, bw_targets, backward_synapses, statemonitors, spikemonitors, poprate_mons)
net.run(simulation_time)
In the main script, I’ve already created objects within a list, but around the “run” section, I’m placing those lists inside the net object. Could this be causing a collision, making it seem like they are duplicated?
But referring to the following post, it seems like there was no other option but to use this method.
existing question here
Also, the second question is, what would the ‘t’ variable be?
The warning message says ‘t’ is an internal variable for a synapse (and a poison group) but I cannot find any lines that I set those variables when creating the synapses.
Could you lend me a hand? It’s quite confusing.
Thanks a lot.
Minimal code to reproduce problem
I am attaching only the part creating neuron groups.
Script 1 - main script
from brian2 import *
from config_cmc import *
from equations_cmc import *
from synapses_cmc import *
neurongroups = []
for G in range(n_groups) :
neurongroups.append(NeuronGroup(n_neurons[G], eqs_list[G], method='euler',
threshold='v > Vthreshold', reset='v=Vl',refractory=2*ms))
neurongroups[G].v = -70*mV
neurongroups = [neurongroups[i : i+len(n_neurons_1area)] for i in range(0, len(neurongroups), len(n_neurons_1area))]
# inhibitory neurongroups
neurongroups_ii = []
for a in range(len(neurongroups)) :
neurongroups_ii.append(neurongroups[a][inh_idx])
# print('len(neurongroups_ii): ', len(neurongroups_ii))
# excitatory neurongroups
neurongroups_exc = []
for a in range(len(neurongroups)) :
for i in range(len(neurongroups[0])) :
if i != inh_idx :
neurongroups_exc.append(neurongroups[a][i])
Script 2 - config_cmc.py
from brian2 import *
from equations_cmc import *
# basic
simulation_time = (50*2*10)*ms
timestep = 0.1*ms
seeds = 7422
# neurons
areas = 4
eqs_list = [eqs_sp, eqs_ii, eqs_ss, eqs_dp] * areas
neurons = {'sp':24, 'ii':20, 'ss':10, 'dp':46}
neuron_names = list(neurons.keys())
n_neurons_1area = list(neurons.values())
n_groups = len(n_neurons_1area) * areas
n_neurons = [n * multiply for n in n_neurons_1area] * areas
input_idx = neuron_names.index('ss')
Script 3 - equations_cmc.py
# time constant
tau_ampa = 4.0*ms # Excitatory synaptic time constant
tau_gaba = 16.0*ms
# Intrinsic neural properties (spm_fx_cmm_NMDA.m 변수 참고)
Css = 128*pfarad # Membrane capacitance (memc)
Csp = 128*pfarad
Cii = 256*pfarad
Cdp = 32*pfarad
Cinput = 200*pfarad
gl = 1.0*nsiemens # Leak conductance
Vl = -70*mV # Resting potential (el)
Vi = -90*mV # Inhibitory reversal potential (er)
Ve = 60.*mV # Excitatory potential
Vthreshold = -40.*mV # Spiking threshold (vt)
sigma = 2.0*mV # sigma of Ornstein-Uhlenbeck noise
tau_noise = 5.0*ms
tau = 5.0*ms
# Parameters for STDP equation
tau_stdp = 20*ms # STDP time constant at excitatory synapses
tau_istdp = 20*ms # STDP time constant at inhibitory synapses
Apre_exc = 0.005 * nS # STDP amplitude (dApre)
Apre_inh = 0.015 * nS # Inhibitory STDP amplitude (dApost)
Apost_exc = (-1.05 * 0.005) * nS
Apost_inh = (-1.05 * 0.015) * nS
gmax = 0.25*nS # maximum synaptic weight for excitatory synapses
relbound = 0.1
# --------------------------------------------------------------------------------------------
# LIF Equations
# --------------------------------------------------------------------------------------------
eqs_sp = '''
dv/dt = (gl*(Vl - v) + Isyn)/Csp + sigma*(2/tau)**0.5 *xi : volt (unless refractory)
Isyn = IsynE + IsynI : amp
IsynE = ge * (Ve - v) : amp
IsynI = gi * (Vi - v) : amp
dge/dt = -ge/tau_ampa : siemens
dgi/dt = -gi/tau_gaba : siemens
'''
eqs_ii = '''
dv/dt = (gl*(Vl - v) + Isyn)/Cii + sigma*(2/tau)**0.5 *xi : volt (unless refractory)
Isyn = IsynE + IsynI : amp
IsynE = ge * (Ve - v) : amp
IsynI = gi * (Vi - v) : amp
dge/dt = -ge/tau_ampa : siemens
dgi/dt = -gi/tau_gaba : siemens
'''
eqs_ss = '''
dv/dt = (gl*(Vl - v) + Isyn)/Css + sigma*(2/tau)**0.5 *xi : volt (unless refractory)
Isyn = IsynE + IsynI : amp
IsynE = ge * (Ve - v) : amp
IsynI = gi * (Vi - v) : amp
dge/dt = -ge/tau_ampa : siemens
dgi/dt = -gi/tau_gaba : siemens
'''
eqs_dp = '''
dv/dt = (gl*(Vl - v) + Isyn)/Cdp + sigma*(2/tau)**0.5 *xi : volt (unless refractory)
Isyn = IsynE + IsynI : amp
IsynE = ge * (Ve - v) : amp
IsynI = gi * (Vi - v) : amp
dge/dt = -ge/tau_ampa : siemens
dgi/dt = -gi/tau_gaba : siemens
'''
For the equations in the synapses objects, I used :
# Excitatory STDP synapses
STDP_E = '''
w : siemens
gmax : siemens
dapre/dt = -apre/tau_stdp : siemens (event-driven)
dapost/dt = -apost/tau_stdp : siemens (event-driven)
plastic : boolean (shared)
'''
# STDP_E weight update
on_pre_STDP_E = '''
ge += w
apre += Apre_exc
w = clip(w + plastic*apost, 0.0*nS, gmax)
'''
What you have aready tried
I looked up the Brian2 documentation, and I’ve made the main script run without collecting or adding instances in the net object.