Skip to content
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

I/O system class restructuring #916

Merged
merged 18 commits into from
Jul 2, 2023

Conversation

murrayrm
Copy link
Member

@murrayrm murrayrm commented Jun 19, 2023

This PR restructures the input/output systems classes as described in issue #904 and summarized in the following diagram:

classes-0 10 0

In addition, a number of deprecated functions were removed and various other changes related to I/O systems were made.

Summary of major changes:

  • The NamedIOSystem class has been renamed InputOutputSystem and serves as the parent class for all input/output system classes.
  • The LinearIOSystems class has been merged into the StateSpace class.
  • Instances of NonlinearIOSystem can now be created using the nlsys() factory function (instead of using the class name, so more like ss and tf).
  • All operations that used to work on a subset of I/O system classes should now work on all compatible I/O system classes:
    • Block diagram functions (series, parallel, feedback, append, neg) now work on all I/O system classes, including nonlinear systems.
    • Simulation functions (initial_response, step_response, forced_response) will now work for nonlinear functions (via an internal call to input_output_response).
    • The impulse_response function only works for LTI systems.
  • Extraneous arguments for simulation functions have been removed (see add/cleanup documentation on simulation functions #905):
    • The impulse_response function no longer accepts the X0 keyword.
    • The initial_response function no longer accepts the input keyword.
    • The step_response function still accepts the X0 keyword (to allow for non-zero equilibrium points for nonlinear systems).
  • The __str__() method for I/O system classes now includes the name of the system and signals (via InputOutputSystem.__str__()).
  • Redundant functions have been marked as deprecated: ss2io, tf2io.
  • Deprecated functions and properties have been removed: pole, zero, LTI.{inputs,outputs, pole, zero}, timebaseEqual. (The pole() and zero() functions are still available in the MATLAB compatibility module, control.matlab.)
  • The connect function generates a DeprecationWarning (use interconnect instead).
  • Configuration defaults in the namedio module are now in the iosys module.
  • Updated user documentation, docstrings, examples, and unit tests.

What you will need to change to run version 0.10.0 (this should go in the release notes):

  • Replace any use of the LinearIOSystem class with the StateSpace class.
  • Replace pole() and zero() with poles() and zeros().

Additional recommended changes:

  • Replace calls to ss2io or tf2io with calls to ss or tf, including moving signal and system naming parameters into the ss or tf call.
  • Replace calls to StateSpace, TransferFunction, and NonlinearIOSystem with calls to the equivalent factory functions: ss(), tf(), nlsys().

@coveralls
Copy link

coveralls commented Jun 19, 2023

Coverage Status

coverage: 94.849%. first build when pulling 39404c4 on murrayrm:iosys_classes-19Jun2023 into bfdfbd5 on python-control:main.

Copy link
Contributor

@sawyerbfuller sawyerbfuller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A big drop - this looks great.

My only real concern is in regards to the tf2io and ss2io functions - are they implemented somehwere with a deprecation warning?

control/bdalg.py Outdated Show resolved Hide resolved
control/bdalg.py Show resolved Hide resolved
control/iosys.py Show resolved Hide resolved
control/sisotool.py Show resolved Hide resolved
control/statesp.py Outdated Show resolved Hide resolved
control/statesp.py Outdated Show resolved Hide resolved
control/statesp.py Show resolved Hide resolved
control/tests/type_conversion_test.py Show resolved Hide resolved
control/timeresp.py Outdated Show resolved Hide resolved
@murrayrm
Copy link
Member Author

@sawyerbfuller I put back ss2io and tf2io. If you have a chance, try running this against some of your existing code to just confirm it works as expected (and to see what else you end up needing to change, if anything).

@sawyerbfuller
Copy link
Contributor

Ok just checked through and pretty much everything I have works with this new code, bravo! (and bravo unit tests!). The two exceptions I found were:

  1. frequency_response raises an error with LinearICSystems.
sys = ct.interconnect([ct.ss(ct.drss(3,1, 1, dt=0.2), inputs='e', outputs='u'), 
                       ct.ss(ct.drss(3,1, 1, dt=0.2), inputs='u', outputs='y')], 
                      inputs='e', outputs='y')
sys.frequency_response(22)

raises
StateSpace.__call__() missing 1 required positional argument: 'x'. No error is raised for sys(22).

  1. In constructing this code, I encountered the bug that that drss cannot take named signals using the 'inputs' keyword. sys = ct.drss(3,1, 1, dt=0.2, inputs='e', outputs='u') raises rss() got multiple values for argument 'inputs'. Not sure if this is new or not.

@murrayrm
Copy link
Member Author

murrayrm commented Jul 2, 2023

The "bug" in the drss call is because the second and third arguments for drss are actually output and input. So Python is complaining because you used both positional arguments for input and output and keyword arguments. The correct call to create a named random system is:

sys = ct.drss(3, inputs='e', outputs='u', dt=0.2)

(note that you can also just call rss, which recognizes the dt keyword and creates a discrete time system).

Fix for #1 is on its way.

Copy link
Contributor

@sawyerbfuller sawyerbfuller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

@murrayrm murrayrm merged commit 4955691 into python-control:main Jul 2, 2023
14 checks passed
@murrayrm murrayrm added this to the 0.10.0 milestone Mar 31, 2024
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.

Add nonlinear system compatibility to time simulation functions
3 participants