However, I cannot get both Vector.play() AND NetCon/NetStim to work. If I use SaveState.restore(), Vector.play() does not work, if I use SaveState.restore(1) the simulation crashes on h.continuerun() when the NetCon/NetStim combination is present. Is there a way to make this work?
Below is a minimal code to reproduce the problem:
Open python session and run:
Code: Select all
from neuron import h,gui
class Collector:
def __init__(self, collection_period_ms, expr):
from neuron import h
self.collection_period_ms = collection_period_ms
self.stim = h.NetStim(0.5)
self.stim.start = 0
self.stim.number = 1e9
self.stim.noise = 0
self.stim.interval = self.collection_period_ms
self.con = h.NetCon(self.stim, None)
self.con.record((self.collect, expr))
self.fih = h.FInitializeHandler(self.clear)
self.clear()
def clear(self):
self.values = []
def collect(self, new_value):
self.values.append(new_value())
class Tester:
def build(self):
self.soma = h.Section()
self.soma.insert('pas')
self.soma.insert('hh')
self.ic = h.IClamp(0.5, sec=self.soma)
self.ic.delay = 0
self.ic.dur = 1e9
self.ic.amp = 0
self.col = Collector(1.0, lambda: h.t) # Including this line and using .restore(1), crashes continuerun()
def save(self):
self.ss = h.SaveState()
self.ss.save()
self.sf = h.File('state.bin')
self.ss.fwrite(self.sf)
def restore(self,arg):
self.ns = h.SaveState()
self.sf = h.File('state.bin')
self.ns.fread(self.sf)
self.ns.restore(arg)
t = Tester()
t.build()
h.stdinit()
h.tstop = 500
h.cvode_active(1)
h.nrncontrolmenu()
h.newPlotV()
h.run()
t.save()
Code: Select all
from neuron import h,gui
class Collector:
def __init__(self, collection_period_ms, expr):
from neuron import h
self.collection_period_ms = collection_period_ms
self.stim = h.NetStim(0.5)
self.stim.start = 0
self.stim.number = 1e9
self.stim.noise = 0
self.stim.interval = self.collection_period_ms
self.con = h.NetCon(self.stim, None)
self.con.record((self.collect, expr))
self.fih = h.FInitializeHandler(self.clear)
self.clear()
def clear(self):
self.values = []
def collect(self, new_value):
self.values.append(new_value())
class Tester:
def build(self):
self.soma = h.Section()
self.soma.insert('pas')
self.soma.insert('hh')
self.ic = h.IClamp(0.5, sec=self.soma)
self.ic.delay = 0
self.ic.dur = 1e9
self.ic.amp = 0
self.col = Collector(1.0, lambda: h.t) # Including this line and using .restore(1), crashes continuerun()
def save(self):
self.ss = h.SaveState()
self.ss.save()
self.sf = h.File('state.bin')
self.ss.fwrite(self.sf)
def restore(self,arg):
self.ns = h.SaveState()
self.sf = h.File('state.bin')
self.ns.fread(self.sf)
self.ns.restore(arg)
t = Tester()
t.build()
# Create a current ramp
rv = h.Vector([0, 0, 10, 0])
tv = h.Vector([0, 500, 600, 600])
rv.play(t.ic._ref_amp, tv, 1)
# Restore steady state and run ramp
h.stdinit()
t.restore(0) # 0 does not play() vector - no ramp - as expected per: https://www.neuron.yale.edu/neuron/static/new_doc/simctrl/savstate.html#SaveState.restore
h.cvode_active(1)
h.nrncontrolmenu()
h.newPlotV()
h.continuerun(700)
t.col.values # Shows NetStim/Con collected values for 500-700ms - as expected
# Restore, but this time preserve the event queue
h.stdinit()
t.restore(1) # 1 causes continuerun() crash when netstim/Collector is present
h.cvode_active(1)
h.nrncontrolmenu()
h.newPlotV()
h.continuerun(700) # This line crashes NEURON
Code: Select all
Assertion failed!
Program: [...]\python.exe
File: ../../../nrn/src/nrniv/../nrncvode/netcvode.cpp, Line 2233
Expression: tdiff == 0.0 || ( gcv_->tstop_begin_ <= tt && tt <= gcv_->tstop_end_)