Page 1 of 1

Destroy a vector in order to restart recording

Posted: Wed Apr 18, 2012 6:10 pm
by uri.cohen
I'm using Python to record from all currents in a model (for example, I record neuron.h.soma.ik_SK which is k-current in the soma). This is quite memory-intensive when for >100 compartments and when running the model for more than a second or so.
As I'm actually interested in the total current of each kind, so I figured I can run the simulation for 100ms, calculate the total current, and resume for another 100ms, and so on.

The part I'm missing is how to restart recording using vectors. Documentation say (in http://www.neuron.yale.edu/neuron/stati ... tml#record) that recording works until the vector is destroyed, so I thought you may just create a new vector and remove the reference for the previous one, and python's gc will do the rest:

Code: Select all

def record_var(sec, var):
   vec = neuron.h.Vector()
   varRef = '_ref_' + var
   vec.record(getattr(sec, varRef))
   my_variables[sec][var] = vec
Where my_variables is a dictionary of dictionaries which hold all 'active' vectors. This code is broken- it succeed to record the first 100ms, but then the second vector and up (of a given section and variable) are all empty.

What do I miss here? Is the old vec which was in my_variables[sec][var] still alive, preventing me from recording the same variable into the new vector?

Re: Destroy a vector in order to restart recording

Posted: Thu Apr 19, 2012 9:18 am
by ted
It isn't necessary or advisable to destroy any Vectors in order to "restart" recording. Just resize them to 0, then resume the simulation by calling continuerun(your_new_tstop). There have been enough questions about how to manage simulations that generate mountains of data that I am developing a short tutorial about it, and will try to post this at NEURON's WWW site later today.

Re: Destroy a vector in order to restart recording

Posted: Thu Apr 19, 2012 4:29 pm
by uri.cohen
Thanks, Ted! Works like a charm. And also simple...
I think I was trying the dead-end approach I was asking about because it actually do work for NetCon recording: due to the single-recording-per-source limitation, recording into a new vector just works.
Thanks again!

Re: Destroy a vector in order to restart recording

Posted: Fri Apr 20, 2012 12:01 am
by ted
Simplicity is so unexpected that it seems almost a shock when something simple works.
Resizing spike time and cell id Vectors also works for segmenting simulations of networks.

The alternative to this is using SaveState, which is attractive because it offers the possibility that one could stop a simulation whenever necessary, then pick it up again at some time in the indefinite future. However, that can be a bit more complicated, e.g. it is essential to avoid situations in which computer states are not saved to the SaveState object. Other caveats also apply when using the SaveState.save/restore approach--quoting from the Programmer's Reference:
Between a save and a restore, it is important not to create or delete sections, NetCon objects, or point processes. Do not change the number of segments, insert or delete mechanisms, or change the location of point processes.
. . .
if you advance using fadvance() calls different cells will be at different t values in general and SaveState will be useless.