Using NMODL integration of ODEs: sparse

NMODL and the Channel Builder.
Post Reply
gaoyy18
Posts: 11
Joined: Tue Mar 14, 2023 11:33 am

Using NMODL integration of ODEs: sparse

Post by gaoyy18 »

Hi,
I want to change the NMODL integration of ODEs from cnexp to sparse, I referred to this: https://bluebrain.github.io/nmodl/html/ ... rview.html

To do this, I simply change the following codes from original hh.mod(from cnexp to sparse):

Code: Select all

NEURON {
        SUFFIX hh1
...

BREAKPOINT {
        SOLVE states sparse
        gna = gnabar*m*m*m*h
	ina = gna*(v - ena)
        gk = gkbar*n*n*n*n
	ik = gk*(v - ek)      
        il = gl*(v - el)
}
I also changed the .mod file name, which my new channel name is "hh1.mod".

When I tried to use the "hh1.mod" referring this:
https://nrn.readthedocs.io/en/8.2.2/cou ... files.html
I run

Code: Select all

nrnivmodl
in terminal but it got wrong:

Code: Select all

(torch1) gyy@cxhpc:~/work/NEURON$ nrnivmodl
/home/gyy/work/NEURON
Mod files: "./hh1.mod"

Creating 'x86_64' directory for .o files.

 -> Compiling mod_func.cpp
 -> NMODL ../hh1.mod
Translating hh1.mod into /home/gyy/work/NEURON/x86_64/hh1.c
syntax error:
 Illegal statement:
 Illegal block at line 65 in file hh1.mod
        SOLVE states sparse
                           ^
    make: *** [makemod2c_inc:3: hh1.c] Error 1
make: *** Waiting for unfinished jobs....
Traceback (most recent call last):
  File "/home/gyy/anaconda3/envs/torch1/bin/nrnivmodl", line 94, in <module>
    subprocess.check_call([exe, *sys.argv[1:]])
  File "/home/gyy/anaconda3/envs/torch1/lib/python3.9/subprocess.py", line 373, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['/home/gyy/anaconda3/envs/torch1/lib/python3.9/site-packages/neuron/.data/bin/nrnivmodl']' returned non-zero exit status 2.
Anyone can help about this? Thanks for advance.
ted
Site Admin
Posts: 6286
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Using NMODL integration of ODEs: sparse

Post by ted »

I want to change the NMODL integration of ODEs from cnexp to sparse
Note for others who might read this thread: this change won't do anything useful.
Anyone can help about this?
The error message points to the line that contains the error. Compare that line with the corresponding line in hh.mod.

A note to others who may read this thread: it is so easy to make a "simple" programming mistake that is difficult to find. Anyone who has done a lot of writing (including programming) has run into situations where they can't "see" a mistake that they made--but they can quickly and easily detect a similar error made by someone else. There is a human tendency to perceive what you "know" you should be seeing, rather than what actually exists. Sometimes the best thing to do is take a break--do something else for a while, then come back to the problem--and then you can perceive your own error.
gaoyy18
Posts: 11
Joined: Tue Mar 14, 2023 11:33 am

Re: Using NMODL integration of ODEs: sparse

Post by gaoyy18 »

ted wrote: Mon Mar 27, 2023 10:58 am
I want to change the NMODL integration of ODEs from cnexp to sparse
Note for others who might read this thread: this change won't do anything useful.
Anyone can help about this?
The error message points to the line that contains the error. Compare that line with the corresponding line in hh.mod.

A note to others who may read this thread: it is so easy to make a "simple" programming mistake that is difficult to find. Anyone who has done a lot of writing (including programming) has run into situations where they can't "see" a mistake that they made--but they can quickly and easily detect a similar error made by someone else. There is a human tendency to perceive what you "know" you should be seeing, rather than what actually exists. Sometimes the best thing to do is take a break--do something else for a while, then come back to the problem--and then you can perceive your own error.
Thank you for your help. I made a stupid mistake. What you said gave me a lot of inspiration. I'm sorry for wasting time because of this mistake. After I corrected the code, I found:
1. change cnexp to derivimplcit is still still unable to compile.
2. change cnexp to euler(although not recommended) is able to compile. But as you said, the result does not change.
But still two questions:
Can I change cnexp method to implicit euler method?
I have read some posts about cnexp and https://bluebrain.github.io/nmodl/html/ ... cnexp.html, it seems that cnexp uses more accurate integration method than implicit euler, is it true?
ted
Site Admin
Posts: 6286
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Using NMODL integration of ODEs: sparse

Post by ted »

No need to apologize. Everybody makes stupid mistakes.

Never use euler--it is not suitable for the equations that describe models with the anatomical and biophysical complexities of real neurons, which are stiff and often require a very small dt for stability.

cnexp is the NMODL name for NEURON's implicit euler method. It is very stable, and its results have first order precision.
gaoyy18
Posts: 11
Joined: Tue Mar 14, 2023 11:33 am

Re: Using NMODL integration of ODEs: sparse

Post by gaoyy18 »

ted wrote: Tue Mar 28, 2023 11:03 am No need to apologize. Everybody makes stupid mistakes.

Never use euler--it is not suitable for the equations that describe models with the anatomical and biophysical complexities of real neurons, which are stiff and often require a very small dt for stability.

cnexp is the NMODL name for NEURON's implicit euler method. It is very stable, and its results have first order precision.
Thanks Ted for your guidance sincerely. I understand now.
The core issue that bothers me, also to anyone who later sees this post: cnexp uses analytical integration method for HH channels instead of numerical integration method.
ted
Site Admin
Posts: 6286
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Using NMODL integration of ODEs: sparse

Post by ted »

The core issue that bothers me
Before proceeding further, it would be useful to read the relevant sections of chapter 7 of The NEURON Book (if you don't have the book, you might want to get this preprint of chapter 7 https://www.neuron.yale.edu/ftp/ted/boo ... xedref.pdf).

As I understand it, a simplified description of the cnexp method's sequence of execution during an advance from t to t+dt is

1. Use v(t) to calculate the gating states' rate constants (or their "inf" and "tau" values (i.e. steady state values and time constants)). This is a first order correct estimate in time of those values during the interval t..t+dt.

2. Plug these rate constants into the analytical solutions to the ODEs that govern the gating states, and use those to update the gating states to new values. These new values of the gating states are also first order correct in time.

3. Use the solution at time t (which includes the values of v at time t) and these updated gating states to set up the terms in a matrix equation of the form

y(t+dt) - y(t) = f(y(t+dt), t+dt)

where y(t) and the terms in f are first order correct in time. Numerical solution of this equation produces a value of y(t+dt) that is first order correct in time, and second order correct in space.

Does that help?
gaoyy18
Posts: 11
Joined: Tue Mar 14, 2023 11:33 am

Re: Using NMODL integration of ODEs: sparse

Post by gaoyy18 »

ted wrote: Wed Mar 29, 2023 12:40 pm
The core issue that bothers me
Before proceeding further, it would be useful to read the relevant sections of chapter 7 of The NEURON Book (if you don't have the book, you might want to get this preprint of chapter 7 https://www.neuron.yale.edu/ftp/ted/boo ... xedref.pdf).

As I understand it, a simplified description of the cnexp method's sequence of execution during an advance from t to t+dt is

1. Use v(t) to calculate the gating states' rate constants (or their "inf" and "tau" values (i.e. steady state values and time constants)). This is a first order correct estimate in time of those values during the interval t..t+dt.

2. Plug these rate constants into the analytical solutions to the ODEs that govern the gating states, and use those to update the gating states to new values. These new values of the gating states are also first order correct in time.

3. Use the solution at time t (which includes the values of v at time t) and these updated gating states to set up the terms in a matrix equation of the form

y(t+dt) - y(t) = f(y(t+dt), t+dt)

where y(t) and the terms in f are first order correct in time. Numerical solution of this equation produces a value of y(t+dt) that is first order correct in time, and second order correct in space.

Does that help?
That does help, I use this and reproduce the membrane voltage and the voltage is completely consistent with NEURON. Thank you for your guidance.
Post Reply