Why do I need to mention the variable in RANGE?

NMODL and the Channel Builder.
Post Reply
Bill Connelly
Posts: 86
Joined: Thu May 22, 2008 11:54 pm
Location: Australian National University

Why do I need to mention the variable in RANGE?

Post by Bill Connelly »

So I was trying to implement a current based synapse. Simple right?

I started with this code

Code: Select all

NEURON {
	POINT_PROCESS isyn
	RANGE del, amp, tau1, tau2, i
	ELECTRODE_CURRENT i
}
UNITS {
	(nA) = (nanoamp)
	(mV) = (millivolt)
}

PARAMETER {
	del=0 (ms)
	tau1=.5 (ms)	<1e-3,1e6>
	tau2=1 (ms)   <1e-3,1e6>
	amp=0 	(nA)	<0,1e9>
	factor
}

ASSIGNED {
  v (mV)
  i (nA) 
}

INITIAL {
  if (tau1==tau2) {
    tau1 = tau1*0.999
  }
  factor = -1*((tau2/tau1)^(tau2/(tau1-tau2)))*((tau2-tau1)/tau1)

}

BREAKPOINT {
	if (amp) { at_time(del) }
	i = twoexp( (t - del) )
}

FUNCTION twoexp(x(ms)) (nA) {
  if (x < 0 || x/tau2 > 10) {
    twoexp = 0
  }else{
    twoexp = -amp/factor*(exp(-x/tau2)-exp(-x/tau1))
  }
}
I didn't include "factor" as a RANGE variable, as the user would never need to access it, and it doesn't vary over space (again, I thought I was being virtuous). However, I normally got a crash with no warning, though occasionally I got the "convergence failed repeatedly or with |h| = hmin" error. The crash was not especially reproducible, I could insert one or two of the point processes, and the simulation would run fine.

But, as soon as factor was set as a RANGE, everything went fine. I'm sure there is a perfectly fine reason, but I can't think of it. What was going on? (during each run of the simulation, tau1 and tau2 were the same, i.e. factor was constant at each instance of the point process)
ted
Site Admin
Posts: 5784
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Why do I need to mention the variable in RANGE?

Post by ted »

Beats the heck out of me. For me, this thing runs like a charm--no problems at all. But then I'm using a relatively recent variant of 7.3, so maybe you have run into an obscure bug into 7.2.

I have two suggestions. The first is to declare factor to be an ASSIGNED variable and not to declare it in the NEURON block at all. That way you'll protect yourself from confusion when, at some future date, you have multiple instances of this mechansm and try to give them different values of tau1 and tau2. You see, by default a PARAMETER has global scope, so if factor is a PARAMETER, every instance of isyn will have the same value of factor, and that value will be a consequence of which one's INITIAL block was executed last during initialization; that's probably not what you had in mind. That won't happen with an ASSIGNED. Also, I wonder if that might eliminate the symptom your reported.

The second suggestion is truly minor: capitalize the name of this point processes. After all, a point process is an instance of a class, and there is a widespread (although not universal) tradition of capitalizing class names--notice that all of NEURON's built-in point processes have capitalized names. A particular instance of any given class may be in whichever case.
Post Reply