# Inconsistency with SavingCallback

**URL:** https://discourse.julialang.org/t/inconsistency-with-savingcallback/132321
**Category:** General Usage
**Tags:** diffeq, differentialequation, diffeqcallbacks
**Created:** [September 12, 2025, 1:04pm UTC](https://discourse.julialang.org/t/inconsistency-with-savingcallback/132321 "2025-09-12T13:04:01Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![dnldlg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnldlg/32/209465_2.png) [@dnldlg](https://discourse.julialang.org/u/dnldlg)
#### Post date: [September 12, 2025, 1:04pm UTC](https://discourse.julialang.org/t/inconsistency-with-savingcallback/132321/1 "2025-09-12T13:04:02Z")

</div>

I try to track the behavior of the parameters throughout an integration with DifferentialEquations.jl while using Callbacks. To do this I used `SavingCallback`, but noticed the following inconsistency with the argument `saveat`. Let us consider a little example: The parameter p is increased at fixed times T = \{1, ..., 9\} by some \Delta p.

```julia-auto
using DifferentialEquations
using DiffEqCallbacks
using Plots

function f(u, p, t)
    return -1im * p * u
end

function affect!(integrator)
    integrator.p += 0.1
end

function test()
    u0 = 1.0 + 0im
    tspan = (0.0, 10.0)
    t_eval = range(tspan[1], tspan[2], length=100)

    prob = ODEProblem(f, u0, tspan, 0.5)
    cb = PresetTimeCallback(range(1, 9), affect!)

    # Defining the SavingCallback
    saved_values = SavedValues(Float64, Float64)
    savecb = SavingCallback((u, t, integrator) -> integrator.p, saved_values)
    sol = solve(prob, callback=CallbackSet(cb, savecb))
    return saved_values
end

sv = test()
plot(sv.t, sv.saveval, xticks=1:9)

```

For that I get the following result:

![plot_75](https://global.discourse-cdn.com/julialang/original/3X/3/2/32a1f0454f54e92a6b04913d660d810535f42c5c.svg)

This is perfect - the parameter seems to change exactly at every t \in T. But I disliked, that the instantaneous changes looked so “slow”, that’s why I changed the setup of the `SavingCallback` to

```julia-auto
savecb = SavingCallback((u, t, integrator) -> integrator.p, saved_values, saveat=t_eval)

```

where `t_eval` should provide a much finer sampling to get sharp flanks. However, instead I got the following result

![plot_76](https://global.discourse-cdn.com/julialang/original/3X/a/f/af17a6b922d76174733561fa5dea22744f62e59e.svg)

The flanks seem to have shifted and are no longer at the defined PresetTimeCallbacks, which looks wrong now. Am I missing something?

---

<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: [September 19, 2025, 12:09am UTC](https://discourse.julialang.org/t/inconsistency-with-savingcallback/132321/2 "2025-09-19T00:09:46Z")

</div>

That looks like an issue in the SavingCallback, though uncertain what exactly is triggering it. Something about how it’s a parameter change (so discontinuous) plus saveat (which uses the interpolation) gets messed up here. Can you open an issue in DiffEqCallbacks.jl?
