Skip to content

Change InputOutputSystem repr to show type, name, inputs, and outputs #699

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

Closed
wants to merge 1 commit into from

Conversation

roryyorke
Copy link
Contributor

@roryyorke roryyorke commented Jan 29, 2022

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.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 93.591% when pulling f06ef73 on roryyorke:rory/iosys-repr into e8db508 on python-control:master.

@murrayrm
Copy link
Member

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:

Screen Shot 2022-03-18 at 1 11 05 PM

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.

@murrayrm murrayrm added this to the 0.9.2 milestone Mar 19, 2022
@murrayrm
Copy link
Member

murrayrm commented Apr 9, 2022

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).

@murrayrm murrayrm removed this from the 0.9.2 milestone Apr 9, 2022
@henklaak
Copy link
Contributor

henklaak commented Feb 20, 2023

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.

image

@murrayrm murrayrm closed this Jan 14, 2025
@murrayrm
Copy link
Member

This has been implemented since v0.10.0.

@murrayrm murrayrm added this to the 0.10.2 milestone Feb 19, 2025
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.

4 participants