Skip to main content

A Multi-phase nonlinear Optimal control problem solver using Pseudo-spectral collocation

Project description

pypi pacakge Build Status Coverage Status Documentation Status python continuous-integration Downloads Code style: black License: LGPL v3

MPOPT

MPOPT is an open-source, extensible, customizable and easy to use python package that includes a collection of modules to solve multi-stage non-linear optimal control problems(OCP) using pseudo-spectral collocation methods.

The package uses collocation methods to construct a Nonlinear programming problem (NLP) representation of OCP. The resulting NLP is then solved by algorithmic differentiation based CasADi nlpsolver ( NLP solver supports multiple solver plugins including IPOPT, SNOPT, sqpmethod, scpgen).

Main features of the package are :

  • Customizable collocation approximation, compatible with Legendre-Gauss-Radau (LGR), Legendre-Gauss-Lobatto (LGL), Chebyshev-Gauss-Lobatto (CGL) roots.
  • Intuitive definition of single/multi-phase OCP.
  • Supports Differential-Algebraic Equations (DAEs).
  • Customized adaptive grid refinement schemes (Extendable)
  • Gaussian quadrature and differentiation matrices are evaluated using algorithmic differentiation, thus, supporting arbitrarily high number of collocation points limited only by the computational resources.
  • Intuitive post-processing module to retrieve and visualize the solution
  • Good test coverage of the overall package
  • Active development

Quick start

  • Install from the Python Package Index repository using the following terminal command, then copy paste the code from example below in a file (test.py) and run (python3 test.py) to confirm the installation.
pip install mpopt
  • (OR) Build directly from source (Terminal). Finally, make run to solve the moon-lander example described below.
git clone https://github.com/mpopt/mpopt.git --branch master
cd mpopt
make install
make test

A sample code to solve moon-lander OCP (2D) under 10 lines

OCP :

Find optimal path, i.e Height ( $x_0$ ), Velocity ( $x_1$ ) and Throttle ( $u$ ) to reach the surface: Height (0m), Velocity (0m/s) from: Height (10m) and velocity(-2m/s) with: minimum fuel (u).

$$\begin{aligned} &\min_{x, u} & \qquad & J = 0 + \int_{t_0}^{t_f}u\ dt\ &\text{subject to} & & \dot{x_0} = x_1; \dot{x_1} = u - 1.5\ & & & x_0(t_f) = 0; \ x_1(t_f) = 0\ & & & x_0(t_0) = 10; \ x_1(t_0) = -2\ & & & x_0 \geq 0; 0 \leq u \leq 3\ & & & t_0 = 0.0; t_f = \text{free variable} \end{aligned}$$

# Moon lander OCP direct collocation/multi-segment collocation

# from context import mpopt # (Uncomment if running from source)
from mpopt import mp

# Define OCP
ocp = mp.OCP(n_states=2, n_controls=1)
ocp.dynamics[0] = lambda x, u, t: [x[1], u[0] - 1.5]
ocp.running_costs[0] = lambda x, u, t: u[0]
ocp.terminal_constraints[0] = lambda xf, tf, x0, t0: [xf[0], xf[1]]
ocp.x00[0] = [10.0, -2.0]
ocp.lbu[0], ocp.ubu[0] = 0, 3
ocp.lbx[0][0] = 0

# Create optimizer(mpo), solve and post process(post) the solution
mpo, post = mp.solve(ocp, n_segments=20, poly_orders=3, scheme="LGR", plot=True)
x, u, t, _ = post.get_data()
mp.plt.show()
  • Experiment with different collocation schemes by changing "LGR" to "CGL" or "LGL" in the above script.
  • Update the grid to recompute solution (Ex. n_segments=3, poly_orders=[3, 30, 3]).
  • For a detailed demo of the mpopt features, refer the notebook getting_started.ipynb

Resources

Features and Limitations

While MPOPT is able to solve any Optimal control problem formulation in the Bolza form, the present limitations of MPOPT are,

  • Only continuous functions and derivatives are supported
  • Dynamics and constraints are to be written in CasADi variables (Familiarity with casadi variables and expressions is expected)
  • The adaptive grid though successful in generating robust solutions for simple problems, doesn't have a concrete proof on convergence.

Authors

  • Devakumar THAMMISETTY
  • Prof. Colin Jones (Co-author)

License

This project is licensed under the GNU LGPL v3 - see the LICENSE file for details

Acknowledgements

  • Petr Listov

Cite

  • D. Thammisetty, “Development of a multi-phase optimal control software for aerospace applications (mpopt),” Master’s thesis, Lausanne, EPFL, 2020.

BibTex entry:

@mastersthesis{thammisetty2020development,
      title={Development of a multi-phase optimal control software for aerospace applications (mpopt)},
      author={Thammisetty, Devakumar},
      year={2020},
      school={Master’s thesis, Lausanne, EPFL}}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mpopt-0.1.8.tar.gz (49.2 kB view details)

Uploaded Source

Built Distributions

mpopt-0.1.8-py3.8.egg (109.1 kB view details)

Uploaded Source

mpopt-0.1.8-py3-none-any.whl (51.8 kB view details)

Uploaded Python 3

File details

Details for the file mpopt-0.1.8.tar.gz.

File metadata

  • Download URL: mpopt-0.1.8.tar.gz
  • Upload date:
  • Size: 49.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.0 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.10

File hashes

Hashes for mpopt-0.1.8.tar.gz
Algorithm Hash digest
SHA256 caf1b531f368ab04c7b322f78fd73f76591fce222a55ae069ee7a451525f945a
MD5 35e00fcb31ea23b65bf80c0ff58954b6
BLAKE2b-256 2fbea8001b6cc5ef29dcf24312b1434f80e24125480f7454d7735e40e3af6418

See more details on using hashes here.

Provenance

File details

Details for the file mpopt-0.1.8-py3.8.egg.

File metadata

  • Download URL: mpopt-0.1.8-py3.8.egg
  • Upload date:
  • Size: 109.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.0 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.10

File hashes

Hashes for mpopt-0.1.8-py3.8.egg
Algorithm Hash digest
SHA256 8bbed5b6ecedbaf6042546961542d08828c68f8559638d8b60c2068247850782
MD5 9f267109787b45bc120852ed756e7a8c
BLAKE2b-256 00a1562bf2c0186958ac5628fb02a4c6b36e31674c3a2f7d08e30ff21bdcd276

See more details on using hashes here.

Provenance

File details

Details for the file mpopt-0.1.8-py3-none-any.whl.

File metadata

  • Download URL: mpopt-0.1.8-py3-none-any.whl
  • Upload date:
  • Size: 51.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.0 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.10

File hashes

Hashes for mpopt-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 7d6066c86c0acaab1c2f429e3f2503a6a01f7339f1e73e4d6c4ec24fc9a8864b
MD5 0a083702360d2c6d962de8933932bc03
BLAKE2b-256 7b281ecd75738044d8bd4945a2fd1e3bb29aa565879037ff8722792b5f3f4f1e

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page