SciML / SciMLBase.jl

The Base interface of the SciML ecosystem
https://docs.sciml.ai/SciMLBase/stable
MIT License
118 stars 91 forks source link

only bail out as instable when dt is small or error is somewhat controlled #692

Closed oscardssmith closed 1 month ago

oscardssmith commented 1 month ago

Previously, we would run the instability check no matter how badly the integrator had controlled the error. This caused issues, especially for the first timestep where the dt chosen was fairly arbitrary. We could end up in a situation very easily where the first timestep was big enough that the step would result in incredibly large (or NaN) u values. This step would get rejected, but because the values were incorrectly really big, we would get killed by instability detection. This is silly because just shrinking the dt would have made it stable, but we didn't get a chance to do so.

function rober(du, u, p, t)
    y₁, y₂, y₃ = u
    k₁, k₂, k₃ = p
    du .= [-k₁ * y₁ + k₃ * y₂ * y₃,
    k₁ * y₁ - k₃ * y₂ * y₃ - k₂ * y₂^2,
    k₂ * y₂^2]
end
prob = ODEProblem(rober, [1.0,0.0,0.0],(0.0,1e5),(0.04,3e7,1e4))
solve(prob, Rodas5P()) #fails
solve(prob, Rodas5P(), dt=1e-3) #works

With this PR, we will only do the instability check in the first place if we either roughly have the error controlled or the dt is already pretty small.

codecov[bot] commented 1 month ago

Codecov Report

Attention: Patch coverage is 0% with 5 lines in your changes are missing coverage. Please review.

Project coverage is 41.40%. Comparing base (541e7fd) to head (ccf79ed).

Files Patch % Lines
src/integrator_interface.jl 0.00% 5 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #692 +/- ## ========================================== - Coverage 41.42% 41.40% -0.02% ========================================== Files 55 55 Lines 4555 4557 +2 ========================================== Hits 1887 1887 - Misses 2668 2670 +2 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.