René's URL Explorer Experiment
Title: Update I/O system repr() and str() by murrayrm · Pull Request #1091 · python-control/python-control · GitHub
Open Graph Title: Update I/O system repr() and str() by murrayrm · Pull Request #1091 · python-control/python-control
X Title: Update I/O system repr() and str() by murrayrm · Pull Request #1091 · python-control/python-control
Description: This PR provides updates to the string representations of I/O systems, including both the __repr__ and __str__ functions (used for repr(), str(), and print()) as well as LaTeX output (via _repr_html_):
Created a set of standard _repr_* formats for InputOutputSystem's that can be overridden in subclasses to get the most useful representations based on the system type, using method names similar to _repr_latex_ used by Jupyter notebooks:
_repr_info_: generates a minimal description of the I/O system in the form [output list][, dt=timebase]>. This is the default format that exists for all I/O systems. The inclusion of the timebase is new.
_repr_eval_: generates an "evaluatable" description of the I/O system, if possible (otherwise return _repr_info_()). This is used in LTI systems to show the state space matrices, numerator/denominator, or freuquency response data. This format is similar to what was done before this PR for LTI classes, but now includes the signal names (if non-generic) or the signal counts (if generic). The inclusion of the string names make sure that you can recreate the system with the proper labels. The inclusion of the string counts lets you see the number of inputs and outputs.
_repr_html_: generates an HTML/LaTeX description of the I/O system, if possible (otherwise return _repr_info_()). This method is picked up by Jupyter notebooks to display the value of a variable and replaces _repr_latex_ used in prior versions. This is similar to what was present before, except that now there is a "header" that shows the system name and signal names before showing a LaTeX representation of the state space matrices and/or transfer functions (this required changing _repr_latex_ to _repr_html_). Note that since the timebase information is included in the header, it is no longer included in the LaTeX formatted code.
Created a new function iosys_repr (similar to np.array_repr) that allows different representations of I/O systems via a format parameter ('info', 'eval', or 'latex').
The transfer function display_format parameter is now handled in a dynamic fashion. If it is set to None (default) on system creation, the display style will follow config.defaults['xferfcn.display_format']. If set to poly or zpk on system creation, that overrides the default.
Updated the str() (print) representation of InputOutputSystems to include dt after the state/input/output names (suppressed if it matches the default dt).
Updated the str() (print) representation for NonlinearIOSystems to include list of parameter labels.
Updated the str() (print) representation for InterconnectedSystems to include the list of subsystems (in 'info' form) as well summaries of the connections and outputs matrix (might be an eventual replacement for connection_table).
All representations now apply np.printoptions to system arrays before generating strings, so you get consistent formatting across representations (including latex) and you can use things like suppress to display near-zero numbers as '0'.
Fixed up various line spacings in str() (print) to make things consistent across the various I/O system classes, including adding some indentation for transfer functions and MIMO systems (see screen shots below).
Added examples/repr_gallery.ipynb and exampes/repr_gallery.py files to show all of the various output formats and options (with dashed lines at the start and end so you can see any extraneous blank lines).
Added config.defaults options 'iosys.repr_format' and 'iosys.repr_show_count' to control representation formats.
The combine_tf function now accepts system and signal name keywords. (This is not strictly related to the main subject of this PR, but I needed since I had to set the name of the system in order for doctests to work.)
Added the ability of config.defaults to be called as a context manager, so that you can temporarily change default parameters (this is used in examples/repr_gallery.py). (This is more general than this PR, but I used it extensively in repr_gallery).
Updated docstrings and unit tests.
A detailed set of before and after views are attached as PDFs, generated by the new examples/repr_gallery.ipynb and exampes/repr_gallery.py files:
Before: repr_gallery-10.1-29Dec2024.pdf
After: repr_gallery-10.1-04Jan2025.pdf
Some highlights (pulled from repr_gallery):
State space system, repr(), 'eval' format:
StateSpace: sys_ss, dt=0:
-------------------------
StateSpace(
array([[ 0., 1.],
[-4., -5.]]),
array([[0.],
[1.]]),
array([[-1., 1.]]),
array([[0.]]),
name='sys_ss', states=2, outputs=1, inputs=1)
----
Discrete time, state space system, repr(), 'eval' format:
StateSpace: sys_dss, dt=0.1:
----------------------------
StateSpace(
array([[ 0.98300988, 0.07817246],
[-0.31268983, 0.59214759]]),
array([[0.00424753],
[0.07817246]]),
array([[-1., 1.]]),
array([[0.]]),
dt=0.1,
name='sys_dss', states=2, outputs=1, inputs=1)
----
MIMO transfer function, repr(), 'eval' format:
TransferFunction: sys_mtf_zpk, dt=0:
------------------------------------
TransferFunction(
[[array([ 1., -1.]), array([0.])],
[array([1, 0]), array([1, 0])]],
[[array([1., 5., 4.]), array([1.])],
[array([1]), array([1, 2, 1])]],
name='sys_mtf_zpk', outputs=2, inputs=2)
----
Discrete time, state space system, repr(), ,'info' format:
TransferFunction: sys_dss_poly, dt=0.1:
---------------------------------------
['y[0]'], dt=0.1>
----
Discrete time, state space systems, str():
: sys_dss
Inputs (1): ['u[0]']
Outputs (1): ['y[0]']
States (2): ['x[0]', 'x[1]']
dt = 0.1
A = [[ 0.98300988 0.07817246]
[-0.31268983 0.59214759]]
B = [[0.00424753]
[0.07817246]]
C = [[-1. 1.]]
D = [[0.]]
----
Nonlinear I/O system, str():
NonlinearIOSystem: sys_nl, dt=0:
--------------------------------
: sys_nl
Inputs (1): ['u[0]']
Outputs (1): ['y[0]']
States (2): ['x[0]', 'x[1]']
Parameters: ['a', 'b']
Update:
Output:
Linear interconnected system, str():
LinearICSystem: sys_ic, dt=0:
-----------------------------
: sys_ic
Inputs (2): ['r[0]', 'r[1]']
Outputs (2): ['y[0]', 'y[1]']
States (2): ['proc_x[0]', 'proc_x[1]']
Subsystems (2):
* ['y[0]', 'y[1]']>
* ['y[0]', 'y[1]'], dt=None>
Connections:
* proc.u[0] <- ctrl.y[0]
* proc.u[1] <- ctrl.y[1]
* ctrl.u[0] <- -proc.y[0] + r[0]
* ctrl.u[1] <- -proc.y[1] + r[1]
Outputs:
* y[0] <- proc.y[0]
* y[1] <- proc.y[1]
A = [[-2. 3.]
[-1. -5.]]
B = [[-2. 0.]
[ 0. -3.]]
C = [[-1. 1.]
[ 1. 0.]]
D = [[0. 0.]
[0. 0.]]
----
Open Graph Description: This PR provides updates to the string representations of I/O systems, including both the __repr__ and __str__ functions (used for repr(), str(), and print()) as well as LaTeX output (via _repr_htm...
X Description: This PR provides updates to the string representations of I/O systems, including both the __repr__ and __str__ functions (used for repr(), str(), and print()) as well as LaTeX output (via _repr_htm...
Opengraph URL: https://github.com/python-control/python-control/pull/1091
X: @github
direct link
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/checks(.:format) |
| route-controller | pull_requests |
| route-action | checks |
| fetch-nonce | v2:5e76b0ae-7e5c-8735-ff96-89ffeae62faa |
| current-catalog-service-hash | 87dc3bc62d9b466312751bfd5f889726f4f1337bdff4e8be7da7c93d6c00a25a |
| request-id | A088:1C9C23:C960F0:11A2993:697B562F |
| html-safe-nonce | d8280319f69038bb16b0315f26c185e71bb67253655e34a904d9172d06e22872 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMDg4OjFDOUMyMzpDOTYwRjA6MTFBMjk5Mzo2OTdCNTYyRiIsInZpc2l0b3JfaWQiOiIyMzY1OTQxMTk1NTcxMTU2NTI3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 0918cb65d3dce42682fc9aff15fcdfacec52511fbca90367fd56fad384d1f571 |
| hovercard-subject-tag | pull_request:2260532387 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,checks,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | ///pull_requests/show/checks |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/python-control/python-control/pull/1091/checks |
| twitter:image | https://avatars.githubusercontent.com/u/293362?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/293362?s=400&v=4 |
| og:image:alt | This PR provides updates to the string representations of I/O systems, including both the __repr__ and __str__ functions (used for repr(), str(), and print()) as well as LaTeX output (via _repr_htm... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7eed3e20c41f6c464df945b1f353a52c450ca1653f4697d4ebcc58c2adc5868a |
| turbo-cache-control | no-cache |
| go-import | github.com/python-control/python-control git https://github.com/python-control/python-control.git |
| octolytics-dimension-user_id | 2285872 |
| octolytics-dimension-user_login | python-control |
| octolytics-dimension-repository_id | 22791752 |
| octolytics-dimension-repository_nwo | python-control/python-control |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 22791752 |
| octolytics-dimension-repository_network_root_nwo | python-control/python-control |
| turbo-body-classes | logged-out env-production page-responsive full-width full-width-p-0 |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | b059c4725f1b62cc8534bdab4092fd840e833907 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width
URLs of crawlers that visited me.