How to run the simulation in-between?

Moderator: wwlytton

breakwave922

How to run the simulation in-between?

Post by breakwave922 »

Hi,

We have a 1000-cell network of 276000ms of training protocol. Is there any way to cut the simulation in-between into two runs, and we save the status at end of the first run to make it serve as the initial condition (perhaps with other changed parameters in future) for the subsequent runs? How can we get the exact same results at final as the one-run simulation?
Learned from the neuron book that SaveState() can do this, but I don't know how. And also, my simulation is paralleled code, SaveSate() can also work in this environment?

Many thanks in advance!
hines
Site Admin
Posts: 1682
Joined: Wed May 18, 2005 3:32 pm

Re: How to run the simulation in-between?

Post by hines »

There are many models at https://senselab.med.yale.edu/modeldb/ that use SaveState (type it into the FullText search. See, for example,
http://senselab.med.yale.edu/modeldb/Sh ... erfrun.hoc In particular, look at the procedures prun, savestate, and restorestate.
breakwave922

Re: How to run the simulation in-between?

Post by breakwave922 »

Hi, Hines,

Thanks for your reply and time. I tried the SaveState() on a very simple single-cell model. I segmented the 1000ms simulation into 2 parts at 200ms: The first run was from 0-200ms, and the second run was from 200-1000ms, note that t always started from 0ms, so in the second run, simulation time was from 0-800ms.
The total # of spikes summed up from those two runs is equal to the original one.
However, if you look closely, you will find the spiking times in the second simulation are slightly different, and voltage values are different too. (image link http://www.imageno.com/uxp02dp28eu8pic.html )

Image
hines
Site Admin
Posts: 1682
Joined: Wed May 18, 2005 3:32 pm

Re: How to run the simulation in-between?

Post by hines »

The second run should start not from 0 but from 200. Please send me the code you are using in a zip file so I can see what the problem is.
Send to michael dot hines at yale dot edu.
breakwave922

Re: How to run the simulation in-between?

Post by breakwave922 »

Hi, Hines,

I still have some problems in using SaveState().
I created a small program to test: Single cell with current injection for 800ms, and split this into 200+600ms. For this setup, SaveState works perfectly. But then I use netstim instead of current injection, once I use svstate.restore(), NEURON give me errors, saying Assertion failed! File:../savstate.cpp, Line 763 Expression: nt==i&&nc==memb_list.nodecount "This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information."

I used my own created syn.mod, but I don't think this should be the problem. Because even without using my synapse file, or even without cell created, just define the netstim class, as long as I use svstate.restore(), it gives me same problem.

My goal is to use SaveState() in the big network, but before doing that, I would like to test it on the single cell.
Could you please help me to diagnose what's happening here? Is there something special I missed when using Netstim with SaveState?
Thanks in advance.
hines
Site Admin
Posts: 1682
Joined: Wed May 18, 2005 3:32 pm

Re: How to run the simulation in-between?

Post by hines »

Send me all the code needed in a zip file and I will try to diagnose the problem.
hines
Site Admin
Posts: 1682
Joined: Wed May 18, 2005 3:32 pm

Re: How to run the simulation in-between?

Post by hines »

The documentation needs to make it clear that even SaveState.write needs an existing model (which must be the same as when SaveState.save was executed).
So I factored your

Code: Select all

svstate = new SaveState()
f = new File ("states_syn.dat")
svstate.fread(f)
statements which were at the beginning of your file and prior to the construction of the model, into your 'proc init' so that it looks like

Code: Select all

proc init() {
finitialize()
svstate = new SaveState()
f = new File ("states_syn.dat")
svstate.fread(f)
svstate.restore()
and that avoids the error.
breakwave922

Re: How to run the simulation in-between?

Post by breakwave922 »

Thanks, Hines, This works.
breakwave922

Re: How to run the simulation in-between?

Post by breakwave922 »

Hi, Hines,

I found that once if I set random noise in the netstim to the synapses, the second simulation results couldn't match the corresponding part in the original one that is before segmentation of the simulation. The first simulation matches well. If I turned off the random noise, both two parts matches. I guess this might be due to the random noise initialization. I read some threads may related to this issue, like http://www.neuron.yale.edu/phpBB/viewto ... f=31&t=723, but still didn't help me to solve this problem. Do you have any suggestions? I can send you the code if needs.
Thanks in advance.
hines
Site Admin
Posts: 1682
Joined: Wed May 18, 2005 3:32 pm

Re: How to run the simulation in-between?

Post by hines »

You need to save the sequence number of the relevant Random instances. I recommend using the Random123 generator

Note that this kind of state can be saved in the SaveState file but you have to do it yourself on return from
SaveState.fwrite(File, 1)
http://www.neuron.yale.edu/neuron/stati ... state.html
On return the file is closed unless the second arg exists and is 1. In that case, extra computer state information may be written to the file, e.g. Random.seq().

See
http://www.neuron.yale.edu/neuron/stati ... Random.seq
breakwave922

Re: How to run the simulation in-between?

Post by breakwave922 »

Hines,

Thank you so much for you reply. But sorry for my not understanding your suggestion quite well.
Here is what I did so far:

In random generator, I switched to Random123, replacing my previous MCellRan4 generator

Code: Select all

r = new Random()
r.Random123(1000)
//r.MCellRan4(1000)
r.negexp(1)
   
stim = new NetStim()
stim.start = 100
stim.number = 20//10//5
stim.interval = 25//50//100
stim.noise = 1
stim.noiseFromRandom(r)	
Then, here is my saving state part:

Code: Select all

objref svstate,f
svstate= new SaveState()
svstate.save()
f= new File ("states_syn_noise.dat")
svstate.fwrite(f,1)
Do I need to do some extra coding in saving state part to solve this random noise initialization problem?
hines
Site Admin
Posts: 1682
Joined: Wed May 18, 2005 3:32 pm

Re: How to run the simulation in-between?

Post by hines »

After the

Code: Select all

svstate.fwrite(f,1)
you need

Code: Select all

f.printf("%g\n", r.seq())
f.close()
On reading you will need something like

Code: Select all

svstate.fread(f, 1)
r,seq(f,scanvar())
f.close()
svstate.restore()
breakwave922

Re: How to run the simulation in-between?

Post by breakwave922 »

Hines,

Thank you for your reply. Yes, the code works now.
But it's very strange that, the spikes only matches for some values of stim.interval.
For example, when I set stim.interval=25 or 30, I can match the number of spikes. But when I set stim.interval=333 or 3, the second part of the simulation didn't match again.

Code: Select all

r = new Random()
r.Random123(1000)
//r.MCellRan4(1000)
r.negexp(1)
   
stim = new NetStim()
stim.start = 100
stim.number = 1e200//10//5
stim.interval = 333//50//100
stim.noise = 1
stim.noiseFromRandom(r)	
hines
Site Admin
Posts: 1682
Joined: Wed May 18, 2005 3:32 pm

Re: How to run the simulation in-between?

Post by hines »

Send me a (complete) zip file again with instructions and I'll take a look.
hines
Site Admin
Posts: 1682
Joined: Wed May 18, 2005 3:32 pm

Re: How to run the simulation in-between?

Post by hines »

The problem is a documentation error in
http://www.neuron.yale.edu/neuron/stati ... tate.fread
The sentence "On return the file is closed unless the second arg exists and is 1." should
be
On return the file is closed unless the second arg exists and is 0.
By explicitly reopening the file after svstate.fread, the file pointer was at the beginning and the following scanvar did not read the last number in the file.
Post Reply