Page 1 of 1

How to stop a simulation from within a nmodl mechanism?

Posted: Wed Oct 25, 2006 9:50 am
by porio
Hi,

I'm running quite long simulations, in batch, doing something like a parameter search. Some (if not many) of the simluations I don't want to run until the end, because I know that something is going wrong. However, when I am not there, there is no way that neuron realize it, stop the simulation and proceed with the next one.... or there is?
I already have figured out how to decide that the simulation should be stopped. With a few modifications of the APCount point process (which I am already using) I can evaluate wether the 'stop criteria' is fulfilled. But, how do I tell neuron to actually stop the simulation? Is there such a command in nmodl?

Suggestion on any other way to do this (within the hoc code, for example) will also be appreciated.

Regards.

Posted: Wed Oct 25, 2006 12:01 pm
by ted
Don't stop simulation execution from inside a mod file.

The best way to do what you want is to abandon APCount and use NetCon instead.
Read about NetCon class's record() method
http://www.neuron.yale.edu/neuron/stati ... tml#record
Note the syntax
netcon.record("stmt")
which lets you execute arbitrary code whenever a "source event" happens (spike, in
this case). stmt could be a call to a proc that decides if it is time to stop.

Code: Select all

proc maybe_stop() {
  if (whatever you like) stoprun=1
}

objref nc, null  // null will be a NULLobject target for nc
// for this example, assume there is a section called soma
nc = new NetCon(&soma.v(0.5), null)
nc.record("maybe_stop()")
If you also want to keep a running count of spikes, add this extra bit of code:

Code: Select all

objref spktim, spnc
spktim = new Vector
spnc = new NetCon(&soma.v(0.5), null)
spnc.record(spktim)
spktim.size() will tell you how many spikes have occurred so far.

Posted: Thu Oct 26, 2006 4:19 am
by porio
Thanks a lot, I'll give it a try.

One quick question: I see that two NetCon objects can coexist in the same location. Can I have an APCount and a NetCon? (Just to make the least possible changes to my code) ;)

Posted: Thu Oct 26, 2006 5:45 am
by porio
I answered myself. They can.
An APCount and a NetCon can coexist; I can even use the APCount.n or the vector which stores the event times for evaluating the stop condition.

Thanks again.