JAX-LaB: A Python-based, Accelerated, Differentiable Massively Parallel Lattice Boltzmann Library for Modeling Multiphase and Multiphysics Flows & Physics-Based Machine Learning
JAX-LaB is a fully differentiable, accelerated multiphysics and multiphase 2D/3D Lattice Boltzmann Method (LBM) Python library written in JAX and it provides a unified workflow for forward and inverse modeling of multiphase flows. JAX-LaB is an extension of XLB and adds support multiphase and multiphysics flows to the original library.
Accompanying Paper
The accompanying paper, published in Journal of Advances in Modeling Earth Systems (JAMES), is available here.
Showcase
Contact angle hysteresis: Left: droplet impinging on inclined surface (MRT collision model). Right: Droplet undergoing evaporation (Cascaded collision model). Simulated using Peng-Robinson EOS, geometric wetting.
Time evolution of liquid distribution in a Fontainebleau sandstone during evaporation simulated using the Cascaded (central-moment) collision model.
Vapor generation and departure during a two-dimensional pool-boiling simulation.
On GPU in-situ rendering using PhantomGaze library (no I/O). Droplet impact on dry surface using MRT collision model with ~16 million cells. (single component, multiphase simulation, density ratio: 350, fluid modeled using Peng-Robinson EOS).
In-situ GPU rendering of drainage in a porous geometry. BGK collision model, 110 million cells.
Temporal evolution of the density field determined using neural network for the inverse multiphase flow control problem of forming a droplet at t = 900. The MLP output is used as the initial condition for LBM and the backpropagation step during training leverages the auto-differentiation capabilities of JAX-LaB (see paper for details).
Key Features
- Integration with JAX Ecosystem: The library can be easily integrated with JAX's robust ecosystem of machine learning libraries such as Equinox Flax, Haiku, Optax, and many more.
- Differentiable LBM Kernels: JAX-LaB provides differentiable LBM kernels that can be used in differentiable physics and deep learning applications.
- Scalability: JAX-LaB is capable of scaling on distributed multi-GPU systems, enabling the execution of large-scale simulations on hundreds of GPUs with billions of cells.
- Support for Various LBM Boundary Conditions and Kernels: JAX-LaB supports several LBM boundary conditions and collision kernels.
- Support for Multiphase, Multiphysics and Multicomponent flows: JAX-LaB can accurately model multiphysics and multiphase flows using Shan-Chen method, simulating complex interface dynamics without tracking any interface.
- User-Friendly Interface: Written entirely in Python, JAX-LaB emphasizes a highly accessible interface that allows users to extend the library with ease and quickly set up and run new simulations.
- Leverages JAX Array and Shardmap: The library incorporates the new JAX array unified array type and JAX shardmap, providing users with a numpy-like interface. This allows users to focus solely on the semantics, leaving performance optimizations to the compiler.
- Platform Versatility: The same JAX-LaB code can be executed on a variety of platforms including multi-core CPUs, single or multi-GPU systems, TPUs, and it also supports distributed runs on multi-GPU systems or TPU Pod slices.
- Visualization: JAX-LaB provides a variety of visualization options including in-situ on GPU rendering using PhantomGaze.
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 collision model only).
Multicomponent Flow Support
JAX-LaB takes advantage of pytrees for computation hence, it can model any number of components (each with their own equation of state, initial condition and boundary conditions) without any user modification.
Thermal Flow Modeling
JAX-LaB provides a hybrid thermal LBM solver for two- and three-dimensional flows. The fluid is advanced with LBM, while the temperature advection-diffusion equation is solved on the same lattice using isotropic finite-difference stencils and fourth-order Runge-Kutta time integration. The complete fluid-temperature update remains implemented in JAX and supports distributed execution.
- Single-phase thermal flow:
Thermalcouples a configured fluid solver to heat transport with constant or spatially varying specific heat and thermal conductivity. User-defined heat sources and buoyancy forcing are supported. - Multiphase thermal flow:
MultiphaseThermalcouples a shared temperature field to the local equation of state and includes the pressure-work phase-change term. This enables evaporation, condensation and boiling without explicitly tracking the liquid-vapor interface. - Thermal boundary conditions: Prescribed-temperature (Dirichlet) and prescribed-normal-gradient (Neumann) conditions can be combined with periodic boundaries.
Wetting model
- Wetting behavior of fluids can be modeled using the geometric wetting scheme and the improved virtual density scheme.
Collision Models
- BGK
- Multi-Relaxation Time (MRT)
- Cascaded Model
- 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)
Output
- Binary and ASCII VTK output (based on PyVista library)
- HDF5/XDMF output (based on h5py) to maximize I/O speed and minimize storage requirement
- In-situ rendering using PhantomGaze library
- Orbax-based distributed asynchronous checkpointing
- Image Output
- 3D mesh voxelizer using trimesh
Boundary conditions
-
Equilibrium BC: In this boundary condition, the fluid populations are assumed to be in at equilibrium. Can be used to set prescribed velocity or pressure.
-
Full-Way Bounceback BC: In this boundary condition, the velocity of the fluid populations is reflected back to the fluid side of the boundary, resulting in zero fluid velocity at the boundary.
-
Half-Way Bounceback BC: Similar to the Full-Way Bounceback BC, in this boundary condition, the velocity of the fluid populations is partially reflected back to the fluid side of the boundary, resulting in a non-zero fluid velocity at the boundary.
-
Do Nothing BC: In this boundary condition, the fluid populations are allowed to pass through the boundary without any reflection or modification.
-
Zouhe BC: This boundary condition is used to impose a prescribed velocity or pressure profile at the boundary.
-
Regularized BC: This boundary condition is used to impose a prescribed velocity or pressure profile at the boundary. This BC is more stable than ZouHe BC, but computationally more expensive.
-
Extrapolation Outflow BC: A type of outflow boundary condition that uses extrapolation to avoid strong wave reflections.
-
Interpolated Bounceback BC: Interpolated bounce-back boundary condition due to Bouzidi for a lattice Boltzmann method simulation.
-
Convective Outflow BC: Convective outflow boundary condition, useful for porous media flows.
Installation Guide
JAX-LaB is distributed as the jax-lab package (import name jax_lab). The default install targets CPU:
pip install jax-lab
Accelerator support
Hardware acceleration is selected through dependency extras, which delegate the compiled backend packages to JAX's own extras:
pip install "jax-lab[cuda13]" # NVIDIA GPU (CUDA 13, bundled)
pip install "jax-lab[cuda12]" # NVIDIA GPU (CUDA 12, bundled)
pip install "jax-lab[tpu]" # Google TPU
pip install "jax-lab[rocm]" # AMD GPU (ROCm, local toolkit)
Use 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_randering |
| h5py | save_fields_hdf5_xdmf |
| matplotlib | save_image, live_volume_randering |
| 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[io]"
Extras can be combined, e.g. 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:
git clone https://github.com/piyush-ppradhan/JAX-LaB
cd JAX-LaB
pip install -e ".[dev,io]"
Note: We encountered challenges when executing JAX-LaB 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 JAX-LaB on Apple's GPUs in the future and will update this section accordingly.
Run an example:
python3 examples/singlephase/cavity2d.py
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file jax_lab-0.4.0.tar.gz.
File metadata
- Download URL: jax_lab-0.4.0.tar.gz
- Upload date:
- Size: 103.1 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a90c7cef9d1fbdf95a16c1fc0e61283dd96c611f1254ee360e3334465e2b5869
|
|
| MD5 |
2216d1e68648f23f8dd87a5bd006f7f8
|
|
| BLAKE2b-256 |
ea85354fb0648938cf0e1e628de1800cb446df2721683d3de171f8d5bf7aeae1
|
Provenance
The following attestation bundles were made for jax_lab-0.4.0.tar.gz:
Publisher:
release.yml on piyush-ppradhan/JAX-LaB
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
jax_lab-0.4.0.tar.gz -
Subject digest:
a90c7cef9d1fbdf95a16c1fc0e61283dd96c611f1254ee360e3334465e2b5869 - Sigstore transparency entry: 2184855222
- Sigstore integration time:
-
Permalink:
piyush-ppradhan/JAX-LaB@5ec15af5c0f72d70b1fad7e3f20ea4a6662be886 -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/piyush-ppradhan
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@5ec15af5c0f72d70b1fad7e3f20ea4a6662be886 -
Trigger Event:
push
-
Statement type:
File details
Details for the file jax_lab-0.4.0-py3-none-any.whl.
File metadata
- Download URL: jax_lab-0.4.0-py3-none-any.whl
- Upload date:
- Size: 86.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2ee4632dcc4204664846c4fa349413fceff316c2ddf93ced77f9f943a637e7c0
|
|
| MD5 |
20fefebc09652c638dd5a91fb16f2527
|
|
| BLAKE2b-256 |
bdbc977005673ca247e9c6441086468b75aa65b164f7c54778f31e3ef16af761
|
Provenance
The following attestation bundles were made for jax_lab-0.4.0-py3-none-any.whl:
Publisher:
release.yml on piyush-ppradhan/JAX-LaB
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
jax_lab-0.4.0-py3-none-any.whl -
Subject digest:
2ee4632dcc4204664846c4fa349413fceff316c2ddf93ced77f9f943a637e7c0 - Sigstore transparency entry: 2184855317
- Sigstore integration time:
-
Permalink:
piyush-ppradhan/JAX-LaB@5ec15af5c0f72d70b1fad7e3f20ea4a6662be886 -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/piyush-ppradhan
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@5ec15af5c0f72d70b1fad7e3f20ea4a6662be886 -
Trigger Event:
push
-
Statement type: