Practical overview
When it fits
Use it when a PyTorch model needs to participate in CasADi numerical optimization or learning-based optimal control, and the model is traceable and differentiable.
Who it is for
- Developers incorporating learned models into CasADi optimization problems.
- Control and robotics practitioners building learning-based optimal-control or trajectory-planning workflows.
Documented uses
- Use a learned PyTorch model as part of a CasADi optimization formulation.
- Build control or planning workflows that optimize trajectories using learned models.
- Explore Acados workflows using PyTorch-to-CasADi integration.
Requirements & limits
The project is a public repository with an MIT license.
- The integrated PyTorch model must be traceable and differentiable.
- The documented prerequisites include PyTorch 2.0 or later and a CMake-compatible C++ compiler.
- The Naive module supports only small multilayer perceptrons and CPU inference.
- The documentation recommends the Naive module for networks smaller than roughly three hidden layers of 64 neurons each.
- Acados is supported, but the documented material here does not specify exact supported configurations.
Check current requirements in the official documentation. Source-based guidance does not mean OpenViST has run or independently tested this project.
Install L4CasADi from PyPI for CPU use
Install the CPU-only L4CasADi package in a Python environment with PyTorch.
Before you start
- Python environment with PyTorch 2.0 or later.
- A CMake-compatible C++ build system; GCC 10 or later is recommended on Linux/macOS.
- Build dependencies: setuptools 68.1 or later, scikit-build 0.17 or later, CMake 3.27 or later, and Ninja 1.11 or later.
Steps
Install the PyTorch CPU version: the command below.
pip install torch>=2.0 --index-url https://download.pytorch.org/whl/cpuInstall the listed build dependencies in the Python environment.
Install L4CasADi with the command below. The flag is required so L4CasADi can find and link against the installed PyTorch.
pip install l4casadi --no-build-isolation
Expected outcome
L4CasADi is installed for CPU use in the Python environment.
Guide limitations
- This recipe is for CPU installation; CUDA setup is a separate process.
- On Windows, CMake and Visual C++ Build Tools are required instead of GCC, and the tools must be on PATH. Keep the build directory path within Windows' maximum character limit.
Install L4CasADi from source for CPU use
Build and install the CPU-only package from the L4CasADi repository.
Before you start
- Python environment with PyTorch 2.0 or later.
- A CMake-compatible C++ build system; GCC 10 or later is recommended on Linux/macOS.
- A working Git installation.
Steps
Clone the repository with the command below.
git clone https://github.com/Tim-Salzmann/l4casadi.gitInstall the build dependencies with the command below.
pip install -r requirements_build.txtBuild and install with the command below; this flag is required for L4CasADi to find and link against the installed PyTorch.
pip install . --no-build-isolation
Expected outcome
L4CasADi is built and installed from the cloned source for CPU use.
Guide limitations
- This recipe covers CPU installation only; CUDA setup is separate.
- On Windows, install CMake and Visual C++ Build Tools, ensure they are on PATH, and use a short build-directory path.
Sources & review
Source record details
- Source availability
- Active
- Sources checked
- 8 November 2026
- Original website title
- Tim-Salzmann/l4casadi · Official homepage title · retained in its source language

