update model_reduction to allow input/output selection + unstable warning (vs exception)#1074
Conversation
slivingston
left a comment
There was a problem hiding this comment.
Good improvement! I made several stylistic and misprint-related comments. Else, ready to merge.
control/modelsimp.py
Outdated
| eliminated or those to be kept. | ||
|
|
||
| Two methods of state reduction are possible: 'truncate' removes the | ||
| states marked for elimination, while 'matchdc' replaces the the |
There was a problem hiding this comment.
| states marked for elimination, while 'matchdc' replaces the the | |
| states marked for elimination, while 'matchdc' replaces the |
control/modelsimp.py
Outdated
| unstable eigenvalues, since in those situations the stability reduced | ||
| order model may be different that the stability of the full model. No | ||
| other checking is done, so users to be careful not to render a system |
There was a problem hiding this comment.
| unstable eigenvalues, since in those situations the stability reduced | |
| order model may be different that the stability of the full model. No | |
| other checking is done, so users to be careful not to render a system | |
| unstable eigenvalues, since in those situations the stability of the reduced | |
| order model may be different than the stability of the full model. No | |
| other checking is done, so users must be careful not to render a system |
control/modelsimp.py
Outdated
| dico = 'C' | ||
| else: | ||
| raise NotImplementedError("Function not implemented in discrete time") | ||
| States, inputs, and outputs can be specified using integer offers or |
There was a problem hiding this comment.
| States, inputs, and outputs can be specified using integer offers or | |
| States, inputs, and outputs can be specified using integer offsets or |
control/tests/modelsimp_test.py
Outdated
| ({'elim_inputs': [0, 1, 2]}, 5, 3, 0), # no inputs | ||
| ({'elim_outputs': [0, 1, 2]}, 5, 0, 3), # no outputs | ||
| ({'elim_states': [0, 1, 2, 3, 4]}, 0, 3, 3), # no states | ||
| ({'elim_states': [0, 1], 'keep_states': [1, 2]}, None, None, None) |
There was a problem hiding this comment.
control/modelsimp.py
Outdated
| See Also | ||
| -------- | ||
| balanced_reduction : Eliminate states using Hankel singular values. | ||
| minimal_realization : Eliminate unreachable or unobseravble states. |
There was a problem hiding this comment.
| minimal_realization : Eliminate unreachable or unobseravble states. | |
| minimal_realization : Eliminate unreachable or unobservable states. |
control/modelsimp.py
Outdated
| warnings.warn("System is unstable; reduction may be meaningless") | ||
|
|
||
| # Utility function to process keep/elim keywords | ||
| def _process_elim_or_keep(elim, keep, labels, allow_both=False): |
There was a problem hiding this comment.
Any reason to keep allow_both? _process_elim_or_keep() is a function defined only in the scope of model_reduction(), and all calls to it have the default allow_both value (allow_both=False).
control/modelsimp.py
Outdated
| method : string | ||
| Method of removing states in `ELIM`: either 'truncate' or | ||
| 'matchdc'. | ||
| Method of removing states in `elim`: either 'truncate' or |
There was a problem hiding this comment.
| Method of removing states in `elim`: either 'truncate' or | |
| Method of removing inputs, outputs, and/or states: either 'truncate' or |
This is confusing because there is no elim parameter and because inputs and outputs can be removed as well, in addition to states.
There was a problem hiding this comment.
Will update, but this only applies to the way states are removed.
control/modelsimp.py
Outdated
|
|
||
| """ | ||
| if not isinstance(sys, StateSpace): | ||
| raise TypeError("system must be a a StateSpace system") |
There was a problem hiding this comment.
| raise TypeError("system must be a a StateSpace system") | |
| raise TypeError("system must be a StateSpace system") |
This PR updates the
model_reductionfunction to add some additional functionality. From the docstring:Specific updates:
ELIMpositional parameter toelim_states(positional or keyword).keep_statesto allow specifying the list of states to keep instead of those to eliminate.elim_inputs,elim_outputs,keep_inputs,keep_outputsto allow selection of inputs and outputs.warn_unstable=False.modelsimp.pysince we know just use theLICENSEfile.This PR was motivated by an example from FBS2e (see steering.py), where I wanted to extract the dynamics of a subsystem (and the original system had an eigenvalue at the origin). It is possible to accomplish the same result by using the old implementation (assuming the exception is changed to a warning) and then indexing the system directly to handle the inputs and outputs, but it seemed natural to include in a single function call.