I am encountering an issue with the use of custom event deliveries using the CVode.event method.
My problem, reproducible with the MWE below, is that the delivery of events does not impact the progress of the simulation time.
Specifically, when I use the variable time step method with maxstep=0.4, and try to deliver events at t=5.0 and t=5.2, these events seem to effectively be delivered (because they are printing stuff in the console), but when I inspect the recorded time vector of the simulation, I see that time went from t=4.84113817206 directly to t=5.24113817206.
The code below
Code: Select all
from neuron import h
h.load_file('stdrun.hoc')
# Create section
s = h.Section()
s.insert('hh')
# s.insert('extracellular')
# Record time
t = h.Vector()
t.record(h._ref_t)
# Simulation parameters
h.tstop = 10.0
h.cvode_active(1)
h.cvode.maxstep(0.4)
h.finitialize()
# Prepare and push events in the queue
def switch_on_eext():
print 'switching on'
print h.t
print ''
# s.e_extracellular = 1.0
def switch_off_eext():
print 'switching off'
print h.t
print ''
# s.e_extracellular = 0.0
h.cvode.event(5.0, switch_on_eext)
h.cvode.event(5.2, switch_off_eext)
# Run simulation
h.cvode.solve(h.tstop)
# Print time steps
for ti in t.to_python():
print ti
It is problematic because I would like to use these events to turn on/off the extracellular batteries of my model, which constitute abrupt changes requiring the time step to get adapted (reduced) locally around these events.NEURON -- VERSION 7.5 master (c693a84) 2017-12-07
Duke, Yale, and the BlueBrain Project -- Copyright 1984-2016
See http://neuron.yale.edu/neuron/credits
switching on
5.0
switching off
5.2
0.0
0.220569086028
0.441138172057
0.841138172057
1.24113817206
1.64113817206
2.04113817206
2.44113817206
2.84113817206
3.24113817206
3.64113817206
4.04113817206
4.44113817206
4.84113817206
5.24113817206
5.64113817206
6.04113817206
6.44113817206
6.84113817206
7.24113817206
7.64113817206
8.04113817206
8.44113817206
8.84113817206
9.24113817206
9.64113817206
10.0
This problem can be circumvented by the use of FInitializeHandler objects, but this solution does not allow to dynamically create new events in the course of a simulation.
I suppose there is something wrong in my code which leads to the observed results, but I don’t know what it is.
If you have a suggestion, it is more than welcome.
With regards,
Nathan