ModelingToolkit.jl
ModelingToolkit.jl copied to clipboard
Parameter dependencies fail with array variables
Bug 1: This should work (it works if you turn c and d into scalars), but fails:
using ModelingToolkit
using ModelingToolkit: t_nounits as t, D_nounits as D
@parameters a b c[1:1] d[1:1]
@variables f(t)
pdeps = [b ~ a, d[1] ~ c[1] + b]
@named M = ODESystem([f ~ 0], t; parameter_dependencies = pdeps)
Ms = structural_simplify(M)
prob = ODEProblem(Ms, [], (0.0, 1.0), [a => 1.0, c[1] => 1.0]; fully_determined = true)
ERROR: ExtraEquationsSystemException: The system is unbalanced. There are 2 highest order derivative variables and 3 equations.
More equations than variables, here are the potential extra equation(s):
0 ~ b + c[1] - d[1]
Note that the process of determining extra equations is a best-effort heuristic. The true extra equations are dependent on the model and may not be in this list.
The error should also say something different than "highest order derivative variables".
Bug 2: This (initialization) problem warns that it is overdetermined, but should not be:
@parameters c[1:1] d[1:1]
@variables f(t)
pdeps = [d[1] ~ c[1]]
@named M = ODESystem([f ~ 0], t; parameter_dependencies = pdeps)
Ms = structural_simplify(M)
prob = ODEProblem(Ms, [], (0.0, 1.0), [c[1] => 1.0]; fully_determined = true)
┌ Warning: Initialization system is overdetermined. 1 equations for 0 unknowns. Initialization will default to using least squares. `SCCNonlinearProblem` can only be used for initialization of fully determined systems and hence will not be used here. To suppress this warning pass warn_initialize_determined = false. To make this warning into an error, pass fully_determined = true
It also does not error with fully_determined = true (although the warning shouldn't be there at all).