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.