Lettuce is a Computational Fluid Dynamics framework based on the lattice Boltzmann method (LBM).
- GPU-Accelerated Computation: Utilizes PyTorch for high performance and efficient GPU utilization.
- Rapid Prototyping: Supports both 2D and 3D simulations for quick and reliable analysis.
- Advanced Techniques: Integrates neural networks and automatic differentiation to enhance LBM.
- Optimized Performance: Includes custom PyTorch extensions for native CUDA kernels.
To find some very simple examples of how to use lettuce, please have a look at the examples. These will guide you through lettuce's main features. Please ensure you have Jupyter installed to run the Jupyter notebooks.
Lettuce is published on PyPI as lettucecfd; the import name and the command line tool stay lettuce.
Python 3.12 or newer is required.
pip install lettucecfdor, in a project managed with uv:
uv add lettucecfdThis installs the default PyTorch build from PyPI. To select a specific build (CPU only, or a particular CUDA version), see the section Depending on lettuce from another project below.
Check the installation by computing the convergence order on the CPU:
lettuce --no-cuda convergenceFor a CUDA-driven simulation on one GPU, omit --no-cuda, e.g. to measure the performance:
lettuce benchmarkIf CUDA is not found, make sure that CUDA-capable GPU drivers are installed and compatible with the CUDA version of the installed PyTorch build.
To work on lettuce itself, install the uv package manager, clone the repository and
let uv set up the environment, choosing one of the hardware extras cpu, cu124, cu126, cu128 or cu130:
git clone https://github.com/lettucecfd/lettuce
cd lettuce
uv sync --extra cpu # or cu124, cu126, cu128, cu130This installs lettuce in editable mode together with the development tools, so code changes take effect immediately. Run the test suite with:
uv run --extra cpu pytest testsWe successfully tested CUDA 12.4, 12.6, 12.8 and 13.0. See CONTRIBUTING.md for details on the development setup.
The distribution is published as lettucecfd; the import name stays
lettuce. Note that the extras (cpu, cu124, cu126, cu128, cu130) only constrain the PyTorch version —
uv's index configuration is not carried in the published package metadata, so
uv add lettucecfd[cu128] on its own installs the default PyTorch build from
PyPI. To get a specific CUDA build, copy the index configuration into your own
pyproject.toml:
[project]
dependencies = ["lettucecfd[cu128]"]
[tool.uv.sources]
torch = [{ index = "pytorch-cu128" }]
[[tool.uv.index]]
name = "pytorch-cu128"
url = "https://download.pytorch.org/whl/cu128"
explicit = trueSubstitute cu124, cu126, cu130 or cpu as needed — the extra and the
index URL have to name the same variant.
If you use Lettuce in your research, please cite the following paper:
@inproceedings{bedrunka2021lettuce,
title={Lettuce: PyTorch-Based Lattice Boltzmann Framework},
author={Bedrunka, Mario Christopher and Wilde, Dominik and Kliemank, Martin and Reith, Dirk and Foysi, Holger and Kr{\"a}mer, Andreas},
booktitle={High Performance Computing: ISC High Performance Digital 2021 International Workshops, Frankfurt am Main, Germany, June 24--July 2, 2021, Revised Selected Papers},
pages={40},
organization={Springer Nature}
}We use the following third-party packages:
This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.
- Free software: MIT license, as found in the LICENSE file.
