# How to get the full history of step sizes and coefficients

**URL:** <https://discourse.julialang.org/t/how-to-get-the-full-history-of-step-sizes-and-coefficients/75597>\
**Category:** General Usage\
**Tags:** diffeq\
**Created:** [February 1, 2022, 7:11pm UTC](https://discourse.julialang.org/t/how-to-get-the-full-history-of-step-sizes-and-coefficients/75597 "2022-02-01T19:11:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![1115](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/1115/32/4465_2.png) [@1115](https://discourse.julialang.org/u/1115)\
**Post date:** [February 1, 2022, 7:11pm UTC](https://discourse.julialang.org/t/how-to-get-the-full-history-of-step-sizes-and-coefficients/75597/1 "2022-02-01T19:11:57Z")

</div>

Regarding to solving an ordinary differential equation `f(u, t)` with [`OrdinaryDiffEq.jl`](https://github.com/SciML/OrdinaryDiffEq.jl). Is it possible to store time steps as `times` and coefficients as `coeffs` so that one can replay the integration as

```julia
for k=1:K
    u += coeffs[k] * f(u, times[k])
end

```

The reason I want to do this is to combine it with optimal checkpointing algorithm in [`TreeverseAlgorithm.jl`](https://github.com/GiggleLiu/TreeverseAlgorithm.jl) so that I can differentiate large scale ODE solvers in a quantum emulator. If there is a better solution, that would be great.

UPDATE:  
Just notice it might be impossible to only record `times` and `coeffs` unless the integrator is the simplest Euclidean one. But I am still interested to know if there is an easy way to record the steps or implement checkpointing algorithms.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [February 1, 2022, 7:57pm UTC](https://discourse.julialang.org/t/how-to-get-the-full-history-of-step-sizes-and-coefficients/75597/2 "2022-02-01T19:57:09Z")

</div>

The `save_everystep` time is enough to reconstruct this. That’s how the checkpointing is implemented in DiffEqSensitivity.

Note that most ODE solvers cannot be written as you wrote above.

---

<div class="post-metadata">

**Author:** ![1115](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/1115/32/4465_2.png) [@1115](https://discourse.julialang.org/u/1115)\
**Post date:** [February 1, 2022, 8:19pm UTC](https://discourse.julialang.org/t/how-to-get-the-full-history-of-step-sizes-and-coefficients/75597/3 "2022-02-01T20:19:12Z")

</div>

> [@ChrisRackauckas](#):
>
> The `save_everystep` time is enough to reconstruct this. That’s how the checkpointing is implemented in DiffEqSensitivity.

Thanks for your prompt reply, but I forgot to mention that my program can not afford saving `u` in every step, because the memory cost can be huge. This is why I seek for **optimal** checkpointing to avoid storing every state. It is more like Seismic or fluid simulation. BTW, I found the APIs `get_proposed_dt` and `step!` in the integrator interface, [https://diffeq.sciml.ai/stable/basics/integrator/#SciMLBase.get\_proposed\_dt](https://diffeq.sciml.ai/stable/basics/integrator/#SciMLBase.get_proposed_dt) , which might satisfy my need.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [February 2, 2022, 5:06am UTC](https://discourse.julialang.org/t/how-to-get-the-full-history-of-step-sizes-and-coefficients/75597/4 "2022-02-02T05:06:16Z")

</div>

I think using a discrete callback to grab the t’s is probably a better idea, but yeah you can also use the integrator interface if you need to control every step in a very specific way.
