-
-
Notifications
You must be signed in to change notification settings - Fork 224
New calculate_statespace
function for AbstractODESystem
#1103
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
Conversation
…s for any AbstractODESystem
Would it make sense to include functionality for the user to specify outputs also? So that one can obtain a system on the form
The controls already indicate what |
I'd be happy implementing this, though I'm a controls engineer, and I worry about us GN&C folks overtaking a modeling package which is designed for a different purpose (scientific machine learning). Right now, I don't see any easy way to specify outputs in an |
Makes sense to me.
I think so. It should somehow carry over the observed equations from the original system, right? |
I hadn't played around with # On MTK's master branch as of this post...
using ModelingToolkit
sys = let
@parameters t f k d
@variables x(t) ẋ(t) y(t)
δ = Differential(t)
eqs = [
δ(x) ~ ẋ,
δ(ẋ) ~ f - k*x - d*ẋ
]
@named HarmonicOscillator = ODESystem(eqs, t, [x, ẋ], [f, k, d]; controls=[f], observed=[y ~ x + ẋ])
end |> structural_simplify
We could have also left I agree it makes sense that Also, if |
The difference though is that the observed equations, if left fully intact, will not be |
Don't worry about it. In fact, the whole purpose of ModelingToolkit is to be a general enough symbolic specification of these systems that all domains can feed into it. I think controls functionality is very necessary for a lot of domains, even if in some cases it's called "input functions" or "dosing". So observed variables, the ability to specify controls, transform this into optimization problems and other things: this is all very necessary to make first class in the ODESystem. |
Might be misunderstanding the question here, but I figured the linearization would work the same way the To find So it's alright for the observed equations to be nonlinear in an Edit. Per my earlier comment...
After writing out the logic myself in this comment, I think it is fine to specify outputs, and have them live alongside other |
yeah, I guess linearize the observed equations and that will give that form. |
It would be fine to have non-output quantities in the left-hand side of the Edit. I guess we need to decide if the number of observed quantities is equivalent to the number of outputs, or if the output equations are a subset of the observed equations. |
As I understand As a side, perhaps
Unrelated to the current discussion, but touching on
It's common in controls to also have a noise/disturbance specification. Such a specification can take the form
This form is used to specify how disturbances enter the system. Commonly, measurement noise, periodic noise (think 50/60Hz measurement disturbances), or low-frequency model errors like Coulomb friction acting in the same place as the input
Maybe this kind of disturbance specification can be left for later, but it would be good to keep in the back of the mind while designing interfaces etc. In typical control-systems design ala matlab or ControlSystems.jl, noise models are often added to a system model, some simple examples are here (mostly undocumented unfortunately) |
That's an |
Closing in favor of the #1111 approach |
As mentioned in #1059, we can now generate the
A
andB
matrices of linear state space models for anyAbstractODESystem
because we have the newcalculate_control_jacobian
function.Users can
generate_jacobian
andgenerate_control_jacobian
for fast functions which return the system'sA
andB
matrices. Still, it would be nice to have a convenience function which simply returns the linearizations for anyAbstractODESystem
. Users could callcalculate_statespace(sys::AbstractODESystem, subs::Dict)
to return the linearization evaluated at the points in theDict
subs
.That's what this PR adds. One additional test has been added, which passes.
The reason I did not use
generate_jacobian
andgenerate_control_jacobian
incalculate_statespace
is because I did not wantcalculate_statespace
to have to compile functions with every call, and it doesn't seem right to cacheRuntimeGeneratedFunction
s in every concreteAbstractODESystem
type.Anyone have any opinions / thoughts on whether this should be included? I'd find it useful for
PolynomialGTM.jl
.