Skip to content

Cases where remake seems to be mutating the original input in some way #3395

Closed
@TorkelE

Description

@TorkelE

Example:

using ModelingToolkit, OrdinaryDiffEq, Test
using ModelingToolkit: t_nounits as t, D_nounits as D

@parameters k1 k2
@variables X1(t) X2(t)
@parameters Γ[1:1] = missing [guess = [1.0]]
eqs = [
    D(X1) ~ k1 * (Γ[1] - X1) - k2 * X1
]
observed = [X2 ~ Γ[1] - X1]
@mtkbuild osys = ODESystem(eqs, t, [X1, X2], [k1, k2, Γ]; observed)

u0 = [X1 => 1.0, X2 => 2.0]
ps = [k1 => 0.1, k2 => 0.2]

# Doesn't work.
oprob1 = ODEProblem(osys, u0, 1.0, ps)
oprob2 = remake(oprob1, u0 = [X1 => 10.0])
integ1 = init(oprob1)
integ1[X1] # Returns 10.0 (should be 1.0).

# Does work.
OPROB1 = ODEProblem(osys, u0, 1.0, ps)
INTEG1 = init(OPROB1)
OPROB2 = remake(OPROB1, u0 = [X1 => 10.0])
INTEG1[X1] # Returns 1.0 (correct).

Metadata

Metadata

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