ModelingToolkit.jl icon indicating copy to clipboard operation
ModelingToolkit.jl copied to clipboard

Superfluous parameter and initial condition values can be provided to Problems

Open TorkelE opened this issue 1 year ago • 1 comments

In this MWE we provide the values of Y and r to the ODEProblem. Since these are not part of the ODESystem, the user have probably done something wrong, and an error should be thrown.

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

@parameters p d r
@variables X(t) Y(t)
eqs = [D(X) ~ p - d*X]
@mtkbuild osys = ODESystem(eqs, t)

u0 = [X => 1.0, Y => 1.0]
tspan = (0.0, 100.0)
ps = [p => 1.0, d => 1.0, r => 1.0]

prob = ODEProblem(osys, u0, tspan, ps) # works fine

The values are filtered away in the resulting problem, e.g.

prob[Y]
prob.ps[r]

both yields errors.

the same is the case for the other problem types as well.

TorkelE avatar Jun 09 '24 00:06 TorkelE

Actually, I should add that this is not as trivial as I first thought. E.g. if you have variables eliminated as observables from MTK, you might still want to provide values for these (e.g. if other parameters/variables have default values depending on these). Hence, there are situations where providing values for superfluous initial conditions might actually make sense.

TorkelE avatar Jun 10 '24 19:06 TorkelE