Installation

Linux/MacOS

Prerequisites

Clone the repository and recursively update submodules:

git clone https://github.com/leap-c/leap-c.git
cd leap-c
git submodule update --init --recursive

Python

Create a virtual environment and activate it. Assuming a required Python version of 3.11 or newer, you can use the following commands:

python3 -m venv .venv
source .venv/bin/activate

The following steps assume that the virtual environment is activated.

acados

Then change into the acados directory

cd external/acados

and build it as described in the acados documentation. When running the cmake command, include the options -DACADOS_WITH_OPENMP=ON -DACADOS_NUM_THREADS=1. Afterwards, install the python interface of acados.

PyTorch

Install PyTorch as described on the PyTorch website.

To install CPU-only PyTorch you can use:

pip install torch --extra-index-url https://download.pytorch.org/whl/cpu

Install leap-c

To install the package containing minimum dependencies in the root directory of the repository, run:

pip install -e .

For also enabling rendering in some of our examples use:

pip install -e ".[rendering]"

For development, you might want to install all additional dependencies:

pip install -e ".[dev]"

See the pyproject.toml for more information on package configurations.

Troubleshooting

In the troubleshooting tab, we highlight how to fix common problems arising while using leap-c with VS Code.

Windows

We recommend to use WSL (Windows Subsystem for Linux) and then following the guide above. You can then conveniently program on your WSL, e.g., by using VS Code on Windows together with the “Remote Development” extension pack.

Note the installation instructions for acados regarding WSL. Also note the troubleshooting section for plt.show() in WSL below.

Testing

To run the tests, use:

pytest tests -vv -s

Linting and Formatting

Only relevant if you want to contribute to the repository. For keeping our code style and our diffs consistent we use the Ruff linter and formatter.

To make this as easy as possible we also provide a pre-commit config for running the linter and formatter automatically at every commit. For enabling pre-commit follow these steps:

  1. Install pre-commit using pip (already done if you installed the additional “[dev]” dependencies of leap-c).

pip install pre-commit
  1. In the leap-c root directory run

pre-commit install

Done! Now every commit will automatically be linted and formatted.