mpopt


Namempopt JSON
Version 1.0.2 PyPI version JSON
download
home_pagehttps://github.com/mpopt
SummaryA Multi-phase nonlinear Optimal control problem solver using Pseudo-spectral collocation
upload_time2024-07-04 07:14:22
maintainerNone
docs_urlNone
authorDevakumar THAMMISETTY, Colin Jones
requires_python>=3.12
licenseNone
keywords optimal control multi-phase ocp collocation adaptive grid refinement nonlinear optimization
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            [![pypi
pacakge](https://img.shields.io/pypi/v/mpopt.svg)](https://pypi.org/project/mpopt)
[![Coverage
Status](https://coveralls.io/repos/github/mpopt/mpopt/badge.svg)](https://coveralls.io/github/mpopt/mpopt)
[![Documentation
Status](https://readthedocs.org/projects/mpopt/badge/?version=latest)](https://mpopt.readthedocs.io/en/latest/?badge=latest)
[![python](https://img.shields.io/pypi/pyversions/mpopt)](https://pypi.org/project/mpopt/)
[![continuous-integration](https://github.com/mpopt/mpopt/actions/workflows/python-app.yml/badge.svg)](https://github.com/mpopt/mpopt/actions/workflows/python-package.yml)
[![Downloads](https://static.pepy.tech/badge/mpopt)](https://pepy.tech/project/mpopt)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![License: LGPL v3](https://img.shields.io/badge/License-LGPL_v3-blue.svg)](https://www.gnu.org/licenses/lgpl-3.0)

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](https://casadi.sourceforge.net/v3.3.0/api/html/d4/d89/group__nlpsol.html)
( NLP solver supports multiple solver plugins including
[IPOPT](https://casadi.sourceforge.net/v3.3.0/api/html/d4/d89/group__nlpsol.html#plugin_Nlpsol_ipopt),
[SNOPT](https://casadi.sourceforge.net/v3.3.0/api/html/d4/d89/group__nlpsol.html#plugin_Nlpsol_snopt),
[sqpmethod](https://casadi.sourceforge.net/v3.3.0/api/html/d4/d89/group__nlpsol.html#plugin_Nlpsol_sqpmethod),
[scpgen](https://casadi.sourceforge.net/v3.3.0/api/html/d4/d89/group__nlpsol.html#plugin_Nlpsol_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](https://pypi.org/project/mpopt/) 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.

```bash
pip install mpopt
```

-   (OR) Build directly from source (Terminal). Finally, `make run` to solve the moon-lander example described below.

```bash
git clone https://github.com/mpopt/mpopt.git --branch master
cd mpopt
make build
make run
source env/bin/activate
```

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}$$

```python
# 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()
```

Resources
---------------

-   Detailed implementation aspects of MPOPT are part of the [master
    thesis](http://dx.doi.org/10.13140/RG.2.2.19519.79528).
-   Quick introduction
    [presentation](http://dx.doi.org/10.13140/RG.2.2.14486.63040).
-   List of solved [examples](examples)
-   Features of MPOPT in [Jupyter
    Notebooks](docs/source/notebooks/getting_started.ipynb)

A pdf version of this documentation can be downloaded from [PDF
document](https://mpopt.readthedocs.io/_/downloads/en/latest/pdf/)

A must read Jupyter notebook on MPOPT features [Getting
Started](docs/source/notebooks/getting_started.ipynb)

Case studies
--------------

-   Quick demo of the solver using simple moon-lander fuel minimization
    OCP (bang-bang type control), refer [Quick features demo
    notebook](docs/source/notebooks/getting_started.ipynb) for more details. The
    image below shows the optimal altitude and the velocity profile
    (states) along with the optimal throttle (controls) to get minimum
    fuel trajectory to land on the Moon.

![image](docs/source/_static/ml_adaptive.png)

-   A complex real-world example of The SpaceX falcon9 rocket orbital
    launch with the booster recovery results are shown below. OCP is
    defined to find the optimal trajectory and the thrust profile for
    booster return, refer [SpaceX Falcon9 booster recovery
    notebook](docs/source/notebooks/falcon9_to_orbit.ipynb) for more details. The
    first image below is the MPOPT solution using adaptive mesh and the
    second one is the real-time data of the SpaceX Falcon9 launch of
    NROL76 mission. The ballistic altitude profile of the booster is
    evident in both MPOPT solution and the real-time telemetry. Further,
    the MPOPT velocity solution compares well with the real-time data
    even though the formulation is only a first order representation of
    the actual booster recovery problem.

![image](docs/source/_static/falcon9_mpopt.svg)

![image](docs/source/_static/real_time_falcon9_NROL76.png)

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](https://github.com/mpopt/mpopt/blob/master/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}}

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/mpopt",
    "name": "mpopt",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.12",
    "maintainer_email": null,
    "keywords": "optimal control, multi-phase OCP, collocation, adaptive grid refinement, nonlinear optimization",
    "author": "Devakumar THAMMISETTY, Colin Jones",
    "author_email": "deva.aerospace@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/e5/ce/7eda2159afd5473e6f8db17dcd9cc20a4d5cde637c12b0509c9364f79d50/mpopt-1.0.2.tar.gz",
    "platform": null,
    "description": "[![pypi\npacakge](https://img.shields.io/pypi/v/mpopt.svg)](https://pypi.org/project/mpopt)\n[![Coverage\nStatus](https://coveralls.io/repos/github/mpopt/mpopt/badge.svg)](https://coveralls.io/github/mpopt/mpopt)\n[![Documentation\nStatus](https://readthedocs.org/projects/mpopt/badge/?version=latest)](https://mpopt.readthedocs.io/en/latest/?badge=latest)\n[![python](https://img.shields.io/pypi/pyversions/mpopt)](https://pypi.org/project/mpopt/)\n[![continuous-integration](https://github.com/mpopt/mpopt/actions/workflows/python-app.yml/badge.svg)](https://github.com/mpopt/mpopt/actions/workflows/python-package.yml)\n[![Downloads](https://static.pepy.tech/badge/mpopt)](https://pepy.tech/project/mpopt)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n[![License: LGPL v3](https://img.shields.io/badge/License-LGPL_v3-blue.svg)](https://www.gnu.org/licenses/lgpl-3.0)\n\nMPOPT\n=====\n\n*MPOPT* is an open-source, extensible, customizable and easy\nto use python package that includes a collection of modules to solve\nmulti-stage non-linear optimal control problems(OCP) using\npseudo-spectral collocation methods.\n\nThe 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](https://casadi.sourceforge.net/v3.3.0/api/html/d4/d89/group__nlpsol.html)\n( NLP solver supports multiple solver plugins including\n[IPOPT](https://casadi.sourceforge.net/v3.3.0/api/html/d4/d89/group__nlpsol.html#plugin_Nlpsol_ipopt),\n[SNOPT](https://casadi.sourceforge.net/v3.3.0/api/html/d4/d89/group__nlpsol.html#plugin_Nlpsol_snopt),\n[sqpmethod](https://casadi.sourceforge.net/v3.3.0/api/html/d4/d89/group__nlpsol.html#plugin_Nlpsol_sqpmethod),\n[scpgen](https://casadi.sourceforge.net/v3.3.0/api/html/d4/d89/group__nlpsol.html#plugin_Nlpsol_scpgen)).\n\nMain features of the package are :\n\n-   Customizable collocation approximation, compatible with\n    Legendre-Gauss-Radau (LGR), Legendre-Gauss-Lobatto (LGL),\n    Chebyshev-Gauss-Lobatto (CGL) roots.\n-   Intuitive definition of single/multi-phase OCP.\n-   Supports Differential-Algebraic Equations (DAEs).\n-   Customized adaptive grid refinement schemes (Extendable)\n-   Gaussian quadrature and differentiation matrices are evaluated using algorithmic differentiation, thus, supporting arbitrarily high number of collocation points limited only by the computational resources.\n-   Intuitive post-processing module to retrieve and visualize the solution\n-   Good test coverage of the overall package\n-   Active development\n\nQuick start\n----------------\n\n-   Install from the [Python Package Index](https://pypi.org/project/mpopt/) 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.\n\n```bash\npip install mpopt\n```\n\n-   (OR) Build directly from source (Terminal). Finally, `make run` to solve the moon-lander example described below.\n\n```bash\ngit clone https://github.com/mpopt/mpopt.git --branch master\ncd mpopt\nmake build\nmake run\nsource env/bin/activate\n```\n\nA sample code to solve moon-lander OCP (2D) under 10 lines\n-------------------------------------------------------------\n\n**OCP** :\n> 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).\n\n$$\\begin{aligned}\n&\\min_{x, u}        & \\qquad & J = 0 + \\int_{t_0}^{t_f}u\\ dt\\\\\n&\\text{subject to} &      & \\dot{x_0} = x_1; \\dot{x_1} = u - 1.5\\\\\n &                 &     & x_0(t_f) = 0; \\ x_1(t_f) = 0\\\\\n&                  &      & x_0(t_0) = 10; \\ x_1(t_0) = -2\\\\\n&                  &       & x_0 \\geq 0; 0 \\leq u \\leq 3\\\\\n&                 &     & t_0 = 0.0; t_f = \\text{free variable}\n\\end{aligned}$$\n\n```python\n# Moon lander OCP direct collocation/multi-segment collocation\n\n# from context import mpopt # (Uncomment if running from source)\nfrom mpopt import mp\n\n# Define OCP\nocp = mp.OCP(n_states=2, n_controls=1)\nocp.dynamics[0] = lambda x, u, t: [x[1], u[0] - 1.5]\nocp.running_costs[0] = lambda x, u, t: u[0]\nocp.terminal_constraints[0] = lambda xf, tf, x0, t0: [xf[0], xf[1]]\nocp.x00[0] = [10.0, -2.0]\nocp.lbu[0], ocp.ubu[0] = 0, 3\nocp.lbx[0][0] = 0\n\n# Create optimizer(mpo), solve and post process(post) the solution\nmpo, post = mp.solve(ocp, n_segments=20, poly_orders=3, scheme=\"LGR\", plot=True)\nx, u, t, _ = post.get_data()\nmp.plt.show()\n```\n\nResources\n---------------\n\n-   Detailed implementation aspects of MPOPT are part of the [master\n    thesis](http://dx.doi.org/10.13140/RG.2.2.19519.79528).\n-   Quick introduction\n    [presentation](http://dx.doi.org/10.13140/RG.2.2.14486.63040).\n-   List of solved [examples](examples)\n-   Features of MPOPT in [Jupyter\n    Notebooks](docs/source/notebooks/getting_started.ipynb)\n\nA pdf version of this documentation can be downloaded from [PDF\ndocument](https://mpopt.readthedocs.io/_/downloads/en/latest/pdf/)\n\nA must read Jupyter notebook on MPOPT features [Getting\nStarted](docs/source/notebooks/getting_started.ipynb)\n\nCase studies\n--------------\n\n-   Quick demo of the solver using simple moon-lander fuel minimization\n    OCP (bang-bang type control), refer [Quick features demo\n    notebook](docs/source/notebooks/getting_started.ipynb) for more details. The\n    image below shows the optimal altitude and the velocity profile\n    (states) along with the optimal throttle (controls) to get minimum\n    fuel trajectory to land on the Moon.\n\n![image](docs/source/_static/ml_adaptive.png)\n\n-   A complex real-world example of The SpaceX falcon9 rocket orbital\n    launch with the booster recovery results are shown below. OCP is\n    defined to find the optimal trajectory and the thrust profile for\n    booster return, refer [SpaceX Falcon9 booster recovery\n    notebook](docs/source/notebooks/falcon9_to_orbit.ipynb) for more details. The\n    first image below is the MPOPT solution using adaptive mesh and the\n    second one is the real-time data of the SpaceX Falcon9 launch of\n    NROL76 mission. The ballistic altitude profile of the booster is\n    evident in both MPOPT solution and the real-time telemetry. Further,\n    the MPOPT velocity solution compares well with the real-time data\n    even though the formulation is only a first order representation of\n    the actual booster recovery problem.\n\n![image](docs/source/_static/falcon9_mpopt.svg)\n\n![image](docs/source/_static/real_time_falcon9_NROL76.png)\n\nFeatures and Limitations\n---------------------------\nWhile MPOPT is able to solve any Optimal control problem formulation in the Bolza form, the present limitations of MPOPT are,\n\n- Only continuous functions and derivatives are supported\n- Dynamics and constraints are to be written in CasADi variables (Familiarity with casadi variables and expressions is expected)\n- The adaptive grid though successful in generating robust solutions for simple problems, doesn't have a concrete proof on convergence.\n\n\nAuthors\n=======\n\n-   **Devakumar THAMMISETTY**\n-   **Prof. Colin Jones** (Co-author)\n\nLicense\n=======\n\nThis project is licensed under the GNU LGPL v3 - see the\n[LICENSE](https://github.com/mpopt/mpopt/blob/master/LICENSE) file for\ndetails\n\nAcknowledgements\n================\n\n-   **Petr Listov**\n\nCite\n=====\n\n-  D. Thammisetty, \u201cDevelopment of a multi-phase optimal control software for aerospace applications (mpopt),\u201d Master\u2019s thesis, Lausanne, EPFL, 2020.\n\n**BibTex entry**:\n\n    @mastersthesis{thammisetty2020development,\n          title={Development of a multi-phase optimal control software for aerospace applications (mpopt)},\n          author={Thammisetty, Devakumar},\n          year={2020},\n          school={Master\u2019s thesis, Lausanne, EPFL}}\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A Multi-phase nonlinear Optimal control problem solver using Pseudo-spectral collocation",
    "version": "1.0.2",
    "project_urls": {
        "Docmentation": "https://mpopt.readthedocs.io/",
        "Homepage": "https://github.com/mpopt",
        "Source": "https://github.com/mpopt/mpopt/",
        "Tracker": "https://github.com/mpopt/mpopt/issues"
    },
    "split_keywords": [
        "optimal control",
        " multi-phase ocp",
        " collocation",
        " adaptive grid refinement",
        " nonlinear optimization"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "117ac402dbef19295d8d76eb26c938a119461cfaf0b6e66e03e51b23a403271d",
                "md5": "9ef7bdd1d539b003129a6a3a2938e3d5",
                "sha256": "c27b6a6c32f8b4340a3b59df0b0e5d7438f62aee8f3969aaab0946523cab9999"
            },
            "downloads": -1,
            "filename": "mpopt-1.0.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9ef7bdd1d539b003129a6a3a2938e3d5",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.12",
            "size": 62894,
            "upload_time": "2024-07-04T07:14:03",
            "upload_time_iso_8601": "2024-07-04T07:14:03.495447Z",
            "url": "https://files.pythonhosted.org/packages/11/7a/c402dbef19295d8d76eb26c938a119461cfaf0b6e66e03e51b23a403271d/mpopt-1.0.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e5ce7eda2159afd5473e6f8db17dcd9cc20a4d5cde637c12b0509c9364f79d50",
                "md5": "a78cf74e10a67d97ed6c655c404a4c44",
                "sha256": "2f9a2a864e644ae04c5549d207d04527e234980f9296c8340f8bc27ad75e65e3"
            },
            "downloads": -1,
            "filename": "mpopt-1.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "a78cf74e10a67d97ed6c655c404a4c44",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.12",
            "size": 53147,
            "upload_time": "2024-07-04T07:14:22",
            "upload_time_iso_8601": "2024-07-04T07:14:22.797273Z",
            "url": "https://files.pythonhosted.org/packages/e5/ce/7eda2159afd5473e6f8db17dcd9cc20a4d5cde637c12b0509c9364f79d50/mpopt-1.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-07-04 07:14:22",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "mpopt",
    "github_project": "mpopt",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "mpopt"
}
        
Elapsed time: 0.40155s