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

Issue with TABLE statement definitions #771

Closed
1 task done
iomaganaris opened this issue Nov 5, 2021 · 6 comments · Fixed by #913 or #916
Closed
1 task done

Issue with TABLE statement definitions #771

iomaganaris opened this issue Nov 5, 2021 · 6 comments · Fixed by #913 or #916
Assignees
Labels
bug Something isn't working codegen Code generation backend netpyne Compatibility with netpyne models

Comments

@iomaganaris
Copy link
Contributor

iomaganaris commented Nov 5, 2021

One of the netpyne mod files https://github.com/Neurosim-lab/netpyne/blob/4e6078d88b832f391dd34aaccb77e6dfeaaaaf9d/examples/evolCell/mod/ch_CavL.mod includes a table definition that seems to be the reason why Inf and NaN values are generated after the first timestep of the simulation.
With prcellstate I see:

type=37 ch_CavL size=13
 1 0 0.0561083520000000002
 1 1 -1.06176913561355483e-10
 1 2 1.56031593453472415e-12
 1 3 -nan
 1 4 inf
 1 5 -1.06176913561355483e-10
 1 6 nan
 1 7 5.00823318023436157e-06
 1 8 2
 1 9 0
 1 10 170.604284826080487
 1 11 -67.6602158131285165
 1 12 1.52273941311743953e-12

and here is the instance struct generated to find the corresponding variables to the above:

/** all mechanism instance variables */
    struct ch_CavL_Instance  {
        const double* __restrict__ gmax;
        double* __restrict__ ica;
        double* __restrict__ g;
        double* __restrict__ minf;
        double* __restrict__ mtau;
        double* __restrict__ myi;
        double* __restrict__ m;
        double* __restrict__ cai;
        double* __restrict__ cao;
        double* __restrict__ Dm;
        double* __restrict__ eca;
        double* __restrict__ v_unused;
        double* __restrict__ g_unused;
        const double* __restrict__ ion_cai;
        const double* __restrict__ ion_cao;
        const double* __restrict__ ion_eca;
        double* __restrict__ ion_ica;
        double* __restrict__ ion_dicadv;
    };

TODO:

  • Provide small reproducible circuit
@iomaganaris iomaganaris added bug Something isn't working codegen Code generation backend netpyne Compatibility with netpyne models labels Nov 5, 2021
@pramodk
Copy link
Contributor

pramodk commented Aug 18, 2022

TABLE FROM -150 TO 150 WITH 200

Without a reproducer, may be we can check the TABLE related generated code from mod2c and see if it is similar to NMODL? After TABLE there are no variables specified and I am wondering if there is something related to it.

@alkino alkino linked a pull request Aug 23, 2022 that will close this issue
@alkino
Copy link
Member

alkino commented Aug 23, 2022

The problem here is that in mod2c the code is quite different if the table is inside a funciton or inside a procedure.
First of all, a table inside a procedure need at list one table argument. In a function, it is impossible to get a variable.
The table variable is the "return variable" of the function.

Second problem is that inside procedure there is no return but in function we should return the value of the table.

@iomaganaris
Copy link
Contributor Author

To test this and reproduce the issue:

  1. Clone https://github.com/iomaganaris/M1/tree/magkanar/M1_vip_ngf
  2. Revert commenting of TABLE statements from the mod files
  3. Install NEURON with CoreNEURON and the desired NMODL version
  4. "Install" NetPyNE [1]
  5. Run M1 sim with prcellstate (gid 5 (NGF cell) has ch_CavL mechanism) [2]
  6. Run the sim with mod2c, nmodl and fixed nmodl versions and compare the prcellstate output

[1] To install NetPyNE and run the M1 simulation:

git clone https://github.com/suny-downstate-medical-center/netpyne
python -m venv venv
. venv/bin/activate
pip install -r netpyne/requirements.txt
pip uninstall neuron # we already have neuron installed
export PYTHONPATH=$(pwd)/netpyne:$PYTHONPATH

[2] Do the following edits in M1 repo:

diff --git a/sim/cfg.py b/sim/cfg.py
index db3acd5..3d52ebe 100644
--- a/sim/cfg.py
+++ b/sim/cfg.py
@@ -160,7 +160,7 @@ cfg.distributeSynsUniformly = True
 #------------------------------------------------------------------------------
 # Network
 #------------------------------------------------------------------------------
-cfg.singleCellPops = 0  # Create pops with 1 single cell (to debug)
+cfg.singleCellPops = 1  # Create pops with 1 single cell (to debug)
 cfg.weightNorm = 1  # use weight normalization
 cfg.weightNormThreshold = 4.0  # weight normalization factor threshold

@@ -171,7 +171,7 @@ cfg.scale = 1.0
 cfg.sizeY = 1350.0
 cfg.sizeX = 300.0
 cfg.sizeZ = 300.0
-cfg.scaleDensity = 1.0
+cfg.scaleDensity = 0.4
 cfg.correctBorderThreshold = 150.0

 cfg.L5BrecurrentFactor = 1.0
diff --git a/sim/init.py b/sim/init.py
index f6a4665..a13df3c 100644
--- a/sim/init.py
+++ b/sim/init.py
@@ -22,13 +22,19 @@ sim.initialize(
     netParams = netParams)                             # create network object and set cfg and net params
 sim.net.createPops()                                   # instantiate network populations
 sim.net.createCells()                                  # instantiate network cells based on defined populations
+for cell in sim.net.cells:
+    if "cellType" in cell.tags.keys() and cell.tags["cellType"] in ['NGF', 'PV']:
+        print("gid: {}".format(cell.gid))
+        print("cell type: {}".format(cell.tags["cellType"]))
+#sim.pc.barrier()
+#quit()
 sim.net.connectCells()                                 # create connections between cells based on params
 sim.net.addStims()                                                     # add network stimulation
 sim.setupRecording()                                   # setup variables to record for each cell (spikes, V traces, etc)
 sim.runSim()                                           # run parallel Neuron simulation
 sim.gatherData()                                       # gather spiking data and cell info from each node
-sim.saveData()                                         # save params, cell info and sim output to file (pickle,mat,txt,etc)#
-sim.analysis.plotData()                                # plot spike raster etc
+#sim.saveData()                                        # save params, cell info and sim output to file (pickle,mat,txt,etc)#
+#sim.analysis.plotData()                               # plot spike raster etc

 if sim.rank == 0:
     with open('out_neuron.dat', 'w') as f:

and these to netpyne (enable prcellstate):

diff --git a/netpyne/sim/run.py b/netpyne/sim/run.py
index 860ac4f6..69d0a0ff 100644
--- a/netpyne/sim/run.py
+++ b/netpyne/sim/run.py
@@ -185,6 +185,7 @@ def postRun(stopTime=None):
     if (stopTime is None) or (stopTime != sim.cfg.duration):
         sim.pc.psolve(sim.cfg.duration)

+    sim.pc.prcellstate(5, 'nrn_end') # 219 didn't have right mechs
     sim.pc.barrier() # Wait for all hosts to get to this point
     sim.timing('stop', 'runTime')
     if sim.rank==0:

To run the sim:

srun -n 36 ../special_mod2c/x86_64/special -mpi -python init.py

@iomaganaris
Copy link
Contributor Author

iomaganaris commented Aug 29, 2022

Above issues are now fixed with #916 .
The only difference now is the following:

image

Not sure whether this is related to the TABLE statements though. I need to investigate a bit more

Edit:
The difference was related to non-debug build. With debug build, NEURON, mod2c and nmodl with TABLE statements enabled have same prcellstate files

@alkino alkino linked a pull request Aug 29, 2022 that will close this issue
@iomaganaris
Copy link
Contributor Author

iomaganaris commented Aug 30, 2022

Revisiting this again I see the following differences between mod2c and nmodl with and without TABLE functions:

bash-4.2$ sdiff -s 5_nrn_end.nrndat.mod2c.table 5_nrn_end.nrndat.nmodl.table
 1 3 -67.66                                                   |  1 3 -67.6602158131285
 3 3 -67.66                                                   |  3 3 -67.6600423002383
bash-4.2$ sdiff -s 5_nrn_end.nrndat.mod2c.notable 5_nrn_end.nrndat.nmodl.notable
 1 3 -67.66                                                   |  1 3 -67.6602158235648
 3 3 -67.66                                                   |  3 3 -67.6600423101646
bash-4.2$ sdiff -s 5_nrn_end.nrndat.nrn.table 5_nrn_end.nrndat.mod2c.table
bash-4.2$ sdiff -s 5_nrn_end.nrndat.nrn.notable 5_nrn_end.nrndat.mod2c.notable

Both differences appear in the pas mechanism. Since with and without TABLE statements there are differences I believe that the differences are due to the different solvers used by NMODL (some of the mod files use derivimplicit solver)

@iomaganaris
Copy link
Contributor Author

Above issue is related to this BlueBrain/mod2c#83.
By manually adding the update of v_unused to the nrn_state function of passive.cpp for mod2c generated c++ files the prcellstate of mod2c and NMODL is the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working codegen Code generation backend netpyne Compatibility with netpyne models
Projects
None yet
3 participants