rockit-meco


Namerockit-meco JSON
Version 0.1.36 PyPI version JSON
download
home_pagehttps://gitlab.kuleuven.be/meco-software/rockit
SummaryRapid Optimal Control Kit
upload_time2023-10-11 20:44:22
maintainer
docs_urlNone
authorMECO-Group
requires_python
licenseLICENSE
keywords ocp optimal control casadi
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # rockit
[![pipeline status](https://gitlab.kuleuven.be/meco-software/rockit/badges/master/pipeline.svg)](https://gitlab.kuleuven.be/meco-software/rockit/commits/master)
[![coverage report](https://gitlab.kuleuven.be/meco-software/rockit/badges/master/coverage.svg)](https://meco-software.pages.gitlab.kuleuven.be/rockit/coverage/index.html)
[![html docs](https://img.shields.io/static/v1.svg?label=docs&message=online&color=informational)](http://meco-software.pages.gitlab.kuleuven.be/rockit)
[![pdf docs](https://img.shields.io/static/v1.svg?label=docs&message=pdf&color=red)](http://meco-software.pages.gitlab.kuleuven.be/rockit/documentation-rockit.pdf)

# Description

![Rockit logo](docs/logo.png)

Rockit (Rapid Optimal Control kit) is a software framework to quickly prototype optimal control problems (aka dynamic optimization) that may arise in engineering: e.g.
iterative learning (ILC), model predictive control (NMPC), system identification, and motion planning.

Notably, the software allows free end-time problems and multi-stage optimal problems.
The software is currently focused on direct methods and relies heavily on [CasADi](http://casadi.org).
The software is developed by the [KU Leuven MECO research team](https://www.mech.kuleuven.be/en/pma/research/meco).

# Installation
Install using pip: `pip install rockit-meco`

# Hello world
(Taken from the [example gallery](https://meco-software.pages.gitlab.kuleuven.be/rockit/examples/))

You may try it live in your browser: [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/git/https%3A%2F%2Fgitlab.kuleuven.be%2Fmeco-software%2Frockit.git/v0.1.9?filepath=examples%2Fhello_world.ipynb).

Import the project:
```python
from rockit import *
```

Start an optimal control environment with a time horizon of 10 seconds
starting from t0=0s.
_(free-time problems can be configured with `FreeTime(initial_guess))_
```python
ocp = Ocp(t0=0, T=10)
```

Define two scalar states (vectors and matrices also supported)
```python
x1 = ocp.state()
x2 = ocp.state()
```

Define one piecewise constant control input
_(use `order=1` for piecewise linear)_
```
u = ocp.control()
```

Compose time-dependent expressions a.k.a. signals
_(explicit time-dependence is supported with `ocp.t`)_
```python
e = 1 - x2**2
```
Specify differential equations for states
_(DAEs also supported with `ocp.algebraic` and `add_alg`)_
```python
ocp.set_der(x1, e * x1 - x2 + u)
ocp.set_der(x2, x1)
```

Lagrange objective term: signals in an integrand
```python
ocp.add_objective(ocp.integral(x1**2 + x2**2 + u**2))
```
Mayer objective term: signals evaluated at t_f = t0_+T
```python
ocp.add_objective(ocp.at_tf(x1**2))
```

Path constraints
_(must be valid on the whole time domain running from `t0` to `tf`,
   grid options available such as `grid='integrator'` or `grid='inf'`)_
```python
ocp.subject_to(x1 >= -0.25)
ocp.subject_to(-1 <= (u <= 1 ))
```

Boundary constraints
```python
ocp.subject_to(ocp.at_t0(x1) == 0)
ocp.subject_to(ocp.at_t0(x2) == 1)
```

Pick an NLP solver backend
_(CasADi `nlpsol` plugin)_
```python
ocp.solver('ipopt')
```

Pick a solution method
such as `SingleShooting`, `MultipleShooting`, `DirectCollocation`
with arguments:
 * N -- number of control intervals
 * M -- number of integration steps per control interval
 * grid -- could specify e.g. UniformGrid() or GeometricGrid(4)
```python
method = MultipleShooting(N=10, intg='rk')
ocp.method(method)
```

Set initial guesses for states, controls and variables.
Default: zero
```python
ocp.set_initial(x2, 0)                 # Constant
ocp.set_initial(x1, ocp.t/10)          # Function of time
ocp.set_initial(u, linspace(0, 1, 10)) # Array
```

Solve:
```python
sol = ocp.solve()
```

In case the solver fails, you can still look at the solution:
_(you may need to wrap the solve line in try/except to avoid the script aborting)_
```python
sol = ocp.non_converged_solution
```

Show structure:
```python
ocp.spy()
```

![Structure of optimization problem](docs/hello_world_structure.png)

Post-processing:
```python
tsa, x1a = sol.sample(x1, grid='control')
tsb, x1b = sol.sample(x1, grid='integrator')
tsc, x1c = sol.sample(x1, grid='integrator', refine=100)
plot(tsa, x1a, '-')
plot(tsb, x1b, 'o')
plot(tsc, x1c, '.')
```

![Solution trajectory of states](docs/hello_world_states.png)

# Matlab interface

Rockit comes with a (almost) feature-complete interface to Matlab.
Installation steps:
 1. [Check](https://www.mathworks.com/content/dam/mathworks/mathworks-dot-com/support/sysreq/files/python-support.pdf) which Python versions your Matlab installation supports, e.g. `Python 3.6`
 2. Open up a compatible Python environment in a terminal (if you don't have one, consider [miniconda](https://docs.conda.io/en/latest/miniconda.html) and create an environment by performing commands `conda create --name myspace python=3.6` and `conda activate myspace` inside the Anaconda Prompt).
 3. Perform `pip install "rockit-meco>=0.1.12" "casadi>=3.5.5"` in that teminal
 4. Launch Matlab from that same terminal (Type the full path+name of the Matlab executable. In Windows you may find the Matlab executable by right-clicking the icon from the start menu; use quotes (") to encapsulate the full name if it contains spaces. e.g. `"C:\Program Files\Matlab\bin\matlab.exe"`)
 5. Install CasADi for Matlab from https://github.com/casadi/casadi/releases/tag/3.5.5: pick the latest applicable matlab archive, unzip it, and add it to the Matlab path (without subdirectories)
 6. Make sure you remove any other CasADi version from the Matlab path.
 7. Only for Matlab >=2019b: make sure you do have in-process ExecutionMode for speed `pyenv('ExecutionMode','InProcess')`
 8. Add rockit to the matlab path: `addpath(char(py.rockit.matlab_path))`
 9. Run the `hello_world` example from the [example directory](https://gitlab.kuleuven.be/meco-software/rockit/-/tree/master/examples)

Debugging:
 * Check if the correct CasADi Python is found: py.imp.find_module('casadi')
 * Check if the correct CasADi Matlab is found: `edit casadi.SerializerBase`, should have a method called 'connect'
 * Matlab error "Conversion to double from py.numpy.ndarray is not possible." -> Consult your Matlab release notes to verify that your Python version is supported
 * Matlab error "Python Error: RuntimeError: .../casadi/core/serializing_stream.hpp:171: Assertion "false" failed:" -> May occur on Linux for some configurations. Consult rockit authors

# External interfaces
In the long run, we aim to add a bunch of interfaces to [third-party dynamic optimization solvers](https://github.com/meco-group/dynamic_optimization_inventory/blob/main/list.csv).
At the moment, the following solvers are interfaced:
 * [acados](https://github.com/acados/acados) -- [examples](https://gitlab.kuleuven.be/meco-software/rockit/-/tree/master/rockit/external/acados/examples)
 * [grampc](https://sourceforge.net/projects/grampc/) -- [examples](https://gitlab.kuleuven.be/meco-software/rockit-plugin-grampc/-/tree/main/examples)

Installation when using rockit from git
 * `git submodule update --init --recursive`
 * Windows only: install Visual Studio (supported: 2017,2019,2022) with the following components: `C++ Desktop Development` workload, and verify that the following components are also installed: `MSBuild`,`MSVC C++ x64/x86 build tools`,`C++ Cmake tools`,`C++/CLI support`

 
# Presentations

 * Benelux 2020: [Effortless modeling of optimal control problems with rockit](https://youtu.be/dS4U_k6B904)
 * Demo @ FM symposium: [Rockit: optimal motion planning made easy](https://github.com/meco-group/rockit_demo)

# Citing
Gillis, Joris ; Vandewal, Bastiaan ; Pipeleers, Goele ; Swevers, Jan
"Effortless modeling of optimal control problems with rockit", 39th Benelux Meeting on Systems and Control 2020, Elspeet, The Netherlands
            

Raw data

            {
    "_id": null,
    "home_page": "https://gitlab.kuleuven.be/meco-software/rockit",
    "name": "rockit-meco",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "OCP optimal control casadi",
    "author": "MECO-Group",
    "author_email": "joris.gillis@kuleuven.be",
    "download_url": "https://files.pythonhosted.org/packages/1c/f4/0e0fb7b78b8efa21fd0becc6af1095049ca88750fbd2f76c2c343c0dd0a1/rockit-meco-0.1.36.tar.gz",
    "platform": null,
    "description": "# rockit\n[![pipeline status](https://gitlab.kuleuven.be/meco-software/rockit/badges/master/pipeline.svg)](https://gitlab.kuleuven.be/meco-software/rockit/commits/master)\n[![coverage report](https://gitlab.kuleuven.be/meco-software/rockit/badges/master/coverage.svg)](https://meco-software.pages.gitlab.kuleuven.be/rockit/coverage/index.html)\n[![html docs](https://img.shields.io/static/v1.svg?label=docs&message=online&color=informational)](http://meco-software.pages.gitlab.kuleuven.be/rockit)\n[![pdf docs](https://img.shields.io/static/v1.svg?label=docs&message=pdf&color=red)](http://meco-software.pages.gitlab.kuleuven.be/rockit/documentation-rockit.pdf)\n\n# Description\n\n![Rockit logo](docs/logo.png)\n\nRockit (Rapid Optimal Control kit) is a software framework to quickly prototype optimal control problems (aka dynamic optimization) that may arise in engineering: e.g.\niterative learning (ILC), model predictive control (NMPC), system identification, and motion planning.\n\nNotably, the software allows free end-time problems and multi-stage optimal problems.\nThe software is currently focused on direct methods and relies heavily on [CasADi](http://casadi.org).\nThe software is developed by the [KU Leuven MECO research team](https://www.mech.kuleuven.be/en/pma/research/meco).\n\n# Installation\nInstall using pip: `pip install rockit-meco`\n\n# Hello world\n(Taken from the [example gallery](https://meco-software.pages.gitlab.kuleuven.be/rockit/examples/))\n\nYou may try it live in your browser: [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/git/https%3A%2F%2Fgitlab.kuleuven.be%2Fmeco-software%2Frockit.git/v0.1.9?filepath=examples%2Fhello_world.ipynb).\n\nImport the project:\n```python\nfrom rockit import *\n```\n\nStart an optimal control environment with a time horizon of 10 seconds\nstarting from t0=0s.\n_(free-time problems can be configured with `FreeTime(initial_guess))_\n```python\nocp = Ocp(t0=0, T=10)\n```\n\nDefine two scalar states (vectors and matrices also supported)\n```python\nx1 = ocp.state()\nx2 = ocp.state()\n```\n\nDefine one piecewise constant control input\n_(use `order=1` for piecewise linear)_\n```\nu = ocp.control()\n```\n\nCompose time-dependent expressions a.k.a. signals\n_(explicit time-dependence is supported with `ocp.t`)_\n```python\ne = 1 - x2**2\n```\nSpecify differential equations for states\n_(DAEs also supported with `ocp.algebraic` and `add_alg`)_\n```python\nocp.set_der(x1, e * x1 - x2 + u)\nocp.set_der(x2, x1)\n```\n\nLagrange objective term: signals in an integrand\n```python\nocp.add_objective(ocp.integral(x1**2 + x2**2 + u**2))\n```\nMayer objective term: signals evaluated at t_f = t0_+T\n```python\nocp.add_objective(ocp.at_tf(x1**2))\n```\n\nPath constraints\n_(must be valid on the whole time domain running from `t0` to `tf`,\n   grid options available such as `grid='integrator'` or `grid='inf'`)_\n```python\nocp.subject_to(x1 >= -0.25)\nocp.subject_to(-1 <= (u <= 1 ))\n```\n\nBoundary constraints\n```python\nocp.subject_to(ocp.at_t0(x1) == 0)\nocp.subject_to(ocp.at_t0(x2) == 1)\n```\n\nPick an NLP solver backend\n_(CasADi `nlpsol` plugin)_\n```python\nocp.solver('ipopt')\n```\n\nPick a solution method\nsuch as `SingleShooting`, `MultipleShooting`, `DirectCollocation`\nwith arguments:\n * N -- number of control intervals\n * M -- number of integration steps per control interval\n * grid -- could specify e.g. UniformGrid() or GeometricGrid(4)\n```python\nmethod = MultipleShooting(N=10, intg='rk')\nocp.method(method)\n```\n\nSet initial guesses for states, controls and variables.\nDefault: zero\n```python\nocp.set_initial(x2, 0)                 # Constant\nocp.set_initial(x1, ocp.t/10)          # Function of time\nocp.set_initial(u, linspace(0, 1, 10)) # Array\n```\n\nSolve:\n```python\nsol = ocp.solve()\n```\n\nIn case the solver fails, you can still look at the solution:\n_(you may need to wrap the solve line in try/except to avoid the script aborting)_\n```python\nsol = ocp.non_converged_solution\n```\n\nShow structure:\n```python\nocp.spy()\n```\n\n![Structure of optimization problem](docs/hello_world_structure.png)\n\nPost-processing:\n```python\ntsa, x1a = sol.sample(x1, grid='control')\ntsb, x1b = sol.sample(x1, grid='integrator')\ntsc, x1c = sol.sample(x1, grid='integrator', refine=100)\nplot(tsa, x1a, '-')\nplot(tsb, x1b, 'o')\nplot(tsc, x1c, '.')\n```\n\n![Solution trajectory of states](docs/hello_world_states.png)\n\n# Matlab interface\n\nRockit comes with a (almost) feature-complete interface to Matlab.\nInstallation steps:\n 1. [Check](https://www.mathworks.com/content/dam/mathworks/mathworks-dot-com/support/sysreq/files/python-support.pdf) which Python versions your Matlab installation supports, e.g. `Python 3.6`\n 2. Open up a compatible Python environment in a terminal (if you don't have one, consider [miniconda](https://docs.conda.io/en/latest/miniconda.html) and create an environment by performing commands `conda create --name myspace python=3.6` and `conda activate myspace` inside the Anaconda Prompt).\n 3. Perform `pip install \"rockit-meco>=0.1.12\" \"casadi>=3.5.5\"` in that teminal\n 4. Launch Matlab from that same terminal (Type the full path+name of the Matlab executable. In Windows you may find the Matlab executable by right-clicking the icon from the start menu; use quotes (\") to encapsulate the full name if it contains spaces. e.g. `\"C:\\Program Files\\Matlab\\bin\\matlab.exe\"`)\n 5. Install CasADi for Matlab from https://github.com/casadi/casadi/releases/tag/3.5.5: pick the latest applicable matlab archive, unzip it, and add it to the Matlab path (without subdirectories)\n 6. Make sure you remove any other CasADi version from the Matlab path.\n 7. Only for Matlab >=2019b: make sure you do have in-process ExecutionMode for speed `pyenv('ExecutionMode','InProcess')`\n 8. Add rockit to the matlab path: `addpath(char(py.rockit.matlab_path))`\n 9. Run the `hello_world` example from the [example directory](https://gitlab.kuleuven.be/meco-software/rockit/-/tree/master/examples)\n\nDebugging:\n * Check if the correct CasADi Python is found: py.imp.find_module('casadi')\n * Check if the correct CasADi Matlab is found: `edit casadi.SerializerBase`, should have a method called 'connect'\n * Matlab error \"Conversion to double from py.numpy.ndarray is not possible.\" -> Consult your Matlab release notes to verify that your Python version is supported\n * Matlab error \"Python Error: RuntimeError: .../casadi/core/serializing_stream.hpp:171: Assertion \"false\" failed:\" -> May occur on Linux for some configurations. Consult rockit authors\n\n# External interfaces\nIn the long run, we aim to add a bunch of interfaces to [third-party dynamic optimization solvers](https://github.com/meco-group/dynamic_optimization_inventory/blob/main/list.csv).\nAt the moment, the following solvers are interfaced:\n * [acados](https://github.com/acados/acados) -- [examples](https://gitlab.kuleuven.be/meco-software/rockit/-/tree/master/rockit/external/acados/examples)\n * [grampc](https://sourceforge.net/projects/grampc/) -- [examples](https://gitlab.kuleuven.be/meco-software/rockit-plugin-grampc/-/tree/main/examples)\n\nInstallation when using rockit from git\n * `git submodule update --init --recursive`\n * Windows only: install Visual Studio (supported: 2017,2019,2022) with the following components: `C++ Desktop Development` workload, and verify that the following components are also installed: `MSBuild`,`MSVC C++ x64/x86 build tools`,`C++ Cmake tools`,`C++/CLI support`\n\n \n# Presentations\n\n * Benelux 2020: [Effortless modeling of optimal control problems with rockit](https://youtu.be/dS4U_k6B904)\n * Demo @ FM symposium: [Rockit: optimal motion planning made easy](https://github.com/meco-group/rockit_demo)\n\n# Citing\nGillis, Joris ; Vandewal, Bastiaan ; Pipeleers, Goele ; Swevers, Jan\n\"Effortless modeling of optimal control problems with rockit\", 39th Benelux Meeting on Systems and Control 2020, Elspeet, The Netherlands",
    "bugtrack_url": null,
    "license": "LICENSE",
    "summary": "Rapid Optimal Control Kit",
    "version": "0.1.36",
    "project_urls": {
        "Download": "https://gitlab.kuleuven.be/meco-software/rockit/-/archive/v0.1.36/rockit-v0.1.36.tar.gz",
        "Homepage": "https://gitlab.kuleuven.be/meco-software/rockit"
    },
    "split_keywords": [
        "ocp",
        "optimal",
        "control",
        "casadi"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1cf40e0fb7b78b8efa21fd0becc6af1095049ca88750fbd2f76c2c343c0dd0a1",
                "md5": "8238fd81b77ef4ece4b07873ed841c9b",
                "sha256": "aafe40c4144b8acf64cda32565fc8caf6446720e74ad6b5ce52454445e52d64e"
            },
            "downloads": -1,
            "filename": "rockit-meco-0.1.36.tar.gz",
            "has_sig": false,
            "md5_digest": "8238fd81b77ef4ece4b07873ed841c9b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 116900,
            "upload_time": "2023-10-11T20:44:22",
            "upload_time_iso_8601": "2023-10-11T20:44:22.082751Z",
            "url": "https://files.pythonhosted.org/packages/1c/f4/0e0fb7b78b8efa21fd0becc6af1095049ca88750fbd2f76c2c343c0dd0a1/rockit-meco-0.1.36.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-11 20:44:22",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "rockit-meco"
}
        
Elapsed time: 0.12520s