ArrayInterface.jl icon indicating copy to clipboard operation
ArrayInterface.jl copied to clipboard

StackOverflowError in DifferentialEquations

Open ederag opened this issue 4 years ago • 5 comments

https://github.com/JuliaArrays/ArrayInterface.jl/pull/144 did fix #142 here as well, but did not help with https://github.com/SciML/DifferentialEquations.jl/issues/740. Is this relevant to this package ?

(try_array_interface) pkg> status ArrayInterface
      Status `~/share/prog/julia/dev/try_array_interface/Project.toml`
  [4fba245c] ArrayInterface v3.1.8 `https://github.com/JuliaArrays/ArrayInterface.jl.git#18aa87e`

Here is the new error message (still with julia-1.6.0) (small change: "repeats 20127 times" instead of the previous 20123):

ERROR: StackOverflowError:
Stacktrace:
 [1] show(io::IOBuffer, x::Type)
   @ Base ./show.jl:814
 [2] print(io::IOBuffer, x::Type)
   @ Base ./strings/io.jl:35
 [3] print_to_string(xs::Type)
   @ Base ./strings/io.jl:135
 [4] string
   @ ./strings/io.jl:174 [inlined]
 [5] Symbol
   @ ./strings/basic.jl:229 [inlined]
 [6] issymbollike(x::Vector{Union{Nothing, Int64}})
   @ SciMLBase ~/.julia/packages/SciMLBase/9EjAY/src/solutions/solution_interface.jl:294
 [7] getindex(A::ODESolution{Float64, 1, Vector{Float64}, Nothing, Nothing, Vector{Float64}, Vector{Vector{Float64}}, ODEProblem{Float64, Tuple{Float64, Float64}, false, SciMLBase.NullParameters, ODEFunction{false, typeof(f), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, Tsit5, OrdinaryDiffEq.InterpolationData{ODEFunction{false, typeof(f), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, Vector{Float64}, Vector{Float64}, Vector{Vector{Float64}}, OrdinaryDiffEq.Tsit5ConstantCache{Float64, Float64}}, DiffEqBase.DEStats}, sym::Vector{Union{Nothing, Int64}}, args::Function)
   @ SciMLBase ~/.julia/packages/SciMLBase/9EjAY/src/solutions/solution_interface.jl:56
 [8] getindex(A::ODESolution{Float64, 1, Vector{Float64}, Nothing, Nothing, Vector{Float64}, Vector{Vector{Float64}}, ODEProblem{Float64, Tuple{Float64, Float64}, false, SciMLBase.NullParameters, ODEFunction{false, typeof(f), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, Tsit5, OrdinaryDiffEq.InterpolationData{ODEFunction{false, typeof(f), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, Vector{Float64}, Vector{Float64}, Vector{Vector{Float64}}, OrdinaryDiffEq.Tsit5ConstantCache{Float64, Float64}}, DiffEqBase.DEStats}, sym::Vector{Union{Nothing, Int64}}, args::Function) (repeats 20127 times)
   @ SciMLBase ~/.julia/packages/SciMLBase/9EjAY/src/solutions/solution_interface.jl:69
 [9] top-level scope
   @ REPL[10]:1

Edit With Julia-1.6.1 and the same project

(try_array_interface) pkg> status ArrayInterface
      Status `~/share/prog/julia/dev/try_array_interface/Project.toml`
  [4fba245c] ArrayInterface v3.1.8 `https://github.com/JuliaArrays/ArrayInterface.jl.git#18aa87e`

almost the same error, except back to "repeats 20123 times":

ERROR: StackOverflowError:
Stacktrace:
 [1] show(io::IOBuffer, x::Type)
   @ Base ./show.jl:814
 [2] print(io::IOBuffer, x::Type)
   @ Base ./strings/io.jl:35
 [3] print_to_string(xs::Type)
   @ Base ./strings/io.jl:135
 [4] string
   @ ./strings/io.jl:174 [inlined]
 [5] Symbol
   @ ./strings/basic.jl:229 [inlined]
 [6] issymbollike(x::Vector{Union{Nothing, Int64}})
   @ SciMLBase ~/.julia/packages/SciMLBase/9EjAY/src/solutions/solution_interface.jl:294
 [7] getindex(A::ODESolution{Float64, 1, Vector{Float64}, Nothing, Nothing, Vector{Float64}, Vector{Vector{Float64}}, ODEProblem{Float64, Tuple{Float64, Float64}, false, SciMLBase.NullParameters, ODEFunction{false, typeof(f), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, Tsit5, OrdinaryDiffEq.InterpolationData{ODEFunction{false, typeof(f), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, Vector{Float64}, Vector{Float64}, Vector{Vector{Float64}}, OrdinaryDiffEq.Tsit5ConstantCache{Float64, Float64}}, DiffEqBase.DEStats}, sym::Vector{Union{Nothing, Int64}}, args::Function)
   @ SciMLBase ~/.julia/packages/SciMLBase/9EjAY/src/solutions/solution_interface.jl:56
 [8] getindex(A::ODESolution{Float64, 1, Vector{Float64}, Nothing, Nothing, Vector{Float64}, Vector{Vector{Float64}}, ODEProblem{Float64, Tuple{Float64, Float64}, false, SciMLBase.NullParameters, ODEFunction{false, typeof(f), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem}, Tsit5, OrdinaryDiffEq.InterpolationData{ODEFunction{false, typeof(f), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, Vector{Float64}, Vector{Float64}, Vector{Vector{Float64}}, OrdinaryDiffEq.Tsit5ConstantCache{Float64, Float64}}, DiffEqBase.DEStats}, sym::Vector{Union{Nothing, Int64}}, args::Function) (repeats 20123 times)
   @ SciMLBase ~/.julia/packages/SciMLBase/9EjAY/src/solutions/solution_interface.jl:69
 [9] top-level scope
   @ REPL[10]:1

ederag avatar Apr 27 '21 20:04 ederag

What is the reproducer?

ChrisRackauckas avatar May 05 '21 12:05 ChrisRackauckas

The same as https://github.com/SciML/DifferentialEquations.jl/issues/740:

using DifferentialEquations
f(u,p,t) = 1.01*u
u0 = 1/2
tspan = (0.0,1.0)
prob = ODEProblem(f,u0,tspan)
sol = solve(prob, Tsit5(), reltol=1e-8, abstol=1e-8)

idxs = Union{Nothing, Int64}[1, 2]
sol[idxs, :]

ederag avatar May 05 '21 12:05 ederag

That example doesn't make much sense. Isn't it on the user to do _idxs = convert(Vector{Int},x)? I mean, what is a nothing index supposed to do anyways?

ChrisRackauckas avatar May 05 '21 12:05 ChrisRackauckas

As stated in SciML/DifferentialEquations.jl#740, this is a contrived minimal example, it actually happened

when the output of indexin is used to index the solution.

indexin(interesting_z, saved_z) was used to get the indexes of interesting points, and use these indexes to extract a subset of sol. But indexin return type is Union{Nothing, Int64}, nothing meaning "no match". [the saved_z construction started with a concatenation of several arrays of z, among which interesting_z, so in my case a match was guaranteed, no nothing at all, but the type is still Union{Nothing, Int64}]

ederag avatar May 05 '21 13:05 ederag

I'm not sure why this would be related to anything here, but I also didn't understand why #142 was either. Even if we find a line in ArrayIinterface.jl that is somehow related, I think we should figure out what is actually going on before making more changes, because that means we are missing a larger issue here.

Tokazama avatar May 05 '21 16:05 Tokazama