SciML / StochasticDelayDiffEq.jl

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

saveat causes incorrect evaluation of the history function #52

Open Jamesafross opened 2 years ago

Jamesafross commented 2 years ago

using the saveat feature seems to cause incorrect evaluation of history function.

The code:

using StochasticDelayDiffEq

function f(du,u,h,p,t) 
     du[1] = -u[1]
     println(h(p, t-0.001))
 end

 function g(du,u,h,p,t)
     du[1] = 0.1
 end

 tspan = (0.0,0.1)
 h(p, t) = 0.0
 u0 = [0.0]
 prob = SDDEProblem(f,g, u0,h,tspan, 0.0,constant_lags=[0.001])
 alg = EM()

 sol = solve(prob,alg,dt=0.01);

 sol = solve(prob,alg,dt=0.01,saveat=0.1);

println output of evaluation of history function for a realisation without saveat

0
[0.0]
[0.0014037592652750368]
[0.0009688081360439431]
[0.00614797237584531]
[0.0035864500205580593]
[0.001500811510678003]

println output of evaluation of history function for a realisation with saveat

 0
[0.0]
[0.0]
[0.0]
[0.0]
[0.0]
[0.0]

Tried other SDE algorithms and the same problem occurs.

Julia Version 1.7.2

ChrisRackauckas commented 2 years ago

It's probably https://github.com/SciML/ModelingToolkit.jl/pull/1490/files#diff-47c27891e951c8cd946b850dc2df31082624afdf57446c21cb6992f5f4b74aa2R475. I don't think that method was made safe for symbolic arrays @ValentinKaisermayer

ValentinKaisermayer commented 2 years ago

Maybe I have, but I don't think that is the problem here. This doesn't even have ModelingToolkit.jl as a dependency.

ChrisRackauckas commented 2 years ago

😅 posted on the wrong issue.