-
Notifications
You must be signed in to change notification settings - Fork 446
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
bnavigator
left a comment
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
mateqnmodule to allow the use of SciPy linear algebra functions as a replacement for Slycot functions. Among other things, this allows the use of thelqrcommand without having to install Slycot.I implemented this by changing all of the
mateqnfunctions (lyap,care,dare, etc) to accept atmethodkeyword that can either bescipyorslycot. The default value formethodisslycotif it is installed, otherwisescipy, so there is no change in behavior if you have Slycot.Other changes:
lqrto callcarerather than replicating the code and cleaned up a lot of the code inmateqnto be more Pythonic.slycot_checkfunction so that it stores the result of checking whetherslycotcan be imported rather than trying to import every time the function is called.mateqnfunctions (mateqn._check_shape) that provides more consistent errors (this also required updating some of the unit tests).dareto solve the generalized Sylvester equation usingslycot.sg02adrather than usingslycot.sg02mdto solve the simplified form of the discrete algebraic Riccati equation because there seems to be an error in the way thatstabilizingis handled insg02md(it returns the closed loop eigenvalues in the wrong order). (I'm working on generating a concrete counterexample for posting to Slycot.)