SciML / StochasticDelayDiffEq.jl

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

SDDE fails if ran on the command line. #66

Closed dirmeier closed 1 year ago

dirmeier commented 1 year ago

Hello,

thank you for developing this package. If I run the SDDE below, it works fine in a REPL session, but it fails if I call it on the command line as julia sdde_problem.jl. Apologies if I am making a stupid mistake, but I cannot seem to fix it. Running this throws the error below. Any ideas what the issue is?

Thanks in advance, Simon

ERROR: LoadError: UndefVarError: ReturnCode not defined
Stacktrace:
 [1] solve!(integrator::StochasticDelayDiffEq.SDDEIntegrator{EM{true}, true, Vector{Float64}, Float64, Float64, Vector{Float64}, Float64, Float64, Float64, NoiseProcess{Float64, 2, Float64, Vector{Float64}, Nothing, Nothing, typeof(DiffEqNoiseProcess.INPLACE_WHITE_NOISE_DIST), typeof(DiffEqNoiseProcess.INPLACE_WHITE_NOISE_BRIDGE), true, ResettableStacks.ResettableStack{Tuple{Float64, Vector{Float64}, Nothing}, true}, ResettableStacks.ResettableStack{Tuple{Float64, Vector{Float64}, 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, Vector{Float64}, Nothing, Nothing, typeof(DiffEqNoiseProcess.INPLACE_WHITE_NOISE_DIST), typeof(DiffEqNoiseProcess.INPLACE_WHITE_NOISE_BRIDGE), true, ResettableStacks.ResettableStack{Tuple{Float64, Vector{Float64}, Nothing}, true}, ResettableStacks.ResettableStack{Tuple{Float64, Vector{Float64}, Nothing}, true}, RSWM{Float64}, Nothing, RandomNumbers.Xorshifts.Xoroshiro128Plus}, SDDEProblem{Vector{Float64}, Tuple{Float64, Float64}, Tuple{Float64}, Tuple{}, true, Vector{Float64}, Nothing, SDDEFunction{true, SciMLBase.FullSpecialize, var"#f#2"{Tuple{Float64}}, var"#g#3", LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing}, var"#g#3", var"#h#1", Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, Nothing}, EM{true}, StochasticDiffEq.LinearInterpolationData{Vector{Vector{Float64}}, Vector{Float64}}, DiffEqBase.DEStats}, StochasticDiffEq.EMCache{Vector{Float64}, Vector{Float64}, Vector{Float64}}, StochasticDelayDiffEq.SDEFunctionWrapper{true, var"#f#2"{Tuple{Float64}}, StochasticDelayDiffEq.SDEDiffusionTermWrapper{true, var"#g#3", DelayDiffEq.HistoryFunction{var"#h#1", StochasticDelayDiffEq.HistorySDEIntegrator{EM{true}, true, Vector{Float64}, Float64, RODESolution{Float64, 2, Vector{Vector{Float64}}, Nothing, Nothing, Vector{Float64}, NoiseProcess{Float64, 2, Float64, Vector{Float64}, Nothing, Nothing, typeof(DiffEqNoiseProcess.INPLACE_WHITE_NOISE_DIST), typeof(DiffEqNoiseProcess.INPLACE_WHITE_NOISE_BRIDGE), true, ResettableStacks.ResettableStack{Tuple{Float64, Vector{Float64}, Nothing}, true}, ResettableStacks.ResettableStack{Tuple{Float64, Vector{Float64}, Nothing}, true}, RSWM{Float64}, Nothing, RandomNumbers.Xorshifts.Xoroshiro128Plus}, SDDEProblem{Vector{Float64}, Tuple{Float64, Float64}, Tuple{Float64}, Tuple{}, true, Vector{Float64}, Nothing, SDDEFunction{true, SciMLBase.FullSpecialize, var"#f#2"{Tuple{Float64}}, var"#g#3", LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing}, var"#g#3", var"#h#1", Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, Nothing}, EM{true}, StochasticDiffEq.LinearInterpolationData{Vector{Vector{Float64}}, Vector{Float64}}, DiffEqBase.DEStats}, StochasticDiffEq.EMCache{Vector{Float64}, Vector{Float64}, Vector{Float64}}}}}, DelayDiffEq.HistoryFunction{var"#h#1", StochasticDelayDiffEq.HistorySDEIntegrator{EM{true}, true, Vector{Float64}, Float64, RODESolution{Float64, 2, Vector{Vector{Float64}}, Nothing, Nothing, Vector{Float64}, NoiseProcess{Float64, 2, Float64, Vector{Float64}, Nothing, Nothing, typeof(DiffEqNoiseProcess.INPLACE_WHITE_NOISE_DIST), typeof(DiffEqNoiseProcess.INPLACE_WHITE_NOISE_BRIDGE), true, ResettableStacks.ResettableStack{Tuple{Float64, Vector{Float64}, Nothing}, true}, ResettableStacks.ResettableStack{Tuple{Float64, Vector{Float64}, Nothing}, true}, RSWM{Float64}, Nothing, RandomNumbers.Xorshifts.Xoroshiro128Plus}, SDDEProblem{Vector{Float64}, Tuple{Float64, Float64}, Tuple{Float64}, Tuple{}, true, Vector{Float64}, Nothing, SDDEFunction{true, SciMLBase.FullSpecialize, var"#f#2"{Tuple{Float64}}, var"#g#3", LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing}, var"#g#3", var"#h#1", Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, Nothing}, EM{true}, StochasticDiffEq.LinearInterpolationData{Vector{Vector{Float64}}, Vector{Float64}}, DiffEqBase.DEStats}, StochasticDiffEq.EMCache{Vector{Float64}, Vector{Float64}, Vector{Float64}}}}, LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing}, StochasticDelayDiffEq.SDEDiffusionTermWrapper{true, var"#g#3", DelayDiffEq.HistoryFunction{var"#h#1", StochasticDelayDiffEq.HistorySDEIntegrator{EM{true}, true, Vector{Float64}, Float64, RODESolution{Float64, 2, Vector{Vector{Float64}}, Nothing, Nothing, Vector{Float64}, NoiseProcess{Float64, 2, Float64, Vector{Float64}, Nothing, Nothing, typeof(DiffEqNoiseProcess.INPLACE_WHITE_NOISE_DIST), typeof(DiffEqNoiseProcess.INPLACE_WHITE_NOISE_BRIDGE), true, ResettableStacks.ResettableStack{Tuple{Float64, Vector{Float64}, Nothing}, true}, ResettableStacks.ResettableStack{Tuple{Float64, Vector{Float64}, Nothing}, true}, RSWM{Float64}, Nothing, RandomNumbers.Xorshifts.Xoroshiro128Plus}, SDDEProblem{Vector{Float64}, Tuple{Float64, Float64}, Tuple{Float64}, Tuple{}, true, Vector{Float64}, Nothing, SDDEFunction{true, SciMLBase.FullSpecialize, var"#f#2"{Tuple{Float64}}, var"#g#3", LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing}, var"#g#3", var"#h#1", Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, Nothing}, EM{true}, StochasticDiffEq.LinearInterpolationData{Vector{Vector{Float64}}, Vector{Float64}}, DiffEqBase.DEStats}, StochasticDiffEq.EMCache{Vector{Float64}, Vector{Float64}, Vector{Float64}}}}}, Nothing, StochasticDiffEq.SDEOptions{Float64, Float64, PIController{Float64}, typeof(DiffEqBase.ODE_DEFAULT_NORM), Nothing, CallbackSet{Tuple{}, 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}, Float64, Vector{Discontinuity{Float64, Rational{Int64}}}}, Nothing, Float64, Nothing, DelayDiffEq.HistoryFunction{var"#h#1", StochasticDelayDiffEq.HistorySDEIntegrator{EM{true}, true, Vector{Float64}, Float64, RODESolution{Float64, 2, Vector{Vector{Float64}}, Nothing, Nothing, Vector{Float64}, NoiseProcess{Float64, 2, Float64, Vector{Float64}, Nothing, Nothing, typeof(DiffEqNoiseProcess.INPLACE_WHITE_NOISE_DIST), typeof(DiffEqNoiseProcess.INPLACE_WHITE_NOISE_BRIDGE), true, ResettableStacks.ResettableStack{Tuple{Float64, Vector{Float64}, Nothing}, true}, ResettableStacks.ResettableStack{Tuple{Float64, Vector{Float64}, Nothing}, true}, RSWM{Float64}, Nothing, RandomNumbers.Xorshifts.Xoroshiro128Plus}, SDDEProblem{Vector{Float64}, Tuple{Float64, Float64}, Tuple{Float64}, Tuple{}, true, Vector{Float64}, Nothing, SDDEFunction{true, SciMLBase.FullSpecialize, var"#f#2"{Tuple{Float64}}, var"#g#3", LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing}, var"#g#3", var"#h#1", Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, Nothing}, EM{true}, StochasticDiffEq.LinearInterpolationData{Vector{Vector{Float64}}, Vector{Float64}}, DiffEqBase.DEStats}, StochasticDiffEq.EMCache{Vector{Float64}, Vector{Float64}, Vector{Float64}}}}, StochasticDelayDiffEq.HistorySDEIntegrator{EM{true}, true, Vector{Float64}, Float64, RODESolution{Float64, 2, Vector{Vector{Float64}}, Nothing, Nothing, Vector{Float64}, NoiseProcess{Float64, 2, Float64, Vector{Float64}, Nothing, Nothing, typeof(DiffEqNoiseProcess.INPLACE_WHITE_NOISE_DIST), typeof(DiffEqNoiseProcess.INPLACE_WHITE_NOISE_BRIDGE), true, ResettableStacks.ResettableStack{Tuple{Float64, Vector{Float64}, Nothing}, true}, ResettableStacks.ResettableStack{Tuple{Float64, Vector{Float64}, Nothing}, true}, RSWM{Float64}, Nothing, RandomNumbers.Xorshifts.Xoroshiro128Plus}, SDDEProblem{Vector{Float64}, Tuple{Float64, Float64}, Tuple{Float64}, Tuple{}, true, Vector{Float64}, Nothing, SDDEFunction{true, SciMLBase.FullSpecialize, var"#f#2"{Tuple{Float64}}, var"#g#3", LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing}, var"#g#3", var"#h#1", Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, Nothing}, EM{true}, StochasticDiffEq.LinearInterpolationData{Vector{Vector{Float64}}, Vector{Float64}}, DiffEqBase.DEStats}, StochasticDiffEq.EMCache{Vector{Float64}, Vector{Float64}, Vector{Float64}}}})
   @ StochasticDelayDiffEq ~/.julia/packages/StochasticDelayDiffEq/TCknU/src/solve.jl:513
 [2] __solve(::SDDEProblem{Vector{Float64}, Tuple{Float64, Float64}, Tuple{Float64}, Tuple{}, true, Vector{Float64}, Nothing, SDDEFunction{true, SciMLBase.FullSpecialize, var"#f#2"{Tuple{Float64}}, var"#g#3", LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing}, var"#g#3", var"#h#1", Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, Nothing}, ::EM{true}; kwargs::Base.Pairs{Symbol, Real, Tuple{Symbol, Symbol, Symbol}, NamedTuple{(:dt, :saveat, :seed), Tuple{Int64, Float64, Int64}}})
   @ StochasticDelayDiffEq ~/.julia/packages/StochasticDelayDiffEq/TCknU/src/solve.jl:5
 [3] #solve_call#39
   @ ~/.julia/packages/DiffEqBase/S7V8q/src/solve.jl:221 [inlined]
 [4] #solve_up#41
   @ ~/.julia/packages/DiffEqBase/S7V8q/src/solve.jl:248 [inlined]
 [5] #solve#40
   @ ~/.julia/packages/DiffEqBase/S7V8q/src/solve.jl:234 [inlined]
 [6] b_field(params::Vector{Float64}, Tobs::Int64, rng::Int64)

sdde_problem:

using DifferentialEquations
using StochasticDelayDiffEq 
using SpecialFunctions
using ForwardDiff

f_tilde(x, Bmin, Bmax) = x/4 * (1 + erf(x^2 - Bmin^2)) * (1 - erf(x^2 - Bmax^2))

function b_field(params::Vector{Float64}, Tobs::Int64, rng::Int64)
    τ, T, Nd, sigma, Bmin, Bmax = params
    lags = (params[2], )
    h(p, t) = [Bmax, 0.]

    function f(du, u, h, p, t)
        τ, T, Nd, sigma, Bmin, Bmax = p
        hist = h(p, t-lags[1])[1]       
        du[1] = u[2]
        du[2] = -u[1]/τ^2-2*u[2]/τ-Nd/τ^2*f_tilde(hist, Bmin, Bmax)
    end

    function g(du, u, h, p, t)     # Diffusion function
        τ, T, Nd, sigma, Bmin, Bmax = p
        du[1] = 0
        du[2] = Bmax*sigma / (τ^(3/2))
    end

    tspan = (0.0, Tobs) 
    prob = SDDEProblem(f, g, [Bmax, 0.], h, tspan, params; constant_lags = lags)
    ret = solve(prob, EM(), dt=1, saveat=1.0, seed = rng)
end

params = [42.0,36.0,2,0.1,1.0,7.0]
Tobs=10
seed=12

ret = b_field(params, Tobs, seed)
print(ret)
dirmeier commented 1 year ago

Updating to Julia 1.8.5 fixed it. Sorry for the noise.