-
Notifications
You must be signed in to change notification settings - Fork 438
BugFix: tf2ss now handles static gains #129
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
BugFix: tf2ss now handles static gains #129
Conversation
Changes Unknown when pulling a44305b on roryyorke:rory/tf2ss-static-gain into ** on python-control:master**. |
Could you split Following my comment on PR #122, tests should not partially change when Slycot is present or not. Otherwise, debugging efficiency is negatively impacted. |
You mean using Sure, will do. |
a44305b
to
5c839c2
Compare
It looks like this is actually a bug in Slycot, as speculated in [1]; I can get SLICOT's |
Because changes from python-control/Slycot#5 are now in Slycot, the only remaining case before we can close #81 is when Slycot is not installed. @roryyorke Some of the changes from your original commit in this PR might be able to address the case of no
|
Is your idea to have three cases: (1) static gain (SISO or MIMO), (2) with-Slycot (any dynamic), (3) no-Slycot (SISO dynamic only) ? We could add a case (0), namely empty systems (or this could be handled in (1)); this would let us sidestep the Slycot issues with empty systems you identified in in the related Slycot PR. |
Unless I am missing something, with Slycot, static gain does not need to be treated as a special case, thanks to your patches to Slycot. However, when Slycot is not installed, static gain would be treated separately. |
so, the cases are:
Before creating a special case to handle empty systems (as noticed during review of python-control/Slycot#5), we might wait until there is a motivating application. |
5c839c2
to
02080e0
Compare
CI won't pass without updated Slycot; it passes on my Ubuntu 14.04 x64 system, with Conda Python 3.5.2, both with Slycot 9a098d12, and without Slycot. |
I also demonstrated success on your tests Tomorrow I will work on releasing the next version of Slycot. |
"""Regression: tf2ss for MIMO static gain""" | ||
import control | ||
# 2x3 TFM | ||
gmimo = control.tf2ss(control.tf([[ [23], [3], [5] ], [ [-1], [0.125], [101.3] ]], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How did you select these coefficients?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's an arbitrary selection of numbers over a (small) range of magnitudes and signs; in all cases the ratios are exactly representable with low precision (see d just below), so I could use np.assert_array_equal().
control/statesp.py
Outdated
lti_sys = lti(squeeze(sys.num), squeeze(sys.den)) | ||
return StateSpace(lti_sys.A, lti_sys.B, lti_sys.C, lti_sys.D, | ||
sys.dt) | ||
# No Slycot. Scipy tf->ss can't handle MIMO, but static MIMO is an easy special case we can check for here |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment lines should have length no more than 79 char. PEP 8 recommends 72 for the case of comments, but in my experience a uniform max line length is easier to follow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, will fix. Sorry, it's pretty obvious now that I look at it. Emacs fills this to 68 columns, which in this case doesn't waste an extra line:
# No Slycot. Scipy tf->ss can't handle MIMO, but static
# MIMO is an easy special case we can check for here
if (sys.inputs != 1 or sys.outputs != 1): | ||
raise TypeError("No support for MIMO without slycot") | ||
|
||
# TODO: do we want to squeeze first and check dimenations? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should "dimenations" be "dimensions"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't take the credit for this one, the comment was there already ;). Not sure it's applicable anymore: the check that sys.inputs and sys.outputs are both 1 implies that squeeze will bring num and den to 1-D?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I agree. The comment is obsolete after the addition in commit c90a399 of the check that sys.inputs = sys.outputs = 1.
I am planning to review and perform maintenance on documentation and code comments, so I can delete this comment at that time.
As you might have noticed, a current Slycot release was made, and now the CI jobs for this PR are passing. Aside from my request about line length and question about the static gains MIMO test case, changes here are good to go. |
Check for static-gain (i.e., constant) transfer function matrix, and handle specially. Added unit tests for static SISO and MIMO plants.
02080e0
to
c5a8ad3
Compare
Fix for #81.