- Notifications
You must be signed in to change notification settings - Fork441
print a connection table for interconnected systems#925
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
coveralls commentedJul 24, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
This looks very useful for sorting out what is connected to what. A couple of questions and comments:
As an experiment, I tried modifying the example above to use a more typical form with a reference input:
which gives
That looks right to me, but it it might be nice to see the fact that |
sawyerbfuller commentedAug 2, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Right now it just breaks alignment. I think a good solution might be to add an elipsis as you suggest, and to allow the user to set the spacing parameter. update forthcoming.
On further thought, I would propose the following:
Great. I agree this could be useful. Open to it going into a future PR? I am not sure this information is stored anywhere in the |
…of whether connection was explicit or implicit and issue a warning in connection_table if explicit
sawyerbfuller commentedAug 14, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@murrayrm I incorporated (most of) your suggested updates:
P1=ct.ss(1,1,1,0,inputs='u',outputs='y',name='Plant1')P2=ct.tf(10, [.1,1],inputs='e',outputs='y',name='Plant2')P3=ct.tf(10, [.1,1],inputs='x',outputs='y',name='Plant3')L=ct.interconnect([P1,P2,P3],inputs=['e','u','x'],outputs='y')L.connection_table(show_names=True,column_width=23)signal|source|destination--------------------------------------------------------x|input|Plant3e|input|Plant2u|input|Plant1y|Plant1,Plant2,Pl..|output
|
control/nlsys.py Outdated
Parameters | ||
---------- | ||
show_names : bool (optional) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Numpydoc standard notation isbool, optional
(comma instead of parens). I'm not sure if Sphinx will parse or not, but probably better to change so that it is consistent with other documentation.
control/nlsys.py Outdated
each system. Default is False because system name is not usually | ||
specified when performing implicit interconnection using | ||
:func:`interconnect`. | ||
column_width : int (optional) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
(optional) → , optional
@@ -1955,7 +2032,7 @@ def interconnect( | |||
signals are given names, then the forms 'sys.sig' or ('sys', 'sig') | |||
are also recognized. Finally, for multivariable systems the signal | |||
index can be given as a list, for example '(subsys_i, [inp_j1, ..., | |||
inp_jn])'; as a slice, for example, 'sys.sig[i:j]'; or as a base | |||
inp_jn])';oras a slice, for example, 'sys.sig[i:j]'; or as a base |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Wasn't this correct before? Now it says 'a; or b; or c' instead of 'a; b; or c'.
control/nlsys.py Outdated
def connection_table(sys, show_names=False, column_width=32): | ||
"""Print table of connections inside an interconnected system model. | ||
Intended primarily for :class:`InterconnectedSystems` that have been | ||
connected implicitly using signal names. | ||
Parameters | ||
---------- | ||
sys : :class:`InterconnectedSystem` | ||
Interconnected system object | ||
show_names : bool (optional) | ||
Instead of printing out the system number, print out the name of | ||
each system. Default is False because system name is not usually | ||
specified when performing implicit interconnection using | ||
:func:`interconnect`. | ||
column_width : int (optional) | ||
Character width of printed columns | ||
Examples | ||
-------- | ||
>>> P = ct.ss(1,1,1,0, inputs='u', outputs='y', name='P') | ||
>>> C = ct.tf(10, [.1, 1], inputs='e', outputs='u', name='C') | ||
>>> L = ct.interconnect([C, P], inputs='e', outputs='y') | ||
>>> L.connection_table(show_names=True) # doctest: +SKIP | ||
signal | source | destination | ||
-------------------------------------------------------------- | ||
e | input | C | ||
u | C | P | ||
y | P | output | ||
""" | ||
assert isinstance(sys, InterconnectedSystem), "system must be"\ | ||
"an InterconnectedSystem." | ||
sys.connection_table(show_names=show_names, column_width=column_width) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Not something that we need to fix in this PR, but we should eventually adopt some mechanism for creating duplicate docstrings from a single primary docstring (see, for example, the discussionhere).
@@ -1459,7 +1459,7 @@ class LinearICSystem(InterconnectedSystem, StateSpace): | |||
""" | |||
def __init__(self, io_sys, ss_sys=None): | |||
def __init__(self, io_sys, ss_sys=None, connection_type=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Is there a reason to allow the connection type to be overridden? It seems like this should just be inherited from the underlyingInterconnectedSystem
.
Uh oh!
There was an error while loading.Please reload this page.
This PR prints out a table of each signal name, where it comes from (source), and where it goes (destination). It is intended primarily for systems that have been connected implicitly, because in that case all of the signal names have been defined. It doesn't really work for systems that have been connected explicitly, because their signal names may not be unique
It was is inspired by a similar table printout inbdsim and the need to have a means to debug interconnections of many systems.
Example:
(edit: in the code above,
signal_table
has been changed toconnection_table
)Remarks:
sys[17]
) are not very descriptive or helpful when you're connecting systems implicitly with signal names. instead the table just references them by the order they appear in the interconnect list, with an option to print names instead.e | input | C
, but this is not straightforward in Python because it is possible to have many variable names pointing to the same object in memory.