LAMMPS-JAX
LAMMPS plugin for running JAX forcefields with
jax.export and a PJRT runtime.
Setup
The Python package is on PyPI; the LAMMPS plugin and the examples build from this repository.
pip install lammps-jax 'jax[cuda12]' # GPU
pip install 'lammps-jax[cpu]' # CPU, with the XLA CPU PJRT plugin
From a checkout:
git clone https://github.com/abhijeetgangan/lammps-jax && cd lammps-jax
uv venv .venv --python python3
source .venv/bin/activate
uv pip install -e '.[test]'
uv pip install -U 'jax[cuda12]'
Build
The pair style needs the KOKKOS precision layer from LAMMPS 10 Sep 2025 or
newer; stable releases do not carry it yet, and older trees stop at a
compile-time error. Build the plugin against the same LAMMPS source tree as
the lmp binary that loads it, and rebuild both together after pulling.
cmake -S cpp -B build-plugin-gpu-pjrt \
-D CMAKE_CXX_COMPILER="$KOKKOS_NVCC_WRAPPER" \
-D CMAKE_BUILD_TYPE=Release \
-D CMAKE_CXX_FLAGS="-fno-lto" \
-D CMAKE_SHARED_LINKER_FLAGS="-fno-lto" \
-D CMAKE_INTERPROCEDURAL_OPTIMIZATION=OFF \
-D LAMMPS_HEADER_DIR="$LAMMPS_SRC/src" \
-D JAXLIB_INCLUDE_DIR="$JAXLIB_INCLUDE_DIR" \
-D KOKKOS_CONFIG_INCLUDE_DIR="$LAMMPS_BUILD/lib/kokkos"
cmake --build build-plugin-gpu-pjrt -j4
Run
python examples/export_model.py lj examples/lj.lammps-jax.json \
--max-atoms 1024 --edges-per-atom 96
The bundle loads as a pair style:
pair_style jax/kk ${pjrt}
pair_coeff * * examples/lj.lammps-jax.json
LAMMPS_PLUGIN_PATH=build-plugin-gpu-pjrt \
"$LAMMPS_INSTALL/bin/lmp" -k on g 1 -pk kokkos newton off neigh full -sf kk \
-var pjrt /absolute/path/xla_cuda_plugin.so -in examples/in.lj_jax
CPU
Kokkos OpenMP builds run bundles exported with platform="cpu" on the XLA CPU
PJRT plugin from the cpu extra (Linux x86-64):
uv pip install -e '.[cpu]'
python -c 'import lammps_jax_pjrt_cpu as p; print(p.PLUGIN_PATH)'
Build LAMMPS with -C cmake/presets/kokkos-openmp.cmake -D PKG_PLUGIN=on -D BUILD_MPI=on -D Kokkos_ENABLE_IMPL_VIEW_LEGACY=on and the plugin as above
against that build, without CMAKE_CXX_COMPILER. One MPI rank per core runs
fastest:
python examples/export_model.py eam cuzr.lammps-jax.json \
--setfl examples/potentials/CuZr.eam.alloy.gz \
--max-atoms 8192 --edges-per-atom 128 --precision float64 --platform cpu
LAMMPS_PLUGIN_PATH=build-plugin-cpu-pjrt \
mpirun -np 4 "$LAMMPS_CPU_INSTALL/bin/lmp" -k on t 1 -sf kk -pk kokkos newton on neigh half \
-var pjrt /absolute/path/pjrt_c_api_cpu_plugin.so -in examples/in.eam_cuzr
cuEquivariance and OpenEquivariance kernels are CUDA only.
Test
JAX_PLATFORMS=cpu python -m pytest
Integration tests, which require a GPU and LAMMPS:
LAMMPS_BIN=$LAMMPS_INSTALL/bin/lmp \
PJRT_PLUGIN=/absolute/path/xla_cuda_plugin.so \
LAMMPS_PLUGIN_PATH=$PWD/build-plugin-gpu-pjrt \
python -m pytest tests/test_lammps.py -v
For a host Kokkos LAMMPS and the CPU plugin, add LAMMPS_JAX_TEST_PLATFORM=cpu.
Design notes
Models are exported with jax.export into a JSON bundle holding the
serialized program and the settings the pair style enforces at load: atom and
edge capacities, cutoff, precision, unit style, and the distribution scheme.
Exported programs have static shapes, so positions and the edge list are
padded to capacity and an edge mask marks the live entries. The pair style
distance-filters pairs to the model cutoff and repacks the edge list every
step, so edge capacity sizes to the cutoff rather than cutoff plus skin.
The pair style executes the bundle through the PJRT C API, loading the same plugin library jax uses on the GPU, so the build never needs XLA. Kokkos kernels pack the LAMMPS neighbor list into sender, receiver, and mask arrays on device, the program runs on the LAMMPS CUDA stream, and forces come back as device buffers, so array data never passes through the host.
Multi-rank runs pick one of two schemes at export. A ghost export widens the ghost shell to n_hops cutoffs and stays communication-free inside the program; a comm export keeps the one-cutoff shell and exchanges per-layer features through LAMMPS forward and reverse communication, called from inside the program as an FFI callback. Exchanges are linear JAX primitives whose transposes swap forward and reverse, so models may call either direction and every differentiation mode traces through them. Communicating half-edge exports pack each pair on one rank, matching the native half neighbor list, and reverse-communicate ghost density partials into their owners. Exchanged rows move in place on device under the Kokkos brick and tiled comm styles and stage through pinned host memory otherwise.
cuEquivariance and OpenEquivariance kernels stay in the exported program as custom call targets, resolved at run time from LAMMPS_JAX_FFI_HANDLERS; contrib/ffi-replay handles libraries whose compiled kernels only exist inside the exporting process. NequIP checkpoints export through the uv-runnable scripts in examples/torch, which trace the torch blocks via torchax into the serialized program; the bundles load and run like any native export.
Citation
If you use lammps-jax or any algorithms implemented here, please cite
the archived Zenodo release: https://doi.org/10.5281/zenodo.20838694
Acknowledgements
Thanks to @mitkotak for API discussions and @wcwitt for guidance on distributed inference. See lammps/lammps#4691 for the original discussion on running JAX models in LAMMPS, and openmm-jax for the OpenMM counterpart.
License
MIT. See LICENSE.
Metadata
Release files for lammps-jax 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| lammps_jax-0.2.1.tar.gz | 98.6 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| lammps_jax-0.2.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 162.2 kB
Release files / lammps_jax-0.2.1.tar.gz
| Download URL | lammps_jax-0.2.1.tar.gz |
|---|---|
| Size | 98.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
699c5acdbce8fa451707584c39483ab1b1a4b4029d82e3f3b359a0ff503a7520
|
|
BLAKE2b-256 checksum How to use checksums |
a0959c30f655b7e2f71662da4fc6a07502220c956ba899cfe8b3d51cd55c2277
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 22, 2026.
Transparency logRelease files / lammps_jax-0.2.1-py3-none-any.whl
| Download URL | lammps_jax-0.2.1-py3-none-any.whl |
|---|---|
| Size | 63.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
db03ee2ed19b2f94011efeac23a645fb09c9785e2b4baeff01d0ee726ce36a11
|
|
BLAKE2b-256 checksum How to use checksums |
c6e6545784a0d6c56ac6e2ca7b9b62db4bbdd9c8c02d4c3b5581946e78e834f9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 22, 2026.
Transparency logSecurity for lammps-jax 0.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for lammps_jax-0.2.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 22, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.