# Solving an SDE with a Continuous Callback

**URL:** https://discourse.julialang.org/t/solving-an-sde-with-a-continuous-callback/135180
**Category:** General Usage
**Tags:** diffeq, sde
**Created:** [January 21, 2026, 9:46am UTC](https://discourse.julialang.org/t/solving-an-sde-with-a-continuous-callback/135180 "2026-01-21T09:46:37Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![diffeqslvr](https://avatars.discourse-cdn.com/v4/letter/d/f475e1/32.png) [@diffeqslvr](https://discourse.julialang.org/u/diffeqslvr)
#### Post date: [January 21, 2026, 9:46am UTC](https://discourse.julialang.org/t/solving-an-sde-with-a-continuous-callback/135180/1 "2026-01-21T09:46:37Z")

</div>

I am solving a stochastic differential equation with a `ContinuousCallback`. Every time the continuous callback is activated, I modify my state vector discontinuously.

All the randomness comes from a phase, which follows a simple Wiener process, i.e., the phase is not coupled to the remaining variables of the differential equation.

Nonetheless, if I use the default tolerances, I sometimes observe a discontinuous change in the phase when the `ContinuousCallback` is activated:

 ![Random phase for high tolerances.](https://global.discourse-cdn.com/julialang/original/3X/e/e/ee744c6c9fe0b9157b7e5608bc4a97c69026013f.png)

When I decrease the tolerances, I don’t see these spikes anymore. Nonetheless, this seems like a strange behavior.

Here is a snippet of my code:

```julia-auto
function jump_condition_func(slv)
    return function (u, t, integrator)
        jump_condition(u, t, integrator, slv)
    end
end

function project_func!(slv, sys)
    return function (integrator)
        project!(integrator, slv, sys)
    end
end

jump_cb = ContinuousCallback(
    jump_condition_func(slv),
    project_func!(slv, sys),
    save_positions = (true, true),
)

prob = SDEProblem(eoms!, noise!, u₀, tspan, p)
sol = SDE.solve(
    prob,
    SDE.SRIW1(),
    abstol = slv.abstol,
    reltol = slv.reltol,
    callback = jump_cb,
    dtmax = slv.dtmax,
    maxiters = slv.maxiters,
    saveat = slv.saveat,
)

```

My questions are:

1. Why does this happen? Is it because I save the dynamics before and after the jump?
2. Can one even use a `ContinuousCallback` in combination with SDE solvers or does that lead to unexpected behavior? I know that there is also the option of using a jump diffusion process - is that preferred?

---

<div class="post-metadata">

### Author: ![diffeqslvr](https://avatars.discourse-cdn.com/v4/letter/d/f475e1/32.png) [@diffeqslvr](https://discourse.julialang.org/u/diffeqslvr)
#### Post date: [January 21, 2026, 10:19am UTC](https://discourse.julialang.org/t/solving-an-sde-with-a-continuous-callback/135180/2 "2026-01-21T10:19:51Z")

</div>

Update:

If I set `saveat = []` (the default), then I also do not see the spikes…

---

<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: [January 21, 2026, 11:39am UTC](https://discourse.julialang.org/t/solving-an-sde-with-a-continuous-callback/135180/3 "2026-01-21T11:39:19Z")

</div>

it could be a saveat bug

---

<div class="post-metadata">

### Author: ![diffeqslvr](https://avatars.discourse-cdn.com/v4/letter/d/f475e1/32.png) [@diffeqslvr](https://discourse.julialang.org/u/diffeqslvr)
#### Post date: [January 21, 2026, 11:59am UTC](https://discourse.julialang.org/t/solving-an-sde-with-a-continuous-callback/135180/4 "2026-01-21T11:59:56Z")

</div>

I think it is! Maybe some problem with the interpolation…

---

<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: [January 21, 2026, 4:24pm UTC](https://discourse.julialang.org/t/solving-an-sde-with-a-continuous-callback/135180/5 "2026-01-21T16:24:09Z")

</div>

open an issue I can figure it out

---

<div class="post-metadata">

### Author: ![diffeqslvr](https://avatars.discourse-cdn.com/v4/letter/d/f475e1/32.png) [@diffeqslvr](https://discourse.julialang.org/u/diffeqslvr)
#### Post date: [January 22, 2026, 8:51am UTC](https://discourse.julialang.org/t/solving-an-sde-with-a-continuous-callback/135180/6 "2026-01-22T08:51:49Z")

</div>

Ok, I will try to make a minimal working example
