Saving fixed timestep data using cvode variable timestep integration
Posted: Tue Feb 20, 2024 1:53 pm
Hello,
I recently have had to do some filtering and additional processing of my model output that I didn't need to do before and now need to save my recorded data using a fixed timestep. However, I have a dramatic improvement in execution time using cvode compared to using a fixed timestep and I would like to preserve this efficiency if possible.
Reading the NEURON Vector().record() documentation it seems like my two options are providing a Dt value to determine the regular interval at which our data will be recorded
or provide a time Vector, tvec, that will determine the sampling rate.
Providing Dt seemed more desirable since we can just create the time vector using our desired Dt and run time.
In a Jupyter Notebook I used the magic command %%timeit to check the execution time of a simple simulation using a fixed timestep and using cvode along with providing the Dt argument.
8.74 ms ± 18.3 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)
11 ms ± 24.3 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)
As a sanity check I also checked to see if providing a time Vector provided a benefit versus providing a Dt and it did not which was expected. So it seems my performance boost is slightly lost which, unless I am ignorant of something, makes sense because I'm assuming that my system of equations need to be solved at the provided time values based on Dt which essentially means I am using a fixed time step.
I also looked into h.cvode.record versus Vector().record() in case that would provide a performance boost but with the following code I got the following error and couldn't discern what to fix from the error message (likely syntax I'm guessing).
Another Idea I had is to keep using cvode and allow my data to not be recorded at regular intervals and then after the simulation resample my data using something like linear interpolation to get the data to have a regular sampling frequency.
If anyone could let me know if I am going about this in the best way that would be greatly appreciated.
I recently have had to do some filtering and additional processing of my model output that I didn't need to do before and now need to save my recorded data using a fixed timestep. However, I have a dramatic improvement in execution time using cvode compared to using a fixed timestep and I would like to preserve this efficiency if possible.
Reading the NEURON Vector().record() documentation it seems like my two options are providing a Dt value to determine the regular interval at which our data will be recorded
Code: Select all
vdest = vdest.record(var_reference, Dt)
Code: Select all
vdest = vdest.record(var_reference, tvec)
In a Jupyter Notebook I used the magic command %%timeit to check the execution time of a simple simulation using a fixed timestep and using cvode along with providing the Dt argument.
Code: Select all
%%timeit
sec1 = h.Section(name="sec1")
sec1.insert(h.hh)
stim = h.IClamp(sec1(0))
stim.delay = 5
stim.dur = 1
stim.amp = 0.5
v_fixed = h.Vector().record(sec1(0.5)._ref_v, dt)
t_fixed = t = h.Vector().record(h._ref_t, dt)
h.cvode.active(True)
h.finitialize()
h.continuerun(run_time)
Code: Select all
%%timeit
sec2 = h.Section(name="sec2")
sec2.insert(h.hh)
stim = h.IClamp(sec2(0))
stim.delay = 5
stim.dur = 1
stim.amp = 0.5
h.cvode.active(False)
h.dt = 0.1
v_fixed = h.Vector().record(sec2(0.5)._ref_v)
t_fixed = t = h.Vector().record(h._ref_t)
h.finitialize()
h.continuerun(run_time)
As a sanity check I also checked to see if providing a time Vector provided a benefit versus providing a Dt and it did not which was expected. So it seems my performance boost is slightly lost which, unless I am ignorant of something, makes sense because I'm assuming that my system of equations need to be solved at the provided time values based on Dt which essentially means I am using a fixed time step.
I also looked into h.cvode.record versus Vector().record() in case that would provide a performance boost but with the following code I got the following error and couldn't discern what to fix from the error message (likely syntax I'm guessing).
Code: Select all
%%timeit
sec4 = h.Section(name="sec4")
sec4.insert(h.hh)
stim = h.IClamp(sec4(0))
stim.delay = 5
stim.dur = 1
stim.amp = 0.5
h.cvode.active(True)
dt = 0.1
fixed_time_vec = np.arange(0,500 + dt, dt)
fixed_time_vec = h.Vector(fixed_time_vec)
v_fixed = h.Vector()
h.cvode.record(sec4(0.5)._ref_v, v_fixed, fixed_time_vec)
h.finitialize()
h.continuerun(run_time)
NEURON: Cvode.record pointer not associated with currently accessed section
Use section ... (&var(x)...) intead of ...(§ion.var(x)...)
near line 0
^
CVode[0].record(..., ..., ...)
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
Cell In[112], line 11
9 fixed_time_vec = h.Vector(fixed_time_vec)
10 v_fixed = h.Vector()
---> 11 h.cvode.record(sec4(0.5)._ref_v, v_fixed, fixed_time_vec)
12 h.finitialize()
13 h.continuerun(run_time)
RuntimeError: hocobj_call error
If anyone could let me know if I am going about this in the best way that would be greatly appreciated.