Skip to content

indexing with symbols fails for discrete parameters #3978

@vyudu

Description

@vyudu

Describe the bug 🐞

Indexing with symbols (i.e. sol[:p] or sol.ps[:p]) throws an error.

Expected behavior

Should return / have the same behavior as sol[p].

Minimal Reproducible Example 👇

t = ModelingToolkit.t_nounits; D = ModelingToolkit.D_nounits
@variables x(t) = 1.
@parameters p(t) = 1.
ev = ModelingToolkit.SymbolicDiscreteCallback((t == 1) => [p ~ Pre(p)*2], discrete_parameters = p)
@mtkcompile sys = System([D(x) ~ p], t; discrete_events = ev)
prob = ODEProblem(sys, [], (0., 2.))
sol = solve(prob, Tsit5())
sol[p] # fine
sol.ps[p] # fine
sol[:p] # errors
sol.ps[:p] # errors

Error & Stacktrace ⚠️

ERROR: BoundsError: attempt to access Tuple{Int64, Int64} at index [3]
Stacktrace:
 [1] getindex(t::Tuple, i::Int64)
   @ Base ./tuple.jl:33
 [2] parameter_index(sys::System, sym::Symbol)
   @ ModelingToolkit ~/.julia/dev/ModelingToolkit/src/systems/abstractsystem.jl:237
 [3] parameter_index (repeats 3 times)
   @ ~/.julia/packages/SymbolicIndexingInterface/hhVqD/src/index_provider_interface.jl:59 [inlined]
 [4] _getp(sys::ODESolution{…}, ::ScalarSymbolic, ::NotSymbolic, p::Symbol)
   @ SymbolicIndexingInterface ~/.julia/packages/SymbolicIndexingInterface/hhVqD/src/parameter_indexing.jl:348
 [5] getp
   @ ~/.julia/packages/SymbolicIndexingInterface/hhVqD/src/parameter_indexing.jl:41 [inlined]
 [6] getindex(::ParameterIndexingProxy{ODESolution{…}}, ::Symbol)
   @ SymbolicIndexingInterface ~/.julia/packages/SymbolicIndexingInterface/hhVqD/src/parameter_indexing_proxy.jl:14
 [7] top-level scope
   @ REPL[212]:1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions