neuronsimulator / nrn

NEURON Simulator
http://nrn.readthedocs.io
Other
406 stars 118 forks source link

Handle top level LOCAL variables transfer when initialization is skipped in CoreNEURON #1461

Open iomaganaris opened 3 years ago

iomaganaris commented 3 years ago

Context

Overview of the issue

Some mod files define LOCAL variables in the top level of the file (for example https://github.com/Neurosim-lab/netpyne/blob/development/examples/M1detailed/mod/kapcb.mod). It seems that the value of these variables are not passed properly in CoreNEURON. Before the psolve-direct changes the variable in the above example was initialized in CoreNEURON through the INITIAL block, however now this isn't the case and the variable has a wrong variable during simulation.

Expected result/behavior

Top level LOCAL variables should be properly transferred from NEURON or initialized on CoreNEURON.

NEURON setup

Minimal working example - MWE

git clone -b pramodk/coreneuron-compatibility-m1 git@github.com:Neurosim-lab/netpyne.git
cd netpyne
export PYTHONPATH=$pwd:$PYTHONPATH
cd examples/M1detailed
vim cfg.py # enable coreneuron
nrnivmodl -coreneuron mod
mpirun special -mpi -python init.py

gdb output of CoreNEURON execution:

 Memory (MBs) :     After nrn_finitialize : Max 386.5312, Min 386.5312, Avg 386.5312

psolve |                                                         | t: 0.00   ETA: 0h00m00s
Breakpoint 2, _INTERNAL30676066::coreneuron::rates_kapcb (_iml=0,
    _cntml_padded=16, _p=0xe091b40, _ppvar=0x18e1680, _thread=0x43977c0,
    _nt=0x3548c28, v=-79.989383948134332, _lv=-79.989383948134332)
    at x86_64/corenrn/mod2c/kapcb.cpp:414
418      taun = betn ( _threadargscomma_ _lv ) / ( _zqt * a0n * ( 1.0 + _la ) ) ;
p _thread[0]._pval[0]
(gdb) $5 = 0

_zqt is the macro for _thread[0]._pval[0] gdb output of the qt variable during initialization in NEURON:

Breakpoint 1, initmodel (_p=0xc4d1178, _ppvar=0x1c17ce0, _thread=0xb38e620,
    _nt=0x1805880) at kapcb.c:503
503       n = n0;
s
(gdb) 505          _zqt = pow( q10 , ( ( celsius - 24.0 ) / 10.0 ) ) ;
s
(gdb) 506          rates ( _threadargscomma_ v ) ;
s
(gdb) rates__kapcb (_p=0xc4d1178, _ppvar=0x1c17ce0, _thread=0xb38e620,
    _nt=0x1805880, _lv=-80) at kapcb.c:341
341      _la = alpn ( _threadargscomma_ _lv ) ;
p _thread[0]._pval[0]
(gdb) $4 = 5
pramodk commented 3 years ago

@nrnhines : do you have any ideas about fixing this without changing mod file? e.g. what if we turn such variables like GLOBAL ?