NetStim causes SaveState crash
Posted: Fri Mar 22, 2024 7:11 pm
The code below is meant to run a simulation in small chunks (basically useless for the toy script here, but useful to control RAM consumption for very large datasets). The h.ExpSyn() / h.NetStim() / h.NetCon() trio causes NEURON to deliver the error message
The problem appears to begin in the interactions between h.NetStim().start, NetStim().number, and SaveState().
Thoughts?
This would seem to be gibberish, since not only am I not running ParallelContext, I have no reason to do so.NEURON: ExpSyn[0] :Event arrived out of order. Must call ParallelContext.set_maxstep AFTER assigning minimum NetCon.delay
The problem appears to begin in the interactions between h.NetStim().start, NetStim().number, and SaveState().
Thoughts?
Code: Select all
from neuron import h
import numpy as np
import matplotlib.pyplot as plt
h.load_file("stdrun.hoc")
# define the model
cell = h.Section(name='cell')
cell.nseg = 5
cell.L = 1e2
cell.diam = 4
cell.insert(h.hh)
# define the synaptic system
syn = h.ExpSyn(cell(0.5))
syn.tau = 0.9
syn.e = -50
syn.i = 1e-9
ns = h.NetStim()
ns.interval = 5 # this represents the delay between pre-synaptic events
ns.number = 2 # fails if > 1
ns.start = 0 # does not appear to make a difference
ns.noise = 0
nc = h.NetCon(ns, syn, sec=cell)
nc.threshold=0
nc.delay=1.2 # this represents the delay of synaptic transmission
nc.weight[0]= 1e-1 # if weight[0] < 0, the connection is off
# the tmp_v and tmp_t Vectors are over-written on each batchrun() loop
# therefore we also declare the v and t Vectors, to which each round of
# tmp_v and tmp_t are appended.
tmp_v = h.Vector().record(cell(0.5)._ref_v)
tmp_t = h.Vector().record(h._ref_t)
v = h.Vector()
t = h.Vector()
# declare the SaveState object
savestate = h.SaveState()
def batchrun_file(iters=3):
# batchrun() performs a simulation in parts, where each part's duration is
# a function of 'chunk' and the data read in from a .xlsx file of time-domain waveform data
for i in range(iters):
# re-initialize at each loop
h.finitialize(-67)
# h.CVode().print_event_queue()
if i > 0:
# after the first loop, restore the previous state
savestate.restore(1)
if h.CVode().active():
# # ensures cvode consistency
h.CVode().re_init()
else:
h.fcurrent()
# frecord_init() is undocumented, but appears to be necessary for the recording Vectors
# to coordinate time-stamping between loops
h.frecord_init()
# the length applied to continuerun() must account for the inherited h.t value and increase
# accordinly
h.continuerun(5*(i+1))
# after the simulation chunk, save the status
savestate.save()
# append the (temporary) recording Vectors to the permanent Vectors
v.append(tmp_v.c())
t.append(tmp_t.c())
batchrun_file(iters=10)
plt.plot(t,v)
plt.show()