-
Notifications
You must be signed in to change notification settings - Fork 438
LQR using SciPy #683
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
LQR using SciPy #683
Conversation
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.
Looks good. A few minor comments:
elif method == 'slycot': | ||
return _dare_slycot(A, B, Q, R, S, E, stabilizing) | ||
|
||
else: | ||
_check_shape("B", B, n, m) | ||
_check_shape("Q", Q, n, n, square=True, symmetric=True) |
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.
Maybe _dare_slycot()
and _dare_scipy()
should be on the same level?
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 agree the asymmetry is annoying. I left it this way to avoid changing code that was working. In care
everything is in the main function, so at some point we should clean all of these up to be more uniform (either a single function or use _method
uniformly).
This PR updates the
mateqn
module to allow the use of SciPy linear algebra functions as a replacement for Slycot functions. Among other things, this allows the use of thelqr
command without having to install Slycot.I implemented this by changing all of the
mateqn
functions (lyap
,care
,dare
, etc) to accept atmethod
keyword that can either bescipy
orslycot
. The default value formethod
isslycot
if it is installed, otherwisescipy
, so there is no change in behavior if you have Slycot.Other changes:
lqr
to callcare
rather than replicating the code and cleaned up a lot of the code inmateqn
to be more Pythonic.slycot_check
function so that it stores the result of checking whetherslycot
can be imported rather than trying to import every time the function is called.mateqn
functions (mateqn._check_shape
) that provides more consistent errors (this also required updating some of the unit tests).dare
to solve the generalized Sylvester equation usingslycot.sg02ad
rather than usingslycot.sg02md
to solve the simplified form of the discrete algebraic Riccati equation because there seems to be an error in the way thatstabilizing
is handled insg02md
(it returns the closed loop eigenvalues in the wrong order). (I'm working on generating a concrete counterexample for posting to Slycot.)