DiffEq: SavingCallback, save befor and after other callback

I use a callback to alter the parameters p of my system. I also use a SavingCallback to save some function f(u,p) at every timestep.
The parameter changing callback has the option save_positions=(true,true) and saves the system state before and after the discontinuity.
The SavingCallback however only saves f(u,p) after the discontinuity. Is there a way to get around this?

save_positions = (true,true).

What do you mean by this? There is no such kw argument for SavingCallback. It is set to (false, false) in the underlying DiscreteCallback but this seems correct. I want to save f(u,p) to the SavedValues bevor and after the other callback. I don’t want to add more steps to the solution object…

Oh I see, yes, you can’t do that in the way it’s setup. You’d need to add such saving behavior to the other callback. This is worth an issue in DifferentialEquations.jl. I hope to improve some of the saving options in the near future.

For a bit more context:
My system has some internal state f(u,p) which I use in a VectorContinousCallback in order to change p of the system. This change of p introduces discontionuities to f. I’d like to check f as a function of time after I’ve solved the system. Right know I’m trying to to this with aseparat SavingCallback.

Alternatively i could save f inside the condition function of the continous callback. This seems a bit hacky though… is there any problem with this?

Thanks for the reply anyway, I’ll open an issue then. I think this is also somewhat related to the whole observed variables thing because f is basicially an important state of my system for callbacks, analysis and so on… but not a real state in a diffeq solver sense.

That’s what I would suggest for now.

FYI, there already is an issue on this:

1 Like

There are certain problems with triggering SavingCallback from other callback functions. I have tried to illustrate them here SavingCallback used together with event handling callbacks · Issue #30 · SciML/DiffEqCallbacks.jl · GitHub . Maybe together we can come up with a working solution