JAX-LaB Documentation
JAX-LaB provides differentiable lattice Boltzmann solvers for single-phase, multiphase, multicomponent, and thermal simulations on JAX-supported hardware.
Run a first simulation
Install the package from a source checkout, including optional visualization dependencies:
Run the two-dimensional lid-driven cavity example:
The example defines the lattice, solver, initial fields, boundary conditions, and output callback in one file. Use it as a compact template for a new single-phase simulation.
Choose an example
- Start with
examples/isothermal/singlephase/for single-phase flows. - Use
examples/isothermal/multiphase/for multiphase and multicomponent flows. - Use
examples/thermal/for coupled fluid-temperature simulations. - Use
examples/isothermal/differentiable/for inverse and differentiable workflows. - Use
examples/rendering/for simulations with JAX-native in-situ rendering.
Package layout
The simulation code is organized under jax_lab.core. Import lattices, collision
models, boundary conditions, equations of state, thermal solvers, and utilities
from their corresponding core modules:
Rendering is an independent package under jax_lab.render:
The most commonly used solver classes remain available directly from jax_lab
for concise application code. The API reference uses the explicit module paths so
that each class’s implementation location is clear.
Validate a source checkout
Install the development and documentation dependencies, then run the tests and build the Zensical site:
Project overview
JAX-LaB
[Documentation](https://piyush-ppradhan.github.io/JAX-LaB/) | [Paper](https://agupubs.onlinelibrary.wiley.com/doi/10.1029/2025MS005313?af=R)
A Python-based, differentiable, massively parallel lattice Boltzmann library for modeling multiphase and multiphysics flows & physics-based machine learning
Evaporation in Fontainebleau sandstone. |
Drainage through a beadpack geometry. |
Rayleigh-Taylor instability. |
Three-dimensional pool boiling. |
Droplet impingement on an inclined surface. |
Droplet growth from a capillary (in situ render). |
Key Features
- JAX Ecosystem Integration: Works with machine learning libraries such as Equinox, Flax, Haiku, and Optax.
- Differentiable LBM: Provides differentiable kernels for physics and deep learning applications.
- Scalable and Portable: Runs on multi-core CPUs, GPUs, and TPUs, with distributed support for simulations spanning hundreds of GPUs and billions of cells.
- Broad LBM Support: Includes several boundary conditions and collision kernels, along with Shan-Chen multiphase, multiphysics, and multicomponent flow modeling.
- User-Friendly Python Interface: Written entirely in Python, simplifying simulation setup and making library easy to extend.
- JAX Array and Shardmap: Offers a NumPy-like interface while leaving performance optimization to the compiler.
- GPU-Optimized: Per-shard boundary indices, scalar wetting/force stencils, and a fused symbolic MRT collision path reduce memory traffic and compiled kernel size.
- Visualization: Supports multiple output options, including JAX-native ray tracer for in situ surface, volume, and vector-field rendering of GPU/TPU arrays.
Capabilities
Multiphase Flow Modeling
Shan-Chen pseudopotential method with various modifications: - Support for high density ratio flows (tested for density ratios > 108) using improved forcing scheme. - Incorporates Equation of State (EOS) to model multiphase flows. Currently implemented EOS include Carnahan-Starling, Peng-Robinson, Redlich-Kwong, Redlich-Kwong-Soave and VanderWaals. - Density ratio independent surface tension control by directly modifying pressure tensor (MRT model).
Multicomponent Flow Support
Computations use pytrees to model any number of components, each with its own equation of state, initial condition, and boundary conditions, without requiring library modifications.
Thermal Flow Modeling
- Hybrid thermal LBM solver for two- and three-dimensional single-phase, multiphase, and multicomponent flows.
- Thermal equation is solved using lattice-based finite-difference stencils and fourth-order Runge-Kutta time integration.
Wetting model
Collision Models
- BGK
- Multi-Relaxation Time (MRT)
- Cascaded (Central Moment)
- KBC
Lattice
- D2Q9
- D3Q19
- D3Q27
Machine Learning
- Easy integration with JAX’s ecosystem of machine learning libraries
- Differentiable LBM kernels both for single and multiphase flows
- Differentiable boundary conditions
Compute Capabilities
- Distributed Multi-GPU support
- Mixed-Precision support (store vs compute)
- Local, per-shard boundary condition indices instead of global lists replicated on every device
- Scalar neighbor stencils for wetting and Shan-Chen force, avoiding per-direction streamed arrays
- Fused, symbolic MRT collision matrix
Output
- Binary and ASCII VTK output using PyVista
- HDF5/XDMF output using h5py
- JAX-native in-situ surface, refractive volume, and vector-field rendering and image output
- Distributed asynchronous checkpointing using orbax
- 3D mesh voxelizer using trimesh
Boundary Conditions
- Equilibrium: Sets prescribed velocity or pressure using equilibrium populations.
- Full-Way Bounceback: Reflects populations to impose a stationary, no-slip wall.
- Half-Way Bounceback: Imposes a no-slip wall halfway between fluid and solid nodes.
- Do Nothing: Allows populations to pass through unmodified.
- Zou-He: Imposes a prescribed velocity or pressure profile.
- Regularized: Provides a more stable, but more expensive, alternative to Zou-He.
- Extrapolation Outflow: Reduces wave reflections using extrapolation.
- Non-Equilibrium Extrapolation: Open boundary condition with prescribed density.
- Exact Non-Equilibrium Extrapolation: Mass-corrected open boundary condition with prescribed density.
- Interpolated Bounceback: Applies the Bouzidi scheme to curved or off-lattice walls.
- Convective Outflow: Supports outflow in applications such as porous media flow.
- Dirichlet: Prescribes temperature at the boundary.
- Neumann: Prescribes the normal temperature gradient.
Experimental Pallas backend
jax_lab.experimentalprovides GPU-optimized, structure-of-arrays (SoA) Pallas kernels for single- and multiphase LBM.- It supports multiple lattices, precision policies, boundary conditions, and multi-GPU execution.
- The API is experimental and requires SoA-compatible boundary conditions.
- ~3x performance of base implementation, ~0.5x memory footprint.
Accompanying Paper
The accompanying paper, published in Journal of Advances in Modeling Earth Systems (JAMES), is available here.
Documentation
Complete API documentation is available here, or you can build and preview it locally:
Installation Guide
JAX-LaB is distributed as the jax-lab package (import name jax_lab). The default install targets CPU:
Accelerator support
Hardware acceleration is selected through dependency extras, which delegate the compiled backend packages to JAX’s own extras:
cuda13-local/cuda12-local instead if you manage the CUDA toolkit yourself.
Optional I/O and visualization dependencies
The I/O and visualization utilities load their dependencies lazily (at call time, not at import time), so the core solver runs without them. The following packages are only needed if you call the corresponding functions:
| Package | Required by |
|---|---|
| PyVista | save_fields_vtk, save_BCs_vtk, live_volume_rendering |
| h5py | save_fields_hdf5_xdmf |
| matplotlib | save_image, live_volume_rendering |
| trimesh + Rtree | voxelize_stl |
Calling one of these functions without its dependency installed raises an ImportError naming the missing package. The io extra installs all of them at once (recommended for running the examples, most of which write VTK or image output):
pip install "jax-lab[cuda13,io]".
Development install
To work on JAX-LaB itself or run the bundled examples, install from source in editable mode:
[!NOTE] On macOS, please use the standard CPU installation, as JAX does not support GPU acceleration on this platform.
Run an example:
Solver components live under jax_lab.core, while the JAX-native rendering API
lives under jax_lab.render. For example:
Citation
If you use this software, please cite it as follows: