Netstim in automated repeating simulations

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

Moderator: hines

Post Reply
Posts: 94
Joined: Mon May 19, 2014 10:39 pm

Netstim in automated repeating simulations

Post by breakwave922 »

I planned to implement a automated repeating simulations scheme to a NEURON network model (running in parallel), with each simulation, cells may receive or abandon external inputs by Netstim. Before I go for the network-level, I tested this scheme in a single neuron model, and I made it work as I wanted, however, something was confusing me:

Below is the code for the single cell model (partially Pseudocode)

Code: Select all

proc givenstim (){    ////this procedure defines the stimulate from Netstim
stim = new NetStim()
stim.start = start
stim.number = 10e20
stim.interval = 20
cell.soma syn = new Exp2Syn(0.9) //or any user-defined synapse file
nc = new NetCon(stim,syn,0,0,1)

proc batchrun() {   ///this procedure defines how to run the simulation for each sub-run

 synlist=new List()
 nclist=new List()
 objref stim
  print i
  if ($1==0) {
  givenstim(22,100)  ///only first sub-run build synapse and deliver Netstim events
run_time=2  ///how many time to run the simulation

for i=0,run_time-1 {

In the example code, the simulation was ran two times: for the first time, Netstim events was delivered through the synapse; for the second time, I wanted to remove the synapse by emptying the lists of synlist and nclist ( synlist=new List(), nclist=new List() ), and also by not calling proc givenstim () but this didn't work, and there were still events delivered and cell responded. The solution was, I have to re-declare stim by objref stim, then the second time of simulation worked without Netstim.

I first want to know whether this is the right solution. Also, I remember I saw some posts that, once if the synlist and nclist are emptied, synapses should not be functioning, but it seems this is not the case in my example, want to know why?

Thanks in advance.
Site Admin
Posts: 5935
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine

Re: Netstim in automated repeating simulations

Post by ted »

Great question.

hoc and Python keep track of how many variables reference each object instance. An object instance persists as long as there is at least one variable that references it. If an object instance's "reference count" drops to 0, the object is destroyed and the memory that it used is freed.

The fact that the statements
cell.soma syn = new Exp2Syn(0.9)
nc = new NetCon(stim,syn,0,0,1)
succeeded tells me that syn and nc were declared as objrefs at the top level of the interpreter (that is, OUTSIDE of any object). This means that, after exiting proc givenstim(), the Exp2Syn and NetCon both had reference counts of 2 (the Exp2Syn was referenced by the variables syn and synlist, etc.). Consequently, declaring
objref synlist
objref nclist
would NOT destroy all references to the Exp2Syn and NetCon.

One way to fix this problem is to get rid of the top level
objref syn
objref nc
statements. Instead, declare syn and nc to be localobj inside of proc givenstim(), like so

proc givenstim() { localobj syn, nc

Then syn and nc will vanish as soon as execution exits proc givenstim().

There are at least two other ways to eliminate all synaptic activations. One would be to execute

for j = 0,nclist.count()-1 nclist.o(j).weight = 0

Another would be

for j = 0,nclist.count()-1 nclist.o(j).delay += foo

where foo is some value larger than tstop (tstop*2 would be convenient).

Be sure to read about
localobj ... d-localobj
reference count ... n/obj.html
List.count() in ... /list.html
Posts: 94
Joined: Mon May 19, 2014 10:39 pm

Re: Netstim in automated repeating simulations

Post by breakwave922 »

Great explanation and solution!
I tested that I can also choose to use synlist.remove_all() and nclist_remove_all(), but needs to be based on that syn and nc are locobj.
Thanks, Ted.
Post Reply