Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
TorkelE opened this issue Feb 18, 2025 · 0 comments · Fixed by #3390
Closed

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

TorkelE opened this issue Feb 18, 2025 · 0 comments · Fixed by #3390
Assignees
Labels
bug Something isn't working

Comments

@TorkelE
Copy link
Member

TorkelE commented Feb 18, 2025

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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants