ModelingToolkit.jl
ModelingToolkit.jl copied to clipboard
parameter is not a parameter, bad error message
The following system gives the cryptic error
ArgumentError: r(t) is not a parameter.
I assume it has something to do with r
being an array and the equation using .~
, but the error message doesn't really tell me what the problem is, r
is certainly a parameter from the user's point of view.
using LinearAlgebra
@component function Temp(; name, r)
@parameters r(t)[1:3]=r [
description = "position vector from frame_a to frame_b, resolved in frame_a",
]
@variables fb(t)[1:3]=r [
description = "force",
]
eqs = cross(r, fb) .~ zeros(3)
ODESystem(eqs, t; name)
end
Temp(; name=:t, r=zeros(3))
Error is because the r
wasn't passed to ODESystem
.
@component function Temp(; name, r)
:
ODESystem(eqs, t, [], [r...]; name)
end
Maybe this^1 error message can be changed from throw(ArgumentError("$p is not a parameter."))
to throw(ArgumentError("Either $p is not a parameter or it is not listed as a parameter of the System."))
.
(It should be possible to say that as check_parameters
is used only inside the JumpSystem, ODESystem SDESystem and DiscreteSystem definitions).
If I change the equation to eqs = cross(r, fb) ~ zeros(3)
(without the dot in .~
) the error goes away without me providing [r...]
to the ODESystem
constructor, why this inconsistency? Also, the variable fb
is not passed to the constructor either, another inconsistency?
I think the reason for the inconsistencies is how check_parameters()
are determining parameters based on
- if they are callable, like
r(t)
- if they are arrays
r(t)[1:3]
I guess the "error" here is that r(t)[1:3]
represents a (constant?) offset vector, so it should really be defined as r[1:3]
, in which case the example runs. But a better error should still be thrown. I think the weirdest behavior is that it is possible that isparameters(par)
returns false
on a parameter defined with @parameters
.