Skip to content

[v10] refactor: change inputs/outputs handling in structural_simplify #3573

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

Open
wants to merge 26 commits into
base: v10
Choose a base branch
from

Conversation

vyudu
Copy link
Member

@vyudu vyudu commented Apr 22, 2025

Standardize the input handling by no longer returning input_idxs. To be merged into #3563

@vyudu vyudu changed the title [v10] refactor: change inputs/outputs handling in structural_simplify, rename to mtkbuild [v10] refactor: change inputs/outputs handling in structural_simplify Apr 22, 2025
@AayushSabharwal AayushSabharwal changed the base branch from master to v10 April 22, 2025 05:35
@@ -24,14 +24,14 @@ lsys3, _ = linearize(sys, [r], [y]; autodiff = AutoFiniteDiff())
@test lsys.C[] == lsys2.C[] == lsys3.C[] == 1
@test lsys.D[] == lsys2.D[] == lsys3.D[] == 0

lsys, ssys = linearize(sys, [r], [r])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't return ssys, how can the user know the state realization used? On line 17 above, the ssys is returned, what's different on this line?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I forgot to correct these.

Re the first question, my thought was that the user always simplifies it with the inputs first and then passes it into the linearization. So I should add a few simplification statements here first. So they examine the state realization by just examining the simplified system. Is this a reasonable approach?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In some cases, like when calling linearize, yes, but there are cases when the user cannot simplify and while provide the inputs themselves. The functions that compute sensitivity functions, such as get_sensitivity, start by adding a new input and then simplify with this input specified, the user cannot do that since this input does not even exist before the function was called.

@@ -114,11 +114,12 @@ Nd = 10
@named pid = LimPID(; k, Ti, Td, Nd)

@unpack reference, measurement, ctr_output = pid
lsys0, ssys = linearize(pid, [reference.u, measurement.u], [ctr_output.u];
pid = structural_simplify(pid, inputs = [reference.u, measurement.u], outputs = [ctr_output.u])
lsys0 = linearize(pid, [reference.u, measurement.u], [ctr_output.u];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the inputs and outputs are passed already on the line above, why do they have to be passed here as well?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They shouldn't be, thanks. Is it reasonable to default inputs to inputs(sys) and outputs to outputs(sys) if the user does not explicitly pass these in?

@baggepinnen
Copy link
Contributor

@vyudu
Copy link
Member Author

vyudu commented Apr 23, 2025

@AayushSabharwal @baggepinnen reverted the linearization stuff, I think this should be ready

Copy link
Contributor

@baggepinnen baggepinnen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are there no tests that need update due to this PR?

@@ -179,9 +179,6 @@ The return values also include the chosen state-realization (the remaining unkno

If `disturbance_inputs` is an array of variables, the generated dynamics function will preserve any state and dynamics associated with disturbance inputs, but the disturbance inputs themselves will (by default) not be included as inputs to the generated function. The use case for this is to generate dynamics for state observers that estimate the influence of unmeasured disturbances, and thus require unknown variables for the disturbance model, but without disturbance inputs since the disturbances are not available for measurement. To add an input argument corresponding to the disturbance inputs, either include the disturbance inputs among the control inputs, or set `disturbance_argument=true`, in which case an additional input argument `w` is added to the generated function `(x,u,p,t,w)->rhs`.

!!! note "Un-simplified system"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This warning is still warranted?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The generate_control_function shouldn't require an un-simplified system anymore since it no longer simplifies the system

@vyudu
Copy link
Member Author

vyudu commented Apr 25, 2025

OK tests should be fixed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants