Avoid use of ion variable in the CONSTANT block#1955
Conversation
* certain mod files use read/write ion variables
from USEION statements in CONSTANT {} block
* the generated code from such usage is not desired
I believe. For example, cdp_spiny.mod from ModelDB
model id 266799 has
```console
NEURON {
SUFFIX cdp4Nsp
USEION ca READ cao, cai, ica WRITE cai
RANGE ica_pmp,scale
...
}
ASSIGNED {
diam (um)
ica (mA/cm2)
ica_pmp (mA/cm2)
parea (um) : pump area per unit length
cai (mM)
}
CONSTANT { cao = 2 (mM) }
```
In this example, the generated code doesn't set ion variable `cao` to 2
but declare a static variable `cao` with value 2 and that is not used
anywhere:
```cpp
#define ica _p[56]
#define ica_columnindex 56
#define parea _p[57]
#define parea_columnindex 57
#define cai _p[58]
...
#define _ion_cao *_ppvar[0]._pval
#define _ion_cai *_ppvar[1]._pval
#define _ion_ica *_ppvar[2]._pval
#define _style_ca *((int*)_ppvar[3]._pvoid)
#define diam *_ppvar[4]._pval
...
static double cao = 2;
...
static void nrn_state(NrnThread* _nt, _Memb_list* _ml, int _type) {
...
cao = _ion_cao;
cai = _ion_cai;
ica = _ion_ica;
cai = _ion_cai;
...
}
```
Note that `cao` variable used/updated here is not ion variable but static one
defined in the file scope.
I believe this is not what user "expected" here.
* As we see this pattern in multiple mod files (including glia__dbbs_mod_collection__cdp5__CAM_GoC.mod
mentioned in BlueBrain/nmodl#888), in this PR we disable
declaring ion variables as CONSTANT. With this PR, we will get an error like:
```console
$ ./bin/nocmodl /.../nmodldb/models/db/modeldb/266799/mod/cdp_spiny.mod
...
cao used in USEION statement can not be re-declared in the CONSTANT block at line 299 in file /.../nmodldb/models/db/modeldb/266799/mod/cdp_spiny.mod
```
Codecov Report
@@ Coverage Diff @@
## master #1955 +/- ##
=======================================
Coverage 46.50% 46.50%
=======================================
Files 526 526
Lines 119216 119231 +15
=======================================
+ Hits 55439 55453 +14
- Misses 63777 63778 +1
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
|
✔️ 690ccab -> Azure artifacts URL |
* Similar to neuronsimulator/nrn#1955 * Add semantic analysis check to avoid declaring ion variables in CONSTANT {} block * Addresses first point in #888 MOD file is glia__dbbs_mod_collection__cdp5__CAM_GoC.mod. * Updated test
|
The explicit error is better. Thanks. |
|
ok good! I think there might be some mod files in the ModelDB. Before merging this PR, I can quickly check this in ModelDB and maybe fix this. |
|
✔️ 0462052 -> Azure artifacts URL |
USEION variable can not be initialized in CONSTANT block. See neuronsimulator/nrn#1955.
USEION variable can not be initialized in a CONSTANT block. See neuronsimulator/nrn#1955.
USEION variable can not be initialized in a CONSTANT block. See neuronsimulator/nrn#1955.
USEION variable can not be initialized in a CONSTANT block. See neuronsimulator/nrn#1955.
USEION variable can not be initialized in a CONSTANT block. See neuronsimulator/nrn#1955.
|
There are 3 models with 8 mod files where this pattern was used. It seems like all those mod files are same / similar and originated from the same implementation (filename with cdp*.mod). I have created PRs here: |
|
✔️ 4afde67 -> Azure artifacts URL |
I approved these, I believe that @ramcdougal needs to do something manual to make sure that the changes are propagated properly after the PRs are merged. |
* Similar to neuronsimulator/nrn#1955 * Add semantic analysis check to avoid declaring ion variables in CONSTANT {} block * Addresses first point in #888 MOD file is glia__dbbs_mod_collection__cdp5__CAM_GoC.mod. * Updated test
* Similar to neuronsimulator/nrn#1955, add semantic analysis check to avoid declaring ion variables in CONSTANT {} block * Addresses first point in #888 MOD file is glia__dbbs_mod_collection__cdp5__CAM_GoC.mod. * Updated test
…ase) * Setting ionic variable like `cao`` in CONSTANT block had no effect See neuronsimulator/nrn#1955 * This will be an error in future neuron v9 and with the latest neuron-nightly pypi package. * As setting cao from MOD file had no effect, simply uncomment this (?)
…ase) * Setting ionic variable like `cao`` in CONSTANT block had no effect See neuronsimulator/nrn#1955 * This will be an error in future neuron v9 and with the latest neuron-nightly pypi package. * As setting cao from MOD file had no effect, simply uncomment this (?)
|
@pramodk looking at the modeldb-ci nightly there is also 138382. I commented out the cao CONSTANT assignment but now I see: |
Should be fixed by ModelDBRepository/138382#1 |
|
thanks. updated to fix |
#1) * Updated MOD file to fix the issue with the upcoming NEURON 9.0 release USEION variable can not be initialized in a CONSTANT block. See neuronsimulator/nrn#1955. * fix missing declaration of cao
#1) * Updated MOD file to fix the issue with the upcoming NEURON 9.0 release USEION variable can not be initialized in a CONSTANT block. See neuronsimulator/nrn#1955. * fix missing declaration of cao
#1) * Updated MOD file to fix the issue with the upcoming NEURON 9.0 release USEION variable can not be initialized in a CONSTANT block. See neuronsimulator/nrn#1955. * fix missing declaration of cao
…pcoming neuron release) (#6) * Ion variables can not be set via CONSTANT block (upcoming neuron release) * Setting ionic variable like `cao`` in CONSTANT block had no effect See neuronsimulator/nrn#1955 * This will be an error in future neuron v9 and with the latest neuron-nightly pypi package. * As setting cao from MOD file had no effect, simply uncomment this (?) * fix missing declaration of cao and remove CONSTANT block
* USEION variable can not be initialized in a CONSTANT block. See neuronsimulator/nrn#1955. * cdp5.mod --------- Co-authored-by: Alexandru Săvulescu <alexandru.savulescu@epfl.ch>
…rain/nmodl#908) * Similar to #1955, add semantic analysis check to avoid declaring ion variables in CONSTANT {} block * Addresses first point in BlueBrain/nmodl#888 MOD file is glia__dbbs_mod_collection__cdp5__CAM_GoC.mod. * Updated test NMODL Repo SHA: BlueBrain/nmodl@af7c772
certain mod files use read/write ion variables
from USEION statements in CONSTANT {} block
the generated code from such usage is not desired
I believe. For example, cdp_spiny.mod from ModelDB
model id 266799 has
In this example, the generated code doesn't set ion variable
caoto 2but declare a static variable
caowith value 2 and that is not usedanywhere:
Note that
caovariable used/updated here is not ion variable but static onedefined in the file scope.
I believe this is not what user "expected" here.
As we see this pattern in multiple mod files (including glia__dbbs_mod_collection__cdp5__CAM_GoC.mod
mentioned in Testing & Fixing issues with DBBS-Lab's MOD file collection BlueBrain/nmodl#888), in this PR we disable
declaring ion variables as CONSTANT. With this PR, we will get an error like:
@nrnhines : do you agree that explicit error like above is better approach than silently generating incorrect/undesired code? 🤔