vector.play massively slowing down simulation

The basics of how to develop, test, and use models.
Post Reply
Bill Connelly
Posts: 86
Joined: Thu May 22, 2008 11:54 pm
Location: Australian National University

vector.play massively slowing down simulation

Post by Bill Connelly »

So I have a multicompartment model, that usually only takes a few milliseconds to run a 3000 ms simulations. I'm trying to play in arbitrary currents. However, as soon as I include the vector.play() function, the simulation slows down by about a factor of 1,000,000. The analysis code is listed below. The code runs in usual rapid fashion if I comment out the line summedEPSC.play(&dendstim.amp, fixeddt). I'm running version 7.2. It doesn't seem to matter if I run in fixed time step, or variable time step. I also tried using summedEPSC.play(&dendstim.amp, fixeddt, 1), however, that causes neuron to crash with no errors reported.

Why does play() cause the simulation to run so slowly (and why does the continuous = 1 arguement cause it to crash?)

Code: Select all

fixeddt = 0.05

objref summedEPSC
summedEPSC = new Vector()

obfunc createEPSC() {local factor, n, t localobj oneEPSC //$1=rise, $2=decay, $3=amplitude
  oneEPSC = new Vector(10001)
  factor = (($2/$1)^($2/($1-$2)))*(($2-$1)/$1)
  for (n=0; n<10001; n+=1) {
    t = n*fixeddt // n = sample number, t = time in ms
    oneEPSC.x(n) = ($3)/factor*(exp(-t/$2)-exp(-t/$1))
  }
  return oneEPSC
}

proc preparePlayVector() {local n, EPSCdel localobj offsetEPSC //$1=number of EPSCs, $2=interevent interval, $3=decay
  EPSCdel = 2000
  offsetEPSC = new Vector(tstop/fixeddt)
  summedEPSC.fill(0)
  
  for (n = 0; n<$1; n+=1) { 
    offsetEPSC.fill(0)
    offsetEPSC.copy(createEPSC(.5, $3, 0.02), (EPSCdel + n*$2)/fixeddt)
    offsetEPSC.resize(tstop/fixeddt)
    summedEPSC.add(offsetEPSC)
  }
  summedEPSC.play(&dendstim.amp, fixeddt) //THIS LINE HERE
}


proc dendEPSP() {local p, tau localobj f6
  dendstim.del = 0
  dendstim.amp = 0
  dendstim.dur = 3000 
  somastim.del = 1e9
  somastim.amp = 0

  oldtstop = tstop
  tstop = 3000

  summedEPSC.resize(tstop/fixeddt)

  f6 = new File()
  f6.aopen("single.txt")

  dend[38] for (p) {  
    dendV.record(&dend[38].v(p))
    somaV.record(&soma.v(0.5))
    tvec.record(&t)
    
    for(tau=1; tau<=10; tau+=1) {
      preparePlayVector(1, 30, tau)
      init()
      run()     
      start = tvec.indwhere(">=", 1999)
      end = tvec.indwhere(">=", 3000)
      f6.printf("%g\t", p*dend[38].L + dend[37].L + dend[33].L) //distance of site
      f6.printf("%g\t", tau)  // tau
      f6.printf("%g\t", somaV.max(start, end)-somaV.x[start])
      f6.printf("%g\t", dendV.max(start, end)-dendV.x[start])
      f6.printf("\n")     
    }
  }
  f6.close()
  tstop=oldtstop
}
ted
Site Admin
Posts: 5786
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: vector.play massively slowing down simulation

Post by ted »

When testing this on a toy model (and with much smaller tstop) I noticed that every call of dendEPSP() resulted in a longer run time. That didn't happen after I revised the code so that each call of preparePlayVector forced creation of a new summedEPSC vector. This makes me suspect that the slow run time is related to repeatedly calling Vector.play without first breaking the previously set up play.

In proc preparePlayVector() change

Code: Select all

  offsetEPSC = new Vector(tstop/fixeddt)
to

Code: Select all

  offsetEPSC = new Vector(tstop/fixeddt)
  summedEPSC = new Vector(offsetEPSC.size()) // this breaks any previously set up play of this vector
In proc dendEPSP() you can then change

Code: Select all

  summedEPSC.resize(tstop/fixeddt)
to

Code: Select all

//  summedEPSC.resize(tstop/fixeddt) // is resized in preparePlayVector()
While you're at it, you might as well change

Code: Select all

  dend for (p) {  
    dendV.record(&dend.v(p))
    somaV.record(&soma.v(0.5))
    tvec.record(&t)
to

Code: Select all

  somaV.record(&soma.v(0.5))
  tvec.record(&t)
  dend for (p) {  
    dendV.record(&dend.v(p))
since the record statements for tvec and somaV only need to be asserted once.
why does the continuous = 1 arguement cause it to crash?
NEURON 7.3 will tell you
"Second argument of Vector.play in continuous mode must be a time vector"
Bill Connelly
Posts: 86
Joined: Thu May 22, 2008 11:54 pm
Location: Australian National University

Re: vector.play massively slowing down simulation

Post by Bill Connelly »

Thanks Ted,

Well that certainly stopped the slowdown over repeated running... However, the first run is still 1,000,000 times slower than it should be, due to the play (or something associated with it).

For the moment I'm going to try to make a mod file, rather than running play into an iclamp. But I'm going to email you the model. If you don't have time to look at it, that's fine, but I thought I might as well send it to you, rather than wait for you to ask for me to send it to you, and then me sending it to you (and wasting 48 hours).
Post Reply