Skip to content

Case of error when applying remake to discrete variable #4198

@TorkelE

Description

@TorkelE

Possibly related to: #4030. This one causes one of Catalyst's doc pages to error, preventing it from being built.

# Fetch packages.
using ModelingToolkitBase
using ModelingToolkitBase: t_nounits as t, D_nounits as D

# Make model.
@parameters pY pZ
@discretes pX(t)
@variables X(t) Y(t) Z(t)
eqs = [
    D(X) ~ pX - X
    D(Y) ~ -Y + pY*X
    D(Z) ~ -Z + (pZ*X) / Y
]
discrete_events = ModelingToolkitBase.SymbolicDiscreteCallback([10.0] => [pX ~ 10*Pre(pX)]; discrete_parameters = [pX])
@mtkcompile sys = System(eqs, t; discrete_events)

# make ODE.
ps = [:pX => 0.1, :pY => 1.0, :pZ => 1.0]
u0 = [:X => 0.1, :Y => 0.1, :Z => 1.0]
oprob = ODEProblem(sys, [u0; ps], (0.0, 50.0))

# Try remake.
oprob_local = remake(oprob; p = [pX => 1.0]) # Fine
oprob_local = remake(oprob; p = [:pX => 1.0]) # ERROR: BoundsError: attempt to access Tuple{Int64, Int64} at index [3]

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