Skip to content

Prevent events from mutating original problem #2680

Open
@TorkelE

Description

@TorkelE

A very common event is one which updates a parameter (often at some time point of a simulation). Currently, these also updates the parameter of the original problem.:

@variables t X(t)
@parameters p d
D = Differential(t)
eqs = [
    D(X) ~ p - d*X
]
discrete_events = [
    [5.0] => [p ~ 0.1]
]
@mtkbuild osys = ODESystem(eqs, t; discrete_events)

u0 = [X => 0.0]
tspan = (0.0, 10.)
ps = [p => 5.0, d => 1.0]
oprob = ODEProblem(osys, u0, tspan, ps)
sol = solve(oprob, Tsit5())
plot(sol)

image

sol = solve(oprob, Tsit5())
plot(sol)

image

This means that if you want to re-simulate the problem, you have to create a new one. In practice when I make ensemble simulations with events I just run a deepcopy whenever a problem is passed into solve.

There are probably perks of this approach, but doesn't it feel more natural to not have events (the same hold for callbacks) mutate the original problem?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions