SciML / StochasticDelayDiffEq.jl

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

How to get example working? #48

Closed sdwfrost closed 2 years ago

sdwfrost commented 2 years ago

I'm not sure whether this system can be solved with the current SDDE solvers, but any pointers would be great - it's a SDE version of this DDE model, and should give similar results to this jump system. I can see what I think is going on (the noise term dimension and the state dimension don't match), but I don't see how to fix it.

using DifferentialEquations
using StochasticDelayDiffEq
using DiffEqCallbacks
using Random
using SparseArrays

function sir_dde!(du,u,h,p,t)
    (S,I,R) = u
    (β,c,τ) = p
    N = S+I+R
    infection = β*c*I/N*S
    (Sd,Id,Rd) = h(p, t-τ) # Time delayed variables
    Nd = Sd+Id+Rd
    recovery = β*c*Id/Nd*Sd
    @inbounds begin
        du[1] = -infection
        du[2] = infection - recovery
        du[3] = recovery
    end
    nothing
end;

# Define a sparse matrix by making a dense matrix and setting some values as not zero
A = zeros(3,2)
A[1,1] = 1
A[2,1] = 1
A[2,2] = 1
A[3,2] = 1
A = SparseArrays.sparse(A);

# Make `g` write the sparse matrix values
function sir_delayed_noise!(du,u,h,p,t)
    (S,I,R) = u
    (β,c,τ) = p
    N = S+I+R
    infection = β*c*I/N*S
    (Sd,Id,Rd) = h(p, t-τ) # Time delayed variables
    Nd = Sd+Id+Rd
    recovery = β*c*Id/Nd*Sd
    du[1,1] = -sqrt(infection)
    du[2,1] = sqrt(infection)
    du[2,2] = -sqrt(recovery)
    du[3,2] = sqrt(recovery)
end;

function condition(u,t,integrator) # Event when event_f(u,t) == 0
  u[2]
end;
function affect!(integrator)
  integrator.u[2] = 0.0
end;
cb = ContinuousCallback(condition,affect!);

δt = 0.1
tmax = 40.0
tspan = (0.0,tmax)
t = 0.0:δt:tmax;
u0 = [990.0,10.0,0.0]; # S,I,R

function sir_history(p, t)
    [1000.0, 0.0, 0.0]
end;

p = [0.05,10.0,4.0]; # β,c,τ
Random.seed!(1234);

prob_sdde = SDDEProblem(sir_dde!,sir_delayed_noise!,u0,sir_history,tspan,p;noise_rate_prototype=A);
sol_sdde = solve(prob_sdde,LambaEM(),callback=cb);

I get the following error:

ERROR: LoadError: BoundsError: attempt to access 3-element Vector{Float64} at index [2, 2]
Stacktrace:
  [1] setindex!
    @ ./array.jl:841 [inlined]
  [2] sir_delayed_noise!(du::Vector{Float64}, u::Vector{Float64}, h::DelayDiffEq.HistoryFunction{typeof(sir_history), StochasticDelayDiffEq.HistorySDEIntegrator{LambaEM{true}, true, Vector{Float64}, Float64, RODESolution{Float64, 2, Vector{Vector{Float64}}, Nothing, Nothing, Vector{Float64}, NoiseProcess{Float64, 2, Float64, SparseVector{Float64, Int64}, Nothing, Nothing, typeof(DiffEqNoiseProcess.INPLACE_WHITE_NOISE_DIST), typeof(DiffEqNoiseProcess.INPLACE_WHITE_NOISE_BRIDGE), true, ResettableStacks.ResettableStack{Tuple{Float64, SparseVector{Float64, Int64}, Nothing}, true}, ResettableStacks.ResettableStack{Tuple{Float64, SparseVector{Float64, Int64}, Nothing}, true}, RSWM{Float64}, Nothing, RandomNumbers.Xorshifts.Xoroshiro128Plus}, SDDEProblem{Vector{Float64}, Tuple{Float64, Float64}, Tuple{}, Tuple{}, true, Vector{Float64}, Nothing, SDDEFunction{true, typeof(sir_dde!), typeof(sir_delayed_noise!), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing}, typeof(sir_delayed_noise!), typeof(sir_history), Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SparseMatrixCSC{Float64, Int64}}, LambaEM{true}, StochasticDiffEq.LinearInterpolationData{Vector{Vector{Float64}}, Vector{Float64}}, DiffEqBase.DEStats}, StochasticDiffEq.LambaEMCache{Vector{Float64}, Vector{Float64}, SparseMatrixCSC{Float64, Int64}, SparseVector{Float64, Int64}}}}, p::Vector{Float64}, t::Float64)
    @ Main ~/Projects/github/sir-julia/script/sdde/sdde.jl:42
  [3] SDEDiffusionTermWrapper
    @ ~/.julia/packages/StochasticDelayDiffEq/tnNkg/src/functionwrapper.jl:8 [inlined]
  [4] sde_determine_initdt(u0::Vector{Float64}, t::Float64, tdir::Int64, dtmax::Float64, abstol::Float64, reltol::Float64, internalnorm::typeof(DiffEqBase.ODE_DEFAULT_NORM), prob::SDEProblem{Vector{Float64}, Tuple{Float64, Float64}, true, Vector{Float64}, Nothing, SDEFunction{true, StochasticDelayDiffEq.SDEFunctionWrapper{true, typeof(sir_dde!), StochasticDelayDiffEq.SDEDiffusionTermWrapper{true, typeof(sir_delayed_noise!), DelayDiffEq.HistoryFunction{typeof(sir_history), StochasticDelayDiffEq.HistorySDEIntegrator{LambaEM{true}, true, Vector{Float64}, Float64, RODESolution{Float64, 2, Vector{Vector{Float64}}, Nothing, Nothing, Vector{Float64}, NoiseProcess{Float64, 2, Float64, SparseVector{Float64, Int64}, Nothing, Nothing, typeof(DiffEqNoiseProcess.INPLACE_WHITE_NOISE_DIST), typeof(DiffEqNoiseProcess.INPLACE_WHITE_NOISE_BRIDGE), true, ResettableStacks.ResettableStack{Tuple{Float64, SparseVector{Float64, Int64}, Nothing}, true}, ResettableStacks.ResettableStack{Tuple{Float64, SparseVector{Float64, Int64}, Nothing}, true}, RSWM{Float64}, Nothing, RandomNumbers.Xorshifts.Xoroshiro128Plus}, SDDEProblem{Vector{Float64}, Tuple{Float64, Float64}, Tuple{}, Tuple{}, true, Vector{Float64}, Nothing, SDDEFunction{true, typeof(sir_dde!), typeof(sir_delayed_noise!), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing}, typeof(sir_delayed_noise!), typeof(sir_history), Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SparseMatrixCSC{Float64, Int64}}, LambaEM{true}, StochasticDiffEq.LinearInterpolationData{Vector{Vector{Float64}}, Vector{Float64}}, DiffEqBase.DEStats}, StochasticDiffEq.LambaEMCache{Vector{Float64}, Vector{Float64}, SparseMatrixCSC{Float64, Int64}, SparseVector{Float64, Int64}}}}}, DelayDiffEq.HistoryFunction{typeof(sir_history), StochasticDelayDiffEq.HistorySDEIntegrator{LambaEM{true}, true, Vector{Float64}, Float64, RODESolution{Float64, 2, Vector{Vector{Float64}}, Nothing, Nothing, Vector{Float64}, NoiseProcess{Float64, 2, Float64, SparseVector{Float64, Int64}, Nothing, Nothing, typeof(DiffEqNoiseProcess.INPLACE_WHITE_NOISE_DIST), typeof(DiffEqNoiseProcess.INPLACE_WHITE_NOISE_BRIDGE), true, ResettableStacks.ResettableStack{Tuple{Float64, SparseVector{Float64, Int64}, Nothing}, true}, ResettableStacks.ResettableStack{Tuple{Float64, SparseVector{Float64, Int64}, Nothing}, true}, RSWM{Float64}, Nothing, RandomNumbers.Xorshifts.Xoroshiro128Plus}, SDDEProblem{Vector{Float64}, Tuple{Float64, Float64}, Tuple{}, Tuple{}, true, Vector{Float64}, Nothing, SDDEFunction{true, typeof(sir_dde!), typeof(sir_delayed_noise!), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing}, typeof(sir_delayed_noise!), typeof(sir_history), Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SparseMatrixCSC{Float64, Int64}}, LambaEM{true}, StochasticDiffEq.LinearInterpolationData{Vector{Vector{Float64}}, Vector{Float64}}, DiffEqBase.DEStats}, StochasticDiffEq.LambaEMCache{Vector{Float64}, Vector{Float64}, SparseMatrixCSC{Float64, Int64}, SparseVector{Float64, Int64}}}}, LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing}, StochasticDelayDiffEq.SDEDiffusionTermWrapper{true, typeof(sir_delayed_noise!), DelayDiffEq.HistoryFunction{typeof(sir_history), StochasticDelayDiffEq.HistorySDEIntegrator{LambaEM{true}, true, Vector{Float64}, Float64, RODESolution{Float64, 2, Vector{Vector{Float64}}, Nothing, Nothing, Vector{Float64}, NoiseProcess{Float64, 2, Float64, SparseVector{Float64, Int64}, Nothing, Nothing, typeof(DiffEqNoiseProcess.INPLACE_WHITE_NOISE_DIST), typeof(DiffEqNoiseProcess.INPLACE_WHITE_NOISE_BRIDGE), true, ResettableStacks.ResettableStack{Tuple{Float64, SparseVector{Float64, Int64}, Nothing}, true}, ResettableStacks.ResettableStack{Tuple{Float64, SparseVector{Float64, Int64}, Nothing}, true}, RSWM{Float64}, Nothing, RandomNumbers.Xorshifts.Xoroshiro128Plus}, SDDEProblem{Vector{Float64}, Tuple{Float64, Float64}, Tuple{}, Tuple{}, true, Vector{Float64}, Nothing, SDDEFunction{true, typeof(sir_dde!), typeof(sir_delayed_noise!), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing}, typeof(sir_delayed_noise!), typeof(sir_history), Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SparseMatrixCSC{Float64, Int64}}, LambaEM{true}, StochasticDiffEq.LinearInterpolationData{Vector{Vector{Float64}}, Vector{Float64}}, DiffEqBase.DEStats}, StochasticDiffEq.LambaEMCache{Vector{Float64}, Vector{Float64}, SparseMatrixCSC{Float64, Int64}, SparseVector{Float64, Int64}}}}}, LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing}, StochasticDelayDiffEq.SDEDiffusionTermWrapper{true, typeof(sir_delayed_noise!), DelayDiffEq.HistoryFunction{typeof(sir_history), StochasticDelayDiffEq.HistorySDEIntegrator{LambaEM{true}, true, Vector{Float64}, Float64, RODESolution{Float64, 2, Vector{Vector{Float64}}, Nothing, Nothing, Vector{Float64}, NoiseProcess{Float64, 2, Float64, SparseVector{Float64, Int64}, Nothing, Nothing, typeof(DiffEqNoiseProcess.INPLACE_WHITE_NOISE_DIST), typeof(DiffEqNoiseProcess.INPLACE_WHITE_NOISE_BRIDGE), true, ResettableStacks.ResettableStack{Tuple{Float64, SparseVector{Float64, Int64}, Nothing}, true}, ResettableStacks.ResettableStack{Tuple{Float64, SparseVector{Float64, Int64}, Nothing}, true}, RSWM{Float64}, Nothing, RandomNumbers.Xorshifts.Xoroshiro128Plus}, SDDEProblem{Vector{Float64}, Tuple{Float64, Float64}, Tuple{}, Tuple{}, true, Vector{Float64}, Nothing, SDDEFunction{true, typeof(sir_dde!), typeof(sir_delayed_noise!), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing}, typeof(sir_delayed_noise!), typeof(sir_history), Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SparseMatrixCSC{Float64, Int64}}, LambaEM{true}, StochasticDiffEq.LinearInterpolationData{Vector{Vector{Float64}}, Vector{Float64}}, DiffEqBase.DEStats}, StochasticDiffEq.LambaEMCache{Vector{Float64}, Vector{Float64}, SparseMatrixCSC{Float64, Int64}, SparseVector{Float64, Int64}}}}}, Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, Nothing}, order::Rational{Int64}, integrator::StochasticDelayDiffEq.SDDEIntegrator{LambaEM{true}, true, Vector{Float64}, Float64, Float64, Vector{Float64}, Float64, Float64, Float64, NoiseProcess{Float64, 2, Float64, SparseVector{Float64, Int64}, Nothing, Nothing, typeof(DiffEqNoiseProcess.INPLACE_WHITE_NOISE_DIST), typeof(DiffEqNoiseProcess.INPLACE_WHITE_NOISE_BRIDGE), true, ResettableStacks.ResettableStack{Tuple{Float64, SparseVector{Float64, Int64}, Nothing}, true}, ResettableStacks.ResettableStack{Tuple{Float64, SparseVector{Float64, Int64}, Nothing}, true}, RSWM{Float64}, Nothing, RandomNumbers.Xorshifts.Xoroshiro128Plus}, Nothing, Vector{Float64}, RODESolution{Float64, 2, Vector{Vector{Float64}}, Nothing, Nothing, Vector{Float64}, NoiseProcess{Float64, 2, Float64, SparseVector{Float64, Int64}, Nothing, Nothing, typeof(DiffEqNoiseProcess.INPLACE_WHITE_NOISE_DIST), typeof(DiffEqNoiseProcess.INPLACE_WHITE_NOISE_BRIDGE), true, ResettableStacks.ResettableStack{Tuple{Float64, SparseVector{Float64, Int64}, Nothing}, true}, ResettableStacks.ResettableStack{Tuple{Float64, SparseVector{Float64, Int64}, Nothing}, true}, RSWM{Float64}, Nothing, RandomNumbers.Xorshifts.Xoroshiro128Plus}, SDDEProblem{Vector{Float64}, Tuple{Float64, Float64}, Tuple{}, Tuple{}, true, Vector{Float64}, Nothing, SDDEFunction{true, typeof(sir_dde!), typeof(sir_delayed_noise!), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing}, typeof(sir_delayed_noise!), typeof(sir_history), Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SparseMatrixCSC{Float64, Int64}}, LambaEM{true}, StochasticDiffEq.LinearInterpolationData{Vector{Vector{Float64}}, Vector{Float64}}, DiffEqBase.DEStats}, StochasticDiffEq.LambaEMCache{Vector{Float64}, Vector{Float64}, SparseMatrixCSC{Float64, Int64}, SparseVector{Float64, Int64}}, StochasticDelayDiffEq.SDEFunctionWrapper{true, typeof(sir_dde!), StochasticDelayDiffEq.SDEDiffusionTermWrapper{true, typeof(sir_delayed_noise!), DelayDiffEq.HistoryFunction{typeof(sir_history), StochasticDelayDiffEq.HistorySDEIntegrator{LambaEM{true}, true, Vector{Float64}, Float64, RODESolution{Float64, 2, Vector{Vector{Float64}}, Nothing, Nothing, Vector{Float64}, NoiseProcess{Float64, 2, Float64, SparseVector{Float64, Int64}, Nothing, Nothing, typeof(DiffEqNoiseProcess.INPLACE_WHITE_NOISE_DIST), typeof(DiffEqNoiseProcess.INPLACE_WHITE_NOISE_BRIDGE), true, ResettableStacks.ResettableStack{Tuple{Float64, SparseVector{Float64, Int64}, Nothing}, true}, ResettableStacks.ResettableStack{Tuple{Float64, SparseVector{Float64, Int64}, Nothing}, true}, RSWM{Float64}, Nothing, RandomNumbers.Xorshifts.Xoroshiro128Plus}, SDDEProblem{Vector{Float64}, Tuple{Float64, Float64}, Tuple{}, Tuple{}, true, Vector{Float64}, Nothing, SDDEFunction{true, typeof(sir_dde!), typeof(sir_delayed_noise!), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing}, typeof(sir_delayed_noise!), typeof(sir_history), Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SparseMatrixCSC{Float64, Int64}}, LambaEM{true}, StochasticDiffEq.LinearInterpolationData{Vector{Vector{Float64}}, Vector{Float64}}, DiffEqBase.DEStats}, StochasticDiffEq.LambaEMCache{Vector{Float64}, Vector{Float64}, SparseMatrixCSC{Float64, Int64}, SparseVector{Float64, Int64}}}}}, DelayDiffEq.HistoryFunction{typeof(sir_history), StochasticDelayDiffEq.HistorySDEIntegrator{LambaEM{true}, true, Vector{Float64}, Float64, RODESolution{Float64, 2, Vector{Vector{Float64}}, Nothing, Nothing, Vector{Float64}, NoiseProcess{Float64, 2, Float64, SparseVector{Float64, Int64}, Nothing, Nothing, typeof(DiffEqNoiseProcess.INPLACE_WHITE_NOISE_DIST), typeof(DiffEqNoiseProcess.INPLACE_WHITE_NOISE_BRIDGE), true, ResettableStacks.ResettableStack{Tuple{Float64, SparseVector{Float64, Int64}, Nothing}, true}, ResettableStacks.ResettableStack{Tuple{Float64, SparseVector{Float64, Int64}, Nothing}, true}, RSWM{Float64}, Nothing, RandomNumbers.Xorshifts.Xoroshiro128Plus}, SDDEProblem{Vector{Float64}, Tuple{Float64, Float64}, Tuple{}, Tuple{}, true, Vector{Float64}, Nothing, SDDEFunction{true, typeof(sir_dde!), typeof(sir_delayed_noise!), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing}, typeof(sir_delayed_noise!), typeof(sir_history), Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SparseMatrixCSC{Float64, Int64}}, LambaEM{true}, StochasticDiffEq.LinearInterpolationData{Vector{Vector{Float64}}, Vector{Float64}}, DiffEqBase.DEStats}, StochasticDiffEq.LambaEMCache{Vector{Float64}, Vector{Float64}, SparseMatrixCSC{Float64, Int64}, SparseVector{Float64, Int64}}}}, LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing}, StochasticDelayDiffEq.SDEDiffusionTermWrapper{true, typeof(sir_delayed_noise!), DelayDiffEq.HistoryFunction{typeof(sir_history), StochasticDelayDiffEq.HistorySDEIntegrator{LambaEM{true}, true, Vector{Float64}, Float64, RODESolution{Float64, 2, Vector{Vector{Float64}}, Nothing, Nothing, Vector{Float64}, NoiseProcess{Float64, 2, Float64, SparseVector{Float64, Int64}, Nothing, Nothing, typeof(DiffEqNoiseProcess.INPLACE_WHITE_NOISE_DIST), typeof(DiffEqNoiseProcess.INPLACE_WHITE_NOISE_BRIDGE), true, ResettableStacks.ResettableStack{Tuple{Float64, SparseVector{Float64, Int64}, Nothing}, true}, ResettableStacks.ResettableStack{Tuple{Float64, SparseVector{Float64, Int64}, Nothing}, true}, RSWM{Float64}, Nothing, RandomNumbers.Xorshifts.Xoroshiro128Plus}, SDDEProblem{Vector{Float64}, Tuple{Float64, Float64}, Tuple{}, Tuple{}, true, Vector{Float64}, Nothing, SDDEFunction{true, typeof(sir_dde!), typeof(sir_delayed_noise!), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing}, typeof(sir_delayed_noise!), typeof(sir_history), Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SparseMatrixCSC{Float64, Int64}}, LambaEM{true}, StochasticDiffEq.LinearInterpolationData{Vector{Vector{Float64}}, Vector{Float64}}, DiffEqBase.DEStats}, StochasticDiffEq.LambaEMCache{Vector{Float64}, Vector{Float64}, SparseMatrixCSC{Float64, Int64}, SparseVector{Float64, Int64}}}}}, Nothing, StochasticDiffEq.SDEOptions{Float64, Float64, PIController{Float64}, typeof(DiffEqBase.ODE_DEFAULT_NORM), Nothing, CallbackSet{Tuple{ContinuousCallback{typeof(condition), typeof(affect!), typeof(affect!), typeof(SciMLBase.INITIALIZE_DEFAULT), typeof(SciMLBase.FINALIZE_DEFAULT), Float64, Int64, Rational{Int64}, Nothing, Int64}}, Tuple{}}, typeof(DiffEqBase.ODE_DEFAULT_ISOUTOFDOMAIN), typeof(DiffEqBase.ODE_DEFAULT_PROG_MESSAGE), typeof(DiffEqBase.ODE_DEFAULT_UNSTABLE_CHECK), DataStructures.BinaryMinHeap{Float64}, DataStructures.BinaryMinHeap{Discontinuity{Float64, Rational{Int64}}}, Nothing, Nothing, Int64, Float64, Float64, Float64, Vector{Float64}, Vector{Float64}, Vector{Discontinuity{Float64, Rational{Int64}}}}, Nothing, Float64, Nothing, DelayDiffEq.HistoryFunction{typeof(sir_history), StochasticDelayDiffEq.HistorySDEIntegrator{LambaEM{true}, true, Vector{Float64}, Float64, RODESolution{Float64, 2, Vector{Vector{Float64}}, Nothing, Nothing, Vector{Float64}, NoiseProcess{Float64, 2, Float64, SparseVector{Float64, Int64}, Nothing, Nothing, typeof(DiffEqNoiseProcess.INPLACE_WHITE_NOISE_DIST), typeof(DiffEqNoiseProcess.INPLACE_WHITE_NOISE_BRIDGE), true, ResettableStacks.ResettableStack{Tuple{Float64, SparseVector{Float64, Int64}, Nothing}, true}, ResettableStacks.ResettableStack{Tuple{Float64, SparseVector{Float64, Int64}, Nothing}, true}, RSWM{Float64}, Nothing, RandomNumbers.Xorshifts.Xoroshiro128Plus}, SDDEProblem{Vector{Float64}, Tuple{Float64, Float64}, Tuple{}, Tuple{}, true, Vector{Float64}, Nothing, SDDEFunction{true, typeof(sir_dde!), typeof(sir_delayed_noise!), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing}, typeof(sir_delayed_noise!), typeof(sir_history), Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SparseMatrixCSC{Float64, Int64}}, LambaEM{true}, StochasticDiffEq.LinearInterpolationData{Vector{Vector{Float64}}, Vector{Float64}}, DiffEqBase.DEStats}, StochasticDiffEq.LambaEMCache{Vector{Float64}, Vector{Float64}, SparseMatrixCSC{Float64, Int64}, SparseVector{Float64, Int64}}}}, StochasticDelayDiffEq.HistorySDEIntegrator{LambaEM{true}, true, Vector{Float64}, Float64, RODESolution{Float64, 2, Vector{Vector{Float64}}, Nothing, Nothing, Vector{Float64}, NoiseProcess{Float64, 2, Float64, SparseVector{Float64, Int64}, Nothing, Nothing, typeof(DiffEqNoiseProcess.INPLACE_WHITE_NOISE_DIST), typeof(DiffEqNoiseProcess.INPLACE_WHITE_NOISE_BRIDGE), true, ResettableStacks.ResettableStack{Tuple{Float64, SparseVector{Float64, Int64}, Nothing}, true}, ResettableStacks.ResettableStack{Tuple{Float64, SparseVector{Float64, Int64}, Nothing}, true}, RSWM{Float64}, Nothing, RandomNumbers.Xorshifts.Xoroshiro128Plus}, SDDEProblem{Vector{Float64}, Tuple{Float64, Float64}, Tuple{}, Tuple{}, true, Vector{Float64}, Nothing, SDDEFunction{true, typeof(sir_dde!), typeof(sir_delayed_noise!), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing}, typeof(sir_delayed_noise!), typeof(sir_history), Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SparseMatrixCSC{Float64, Int64}}, LambaEM{true}, StochasticDiffEq.LinearInterpolationData{Vector{Vector{Float64}}, Vector{Float64}}, DiffEqBase.DEStats}, StochasticDiffEq.LambaEMCache{Vector{Float64}, Vector{Float64}, SparseMatrixCSC{Float64, Int64}, SparseVector{Float64, Int64}}}})
    @ StochasticDiffEq ~/.julia/packages/StochasticDiffEq/nKdYj/src/initdt.jl:34
  [5] auto_dt_reset!
    @ ~/.julia/packages/StochasticDelayDiffEq/tnNkg/src/integrators/interface.jl:111 [inlined]
  [6] handle_dt!(integrator::StochasticDelayDiffEq.SDDEIntegrator{LambaEM{true}, true, Vector{Float64}, Float64, Float64, Vector{Float64}, Float64, Float64, Float64, NoiseProcess{Float64, 2, Float64, SparseVector{Float64, Int64}, Nothing, Nothing, typeof(DiffEqNoiseProcess.INPLACE_WHITE_NOISE_DIST), typeof(DiffEqNoiseProcess.INPLACE_WHITE_NOISE_BRIDGE), true, ResettableStacks.ResettableStack{Tuple{Float64, SparseVector{Float64, Int64}, Nothing}, true}, ResettableStacks.ResettableStack{Tuple{Float64, SparseVector{Float64, Int64}, Nothing}, true}, RSWM{Float64}, Nothing, RandomNumbers.Xorshifts.Xoroshiro128Plus}, Nothing, Vector{Float64}, RODESolution{Float64, 2, Vector{Vector{Float64}}, Nothing, Nothing, Vector{Float64}, NoiseProcess{Float64, 2, Float64, SparseVector{Float64, Int64}, Nothing, Nothing, typeof(DiffEqNoiseProcess.INPLACE_WHITE_NOISE_DIST), typeof(DiffEqNoiseProcess.INPLACE_WHITE_NOISE_BRIDGE), true, ResettableStacks.ResettableStack{Tuple{Float64, SparseVector{Float64, Int64}, Nothing}, true}, ResettableStacks.ResettableStack{Tuple{Float64, SparseVector{Float64, Int64}, Nothing}, true}, RSWM{Float64}, Nothing, RandomNumbers.Xorshifts.Xoroshiro128Plus}, SDDEProblem{Vector{Float64}, Tuple{Float64, Float64}, Tuple{}, Tuple{}, true, Vector{Float64}, Nothing, SDDEFunction{true, typeof(sir_dde!), typeof(sir_delayed_noise!), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing}, typeof(sir_delayed_noise!), typeof(sir_history), Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SparseMatrixCSC{Float64, Int64}}, LambaEM{true}, StochasticDiffEq.LinearInterpolationData{Vector{Vector{Float64}}, Vector{Float64}}, DiffEqBase.DEStats}, StochasticDiffEq.LambaEMCache{Vector{Float64}, Vector{Float64}, SparseMatrixCSC{Float64, Int64}, SparseVector{Float64, Int64}}, StochasticDelayDiffEq.SDEFunctionWrapper{true, typeof(sir_dde!), StochasticDelayDiffEq.SDEDiffusionTermWrapper{true, typeof(sir_delayed_noise!), DelayDiffEq.HistoryFunction{typeof(sir_history), StochasticDelayDiffEq.HistorySDEIntegrator{LambaEM{true}, true, Vector{Float64}, Float64, RODESolution{Float64, 2, Vector{Vector{Float64}}, Nothing, Nothing, Vector{Float64}, NoiseProcess{Float64, 2, Float64, SparseVector{Float64, Int64}, Nothing, Nothing, typeof(DiffEqNoiseProcess.INPLACE_WHITE_NOISE_DIST), typeof(DiffEqNoiseProcess.INPLACE_WHITE_NOISE_BRIDGE), true, ResettableStacks.ResettableStack{Tuple{Float64, SparseVector{Float64, Int64}, Nothing}, true}, ResettableStacks.ResettableStack{Tuple{Float64, SparseVector{Float64, Int64}, Nothing}, true}, RSWM{Float64}, Nothing, RandomNumbers.Xorshifts.Xoroshiro128Plus}, SDDEProblem{Vector{Float64}, Tuple{Float64, Float64}, Tuple{}, Tuple{}, true, Vector{Float64}, Nothing, SDDEFunction{true, typeof(sir_dde!), typeof(sir_delayed_noise!), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing}, typeof(sir_delayed_noise!), typeof(sir_history), Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SparseMatrixCSC{Float64, Int64}}, LambaEM{true}, StochasticDiffEq.LinearInterpolationData{Vector{Vector{Float64}}, Vector{Float64}}, DiffEqBase.DEStats}, StochasticDiffEq.LambaEMCache{Vector{Float64}, Vector{Float64}, SparseMatrixCSC{Float64, Int64}, SparseVector{Float64, Int64}}}}}, DelayDiffEq.HistoryFunction{typeof(sir_history), StochasticDelayDiffEq.HistorySDEIntegrator{LambaEM{true}, true, Vector{Float64}, Float64, RODESolution{Float64, 2, Vector{Vector{Float64}}, Nothing, Nothing, Vector{Float64}, NoiseProcess{Float64, 2, Float64, SparseVector{Float64, Int64}, Nothing, Nothing, typeof(DiffEqNoiseProcess.INPLACE_WHITE_NOISE_DIST), typeof(DiffEqNoiseProcess.INPLACE_WHITE_NOISE_BRIDGE), true, ResettableStacks.ResettableStack{Tuple{Float64, SparseVector{Float64, Int64}, Nothing}, true}, ResettableStacks.ResettableStack{Tuple{Float64, SparseVector{Float64, Int64}, Nothing}, true}, RSWM{Float64}, Nothing, RandomNumbers.Xorshifts.Xoroshiro128Plus}, SDDEProblem{Vector{Float64}, Tuple{Float64, Float64}, Tuple{}, Tuple{}, true, Vector{Float64}, Nothing, SDDEFunction{true, typeof(sir_dde!), typeof(sir_delayed_noise!), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing}, typeof(sir_delayed_noise!), typeof(sir_history), Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SparseMatrixCSC{Float64, Int64}}, LambaEM{true}, StochasticDiffEq.LinearInterpolationData{Vector{Vector{Float64}}, Vector{Float64}}, DiffEqBase.DEStats}, StochasticDiffEq.LambaEMCache{Vector{Float64}, Vector{Float64}, SparseMatrixCSC{Float64, Int64}, SparseVector{Float64, Int64}}}}, LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing}, StochasticDelayDiffEq.SDEDiffusionTermWrapper{true, typeof(sir_delayed_noise!), DelayDiffEq.HistoryFunction{typeof(sir_history), StochasticDelayDiffEq.HistorySDEIntegrator{LambaEM{true}, true, Vector{Float64}, Float64, RODESolution{Float64, 2, Vector{Vector{Float64}}, Nothing, Nothing, Vector{Float64}, NoiseProcess{Float64, 2, Float64, SparseVector{Float64, Int64}, Nothing, Nothing, typeof(DiffEqNoiseProcess.INPLACE_WHITE_NOISE_DIST), typeof(DiffEqNoiseProcess.INPLACE_WHITE_NOISE_BRIDGE), true, ResettableStacks.ResettableStack{Tuple{Float64, SparseVector{Float64, Int64}, Nothing}, true}, ResettableStacks.ResettableStack{Tuple{Float64, SparseVector{Float64, Int64}, Nothing}, true}, RSWM{Float64}, Nothing, RandomNumbers.Xorshifts.Xoroshiro128Plus}, SDDEProblem{Vector{Float64}, Tuple{Float64, Float64}, Tuple{}, Tuple{}, true, Vector{Float64}, Nothing, SDDEFunction{true, typeof(sir_dde!), typeof(sir_delayed_noise!), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing}, typeof(sir_delayed_noise!), typeof(sir_history), Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SparseMatrixCSC{Float64, Int64}}, LambaEM{true}, StochasticDiffEq.LinearInterpolationData{Vector{Vector{Float64}}, Vector{Float64}}, DiffEqBase.DEStats}, StochasticDiffEq.LambaEMCache{Vector{Float64}, Vector{Float64}, SparseMatrixCSC{Float64, Int64}, SparseVector{Float64, Int64}}}}}, Nothing, StochasticDiffEq.SDEOptions{Float64, Float64, PIController{Float64}, typeof(DiffEqBase.ODE_DEFAULT_NORM), Nothing, CallbackSet{Tuple{ContinuousCallback{typeof(condition), typeof(affect!), typeof(affect!), typeof(SciMLBase.INITIALIZE_DEFAULT), typeof(SciMLBase.FINALIZE_DEFAULT), Float64, Int64, Rational{Int64}, Nothing, Int64}}, Tuple{}}, typeof(DiffEqBase.ODE_DEFAULT_ISOUTOFDOMAIN), typeof(DiffEqBase.ODE_DEFAULT_PROG_MESSAGE), typeof(DiffEqBase.ODE_DEFAULT_UNSTABLE_CHECK), DataStructures.BinaryMinHeap{Float64}, DataStructures.BinaryMinHeap{Discontinuity{Float64, Rational{Int64}}}, Nothing, Nothing, Int64, Float64, Float64, Float64, Vector{Float64}, Vector{Float64}, Vector{Discontinuity{Float64, Rational{Int64}}}}, Nothing, Float64, Nothing, DelayDiffEq.HistoryFunction{typeof(sir_history), StochasticDelayDiffEq.HistorySDEIntegrator{LambaEM{true}, true, Vector{Float64}, Float64, RODESolution{Float64, 2, Vector{Vector{Float64}}, Nothing, Nothing, Vector{Float64}, NoiseProcess{Float64, 2, Float64, SparseVector{Float64, Int64}, Nothing, Nothing, typeof(DiffEqNoiseProcess.INPLACE_WHITE_NOISE_DIST), typeof(DiffEqNoiseProcess.INPLACE_WHITE_NOISE_BRIDGE), true, ResettableStacks.ResettableStack{Tuple{Float64, SparseVector{Float64, Int64}, Nothing}, true}, ResettableStacks.ResettableStack{Tuple{Float64, SparseVector{Float64, Int64}, Nothing}, true}, RSWM{Float64}, Nothing, RandomNumbers.Xorshifts.Xoroshiro128Plus}, SDDEProblem{Vector{Float64}, Tuple{Float64, Float64}, Tuple{}, Tuple{}, true, Vector{Float64}, Nothing, SDDEFunction{true, typeof(sir_dde!), typeof(sir_delayed_noise!), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing}, typeof(sir_delayed_noise!), typeof(sir_history), Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SparseMatrixCSC{Float64, Int64}}, LambaEM{true}, StochasticDiffEq.LinearInterpolationData{Vector{Vector{Float64}}, Vector{Float64}}, DiffEqBase.DEStats}, StochasticDiffEq.LambaEMCache{Vector{Float64}, Vector{Float64}, SparseMatrixCSC{Float64, Int64}, SparseVector{Float64, Int64}}}}, StochasticDelayDiffEq.HistorySDEIntegrator{LambaEM{true}, true, Vector{Float64}, Float64, RODESolution{Float64, 2, Vector{Vector{Float64}}, Nothing, Nothing, Vector{Float64}, NoiseProcess{Float64, 2, Float64, SparseVector{Float64, Int64}, Nothing, Nothing, typeof(DiffEqNoiseProcess.INPLACE_WHITE_NOISE_DIST), typeof(DiffEqNoiseProcess.INPLACE_WHITE_NOISE_BRIDGE), true, ResettableStacks.ResettableStack{Tuple{Float64, SparseVector{Float64, Int64}, Nothing}, true}, ResettableStacks.ResettableStack{Tuple{Float64, SparseVector{Float64, Int64}, Nothing}, true}, RSWM{Float64}, Nothing, RandomNumbers.Xorshifts.Xoroshiro128Plus}, SDDEProblem{Vector{Float64}, Tuple{Float64, Float64}, Tuple{}, Tuple{}, true, Vector{Float64}, Nothing, SDDEFunction{true, typeof(sir_dde!), typeof(sir_delayed_noise!), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing}, typeof(sir_delayed_noise!), typeof(sir_history), Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SparseMatrixCSC{Float64, Int64}}, LambaEM{true}, StochasticDiffEq.LinearInterpolationData{Vector{Vector{Float64}}, Vector{Float64}}, DiffEqBase.DEStats}, StochasticDiffEq.LambaEMCache{Vector{Float64}, Vector{Float64}, SparseMatrixCSC{Float64, Int64}, SparseVector{Float64, Int64}}}})
    @ StochasticDiffEq ~/.julia/packages/StochasticDiffEq/nKdYj/src/solve.jl:636
  [7] __init(prob::SDDEProblem{Vector{Float64}, Tuple{Float64, Float64}, Tuple{}, Tuple{}, true, Vector{Float64}, Nothing, SDDEFunction{true, typeof(sir_dde!), typeof(sir_delayed_noise!), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing}, typeof(sir_delayed_noise!), typeof(sir_history), Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SparseMatrixCSC{Float64, Int64}}, alg::LambaEM{true}, timeseries_init::Vector{Vector{Float64}}, ts_init::Vector{Float64}, ks_init::Nothing, recompile::Type{Val{true}}; saveat::Vector{Float64}, tstops::Vector{Float64}, d_discontinuities::Vector{Discontinuity{Float64, Rational{Int64}}}, save_idxs::Nothing, save_everystep::Bool, save_noise::Bool, save_on::Bool, save_start::Bool, save_end::Nothing, callback::ContinuousCallback{typeof(condition), typeof(affect!), typeof(affect!), typeof(SciMLBase.INITIALIZE_DEFAULT), typeof(SciMLBase.FINALIZE_DEFAULT), Float64, Int64, Rational{Int64}, Nothing, Int64}, dense::Bool, calck::Bool, dt::Float64, adaptive::Bool, gamma::Rational{Int64}, abstol::Nothing, reltol::Nothing, qmax::Rational{Int64}, qmin::Rational{Int64}, qsteady_min::Int64, qsteady_max::Int64, qoldinit::Rational{Int64}, fullnormalize::Bool, controller::Nothing, failfactor::Int64, beta2::Nothing, beta1::Nothing, delta::Rational{Int64}, maxiters::Int64, dtmax::Float64, dtmin::Float64, internalnorm::typeof(DiffEqBase.ODE_DEFAULT_NORM), isoutofdomain::typeof(DiffEqBase.ODE_DEFAULT_ISOUTOFDOMAIN), unstable_check::typeof(DiffEqBase.ODE_DEFAULT_UNSTABLE_CHECK), verbose::Bool, force_dtmin::Bool, timeseries_errors::Bool, dense_errors::Bool, advance_to_tstop::Bool, stop_at_next_tstop::Bool, initialize_save::Bool, progress::Bool, progress_steps::Int64, progress_name::String, progress_message::typeof(DiffEqBase.ODE_DEFAULT_PROG_MESSAGE), userdata::Nothing, initialize_integrator::Bool, seed::UInt64, alias_u0::Bool, discontinuity_interp_points::Int64, discontinuity_abstol::Float64, discontinuity_reltol::Int64, kwargs::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ StochasticDelayDiffEq ~/.julia/packages/StochasticDelayDiffEq/tnNkg/src/solve.jl:452
  [8] __solve(::SDDEProblem{Vector{Float64}, Tuple{Float64, Float64}, Tuple{}, Tuple{}, true, Vector{Float64}, Nothing, SDDEFunction{true, typeof(sir_dde!), typeof(sir_delayed_noise!), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing}, typeof(sir_delayed_noise!), typeof(sir_history), Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SparseMatrixCSC{Float64, Int64}}, ::LambaEM{true}; kwargs::Base.Iterators.Pairs{Symbol, ContinuousCallback{typeof(condition), typeof(affect!), typeof(affect!), typeof(SciMLBase.INITIALIZE_DEFAULT), typeof(SciMLBase.FINALIZE_DEFAULT), Float64, Int64, Rational{Int64}, Nothing, Int64}, Tuple{Symbol}, NamedTuple{(:callback,), Tuple{ContinuousCallback{typeof(condition), typeof(affect!), typeof(affect!), typeof(SciMLBase.INITIALIZE_DEFAULT), typeof(SciMLBase.FINALIZE_DEFAULT), Float64, Int64, Rational{Int64}, Nothing, Int64}}}})
    @ StochasticDelayDiffEq ~/.julia/packages/StochasticDelayDiffEq/tnNkg/src/solve.jl:4
  [9] #solve_call#37
    @ ~/.julia/packages/DiffEqBase/gWYWc/src/solve.jl:61 [inlined]
 [10] #solve_up#39
    @ ~/.julia/packages/DiffEqBase/gWYWc/src/solve.jl:87 [inlined]
 [11] #solve#38
    @ ~/.julia/packages/DiffEqBase/gWYWc/src/solve.jl:73 [inlined]
 [12] top-level scope
    @ ~/Projects/github/sir-julia/script/sdde/sdde.jl:68
 [13] include(fname::String)
    @ Base.MainInclude ./client.jl:444
 [14] top-level scope
    @ none:1
ChrisRackauckas commented 2 years ago

The fix is in https://github.com/SciML/StochasticDelayDiffEq.jl/pull/49

sdwfrost commented 2 years ago

Thanks, this seems to work, but the following fails (even though the solve above works):

using BenchmarkTools
@benchmark solve(prob_sdde,LambaEM(),callback=cb)
ERROR: set_proposed_dt!: method has not been implemented for the integrator
ChrisRackauckas commented 2 years ago

Fixed in v1.2.1

sdwfrost commented 2 years ago

Thanks! Now to work out why the results are off - I should settle down to zero, as seen in the jump process here.