SciML / DiffEqCallbacks.jl

A library of useful callbacks for hybrid scientific machine learning (SciML) with augmented differential equation solvers
https://docs.sciml.ai/DiffEqCallbacks/stable/
Other
95 stars 47 forks source link

SavingCallback scalar saveat support #156

Closed visr closed 1 year ago

visr commented 1 year ago

The docs for SavingCallback mention

saveat mimics saveat in solve

Therefore I assumed passing a number would work like this:

If saveat is given a number, then it will automatically expand to tspan[1]:saveat:tspan[2].

It makes sense that this doesn't work, since the SavingCallback doesn't know the tspan. Right now it errors on numbers, since collect(saveat) creates a 0D array which isn't supported by BinaryMinHeap. Though the code has saveat isa Number so it looks like it was supposed to work.

Should we not support saveat numbers, or support it by adding a tspan kwarg? Or is there another way?

ChrisRackauckas commented 1 year ago

Yeah it's just not implemented in full right now. FunctionCallingCallback should similarly fix it. What should be done is that it should just make a "fake" empty one and then in the initialize https://github.com/SciML/DiffEqCallbacks.jl/blob/master/src/saving.jl#L87-L89 which is always called at the start of the solve, it should do Heap(integ.sol.prob.tspan[1]:saveat_cache:integ.sol.prob.tspan[2]) since at the initialize point it will know what the tspan is from the integrator. I just never got around to it so if anyone has a second this would be nice to finally fix.