Brian2 Error encountered with object named 'neurongroup_4_stateupdater'

Description of problem

I’m working on a Brian2 project structured across multiple Python files. I’ve defined a NeuronGroup in one file (network.py) and am trying to use it in my main simulation script. However, I’m encountering an issue where the NeuronGroup appears to be undefined in the main script, possibly due to incorrect importing or file structure.

Minimal code to reproduce problem

Pinksy_rinzel_eqs='''
dVs/dt=(-gLs*(Vs-VL)-gNa*(Minfs**2)*hs*(Vs-VNa)-gKdr*ns*(Vs-VK)+(gc/pp)*(Vd-Vs)+(Ip0-Iinssyn)/pp)/Cm : volt 
dVd/dt=(-gLd*(Vd-VL)-ICad-gKahp*qd*(Vd-VK)-gKC*cd*chid*(Vd-VK)+(gc*(Vs-Vd))/(1.0-pp)-Isyn/(1.0-pp))/Cm : volt
dCad/dt=  -0.13*ICad/uamp/ms*scaler-0.075*Cad/ms : 1
dhs/dt=  alphahs-(alphahs+betahs)*hs : 1
dns/dt=  alphans-(alphans+betans)*ns : 1
dsd/dt=  alphasd-(alphasd+betasd)*sd : 1
dcd/dt=  alphacd-(alphacd+betacd)*cd : 1
dqd/dt=  alphaqd-(alphaqd+betaqd)*qd : 1
ICad=     gCa*sd*sd*(Vd-VCa) : amp
alphams=  0.32*(-46.9-Vs/mV)/(exp((-46.9-Vs/mV)/4.0)-1.000001)/ms : Hz
betams=   0.28*(Vs/mV+19.9)/(exp((Vs/mV+19.9)/5.0)-1.000001)/ms : Hz
Minfs=    alphams/(alphams+betams) : 1
alphans=  0.016*(-24.9-Vs/mV)/(exp((-24.9-Vs/mV)/5.0)-1.000001)/ms : Hz
betans=   0.25*exp(-1.0-0.025*Vs/mV)/ms : Hz
alphahs=  0.128*exp((-43.0-Vs/mV)/18.0)/ms : Hz
betahs=   4.0/(1.00001+exp((-20.0-Vs/mV)/5.0))/ms : Hz
alphasd=  1.6/(1.0001+exp(-0.072*(Vd/mV-5.0)))/ms : Hz
betasd=   0.02*(Vd/mV+8.9)/(exp((Vd/mV+8.9)/5.0)-1.0)/ms : Hz
alphacd=(int(Vd/mV<=-10)*exp((Vd/mV+50.0)/11-(Vd/mV+53.5)/27)/18.975+int(1.0*Vd/mV>-10)*2.0*exp((-53.5-Vd/mV)/27.0))/ms  : Hz
betacd=   (int(Vd/mV<=-10)*(2.0*exp((-53.5-Vd/mV)/27.0)-alphacd*ms)+int(Vd/mV>-10)*0)/ms : Hz
alphaqd=  clip(0.00002*Cad,0,0.01)/ms : Hz
betaqd=   0.001/ms : Hz
chid=     clip(Cad/250.0,0,1.0) : 1
INMDA=gNMDA*Si*(1+0.28*exp(-0.062*(Vs/mV)))**(-1)*(Vd-Vsyn) : amp
Hxs=0<=((Vs/mV+50)*1) : boolean
Hxw=0<=((Vs/mV+40)*1) : boolean
dSi/dt=(Hxs-Si/150)/second : 1
Isyn=Issyn+INMDA+Iapp+Iarray : amp
Issyn=gbarsyn*clip((ssyn+essyn),0,7000)*(Vd-Vsyn): amp
dssyn/dt=-ssyn/tausyn: 1
dessyn/dt=-essyn/taueyn :1
dinssyn/dt=-inssyn/tauisyn: 1
dinssynslo/dt=-inssynslo/tauinssynslo :1
Iinssyn=gbaryisyn*clip(inssyn+inssynslo,0,7000)*(Vs-VK): amp
dIapp/dt=0*amp/ms : amp
Iarray=stim(t,i) :amp
dCa/dt=-Ca/tauCa :1
counter:1
'''

buzsaki_eqs = '''
dv/dt = (-gNai*m**3*h*(v-VNa)-gKi*n**4*(v-VK)-gL*(v-VL2)-Issyn-Iinssyn-Iapp2)/Cmi : volt
m = alpha_m/(alpha_m+beta_m) : 1
alpha_m = -0.1/mV*(v+35*mV)/(exp(-0.1/mV*(v+35*mV))-1)/ms : Hz
beta_m = 4*exp(-(v+60*mV)/(18*mV))/ms : Hz
dh/dt = 5*(alpha_h*(1-h)-beta_h*h) : 1
alpha_h = 0.07*exp(-(v+58*mV)/(20*mV))/ms : Hz
beta_h = 1./(exp(-0.1/mV*(v+28*mV))+1)/ms : Hz
dn/dt = 5*(alpha_n*(1-n)-beta_n*n) : 1
alpha_n = -0.01/mV*(v+34*mV)/(exp(-0.1/mV*(v+34*mV))-1)/ms : Hz
beta_n = 0.125*exp(-(v+44*mV)/(80*mV))/ms : Hz
Issyn=gbarsyn*(clip(ssyn,0,7000))*(v-Vsyn): amp
dssyn/dt=-ssyn/tausyn: 1
dinssyn/dt=-inssyn/taguisyn: 1
Iinssyn=gbaryisyn*clip(inssyn,0,7000)*(v-VK):amp
'''

Pii = NeuronGroup(100, model=buzsaki_eqs, threshold='v>-20*mV', refractory='v>-60*mV', method='euler')
Pii.v='(randn()*60*.05-60)*mV'
Pii.h=.999
Pii.n=.0001
Pii.ssyn=0    
Pe = NeuronGroup(1000, model=Pinksy_rinzel_eqs, threshold='Vs>-20*mV', reset='Ca=50*mV', refractory='Vs>-60*mV', method='euler')
Pe.Vs='(randn()*60*.05-60)*mV'
Pe.Vd='(randn()*65*.05-65)*mV'
Pe.hs=.999
Pe.ns=.0001
Pe.sd=.009
Pe.cd=.007
Pe.qd=.01
Pe.Cad=.20
Pe.Si=0
Pe.ssyn=0
Pe.inssyn=0
Pe.essyn=0

Full traceback of error (if relevant)

What does this error mean?

BrianObjectException: Error encountered with object named 'neurongroup_7_stateupdater'.
Object was created here (most recent call only, full details in debug log):
  File '/Users/carolinecho/Downloads/CoxCoxGunnetal2019-master/model_and_helper_files/recurrent_fire.py', line 261, in <module>
    Pe = NeuronGroup(1000, model=Pinksy_rinzel_eqs, threshold='Vs>-20*mV', reset='Ca=50*mV', refractory='Vs>-60*mV', method='euler')

An error occurred when preparing an object. (See above for original error message and traceback.)

Hi @carolineecho. From what you are describing, I think the problem is that Brian cannot find the value of an external constant that you reference in your equations (I cannot be entirely sure, since the error message you posted is not complete). External constants need to be available where you run the simulation, not where you define the NeuronGroup. If you prefer to define constants together with the NeuronGroup, you can use its namespace argument. See the documentation here: Namespaces — Brian 2 2.5.4 documentation
Also, have a look at another forum post that raised a similar question recently: KeyError: 'The identifier "a" could not be resolved.' - Izhikevich Model

Hope that helps, best
Marcel

PS: Note that for better readability of code snippets, you can enclose them in triple backticks like this:

```
# a comment
print("My code")
```

Hello @carolineecho, I think your original error that leads to ‘NeuronGroup4 stateupdater’ error is before the traceback you have shared here. Your traceback message also says ‘(See above for original error message and traceback.)’. If incase you are working in jupyter notebook you can change the traceback presentation into a scrollable element to see the full traceback. Or you should also be able to see the full traceback in terminal. I think that should be able to give you a better idea of where your error is coming from.