SciML / OrdinaryDiffEq.jl

High performance ordinary differential equation (ODE) and differential-algebraic equation (DAE) solvers, including neural ordinary differential equations (neural ODEs) and scientific machine learning (SciML)
https://diffeq.sciml.ai/latest/
Other
556 stars 210 forks source link

StackoverflowError for pendulum example #1011

Closed jstrube closed 4 years ago

jstrube commented 4 years ago

Setup:

julia> versioninfo()
Julia Version 1.3.1
Commit 2d5741174c (2019-12-30 21:36 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin18.6.0)
  CPU: Intel(R) Core(TM) i5-6267U CPU @ 2.90GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.1 (ORCJIT, skylake)
(v1.3) pkg> st
    Status `~/.julia/environments/v1.3/Project.toml`
  [12aac903] BinaryBuilder v0.2.2
  [2445eb08] DataDrivenDiffEq v0.1.1 #master (https://github.com/JuliaDiffEq/DataDrivenDiffEq.jl.git)
  [aae7a2af] DiffEqFlux v1.1.0
  [0c46a032] DifferentialEquations v6.10.1 #master (https://github.com/JuliaDiffEq/DifferentialEquations.jl.git)
  [587475ba] Flux v0.10.1
  [961ee093] ModelingToolkit v1.1.3
  [1dea7af3] OrdinaryDiffEq v5.27.1 #master (https://github.com/JuliaDiffEq/OrdinaryDiffEq.jl.git)
  [91a5bcdd] Plots v0.28.4
  [f3b207a7] StatsPlots v0.13.0

How to reproduce:

using OrdinaryDiffEq
# Create a test problem
function pendulum(u, p, t)
   x = u[2]
   y = -9.81sin(u[1]) - 0.1u[2]
   return [x;y]
end
u0 = [0.2π; -1.0]
tspan = (0.0, 40.0)
prob = ODEProblem(pendulum, u0, tspan)
sol = solve(prob)

Result:

ERROR: StackOverflowError:
Stacktrace:
 [1] (::DiffEqBase.var"#kw##__solve")(::NamedTuple{(:default_set,),Tuple{Bool}}, ::typeof(DiffEqBase.__solve), ::ODEProblem{Array{Float64,1},Tuple{Float64,Float64},false,DiffEqBase.NullParameters,ODEFunction{false,typeof(pendulum),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}},DiffEqBase.StandardODEProblem}, ::Nothing, ::Nothing, ::Nothing, ::Vararg{Nothing,N} where N) at ./none:0
 [2] #__solve#447(::Bool, ::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::typeof(DiffEqBase.__solve), ::ODEProblem{Array{Float64,1},Tuple{Float64,Float64},false,DiffEqBase.NullParameters,ODEFunction{false,typeof(pendulum),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}},DiffEqBase.StandardODEProblem}, ::Nothing, ::Vararg{Nothing,N} where N) at /Users/jstrube/.julia/packages/DiffEqBase/syO0w/src/solve.jl:177
 ... (the last 2 lines are repeated 2498 more times)
 [4999] __solve(::ODEProblem{Array{Float64,1},Tuple{Float64,Float64},false,DiffEqBase.NullParameters,ODEFunction{false,typeof(pendulum),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}},DiffEqBase.StandardODEProblem}) at /Users/jstrube/.julia/packages/DiffEqBase/syO0w/src/solve.jl:174
 [5000] #solve_call#442(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::typeof(DiffEqBase.solve_call), ::ODEProblem{Array{Float64,1},Tuple{Float64,Float64},false,DiffEqBase.NullParameters,ODEFunction{false,typeof(pendulum),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}},DiffEqBase.StandardODEProblem}) at /Users/jstrube/.julia/packages/DiffEqBase/syO0w/src/solve.jl:0
 [5001] solve_call(::ODEProblem{Array{Float64,1},Tuple{Float64,Float64},false,DiffEqBase.NullParameters,ODEFunction{false,typeof(pendulum),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}},DiffEqBase.StandardODEProblem}) at /Users/jstrube/.julia/packages/DiffEqBase/syO0w/src/solve.jl:37
 [5002] #solve#443(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::typeof(solve), ::ODEProblem{Array{Float64,1},Tuple{Float64,Float64},false,DiffEqBase.NullParameters,ODEFunction{false,typeof(pendulum),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}},DiffEqBase.StandardODEProblem}) at /Users/jstrube/.julia/packages/DiffEqBase/syO0w/src/solve.jl:61
 [5003] solve(::ODEProblem{Array{Float64,1},Tuple{Float64,Float64},false,DiffEqBase.NullParameters,ODEFunction{false,typeof(pendulum),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}},DiffEqBase.StandardODEProblem}) at /Users/jstrube/.julia/packages/DiffEqBase/syO0w/src/solve.jl:45

I've tried this on a linux system, and there the solve step just gets stuck and doesn't return, and the CPU doesn't do anything.

ChrisRackauckas commented 4 years ago

You didn't import DifferentialEquations.jl so default algorithms won't work. Now it throws a better error message:

Default algorithm choices require DifferentialEquations.jl. Please specify an algorithm or import DifferentialEquations directly.
error(::String) at error.jl:33
#__solve#447(::Bool, ::Bool, ::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::typeof(DiffEqBase.__solve), ::ODEProblem{Array{Float64,1},Tuple{Float64,Float64},false,DiffEqBase.NullParameters,ODEFunction{false,typeof(pendulum),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}},DiffEqBase.StandardODEProblem}, ::Nothing) at solve.jl:175
(::DiffEqBase.var"#kw##__solve")(::NamedTuple{(:default_set, :second_time),Tuple{Bool,Bool}}, ::typeof(DiffEqBase.__solve), ::ODEProblem{Array{Float64,1},Tuple{Float64,Float64},false,DiffEqBase.NullParameters,ODEFunction{false,typeof(pendulum),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}},DiffEqBase.StandardODEProblem}, ::Nothing) at none:0
#__solve#447(::Bool, ::Bool, ::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::typeof(DiffEqBase.__solve), ::ODEProblem{Array{Float64,1},Tuple{Float64,Float64},false,DiffEqBase.NullParameters,ODEFunction{false,typeof(pendulum),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}},DiffEqBase.StandardODEProblem}) at solve.jl:179
__solve(::ODEProblem{Array{Float64,1},Tuple{Float64,Float64},false,DiffEqBase.NullParameters,ODEFunction{false,typeof(pendulum),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}},DiffEqBase.StandardODEProblem}) at solve.jl:174
#solve_call#442(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::typeof(DiffEqBase.solve_call), ::ODEProblem{Array{Float64,1},Tuple{Float64,Float64},false,DiffEqBase.NullParameters,ODEFunction{false,typeof(pendulum),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}},DiffEqBase.StandardODEProblem}) at solve.jl:0
solve_call(::ODEProblem{Array{Float64,1},Tuple{Float64,Float64},false,DiffEqBase.NullParameters,ODEFunction{false,typeof(pendulum),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}},DiffEqBase.StandardODEProblem}) at solve.jl:37
#solve#443(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::typeof(solve), ::ODEProblem{Array{Float64,1},Tuple{Float64,Float64},false,DiffEqBase.NullParameters,ODEFunction{false,typeof(pendulum),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}},DiffEqBase.StandardODEProblem}) at solve.jl:61
solve(::ODEProblem{Array{Float64,1},Tuple{Float64,Float64},false,DiffEqBase.NullParameters,ODEFunction{false,typeof(pendulum),LinearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}},DiffEqBase.StandardODEProblem}) at solve.jl:45
top-level scope at test.jl:11