GeezerVison is showing github.com — Change InputOutputSystem repr to show type, name, inputs, and outputs by roryyorke · Pull Request #699 · python-control/python-control
Conversation
roryyorke
commented
Jan 29, 2022
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
I didn't know about InputOutputSystem 's __str__ implementation, and I find the __repr__ a bit bare-bones. With this change:
In [8]: import control as ct
...: P1 = ct.LinearIOSystem(ct.rss(2,1,1), inputs='u1', outputs='y1')
...: P2 = ct.LinearIOSystem(ct.rss(2,1,1), inputs='y1', outputs='y2')
...:
In [9]: display(P1)
...:
<LinearIOSystem:sys[6]:['u1']->['y1']>
In [10]: ct.interconnect([P1, P2], inputs=['u1'], outputs=['y2'])
...:
Out[10]: <LinearICSystem:y2:['u1']->['y2']>
In [11]: display(ct.InputOutputSystem())
...:
<InputOutputSystem:sys[9]:[]->[]>
This is a draft for comment - if it looks OK, I'll (eventually) improve it and add tests. One improvement I can see already: make the input and output lists a little prettier by removing the quotes.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|

Coverage remained the same at 93.591% when pulling f06ef73 on roryyorke:rory/iosys-repr into e8db508 on python-control:master.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
I agree that a change would be useful here. More generally, it would be nice to think through what we want to have displayed in various situations:
__repr__: this is the default display for objects in iPython/Jupyter and is supposed to be something that could, in principle, be used to recreate the object. For StateSpace systems, for example, this currently gives
StateSpace(array([[ 0., 1.],
[-1., -2.]]), array([[0.],
[1.]]), array([[1., 0.]]), array([[0.]]))
__str__: this is what you get when you type print(sys) and it gives a more verbose output. The current output for a state space systems is:
A = [[ 0. 1.]
[-1. -2.]]
B = [[0.]
[1.]]
C = [[1. 0.]]
D = [[0.]]
- After PR I/O system enhancements #710 gets merged, creating a system with
ss will produce a LinearIOSystem, which has a different __str___ representation:
Object: sys[0]
Inputs (1): u[0],
Outputs (1): y[0],
States (2): x[0], x[1],
A = [[ 0. 1.]
[-1. -2.]]
B = [[0.]
[1.]]
C = [[1. 0.]]
D = [[0.]]
- We also have a
_repr_latex_ method, which gets used in Jupyter notebooks. This produces the following output:

Finally, PR #710 has a conflicting change since I reset the repr format there to include the type and system name. So an InputOutputSystem object has output:
<class 'control.iosys.LinearIOSystem'>: sys[0]
I like the version in this draft PR better, but note that if you get something with lots of inputs and outputs, it could be a bit odd looking.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
PR #721 has a portion of this (__repr__) implemented, but leaves the other issues touched on above unchanged. It would be nice to sort out a consistent set of representations that make sense in different environments (eg, Jupyter vs command line).
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
henklaak
commented
Feb 20, 2023
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|
FYI, Spyder (a nifty little IDE) also uses the _repr_latex_() output
It sure is handy to get your SS in a compact matrix in such editors.

|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
This has been implemented since v0.10.0.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|