Skip to content

Unsafe parameter mutation breaks latest release #3346

@hersle

Description

@hersle

On the latest 9.61.0 release:

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

@variables x(t)
@parameters p
@named sys = ODESystem([D(x) ~ 0], t, [x], [p]; initialization_eqs = [x ~ p]) # solution is constant x(t) ~ p
sys = structural_simplify(sys)

prob = ODEProblem(sys, [], (0.0, 1.0), [p => 1.0])
sol1 = solve(prob, Tsit5())
sol1[x+p] # gives 2.0, as it should

ModelingToolkit.setp(prob, p)(prob, 2.0)
sol2 = solve(prob, Tsit5())

sol1[x+p] # gives 3.0, but should give 2.0
sol2[x+p] # gives 4.0, as it should

This is bad. It looks like the setp effectively changes the value of p when reading sol1, which it should not.

I have narrowed down that this code ran as expected before commit 39f8271.

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