POINTER is not thread safe

When Python is the interpreter, what is a good
design for the interface to the basic NEURON
concepts.

Moderator: hines

Post Reply
alexandrapierri
Posts: 69
Joined: Wed Jun 17, 2015 5:31 pm

POINTER is not thread safe

Post by alexandrapierri »

Dear developers

I have written the following mod file describing a GABA synapse with DSI (depolarization-induced suppression of inhibition) according to the equations of page 544 in Zachriou et al 2014 https://pubmed.ncbi.nlm.nih.gov/25123173/. I am in the process of correcting/debugging/compiling this mod file. I have defined two pointers, vpre and post as my code requires access to the presynaptic and postsynaptic voltage.

In running nrnivmodl I get the error:

Use of POINTER is not thread-safe. And non-Ascii character in line 42:ICAG_50 =0.000002 (mΜ) :Half-inhibition concentration (WIN).

I am not sure what these two errors mean/refer to.

thank you for any help/guidance with this,
Alexandra


Code: Select all

TITLE model of GABAa receptors with endocanabinoid release

COMMENT
-----------------------------------------------------------------------------
Author: Alexandra Chatzikalymniou 
Reference: Zachariou et al 2013, 
-----------------------------------------------------------------------------
ENDCOMMENT



INDEPENDENT {t FROM 0 TO 1 WITH 1 (ms)}

NEURON {
	POINT_PROCESS GABAa_endocan
	POINTER vpre, vpost
	RANGE kA_minus, IGABA_A, gA_inf, kA_plus, h_AG_AG_bar, qA_inf, AG_bar       
	NONSPECIFIC_CURRENT i
	GLOBAL kappa_plus, BAG_max, ICAG_50, nh, tau_qA, kd_max, gA_bar, VA, tau_GA, MGL

}

UNITS {
	(nA) = (nanoamp)
	(mV) = (millivolt)
	(umho) = (micromho)
	(mS) = (millisiemens)
	(mM) = (millimolar)
}



PARAMETER {  

	kappa_plus  	=0.3	(1/ms)		:Maximal reluctant-to-willing transition rate
	BAG_max 	=0.5		:Maximum inhibition (due to AG)  
	nh	=1.2		:Hill coefficient
	tau_qA  	=1000	(ms) 		:CB1 recending time constant    
	kd_max	=100	(mV)		:Scaling factor 
	gA_bar  	=0.3	(mS/cm2)		:GABA peak conductance 
	VA  	=-80	(mV)		: GABA reversal potential
	tauA	=1	(ms)		:GABA synaptic time constant
	MGL 	=0.64		:monoacylglycerol lipase (MGL) controls the duration of DSE, DSI duration is determined by both MGL and COX-2.
	ICAG_50 	=0.000002	(mΜ)		:Half-inhibition concentration (WIN)

}


ASSIGNED {
   
	kappa_minus 		(ms)		:Maximal reluctant-to-willing transition rate
	gA_inf		(mS/cm2)		:inf conductance
	kA_plus 		(ms)		: willing to reluctant transition rate
	h_AG(AG_bar) 		(ms)		:
	qA_inf  		(ms)		: maximum fraction of bound G proteins
	AG_bar		(ms)		:fraction of AG mobilised by the post-synaptic cell
	gA  		(mS/cm2)		:conductance
	wA  		(mS/cm2)		:The fraction of willing pre-synaptic Ca2+ channels
	qA  		(1/ms)		:fraction of bound G proteins
	AG		(1/ms)		:AG mobilised by the post-synaptic cell

}


BREAKPOINT {
	SOLVE release
	kA_minus = kA_minus/(1+exp(-(vpre/5)))     
	IGABA_A = gA_bar*gA*(vpost - VA)
	gA_inf(vpre, wA)= 1/(1+exp(-(vpre-kd_max*(1-wA))/5))
	kA_plus = kappa_plus*qA      
	h_AG(AG_bar) = BAG_max/(1+(ICAG_50/AG_bar)^nh)
	qA_inf = h_AG(AG_bar)
	AG_bar = (1-MGL)*AG             
}


DERIVATIVE scheme1 {
gA'=((gA_inf(vpre, wA))-gA)/tauA
}

DERIVATIVE scheme2 {
wA'=kA_minus*(1-wA)-kA_plus*wA
}     
     
DERIVATIVE scheme3 {     
qA'=(qA_inf-qA)/tau_qA 
}



oitani
Posts: 8
Joined: Fri Feb 21, 2020 7:11 am

Re: POINTER is not thread safe

Post by oitani »

Hi Alexandra,

The first error of "Use of POINTER is not thread-safe" is due to the use of Pointers "vpre" and "vpost", and is only a concern when enabling multi-threaded simulations. If multi-threading is not being used, then this error can be safely ignored and nrnivmodl should compile.

The second error of "non-Ascii character" is due to the capital "M" in "(mM)" on line 44.
An Ascii character checker returns: 'U+039c "Μ" could be confused with the character U+004d "M", which is more common in source code'
Replacing this character with an standard Ascii "M" should fix the issue and the mod file should compile.

The below code compiled on my machine after some minor edits, feel free to reach out if the edits are obscure at all

Best,
Omar

Code: Select all

TITLE model of GABAa receptors with endocanabinoid release

COMMENT
-----------------------------------------------------------------------------
Author: Alexandra Chatzikalymniou 
Reference: Zachariou et al 2013, 
-----------------------------------------------------------------------------
ENDCOMMENT



INDEPENDENT {t FROM 0 TO 1 WITH 1 (ms)}

NEURON {
	POINT_PROCESS GABAa_endocan
	POINTER vpre, vpost
	RANGE kA_minus, IGABA_A, gA_inf, kA_plus, h_AG_AG_bar, qA_inf, AG_bar       
	NONSPECIFIC_CURRENT i
	GLOBAL kappa_plus, BAG_max, ICAG_50, nh, tau_qA, kd_max, gA_bar, VA, tau_GA, MGL

}

UNITS {
	(nA) = (nanoamp)
	(mV) = (millivolt)
	(umho) = (micromho)
	(mS) = (millisiemens)
	(molar) =  (/liter)
    (mM)    =  (millimolar)
}



PARAMETER {  

	kappa_plus  	=0.3	(1/ms)		:Maximal reluctant-to-willing transition rate
	BAG_max 	=0.5		:Maximum inhibition (due to AG)  
	nh	=1.2		:Hill coefficient
	tau_qA  	=1000	(ms) 		:CB1 recending time constant    
	kd_max	=100	(mV)		:Scaling factor 
	gA_bar  	=0.3	(mS/cm2)		:GABA peak conductance 
	VA  	=-80	(mV)		: GABA reversal potential
	tauA	=1	(ms)		:GABA synaptic time constant
	MGL 	=0.64		:monoacylglycerol lipase (MGL) controls the duration of DSE, DSI duration is determined by both MGL and COX-2.
	ICAG_50 	=0.000002	(mM)		:Half-inhibition concentration (WIN)

}


ASSIGNED {
   
	kappa_minus 		(ms)		:Maximal reluctant-to-willing transition rate
	gA_inf		(mS/cm2)		:inf conductance
	kA_plus 		(ms)		: willing to reluctant transition rate
	h_AG_AG_bar 		(ms)		:
	qA_inf  		(ms)		: maximum fraction of bound G proteins
	AG_bar		(ms)		:fraction of AG mobilised by the post-synaptic cell

	AG		(1/ms)		:AG mobilised by the post-synaptic cell

}

STATE {
	gA  		(mS/cm2)		:conductance
	wA  		(mS/cm2)		:The fraction of willing pre-synaptic Ca2+ channels
	qA  		(1/ms)		:fraction of bound G proteins
}


BREAKPOINT {
	SOLVE release
	kA_minus = kA_minus/(1+exp(-(vpre/5)))     
	IGABA_A = gA_bar*gA*(vpost - VA)
	gA_inf= 1/(1+exp(-(vpre-kd_max*(1-wA))/5))
	kA_plus = kappa_plus*qA      
	h_AG_AG_bar = BAG_max/(1+(ICAG_50/AG_bar)^nh)
	qA_inf = h_AG_AG_bar
	AG_bar = (1-MGL)*AG             
}


DERIVATIVE scheme1 {
gA'=((gA_inf)-gA)/tauA
}

DERIVATIVE scheme2 {
wA'=kA_minus*(1-wA)-kA_plus*wA
}     
     
DERIVATIVE scheme3 {     
qA'=(qA_inf-qA)/tau_qA 
}
alexandrapierri
Posts: 69
Joined: Wed Jun 17, 2015 5:31 pm

Re: POINTER is not thread safe

Post by alexandrapierri »

thank you Omar

the file takes time to compile using a lot of resources, it looks stuck. The notice: Use of pointer is not thread-safe still appears but I assume I can ignore that for now. Can I share via email the equations I have attempted to convert to a mod file? I don't think I can attach a screenshot here. If so, possible to take a look and see if my mod file represents these sets of equations and/or whether there are other omissions in the syntax? The only variables that are time-dependent in this script are the vpre and vpost. Eventually, AG should also be time-dependent and accessed from another file (likely using a pointer) but for now, I have kept it constant.

thank you,
Alexandra
oitani
Posts: 8
Joined: Fri Feb 21, 2020 7:11 am

Re: POINTER is not thread safe

Post by oitani »

Ah, is the compilation output giving any clues about why it might be stuck?

Yes, I think it's fair to ignore the thread-safe warning if there isn't plans to use multi-threading

Sure, we can take a look at the equations to see if they match up - I'll share my email with you in a direct message
ted
Site Admin
Posts: 6287
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: POINTER is not thread safe

Post by ted »

The sample mod file provided has several fatal problems.
non-Ascii character in line 42
This is trivially easy to fix; unfixed, it could cause a lot of trouble. Has it been resolved? Strong hint: stick with the ASCII character set until this particular limitation of NMODL code has been resolved.

The SOLVE statement refers to a non-existent equation block. This is a fatal problem.

From the supplied NMODL code, it looks like this synaptic mechanism has three state variables--gA, wA, and qA. A STATE block is needed to declare these variables. An INITIAL block is needed to specify their initial conditions (you could omit it, but then they'd all be 0 at the start of every run, which is hardly ever a useful initialization).

As the code now stands, even if the state variables are declared, their values will not change. Why? Because the dynamics of the state variables are defined by ordinary differential equations contained in 3 DERIVATIVE blocks, but the SOLVE statement is written in a way that requires the (heavily depricated)
newvalue = oldvalue + dt * derivativeformula
syntax.

By the way, the contents of those DERIVATIVE blocks could be condensed into a single DERIVATIVE block. If that isn't done, three SOLVE statements will be needed--an unnecessary complication of the source code.

If the purpose of this code is to implement a representation of use-dependent depression of gabaergic synaptic transmission mediated by endocannabinoid signaling, wouldn't it make more sense to abandon POINTERs (especially to membrane potential!) and instead use an event-driven mechanism? Such an implementation could include equations that specify the dynamics of EC production and breakdown, and how they are affected by one or more postsynaptic factors (e.g. local cai).

It might be useful to examine the NMODL code that specifies the synaptic mechanisms in modeldb.yale.edu/3815 and modeldb.yale.edu/3264 (enter these strings directly into your browser's URL field), for the sake of seeing a working code pattern if nothing else. What do you think, oltani?
Last edited by ted on Thu Aug 11, 2022 10:04 pm, edited 1 time in total.
Reason: clarified usage of modeldb.yale.edu/nnnn syntax as a shortcut to a particular model entry
alexandrapierri
Posts: 69
Joined: Wed Jun 17, 2015 5:31 pm

Re: POINTER is not thread safe

Post by alexandrapierri »

Dear Ted

I've attempted to correct the code according to your remarks.

Here are some answers:
The SOLVE statement refers to a non-existent equation block. This is a fatal problem.
I now use cnexp which from what I have seen in numerous examples aside from differential equations is also used to solve algebraic equations as in my case, is that correct?
If the purpose of this code is to implement a representation of use-dependent depression of gabaergic synaptic transmission mediated by endocannabinoid signaling, wouldn't it make more sense to abandon POINTERs (especially to membrane potential!) and instead use an event-driven mechanism? Such an implementation could include equations that specify the dynamics of EC production and breakdown, and how they are affected by one or more postsynaptic factors (e.g. local cai).
I use the formulations in Zachariou et al 2014, page 547, where variables such as the κA_minus (the maximal reluctant-to-willing transition rate) depend on vpre. the AG concentration depends on the postsynaptic calcium concentration. I haven't implemented that yet, I assumed to get access to cai I would need another pointer? This is a separate matter I am still figuring out.

PS: I was not able to open the links you shared in the previous thread, looks like they are non-existent

Code: Select all

TITLE model of GABAa receptors with endocanabinoid release

COMMENT
-----------------------------------------------------------------------------
Author: Alexandra Chatzikalymniou 
Reference: Zachariou et al 2013, 
-----------------------------------------------------------------------------
ENDCOMMENT



INDEPENDENT {t FROM 0 TO 1 WITH 1 (ms)}

NEURON {
	POINT_PROCESS GABAa_endocan
	POINTER vpre, vpost
	RANGE kA_minus, IGABA_A, gA_inf, kA_plus, h_AG_AG_bar, qA_inf, AG_bar       
	NONSPECIFIC_CURRENT i
	GLOBAL kappa_plus, BAG_max, ICAG_50, nh, tau_qA, kd_max, gA_bar, VA, tau_GA, MGL

}

UNITS {
	(nA) = (nanoamp)
	(mV) = (millivolt)
	(umho) = (micromho)
	(mS) = (millisiemens)
	(molar) =  (/liter)
    (mM)    =  (millimolar)
}



PARAMETER {  

	kappa_plus  	=0.3	(1/ms)		:Maximal reluctant-to-willing transition rate
	BAG_max 	=0.5		:Maximum inhibition (due to AG)  
	nh	=1.2		:Hill coefficient
	tau_qA  	=1000	(ms) 		:CB1 recending time constant    
	kd_max	=100	(mV)		:Scaling factor 
	gA_bar  	=0.3	(mS/cm2)		:GABA peak conductance 
	VA  	=-80	(mV)		: GABA reversal potential
	tauA	=1	(ms)		:GABA synaptic time constant
	MGL 	=0.64		:monoacylglycerol lipase (MGL) controls the duration of DSE, DSI duration is determined by both MGL and COX-2.
	ICAG_50 	=0.000002	(mM)		:Half-inhibition concentration (WIN)

}


ASSIGNED {
   
	kappa_minus 		(ms)		:Maximal reluctant-to-willing transition rate
	gA_inf		(mS/cm2)		:inf conductance
	kA_plus 		(ms)		: willing to reluctant transition rate
	h_AG_AG_bar 		(ms)		:
	qA_inf  		(ms)		: maximum fraction of bound G proteins
	AG_bar		(ms)		:fraction of AG mobilised by the post-synaptic cell
	AG		(1/ms)		:AG mobilised by the post-synaptic cell

}

STATE {
	gA  		(mS/cm2)		:conductance
	wA  		(mS/cm2)		:The fraction of willing pre-synaptic Ca2+ channels
	qA  		(1/ms)		:fraction of bound G proteins
}


INITIAL {
	gA = 0.1
	wA = 0.2
	qA = 0.15

}


BREAKPOINT {
	SOLVE state METHOD cnexp
	kA_minus = kA_minus/(1+exp(-(vpre/5)))     
	IGABA_A = gA_bar*gA*(vpost - VA)
	gA_inf= 1/(1+exp(-(vpre-kd_max*(1-wA))/5))
	kA_plus = kappa_plus*qA      
	h_AG_AG_bar = BAG_max/(1+(ICAG_50/AG_bar)^nh)
	qA_inf = h_AG_AG_bar
	AG_bar = (1-MGL)*AG             
}


DERIVATIVE scheme1 {
gA'=((gA_inf)-gA)/tauA

wA'=kA_minus*(1-wA)-kA_plus*wA
   
qA'=(qA_inf-qA)/tau_qA 
}
ted
Site Admin
Posts: 6287
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: POINTER is not thread safe

Post by ted »

I was not able to open the links you shared in the previous thread
Hmm, the Forum automatically (and incorrectly) "promoted" those to incorrect URLs. I have now revised that post. Alternatively, you could try modeldb.science/3815 and modeldb.science/3264 entered into your browser's URL field exactly as shown in this reply (don't just click on them).
I now use cnexp which from what I have seen in numerous examples aside from differential equations is also used to solve algebraic equations
If you're going to write your own NMODL code, you really should read the "expanded version" of
Hines, M.L. and Carnevale, N.T. Expanding NEURON's Repertoire of Mechanisms with NMODL. Neural Computation 12:995-1007, 2000.
You'll find it here https://neuron.yale.edu/neuron/static/p ... odl400.pdf, and here is the list of errata https://neuron.yale.edu/neuron/static/p ... rrata.html.

Or maybe better--read chapter 9 of The NEURON Book (preprint https://www.neuron.yale.edu/ftp/ted/boo ... xedref.pdf). To learn about various ways to implement synaptic transmission, see chapter 10 (preprint https://www.neuron.yale.edu/ftp/ted/boo ... xedref.pdf).

For a short discussion of what integration method to specify in a SOLVE statement see viewtopic.php?t=592.

The BREAKPOINT block in your most recent post calls a nonexistent equation block.

The intermediate variables that are used by the ODEs in the DERIVATIVE block should themselves be calculated in that same DERIVATIVE block, not in the BREAKPOINT block. Constant terms (variables whose values will remain unaltered during a simulation) should probably be calculated in the INITIAL block, which is executed only at the beginning of a simulation.

Zachariou and Thul's abstract states that their "simplified model describes cannabinoid-mediated short-term modulation of both hippocampal inhibition and excitation and is ideally suited for large network studies." That last "ideally suited" bit is not correct if the simplified synaptic mechanism must access the values of pre- and postsynaptic membrane potential during a simulation. Why? Because in a large-scale model there is no guarantee that the pre- and postsynaptic cells will exist on the same host (CPU core). Consequently there will be data exchange between hosts at every time step during a simulation, a process that is inherently slow.
Post Reply