Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug with infinite timespan in SDEProblem #426

Open
eviatarbach opened this issue Jul 22, 2021 · 3 comments
Open

Bug with infinite timespan in SDEProblem #426

eviatarbach opened this issue Jul 22, 2021 · 3 comments

Comments

@eviatarbach
Copy link

With ODEProblem, the timespan can be set to be infinite, and this is useful for the iterator interface. For example, this feature is used in DynamicalSystemsBase.jl for creating a tangent integrator. However, doing this with SDEProblem results in the simulation time being set to Inf after one time step.

Example:

f(u, p, t) = [1.0]
p = SDEProblem(f, f, [1.0], (0.0, Inf))
i = init(p, EM(); dt=.02)

Then, running step!(i) results in i.t becoming Inf.

@ChrisRackauckas
Copy link
Member

On Julia v1.6 with StochasticDiffEq v6.35? I cannot reproduce.

@eviatarbach
Copy link
Author

eviatarbach commented Jul 27, 2021

Thank you for looking into this!

Yes, this is on Julia 1.6.2 with StochasticDiffEq v6.35.0. Weird that it doesn't do the same on your end. I'm pretty sure it's due to this line

@fastmath abs(ttmp - tstop) < 100eps(max(integrator.t,tstop)) ? (integrator.t = tstop) : (integrator.t = ttmp)

in integrator_utils.jl. When tstop is Inf, 100eps(max(integrator.t,tstop)) evaluates to NaN, and since a comparison with NaN is false, it should take the integrator.t = ttmp branch. But since @fastmath isn't supposed to deal with NaNs it gives an unexpected result on my end:

julia> t = 0.0; ttmp = 0.02; tstop = Inf;

julia> abs(ttmp - tstop) < 100eps(max(t,tstop)) ? tstop : ttmp
0.02

julia> @fastmath abs(ttmp - tstop) < 100eps(max(t,tstop)) ? tstop : ttmp
Inf

Maybe it would make sense to add an explicit check for isinf(tstop)?

@ChrisRackauckas
Copy link
Member

odd, your test case gives Inf for me. But yes, try adding an isinf for safety.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants