Home

Awesome

License GitHub star chart

<p align="center"> <img src="assets/logo-transparent.png" alt="" width="300"> </p>

XLB: A Differentiable Massively Parallel Lattice Boltzmann Library in Python for Physics-Based Machine Learning

XLB is a fully differentiable 2D/3D Lattice Boltzmann Method (LBM) library that leverages hardware acceleration. It's built on top of the JAX library and is specifically designed to solve fluid dynamics problems in a computationally efficient and differentiable manner. Its unique combination of features positions it as an exceptionally suitable tool for applications in physics-based machine learning.

Accompanying Paper

Please refer to the accompanying paper for benchmarks, validation, and more details about the library.

Citing XLB

If you use XLB in your research, please cite the following paper:

@article{ataei2024xlb,
  title={{XLB}: A differentiable massively parallel lattice {Boltzmann} library in {Python}},
  author={Ataei, Mohammadmehdi and Salehipour, Hesam},
  journal={Computer Physics Communications},
  volume={300},
  pages={109187},
  year={2024},
  publisher={Elsevier}
}

Key Features

Showcase

<p align="center"> <img src="assets/airfoil.gif" width="800"> </p> <p align="center"> On GPU in-situ rendering using <a href="https://github.com/loliverhennigh/PhantomGaze">PhantomGaze</a> library (no I/O). Flow over a NACA airfoil using KBC Lattice Boltzmann Simulation with ~10 million cells. </p> <p align="center"> <img src="assets/car.png" alt="" width="500"> </p> <p align="center"> <a href=https://www.epc.ed.tum.de/en/aer/research-groups/automotive/drivaer > DrivAer model </a> in a wind-tunnel using KBC Lattice Boltzmann Simulation with approx. 317 million cells </p> <p align="center"> <img src="assets/building.png" alt="" width="700"> </p> <p align="center"> Airflow in to, out of, and within a building (~400 million cells) </p> <p align="center"> <img src="assets/XLB_diff.png" alt="" width="900"> </p> <p align="center"> The stages of a fluid density field from an initial state to the emergence of the "XLB" pattern through deep learning optimization at timestep 200 (see paper for details) </p> <br> <p align="center"> <img src="assets/cavity.gif" alt="" width="500"> </p> <p align="center"> Lid-driven Cavity flow at Re=100,000 (~25 million cells) </p>

Capabilities

LBM

Machine Learning

Lattice Models

Compute Capabilities

Output

Boundary conditions

Installation Guide

To use XLB, you must first install JAX and other dependencies using the following commands:

Please refer to https://github.com/google/jax for the latest installation documentation. The following table is taken from JAX's Github page.

HardwareInstructions
CPUpip install -U "jax[cpu]"
NVIDIA GPU on x86_64pip install -U "jax[cuda12_pip]" -f https://storage.googleapis.com/jax-releases/jax_cuda_releases.html
Google TPUpip install -U "jax[tpu]" -f https://storage.googleapis.com/jax-releases/libtpu_releases.html
AMD GPUUse Docker or build from source.
Apple GPUFollow Apple's instructions.

Note: We encountered challenges when executing XLB on Apple GPUs due to the lack of support for certain operations in the Metal backend. We advise using the CPU backend on Mac OS. We will be testing XLB on Apple's GPUs in the future and will update this section accordingly.

Install dependencies:

pip install pyvista numpy matplotlib Rtree trimesh jmp orbax-checkpoint termcolor

Run an example:

git clone https://github.com/Autodesk/XLB
cd XLB
export PYTHONPATH=.
python3 examples/CFD/cavity2d.py

Roadmap

Work in Progress (WIP)

Note: Some of the work-in-progress features can be found in the branches of the XLB repository. For contributions to these features, please reach out.

Wishlist

Contributions to these features are welcome. Please submit PRs for the Wishlist items.