How to run the simulation in-between?
Moderator: wwlytton
How to run the simulation in-between?
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!
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!
Re: How to run the simulation in-between?
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.
http://senselab.med.yale.edu/modeldb/Sh ... erfrun.hoc In particular, look at the procedures prun, savestate, and restorestate.
Re: How to run the simulation in-between?
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 )
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 )
Re: How to run the simulation in-between?
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.
Send to michael dot hines at yale dot edu.
Re: How to run the simulation in-between?
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.
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.
Re: How to run the simulation in-between?
Send me all the code needed in a zip file and I will try to diagnose the problem.
Re: How to run the simulation in-between?
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
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
and that avoids the error.
So I factored your
Code: Select all
svstate = new SaveState()
f = new File ("states_syn.dat")
svstate.fread(f)
Code: Select all
proc init() {
finitialize()
svstate = new SaveState()
f = new File ("states_syn.dat")
svstate.fread(f)
svstate.restore()
Re: How to run the simulation in-between?
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.
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.
Re: How to run the simulation in-between?
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
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
Re: How to run the simulation in-between?
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
Then, here is my saving state part:
Do I need to do some extra coding in saving state part to solve this random noise initialization problem?
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)
Code: Select all
objref svstate,f
svstate= new SaveState()
svstate.save()
f= new File ("states_syn_noise.dat")
svstate.fwrite(f,1)
Re: How to run the simulation in-between?
After the
you need
On reading you will need something like
Code: Select all
svstate.fwrite(f,1)
Code: Select all
f.printf("%g\n", r.seq())
f.close()
Code: Select all
svstate.fread(f, 1)
r,seq(f,scanvar())
f.close()
svstate.restore()
Re: How to run the simulation in-between?
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.
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)
Re: How to run the simulation in-between?
Send me a (complete) zip file again with instructions and I'll take a look.
Re: How to run the simulation in-between?
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.
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.