SciML / StochasticDelayDiffEq.jl

Stochastic delay differential equations (SDDE) solvers for the SciML scientific machine learning ecosystem
MIT License
25 stars 10 forks source link

PresetTimeCallback - add_tstop! method implementation #38

Closed laserschwelle closed 2 years ago

laserschwelle commented 3 years ago

When I try to solve a SDDE with PresetTimeCallbacks the solver fails with this error message: add_tstop!: method has not been implemented for the integrator

Julia Version v1.5.3 StochasticDelayDiffEq v0.2.8 DiffEqCallbacks v2.16.0

Example to reproduce the error:

using StochasticDelayDiffEq, DiffEqCallbacks

delay(u,h,p,t) = -0.1*u
stoc(u,h,p,t) = 1e-3

h(p,t) = 1.0

τ = 0.1
tspan = (0.0, 1.0)
lags = [τ];
p = []

data_stepper!(integrator) = 1.0
step_times = [0.1, 0.2]
cb = PresetTimeCallback(step_times, data_stepper!)

prob = SDDEProblem(
    delay,
    stoc,
    h,
    tspan,
    p;
    constant_lags=lags
);

sol = solve(prob, SROCK1(), dt=1e-3, callback=cb, adaptive=false)

If I'm not explicitly referencing DiffEqCallbacks the creation of the callback already fails with: UndefVarError: PresetTimeCallback not defined. Is this behavior intended? If I'm using DifferentialEquations I get the same add_tstop!-error as above.

Thank you!

ChrisRackauckas commented 3 years ago

If I'm not explicitly referencing DiffEqCallbacks the creation of the callback already fails with: UndefVarError: PresetTimeCallback not defined. Is this behavior intended?

Yes, it needs DiffEqCallbacks.

When I try to solve a SDDE with PresetTimeCallbacks the solver fails with this error message

Looks like it's just a missing method.

laserschwelle commented 3 years ago

Changing this function https://github.com/SciML/StochasticDelayDiffEq.jl/blob/25524178668e5b40bb74417dfc0773ca03d564ab/src/integrators/interface.jl#L217 DiffEqBase.add_tstop!() seems to solve the problem.

ChrisRackauckas commented 3 years ago

That looks like it's the right solution. It just wasn't namespaced property to overload.

slwu89 commented 2 years ago

@ChrisRackauckas sorry to hop on an old method but I'm also having this issue, what is the correct way to use PresetTimeCallback with the SDDE solvers?

ChrisRackauckas commented 2 years ago

To merge https://github.com/SciML/StochasticDelayDiffEq.jl/pull/50