-
-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Making parameters @parameters
#50
Comments
Have you tested simply adding
They will end up as default values in other blocks, but that should not be a problem anymore: |
Ah cool, I didn't know that was fixed, thanks for pointing that out! Then we have one less problem to worry about. It currently appears to work for some parameters but not for others julia> @parameters k=2 Ti=3 Td=4;
julia> @named pid = LimPID(; k) # works
julia> @named pid = LimPID(; k, Ti, Td)
ERROR: TypeError: non-boolean (Num) used in boolean context
Stacktrace:
[1] top-level scope
@ REPL[9]:1 It does not work for the time constants due to the argument checking !isequal(Ti, false) && (Ti ≥ 0 || throw(ArgumentError("Ti out of bounds, got $(Ti) but expected Ti ≥ 0"))) I'm wondering if argument checking can be handled slightly differently. Either we can introduce some convenience functionality like a macro that only checks numerical values and leaves julia> @parameters Ti [bounds=(0, Inf)]
1-element Vector{Num}:
Ti
julia> getbounds(Ti)
(0, Inf) and check parameter values once the final numerical values have been provided before the call to I would eventually like to add this kind of metadata everywhere it makes sense, it would make it really smooth when optimizing over parameters if trivial bounds like |
For normal stuff (e.g. parameter must be positive,...) it might be easy to use such a system. But in this specific case the parameter is "misused" as an option as well. But it would be nice to use the parameter bounds and simply let MTK do the check if the provided default values is ok. |
How could a relational check be done? e.g. |
The following already works, so maybe a function that checks parameters before solving could evaluate any symbolic expressions appearing in the bounds using the numerical values provided in the varmap. julia> @parameters T [bounds = (0, Inf)]
1-element Vector{Num}:
T
julia> @parameters k [bounds = (0, T^2+1)]
1-element Vector{Num}:
k
julia> getbounds(k)
(0, 1 + T^2) |
You mean somewhere like here ? |
Exactly, the check could probably be performed as soon as numerical values are known for all parameters? |
Similar problem with
giving
|
It would be nice if we could figure out a way to have the parameters of components be
@parameters
rather than hard-coded. Take this PID controller as an examplewhere are
k, Ti, Td
that the user provided? They are likely in there somewhere, but not under their original names. I tried this a while back but ran into problems and made a commenthttps://github.com/baggepinnen/ModelingToolkitStandardLibrary.jl/blob/281ee9715512bbeacd054240f4fb56165f9b1b98/src/Blocks/continuous.jl#L157
When models get more complicated, it would be good to
k, Ti, Td
Ti=3
leads toint₊k => 0.333333
being the parameter, while the input argumentk
influences multiple different parameters in the resulting system.What I have in mind is workflows like parameter tuning etc. where the user must be able to specify which parameters to tune. It's going to be rather hard to figure out how to tune the PID controller if the PID parameters do not appear (directly) in the system equations.
The text was updated successfully, but these errors were encountered: