Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid use of ion variable in the CONSTANT block #1955

Merged
merged 6 commits into from
Sep 7, 2022

Conversation

pramodk
Copy link
Member

@pramodk pramodk commented Aug 17, 2022

  • 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

    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:

     #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 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:

     $ ./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

@nrnhines : do you agree that explicit error like above is better approach than silently generating incorrect/undesired code? 🤔

* 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-commenter
Copy link

codecov-commenter commented Aug 17, 2022

Codecov Report

Merging #1955 (e4d57da) into master (1b76917) will increase coverage by 0.00%.
The diff coverage is 93.33%.

@@           Coverage Diff           @@
##           master    #1955   +/-   ##
=======================================
  Coverage   46.50%   46.50%           
=======================================
  Files         526      526           
  Lines      119216   119231   +15     
=======================================
+ Hits        55439    55453   +14     
- Misses      63777    63778    +1     
Impacted Files Coverage Δ
src/nmodl/nocpout.cpp 93.25% <92.85%> (-0.01%) ⬇️
src/nmodl/modl.cpp 67.92% <100.00%> (+0.30%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@azure-pipelines
Copy link

✔️ 690ccab -> Azure artifacts URL

pramodk added a commit to BlueBrain/nmodl that referenced this pull request Aug 17, 2022
* 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
@pramodk
Copy link
Member Author

pramodk commented Aug 25, 2022

@nrnhines : do you agree that explicit error like above is better approach than silently generating incorrect/undesired code? 🤔

@nrnhines : what do you think?

@nrnhines
Copy link
Member

The explicit error is better. Thanks.

@pramodk
Copy link
Member Author

pramodk commented Aug 25, 2022

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.

@azure-pipelines
Copy link

✔️ 0462052 -> Azure artifacts URL

pramodk added a commit to ModelDBRepository/244679 that referenced this pull request Sep 7, 2022
USEION variable can not be initialized in CONSTANT block.
See neuronsimulator/nrn#1955.
pramodk added a commit to ModelDBRepository/244679 that referenced this pull request Sep 7, 2022
USEION variable can not be initialized in a CONSTANT block.
See neuronsimulator/nrn#1955.
pramodk added a commit to ModelDBRepository/265584 that referenced this pull request Sep 7, 2022
USEION variable can not be initialized in a CONSTANT block.
See neuronsimulator/nrn#1955.
pramodk added a commit to ModelDBRepository/243446 that referenced this pull request Sep 7, 2022
USEION variable can not be initialized in a CONSTANT block.
See neuronsimulator/nrn#1955.
pramodk added a commit to ModelDBRepository/243446 that referenced this pull request Sep 7, 2022
USEION variable can not be initialized in a CONSTANT block.
See neuronsimulator/nrn#1955.
@pramodk
Copy link
Member Author

pramodk commented Sep 7, 2022

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:

@azure-pipelines
Copy link

✔️ 4afde67 -> Azure artifacts URL

@pramodk pramodk merged commit e8fe008 into master Sep 7, 2022
@pramodk pramodk deleted the pramodk/ion-var-as-constant branch September 7, 2022 11:56
@olupton
Copy link
Collaborator

olupton commented Sep 7, 2022

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:
* ModelDBRepository/244679#1
* ModelDBRepository/265584#1
* ModelDBRepository/243446#1

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.

pramodk added a commit to BlueBrain/nmodl that referenced this pull request Sep 9, 2022
* 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
pramodk added a commit to BlueBrain/nmodl that referenced this pull request Sep 9, 2022
* 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
pramodk added a commit to pramodk/dbbs-mod-collection that referenced this pull request Sep 9, 2022
…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 added a commit to pramodk/dbbs-mod-collection that referenced this pull request Sep 9, 2022
…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 (?)
@alexsavulescu
Copy link
Member

@pramodk looking at the modeldb-ci nightly there is also 138382. I commented out the cao CONSTANT assignment but now I see:

cdp3.cpp:2144:3: error: ‘cao’ was not declared in this scope; did you mean ‘ca0’?
 2144 |   cao = _ion_cao;
      |   ^~~
      |   ca0
cdp5.cpp: In function ‘void _ode_spec(NrnThread*, Memb_list*, int)’:
cdp5.cpp:1611:3: error: ‘cao’ was not declared in this scope; did you mean ‘ca0’?
....

@pramodk
Copy link
Member Author

pramodk commented Sep 12, 2022

@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

@alexsavulescu
Copy link
Member

thanks. updated to fix cdp5.mod in the same manner

ramcdougal pushed a commit to ModelDBRepository/244679 that referenced this pull request Sep 23, 2022
#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
ramcdougal pushed a commit to ModelDBRepository/265584 that referenced this pull request Sep 23, 2022
#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
ramcdougal pushed a commit to ModelDBRepository/243446 that referenced this pull request Sep 23, 2022
#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
Helveg pushed a commit to dbbs-lab/dbbs-mod-collection that referenced this pull request Sep 23, 2022
…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
RuiLi7222 pushed a commit to ModelDBRepository/138382 that referenced this pull request Jan 30, 2023
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants