Skip to main content

License

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: Thermal couples 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: MultiphaseThermal couples 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

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

jax_lab-0.4.0.tar.gz (103.1 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jax_lab-0.4.0-py3-none-any.whl (86.5 kB view details)

Uploaded Python 3

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

Hashes for jax_lab-0.4.0.tar.gz
Algorithm Hash digest
SHA256 a90c7cef9d1fbdf95a16c1fc0e61283dd96c611f1254ee360e3334465e2b5869
MD5 2216d1e68648f23f8dd87a5bd006f7f8
BLAKE2b-256 ea85354fb0648938cf0e1e628de1800cb446df2721683d3de171f8d5bf7aeae1

See more details on using hashes here.

Provenance

The following attestation bundles were made for jax_lab-0.4.0.tar.gz:

Publisher: release.yml on piyush-ppradhan/JAX-LaB

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for jax_lab-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2ee4632dcc4204664846c4fa349413fceff316c2ddf93ced77f9f943a637e7c0
MD5 20fefebc09652c638dd5a91fb16f2527
BLAKE2b-256 bdbc977005673ca247e9c6441086468b75aa65b164f7c54778f31e3ef16af761

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.5.7

2 files

0.5.6

2 files

0.5.5

2 files

0.5.4

2 files

0.5.3

2 files

0.5.2

2 files

0.5.1

2 files

0.5.0

2 files

0.4.6

2 files

0.4.5

2 files

0.4.4

2 files

0.4.3

2 files

This release

0.4.0 This release

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page