Issue with SaveState

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

Moderator: hines

Post Reply
pascal
Posts: 106
Joined: Thu Apr 26, 2012 11:51 am

Issue with SaveState

Post by pascal »

I am having a few issues using h.SaveState(). First, I've found that switching the order of recording vector statements results in the program crashing when trying to restore. Here is my code (which the BallandStick class from https://neuron.yale.edu/neuron/docs/bal ... del-part-1), which simulates HH dynamics and stops at a peak, then saves state, and finally restores from the saved state and continues simulation:

Code: Select all

from neuron import h
import matplotlib.pyplot as plt
h.load_file("stdrun.hoc")

my_cell = BallAndStick(0)
my_cell.createIClamp(amp=0.25,dur=1e9,delay=20)
t = h.Vector().record(h._ref_t)
soma_v = h.Vector().record(my_cell.soma(0.5)._ref_v)

h.finitialize(-65)
h.continuerun(204.6) #chosen to end near voltage peak

plt.figure()
plt.plot(t,soma_v)

ss = h.SaveState()
ss.save()
sf = h.File('hh_state.bin')
ss.fwrite(sf)

my_cell = BallAndStick(0)
my_cell.createIClamp(amp=0.25,dur=1e9,delay=20)
t = h.Vector().record(h._ref_t) #if this line is moved to after the next one, for some reasons it causes program to crash (presumably related to the restore statement)
soma_v = h.Vector().record(my_cell.soma(0.5)._ref_v)

# see https://www.neuron.yale.edu/phpBB/viewtopic.php?t=3845
h.finitialize(-65)
ns = h.SaveState()
sf = h.File('hh_state.bin')
ns.fread(sf)
ns.restore(1) #problem with program crashing occurs with both ns.restore() and ns.restore(1)

if (h.cvode.active()):
  h.cvode.re_init() # make adaptive integrator update its copy of initial states

h.t = 0

h.continuerun(300)

plt.figure()
plt.plot(t, soma_v)
plt.show()

Right before the restore, if I move the t = h.Vector().record line to after the soma_V = h.Vector().record line, the program crashes when attempting to restore.

So my first question (I have a more substantial follow-up question, but I want to ask this first) is this: is this expected behavior from h.SaveState() and restore()? It seems very odd that the order in which I define my recording vectors should cause the program to crash.
ted
Site Admin
Posts: 6300
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Issue with SaveState

Post by ted »

Quoting from the documentation of SaveState, which you will find at nrn.readthedocs.io:
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.
I seem to recall that, in the past, one was also cautioned against creating new instances of any object class. Not sure if that particular injunction still applies, but . . .
pascal
Posts: 106
Joined: Thu Apr 26, 2012 11:51 am

Re: Issue with SaveState

Post by pascal »

Okay, I guess I'll just be more careful in using SaveState. And this actually cleared up my other question, too. Thanks, Ted!
Post Reply