# Best way to cache data during DifferentialEquations.jl integration

**URL:** <https://discourse.julialang.org/t/best-way-to-cache-data-during-differentialequations-jl-integration/78996>\
**Category:** Modelling & Simulations\
**Tags:** question, diffeq\
**Created:** [April 4, 2022, 9:43am UTC](https://discourse.julialang.org/t/best-way-to-cache-data-during-differentialequations-jl-integration/78996 "2022-04-04T09:43:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![josuagrw](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/josuagrw/32/1015_2.png) [@josuagrw](https://discourse.julialang.org/u/josuagrw)\
**Post date:** [April 4, 2022, 9:43am UTC](https://discourse.julialang.org/t/best-way-to-cache-data-during-differentialequations-jl-integration/78996/1 "2022-04-04T09:43:28Z")

</div>

I have a problem which could be written (not exactly) as

\dot u = \min\_w f(u,w)

Naturally, I would like use some previous value of \dot u as the starting point for the optimization problem on the _r.h.s._ — I might even like to store some additional data from the previous minimization (such as the solution of a dual problem) to speed up the optimization.

What’s the best way to do this? And can I rely on `du` being unchanged during calls to my r.h.s. function (in `solve` from DifferentialEquations.jl)?

EDIT: The minimization is subject to some constraints, so this is not entirely trivial.

---

<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:** [April 5, 2022, 11:44am UTC](https://discourse.julialang.org/t/best-way-to-cache-data-during-differentialequations-jl-integration/78996/2 "2022-04-05T11:44:35Z")

</div>

You can cache such stuff in the “parameters”, and use a discrete callback to pullback history if you also have a step cache.
