SciML / DiffEqDevTools.jl

Benchmarking, testing, and development tools for differential equations and scientific machine learning (SciML)
https://benchmarks.sciml.ai/
Other
46 stars 35 forks source link

Throw nice error when running convergence test without analytical solution #98

Closed ranocha closed 1 year ago

ranocha commented 1 year ago

Reported by a colleague who is not on GitHub yet:

using OrdinaryDiffEq, DiffEqDevTools

f_analytic(u0,p,t) = u0*exp(t)
ff = ODEFunction((u, p, t) -> u, analytic=f_analytic)
prob1 = ODEProblem(ff, 1.0, (0.0, 5.0))

prob2 = ODEProblem((u, p, t) -> u, 1.0, (0.0, 5.0))

dts = (1 / 2) .^ (7:-1:4)

sim1 = test_convergence(dts, prob1, DP5()) #fine
sim2 = test_convergence(dts, prob2, DP5()) #error

This yields

julia> sim2 = test_convergence(dts, prob2, DP5()) #error
ERROR: MethodError: no method matching iterate(::Nothing)
Closest candidates are:
  iterate(::Union{LinRange, StepRangeLen}) at range.jl:872
  iterate(::Union{LinRange, StepRangeLen}, ::Integer) at range.jl:872
  iterate(::T) where T<:Union{Base.KeySet{<:Any, <:Dict}, Base.ValueIterator{<:Dict}} at dict.jl:712
  ...
Stacktrace:
 [1] isempty(itr::Nothing)
   @ Base ./essentials.jl:788
 [2] ConvergenceSimulation(solutions::Vector{ODESolution{Float64, 1, Vector{Float64}, Nothing, Nothing, Vector{Float64}, Vector{Vector{Float64}}, ODEProblem{Float64, Tuple{Float64, Float64}, false, SciMLBase.NullParameters, ODEFunction{false, SciMLBase.AutoSpecialize, var"#3#4", LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing}, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, DP5, OrdinaryDiffEq.InterpolationData{ODEFunction{false, SciMLBase.AutoSpecialize, var"#3#4", LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing}, Vector{Float64}, Vector{Float64}, Vector{Vector{Float64}}, OrdinaryDiffEq.DP5ConstantCache{Float64, Float64}}, DiffEqBase.DEStats}}, convergence_axis::Vector{Float64}; auxdata::Dict{Symbol, Vector{Float64}}, additional_errors::Nothing, expected_value::Nothing)
   @ DiffEqDevTools ~/.julia/packages/DiffEqDevTools/sfX7w/src/convergence.jl:17
 [3] test_convergence(dts::Vector{Float64}, prob::ODEProblem{Float64, Tuple{Float64, Float64}, false, SciMLBase.NullParameters, ODEFunction{false, SciMLBase.AutoSpecialize, var"#3#4", LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing}, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, alg::DP5; save_everystep::Bool, adaptive::Bool, kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
   @ DiffEqDevTools ~/.julia/packages/DiffEqDevTools/sfX7w/src/convergence.jl:207
 [4] test_convergence(dts::Vector{Float64}, prob::ODEProblem{Float64, Tuple{Float64, Float64}, false, SciMLBase.NullParameters, ODEFunction{false, SciMLBase.AutoSpecialize, var"#3#4", LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing}, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, alg::DP5)
   @ DiffEqDevTools ~/.julia/packages/DiffEqDevTools/sfX7w/src/convergence.jl:200
 [5] top-level scope
   @ REPL[10]:1

It would be nice to throw a good error message in this case.