GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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

@roryyorke roryyorke commented Jan 29, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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.

All reactions
@roryyorke
Change InputOutputSystem repr to show type, name, inputs, and outputs
f06ef73
@coveralls

coveralls commented Jan 29, 2022

Copy link
Copy Markdown

Coverage Status

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@murrayrm

murrayrm commented Mar 18, 2022

Copy link
Copy Markdown
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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@murrayrm murrayrm added this to the 0.9.2 milestone Mar 19, 2022
@murrayrm murrayrm mentioned this pull request Apr 9, 2022
Updated system class functionality #721
Merged
@murrayrm

murrayrm commented Apr 9, 2022

Copy link
Copy Markdown
Member

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

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

henklaak commented Feb 20, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@murrayrm murrayrm closed this Jan 14, 2025
@murrayrm

murrayrm commented Jan 14, 2025

Copy link
Copy Markdown
Member

This has been implemented since v0.10.0.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@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

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

0.10.2

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@roryyorke @coveralls @murrayrm @henklaak
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.