Issue with SaveState
Posted: Fri Nov 17, 2023 7:42 pm
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:
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.
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()
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.