Skip to content

Cannot call to_index(::RaggedEnd) #508

Description

@vyudu

Describe the bug 🐞

This threw for me when trying to symbolically index a solution using sol[:x, end] which used to work. sol[:x][end] does work, but I wanted to flag this in case.

Expected behavior

Should return the last value instead of erroring.

Minimal Reproducible Example 👇

using ModelingToolkit: t_nounits as t, D_nounits as D
using OrdinaryDiffEqTsit5
@variables x(t)
@named sys = System([D(x) ~ 1], t)
prob = ODEProblem(complete(sys), [x => 1], (0, 1))
sol = solve(prob, Tsit5())
sol[x, end]

Error & Stacktrace ⚠️

ERROR: ArgumentError: invalid index: RaggedEnd(0, 2) of type RaggedEnd
Stacktrace:
  [1] to_index(i::RaggedEnd)
    @ Base ./indices.jl:315
  [2] to_index(A::Vector{Vector{Float64}}, i::RaggedEnd)
    @ Base ./indices.jl:292
  [3] to_indices
    @ ./indices.jl:368 [inlined]
  [4] to_indices
    @ ./indices.jl:360 [inlined]
  [5] getindex
    @ ./abstractarray.jl:1342 [inlined]
  [6] state_values(sol::ODESolution{…}, i::RaggedEnd)
    @ SciMLBase ~/.julia/packages/SciMLBase/hHrRi/src/solutions/solution_interface.jl:83
  [7] (::SymbolicIndexingInterface.GetStateIndex{…})(::SymbolicIndexingInterface.Timeseries, prob::ODESolution{…}, i::RaggedEnd)
    @ SymbolicIndexingInterface ~/.julia/packages/SymbolicIndexingInterface/D9aQf/src/state_indexing.jl:44
  [8] (::SymbolicIndexingInterface.GetStateIndex{…})(prob::ODESolution{…}, i::RaggedEnd)
    @ SymbolicIndexingInterface ~/.julia/packages/SymbolicIndexingInterface/D9aQf/src/value_provider_interface.jl:167
  [9] _getindex
    @ ~/.julia/packages/RecursiveArrayTools/cqMRn/src/vector_of_array.jl:476 [inlined]
 [10] getindex(A::ODESolution{…}, _arg::Symbol, args::RaggedEnd)
    @ RecursiveArrayTools ~/.julia/packages/RecursiveArrayTools/2UpjF/src/vector_of_array.jl:750
 [11] top-level scope
    @ REPL[39]:1

Additional context

Add any other context about the problem here.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions