Replies: 2 comments 2 replies
-
|
This is all very attractive and, yes, I'd be interested improving opty with these ideas. Opty is an implementation of the simplest collocation method based on me reading Ton's various implementations he shared with me versus me studying the state of the art in collocation methods. I keep using it because I understand it, versus it being the best tool for the job. Deciding if expanding opty is a good idea to pursue, begs the question of whether I should study your dissertation and pycollo, and then give my efforts there. For example, is figuring out how to get pycollo to work with big EoMs a shorter solution path to get all what you list above for free? |
Beta Was this translation helpful? Give feedback.
-
|
On "A. Add support for the trapezoidal method". I think my current implementation may not allow methods that require evaluating the differential equations more than once at a node. Trapezoidal integration is: I'm not sure evaluation of f() with two different arguments works. Looks like I tried to figure out the trapezoidal method in #16 but abandoned it as I didn't see how it fit with the design. opty is, at least partially, fast because I never invert the mass matrix. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Just dropping some thoughts on things that could potentially be implemented in opty to improve (computational) performance and solutions. I've proposed these in an order that I think would make sense to work on them. Hopefully this acts as a starter for some discussion. If we agree that any of these are of interest we can open separate issues.
A. Add support the Trapezoidal method
opty currently supports the Backwards Euler and Midpoint methods. Both of these are implicit Runge-Kutta methods based on a specific set of quadrature points related to the Legendre polynomials; the Backwards Euler method is the first method from the Radau IIA family and the Midpoint method is the first method from the Gauss I family. Both of these are collocation schemes. In simple terms this means that the numerical method ensures that the approximating quadrature matches both the value of the underlying time function (state or control) and its derivative. The collocation condition (matching the derivative at the quadrature points) is enforced in different places for different schemes. The Backwards Euler method enforces the collocation condition at only the RHS of each stage while the Midpoint method enforces it at only the midpoint of each stage.
A third family of related collocation schemes is the Lobatto IIIA family. It's based on Lobatto quadrature points and enforces the collocation condition at both the LHS and RHS of each stage. The lowest order Lobatto IIIA method is the Trapezoidal method. Implementing this would be relatively straightforward as we could reuse the majority of the Backwards Euler method code. This would close #412.
B. Generalise constraints/Jacobian functions
opty currently formulates the constraints and Jacobian of the OCP differently depending on which integration method is selected. This means that we can't reuse cached C code if the integration method changes. It also potentially limits the ability to change the uniformity of discretisation in the future, e.g. have stages of different widths of stages using different orders of collocation method. This is important for efficient discretisation and mesh refinement, which could significantly improve computational performance for larger problems, i.e. allowing wide stages for smooth parts of the solution but making the mesh more dense where the solution is more nonlinear.
Currently, the Jacobian is formed by constructing the collocation constraint for a generic stage symbolically and then differentiating this with respect to the various variables in the problem. Instead, we could differentiate just the equations of motion (and any other equations that form the constraint equations of the OCP) with respect to all of the types of variable in the OCP and then use sparse matrix operations to transform this into the required Jacobian. The approach is detailed in Patterson, Michael A., and Anil V. Rao. "Exploiting sparsity in direct collocation pseudospectral methods for solving optimal control problems." Journal of Spacecraft and Rockets 49.2 (2012): 354-377.
C. Add support for higher-order Gauss I, Radau IIA (and Radau IA), and Lobatto IIIA methods
Higher order collocation methods are more computationally efficient than lower order ones as they allow the state/control of the OCP to be approximated to the same accuracy with fewer discretisation points. Implementing the first few higher order methods for each family of Legendre-Gauss quadrature would be relatively straightforward as the coefficients are well known:
If the constraint/Jacobian functions have been generalised, it would also be possible to implement even higher-order methods by programmatically generating the coefficients. The maths for this is well described in Butcher, John Charles. Numerical methods for ordinary differential equations. John Wiley & Sons, 2016.
D. Add support for exact second-order mode by computing the Lagrangian Hessian
IPOPT is significantly more efficient and stable if it can operate in second-order mode and use an exact Hessian. For an OCP, this required formulating and evaluating the Lagrangian Hessian for the problem. This can be pretty expensive as it requires taking an additional derivative and this is for an expression that already contains the Jacobian. However, this can be done efficiently by exploiting sparsity using the approach described again by Patterson, Michael A., and Anil V. Rao. "Exploiting sparsity in direct collocation pseudospectral methods for solving optimal control problems." Journal of Spacecraft and Rockets 49.2 (2012): 354-377.
E. Add support for computing mesh error after a successful NLP solve
A discretisation is only useful if it accurately approximates the state and control of an OCP. This can only really be determined by analysing the solution once a transcribed OCP has been numerically solved. There are lots of different approaches to determining the accuracy of a transcription that have been proposed. I think the simplest and most intuitive is the one described by Patterson, Michael A., William W. Hager, and Anil V. Rao. "A ph mesh refinement method for optimal control." Optimal Control Applications and Methods 36.4 (2015): 398-421. It looks at the solution and sees how well a polynomial of degree one greater than that used in the initial discretisation would approximate the solution for each stage. Doing something like this would open the door for implementing mesh refinement in the future.
Beta Was this translation helpful? Give feedback.
All reactions