lammps-jax 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- lammps_jax-0.2.0/LICENSE +21 -0
- lammps_jax-0.2.0/NOTICE +13 -0
- lammps_jax-0.2.0/PKG-INFO +187 -0
- lammps_jax-0.2.0/README.md +162 -0
- lammps_jax-0.2.0/pyproject.toml +65 -0
- lammps_jax-0.2.0/python/lammps_jax/__init__.py +1 -0
- lammps_jax-0.2.0/python/lammps_jax/comm.py +262 -0
- lammps_jax-0.2.0/python/lammps_jax/dist/__init__.py +0 -0
- lammps_jax-0.2.0/python/lammps_jax/dist/parallel/__init__.py +0 -0
- lammps_jax-0.2.0/python/lammps_jax/dist/parallel/feature_exchange.py +330 -0
- lammps_jax-0.2.0/python/lammps_jax/dist/parallel/force_decomposition.py +138 -0
- lammps_jax-0.2.0/python/lammps_jax/dist/parallel/ghost_exchange.py +550 -0
- lammps_jax-0.2.0/python/lammps_jax/dist/parallel/local_neighbor_list.py +273 -0
- lammps_jax-0.2.0/python/lammps_jax/dist/parallel/replicate_data.py +611 -0
- lammps_jax-0.2.0/python/lammps_jax/dist/scripts/__init__.py +0 -0
- lammps_jax-0.2.0/python/lammps_jax/dist/scripts/lj_bench.py +313 -0
- lammps_jax-0.2.0/python/lammps_jax/dist/scripts/nequix_bench.py +290 -0
- lammps_jax-0.2.0/python/lammps_jax/eam.py +409 -0
- lammps_jax-0.2.0/python/lammps_jax/eam_pallas.py +379 -0
- lammps_jax-0.2.0/python/lammps_jax/export.py +567 -0
- lammps_jax-0.2.0/python/lammps_jax/mace.py +167 -0
- lammps_jax-0.2.0/python/lammps_jax.egg-info/PKG-INFO +187 -0
- lammps_jax-0.2.0/python/lammps_jax.egg-info/SOURCES.txt +32 -0
- lammps_jax-0.2.0/python/lammps_jax.egg-info/dependency_links.txt +1 -0
- lammps_jax-0.2.0/python/lammps_jax.egg-info/requires.txt +18 -0
- lammps_jax-0.2.0/python/lammps_jax.egg-info/top_level.txt +1 -0
- lammps_jax-0.2.0/setup.cfg +4 -0
- lammps_jax-0.2.0/tests/test_dist_parallel.py +871 -0
- lammps_jax-0.2.0/tests/test_distributed.py +539 -0
- lammps_jax-0.2.0/tests/test_eam.py +687 -0
- lammps_jax-0.2.0/tests/test_eam_pallas.py +243 -0
- lammps_jax-0.2.0/tests/test_export.py +382 -0
- lammps_jax-0.2.0/tests/test_lammps.py +1141 -0
- lammps_jax-0.2.0/tests/test_mace.py +244 -0
lammps_jax-0.2.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Abhijeet Gangan
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
lammps_jax-0.2.0/NOTICE
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
lammps-jax is licensed under the MIT license (see LICENSE).
|
|
2
|
+
|
|
3
|
+
The following files are vendored from OpenXLA
|
|
4
|
+
(https://github.com/openxla/xla), Copyright 2022-2024 The OpenXLA
|
|
5
|
+
Authors, licensed under the Apache License, Version 2.0
|
|
6
|
+
(http://www.apache.org/licenses/LICENSE-2.0):
|
|
7
|
+
|
|
8
|
+
cpp/third_party/pjrt_c_api.h (xla/pjrt/c/pjrt_c_api.h)
|
|
9
|
+
cpp/third_party/pjrt_c_api_ffi_extension.h
|
|
10
|
+
(xla/pjrt/c/pjrt_c_api_ffi_extension.h)
|
|
11
|
+
|
|
12
|
+
The only modification is the pjrt_c_api.h include path in the extension
|
|
13
|
+
header; the C API header is unmodified apart from a provenance note.
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: lammps-jax
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: CUDA-first LAMMPS/Kokkos plugin support for exported JAX models
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Project-URL: Repository, https://github.com/abhijeetgangan/lammps-jax
|
|
7
|
+
Requires-Python: >=3.10
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
License-File: NOTICE
|
|
11
|
+
Requires-Dist: jax>=0.8
|
|
12
|
+
Requires-Dist: jaxlib!=0.10.2,>=0.8
|
|
13
|
+
Provides-Extra: cpu
|
|
14
|
+
Requires-Dist: lammps-jax-pjrt-cpu>=0.11.2; (sys_platform == "linux" and platform_machine == "x86_64") and extra == "cpu"
|
|
15
|
+
Provides-Extra: dist
|
|
16
|
+
Requires-Dist: ase>=3.22; extra == "dist"
|
|
17
|
+
Requires-Dist: e3nn-jax>=0.20; extra == "dist"
|
|
18
|
+
Requires-Dist: jax!=0.11.2; extra == "dist"
|
|
19
|
+
Requires-Dist: jax-md>=0.2.27; extra == "dist"
|
|
20
|
+
Requires-Dist: nequix>=0.4; extra == "dist"
|
|
21
|
+
Provides-Extra: test
|
|
22
|
+
Requires-Dist: pytest>=7; extra == "test"
|
|
23
|
+
Requires-Dist: numpy>=1.24; extra == "test"
|
|
24
|
+
Dynamic: license-file
|
|
25
|
+
|
|
26
|
+
# LAMMPS-JAX
|
|
27
|
+
|
|
28
|
+
[](https://doi.org/10.5281/zenodo.20838693)
|
|
29
|
+
|
|
30
|
+
[LAMMPS](https://www.lammps.org) plugin for running JAX forcefields with
|
|
31
|
+
`jax.export` and a PJRT runtime.
|
|
32
|
+
|
|
33
|
+
## Setup
|
|
34
|
+
|
|
35
|
+
The Python package is on PyPI; the LAMMPS plugin and the examples build from
|
|
36
|
+
this repository.
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
pip install lammps-jax 'jax[cuda12]' # GPU
|
|
40
|
+
pip install 'lammps-jax[cpu]' # CPU, with the XLA CPU PJRT plugin
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
From a checkout:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
git clone https://github.com/abhijeetgangan/lammps-jax && cd lammps-jax
|
|
47
|
+
uv venv .venv --python python3
|
|
48
|
+
source .venv/bin/activate
|
|
49
|
+
uv pip install -e '.[test]'
|
|
50
|
+
uv pip install -U 'jax[cuda12]'
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Build
|
|
54
|
+
|
|
55
|
+
The pair style needs the KOKKOS precision layer from LAMMPS 10 Sep 2025 or
|
|
56
|
+
newer; stable releases do not carry it yet, and older trees stop at a
|
|
57
|
+
compile-time error. Build the plugin against the same LAMMPS source tree as
|
|
58
|
+
the `lmp` binary that loads it, and rebuild both together after pulling.
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
cmake -S cpp -B build-plugin-gpu-pjrt \
|
|
62
|
+
-D CMAKE_CXX_COMPILER="$KOKKOS_NVCC_WRAPPER" \
|
|
63
|
+
-D CMAKE_BUILD_TYPE=Release \
|
|
64
|
+
-D CMAKE_CXX_FLAGS="-fno-lto" \
|
|
65
|
+
-D CMAKE_SHARED_LINKER_FLAGS="-fno-lto" \
|
|
66
|
+
-D CMAKE_INTERPROCEDURAL_OPTIMIZATION=OFF \
|
|
67
|
+
-D LAMMPS_HEADER_DIR="$LAMMPS_SRC/src" \
|
|
68
|
+
-D JAXLIB_INCLUDE_DIR="$JAXLIB_INCLUDE_DIR" \
|
|
69
|
+
-D KOKKOS_CONFIG_INCLUDE_DIR="$LAMMPS_BUILD/lib/kokkos"
|
|
70
|
+
cmake --build build-plugin-gpu-pjrt -j4
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Run
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
python examples/export_model.py lj examples/lj.lammps-jax.json \
|
|
77
|
+
--max-atoms 1024 --edges-per-atom 96
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
The bundle loads as a pair style:
|
|
81
|
+
|
|
82
|
+
```
|
|
83
|
+
pair_style jax/kk ${pjrt}
|
|
84
|
+
pair_coeff * * examples/lj.lammps-jax.json
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
LAMMPS_PLUGIN_PATH=build-plugin-gpu-pjrt \
|
|
89
|
+
"$LAMMPS_INSTALL/bin/lmp" -k on g 1 -pk kokkos newton off neigh full -sf kk \
|
|
90
|
+
-var pjrt /absolute/path/xla_cuda_plugin.so -in examples/in.lj_jax
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## CPU
|
|
94
|
+
|
|
95
|
+
Kokkos OpenMP builds run bundles exported with `platform="cpu"` on the XLA CPU
|
|
96
|
+
PJRT plugin from the `cpu` extra (Linux x86-64):
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
uv pip install -e '.[cpu]'
|
|
100
|
+
python -c 'import lammps_jax_pjrt_cpu as p; print(p.PLUGIN_PATH)'
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Build LAMMPS with `-C cmake/presets/kokkos-openmp.cmake -D PKG_PLUGIN=on
|
|
104
|
+
-D BUILD_MPI=on -D Kokkos_ENABLE_IMPL_VIEW_LEGACY=on` and the plugin as above
|
|
105
|
+
against that build, without `CMAKE_CXX_COMPILER`. One MPI rank per core runs
|
|
106
|
+
fastest:
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
python examples/export_model.py eam cuzr.lammps-jax.json \
|
|
110
|
+
--setfl examples/potentials/CuZr.eam.alloy.gz \
|
|
111
|
+
--max-atoms 8192 --edges-per-atom 128 --precision float64 --platform cpu
|
|
112
|
+
LAMMPS_PLUGIN_PATH=build-plugin-cpu-pjrt \
|
|
113
|
+
mpirun -np 4 "$LAMMPS_CPU_INSTALL/bin/lmp" -k on t 1 -sf kk -pk kokkos newton on neigh half \
|
|
114
|
+
-var pjrt /absolute/path/pjrt_c_api_cpu_plugin.so -in examples/in.eam_cuzr
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
cuEquivariance and OpenEquivariance kernels are CUDA only.
|
|
118
|
+
|
|
119
|
+
## Test
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
JAX_PLATFORMS=cpu python -m pytest
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Integration tests, which require a GPU and LAMMPS:
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
LAMMPS_BIN=$LAMMPS_INSTALL/bin/lmp \
|
|
129
|
+
PJRT_PLUGIN=/absolute/path/xla_cuda_plugin.so \
|
|
130
|
+
LAMMPS_PLUGIN_PATH=$PWD/build-plugin-gpu-pjrt \
|
|
131
|
+
python -m pytest tests/test_lammps.py -v
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
For a host Kokkos LAMMPS and the CPU plugin, add `LAMMPS_JAX_TEST_PLATFORM=cpu`.
|
|
135
|
+
|
|
136
|
+
## Design notes
|
|
137
|
+
|
|
138
|
+
Models are exported with `jax.export` into a JSON bundle holding the
|
|
139
|
+
serialized program and the settings the pair style enforces at load: atom and
|
|
140
|
+
edge capacities, cutoff, precision, unit style, and the distribution scheme.
|
|
141
|
+
Exported programs have static shapes, so positions and the edge list are
|
|
142
|
+
padded to capacity and an edge mask marks the live entries. The pair style
|
|
143
|
+
distance-filters pairs to the model cutoff and repacks the edge list every
|
|
144
|
+
step, so edge capacity sizes to the cutoff rather than cutoff plus skin.
|
|
145
|
+
|
|
146
|
+
The pair style executes the bundle through the PJRT C API, loading the same
|
|
147
|
+
plugin library jax uses on the GPU, so the build never needs XLA. Kokkos kernels
|
|
148
|
+
pack the LAMMPS neighbor list into sender, receiver, and mask arrays on
|
|
149
|
+
device, the program runs on the LAMMPS CUDA stream, and forces come back as
|
|
150
|
+
device buffers, so array data never passes through the host.
|
|
151
|
+
|
|
152
|
+
Multi-rank runs pick one of two schemes at export. A ghost export widens the
|
|
153
|
+
ghost shell to n_hops cutoffs and stays communication-free inside the
|
|
154
|
+
program; a comm export keeps the one-cutoff shell and exchanges per-layer
|
|
155
|
+
features through LAMMPS forward and reverse communication, called from inside
|
|
156
|
+
the program as an FFI callback. Exchanges are linear JAX primitives whose
|
|
157
|
+
transposes swap forward and reverse, so models may call either direction and
|
|
158
|
+
every differentiation mode traces through them. Communicating half-edge
|
|
159
|
+
exports pack each pair on one rank, matching the native half neighbor list,
|
|
160
|
+
and reverse-communicate ghost density partials into their owners. Exchanged
|
|
161
|
+
rows move in place on device under the Kokkos brick and tiled comm styles and
|
|
162
|
+
stage through pinned host memory otherwise.
|
|
163
|
+
|
|
164
|
+
cuEquivariance and OpenEquivariance kernels stay in the exported program as
|
|
165
|
+
custom call targets, resolved at run time from LAMMPS_JAX_FFI_HANDLERS;
|
|
166
|
+
contrib/ffi-replay handles libraries whose compiled kernels only exist inside
|
|
167
|
+
the exporting process. NequIP checkpoints export through the uv-runnable
|
|
168
|
+
scripts in examples/torch, which trace the torch blocks via torchax into
|
|
169
|
+
the serialized program; the bundles load and run like any native export.
|
|
170
|
+
|
|
171
|
+
## Citation
|
|
172
|
+
|
|
173
|
+
If you use `lammps-jax` or any algorithms implemented here, please cite
|
|
174
|
+
the archived Zenodo release: https://doi.org/10.5281/zenodo.20838694
|
|
175
|
+
|
|
176
|
+
## Acknowledgements
|
|
177
|
+
|
|
178
|
+
Thanks to @mitkotak for API discussions and @wcwitt for guidance on
|
|
179
|
+
distributed inference. See
|
|
180
|
+
[lammps/lammps#4691](https://github.com/lammps/lammps/pull/4691) for the
|
|
181
|
+
original discussion on running JAX models in LAMMPS, and
|
|
182
|
+
[openmm-jax](https://github.com/atomicarchitects/openmm-jax) for the OpenMM
|
|
183
|
+
counterpart.
|
|
184
|
+
|
|
185
|
+
## License
|
|
186
|
+
|
|
187
|
+
MIT. See `LICENSE`.
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
# LAMMPS-JAX
|
|
2
|
+
|
|
3
|
+
[](https://doi.org/10.5281/zenodo.20838693)
|
|
4
|
+
|
|
5
|
+
[LAMMPS](https://www.lammps.org) plugin for running JAX forcefields with
|
|
6
|
+
`jax.export` and a PJRT runtime.
|
|
7
|
+
|
|
8
|
+
## Setup
|
|
9
|
+
|
|
10
|
+
The Python package is on PyPI; the LAMMPS plugin and the examples build from
|
|
11
|
+
this repository.
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pip install lammps-jax 'jax[cuda12]' # GPU
|
|
15
|
+
pip install 'lammps-jax[cpu]' # CPU, with the XLA CPU PJRT plugin
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
From a checkout:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
git clone https://github.com/abhijeetgangan/lammps-jax && cd lammps-jax
|
|
22
|
+
uv venv .venv --python python3
|
|
23
|
+
source .venv/bin/activate
|
|
24
|
+
uv pip install -e '.[test]'
|
|
25
|
+
uv pip install -U 'jax[cuda12]'
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Build
|
|
29
|
+
|
|
30
|
+
The pair style needs the KOKKOS precision layer from LAMMPS 10 Sep 2025 or
|
|
31
|
+
newer; stable releases do not carry it yet, and older trees stop at a
|
|
32
|
+
compile-time error. Build the plugin against the same LAMMPS source tree as
|
|
33
|
+
the `lmp` binary that loads it, and rebuild both together after pulling.
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
cmake -S cpp -B build-plugin-gpu-pjrt \
|
|
37
|
+
-D CMAKE_CXX_COMPILER="$KOKKOS_NVCC_WRAPPER" \
|
|
38
|
+
-D CMAKE_BUILD_TYPE=Release \
|
|
39
|
+
-D CMAKE_CXX_FLAGS="-fno-lto" \
|
|
40
|
+
-D CMAKE_SHARED_LINKER_FLAGS="-fno-lto" \
|
|
41
|
+
-D CMAKE_INTERPROCEDURAL_OPTIMIZATION=OFF \
|
|
42
|
+
-D LAMMPS_HEADER_DIR="$LAMMPS_SRC/src" \
|
|
43
|
+
-D JAXLIB_INCLUDE_DIR="$JAXLIB_INCLUDE_DIR" \
|
|
44
|
+
-D KOKKOS_CONFIG_INCLUDE_DIR="$LAMMPS_BUILD/lib/kokkos"
|
|
45
|
+
cmake --build build-plugin-gpu-pjrt -j4
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Run
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
python examples/export_model.py lj examples/lj.lammps-jax.json \
|
|
52
|
+
--max-atoms 1024 --edges-per-atom 96
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
The bundle loads as a pair style:
|
|
56
|
+
|
|
57
|
+
```
|
|
58
|
+
pair_style jax/kk ${pjrt}
|
|
59
|
+
pair_coeff * * examples/lj.lammps-jax.json
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
LAMMPS_PLUGIN_PATH=build-plugin-gpu-pjrt \
|
|
64
|
+
"$LAMMPS_INSTALL/bin/lmp" -k on g 1 -pk kokkos newton off neigh full -sf kk \
|
|
65
|
+
-var pjrt /absolute/path/xla_cuda_plugin.so -in examples/in.lj_jax
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## CPU
|
|
69
|
+
|
|
70
|
+
Kokkos OpenMP builds run bundles exported with `platform="cpu"` on the XLA CPU
|
|
71
|
+
PJRT plugin from the `cpu` extra (Linux x86-64):
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
uv pip install -e '.[cpu]'
|
|
75
|
+
python -c 'import lammps_jax_pjrt_cpu as p; print(p.PLUGIN_PATH)'
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Build LAMMPS with `-C cmake/presets/kokkos-openmp.cmake -D PKG_PLUGIN=on
|
|
79
|
+
-D BUILD_MPI=on -D Kokkos_ENABLE_IMPL_VIEW_LEGACY=on` and the plugin as above
|
|
80
|
+
against that build, without `CMAKE_CXX_COMPILER`. One MPI rank per core runs
|
|
81
|
+
fastest:
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
python examples/export_model.py eam cuzr.lammps-jax.json \
|
|
85
|
+
--setfl examples/potentials/CuZr.eam.alloy.gz \
|
|
86
|
+
--max-atoms 8192 --edges-per-atom 128 --precision float64 --platform cpu
|
|
87
|
+
LAMMPS_PLUGIN_PATH=build-plugin-cpu-pjrt \
|
|
88
|
+
mpirun -np 4 "$LAMMPS_CPU_INSTALL/bin/lmp" -k on t 1 -sf kk -pk kokkos newton on neigh half \
|
|
89
|
+
-var pjrt /absolute/path/pjrt_c_api_cpu_plugin.so -in examples/in.eam_cuzr
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
cuEquivariance and OpenEquivariance kernels are CUDA only.
|
|
93
|
+
|
|
94
|
+
## Test
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
JAX_PLATFORMS=cpu python -m pytest
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Integration tests, which require a GPU and LAMMPS:
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
LAMMPS_BIN=$LAMMPS_INSTALL/bin/lmp \
|
|
104
|
+
PJRT_PLUGIN=/absolute/path/xla_cuda_plugin.so \
|
|
105
|
+
LAMMPS_PLUGIN_PATH=$PWD/build-plugin-gpu-pjrt \
|
|
106
|
+
python -m pytest tests/test_lammps.py -v
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
For a host Kokkos LAMMPS and the CPU plugin, add `LAMMPS_JAX_TEST_PLATFORM=cpu`.
|
|
110
|
+
|
|
111
|
+
## Design notes
|
|
112
|
+
|
|
113
|
+
Models are exported with `jax.export` into a JSON bundle holding the
|
|
114
|
+
serialized program and the settings the pair style enforces at load: atom and
|
|
115
|
+
edge capacities, cutoff, precision, unit style, and the distribution scheme.
|
|
116
|
+
Exported programs have static shapes, so positions and the edge list are
|
|
117
|
+
padded to capacity and an edge mask marks the live entries. The pair style
|
|
118
|
+
distance-filters pairs to the model cutoff and repacks the edge list every
|
|
119
|
+
step, so edge capacity sizes to the cutoff rather than cutoff plus skin.
|
|
120
|
+
|
|
121
|
+
The pair style executes the bundle through the PJRT C API, loading the same
|
|
122
|
+
plugin library jax uses on the GPU, so the build never needs XLA. Kokkos kernels
|
|
123
|
+
pack the LAMMPS neighbor list into sender, receiver, and mask arrays on
|
|
124
|
+
device, the program runs on the LAMMPS CUDA stream, and forces come back as
|
|
125
|
+
device buffers, so array data never passes through the host.
|
|
126
|
+
|
|
127
|
+
Multi-rank runs pick one of two schemes at export. A ghost export widens the
|
|
128
|
+
ghost shell to n_hops cutoffs and stays communication-free inside the
|
|
129
|
+
program; a comm export keeps the one-cutoff shell and exchanges per-layer
|
|
130
|
+
features through LAMMPS forward and reverse communication, called from inside
|
|
131
|
+
the program as an FFI callback. Exchanges are linear JAX primitives whose
|
|
132
|
+
transposes swap forward and reverse, so models may call either direction and
|
|
133
|
+
every differentiation mode traces through them. Communicating half-edge
|
|
134
|
+
exports pack each pair on one rank, matching the native half neighbor list,
|
|
135
|
+
and reverse-communicate ghost density partials into their owners. Exchanged
|
|
136
|
+
rows move in place on device under the Kokkos brick and tiled comm styles and
|
|
137
|
+
stage through pinned host memory otherwise.
|
|
138
|
+
|
|
139
|
+
cuEquivariance and OpenEquivariance kernels stay in the exported program as
|
|
140
|
+
custom call targets, resolved at run time from LAMMPS_JAX_FFI_HANDLERS;
|
|
141
|
+
contrib/ffi-replay handles libraries whose compiled kernels only exist inside
|
|
142
|
+
the exporting process. NequIP checkpoints export through the uv-runnable
|
|
143
|
+
scripts in examples/torch, which trace the torch blocks via torchax into
|
|
144
|
+
the serialized program; the bundles load and run like any native export.
|
|
145
|
+
|
|
146
|
+
## Citation
|
|
147
|
+
|
|
148
|
+
If you use `lammps-jax` or any algorithms implemented here, please cite
|
|
149
|
+
the archived Zenodo release: https://doi.org/10.5281/zenodo.20838694
|
|
150
|
+
|
|
151
|
+
## Acknowledgements
|
|
152
|
+
|
|
153
|
+
Thanks to @mitkotak for API discussions and @wcwitt for guidance on
|
|
154
|
+
distributed inference. See
|
|
155
|
+
[lammps/lammps#4691](https://github.com/lammps/lammps/pull/4691) for the
|
|
156
|
+
original discussion on running JAX models in LAMMPS, and
|
|
157
|
+
[openmm-jax](https://github.com/atomicarchitects/openmm-jax) for the OpenMM
|
|
158
|
+
counterpart.
|
|
159
|
+
|
|
160
|
+
## License
|
|
161
|
+
|
|
162
|
+
MIT. See `LICENSE`.
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "lammps-jax"
|
|
7
|
+
version = "0.2.0"
|
|
8
|
+
description = "CUDA-first LAMMPS/Kokkos plugin support for exported JAX models"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
requires-python = ">=3.10"
|
|
12
|
+
# Comm bundles need the plugin's FFI registration from 0.10.0; the 0.10.2
|
|
13
|
+
# plugin slows GPU scatter-add about 4x, so run 0.10.1.
|
|
14
|
+
dependencies = [
|
|
15
|
+
"jax>=0.8",
|
|
16
|
+
"jaxlib>=0.8,!=0.10.2",
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
[project.urls]
|
|
20
|
+
Repository = "https://github.com/abhijeetgangan/lammps-jax"
|
|
21
|
+
|
|
22
|
+
[project.optional-dependencies]
|
|
23
|
+
# The XLA CPU PJRT plugin for host Kokkos builds (pjrt-cpu/); jax ships none.
|
|
24
|
+
cpu = [
|
|
25
|
+
"lammps-jax-pjrt-cpu>=0.11.2; sys_platform == 'linux' and platform_machine == 'x86_64'",
|
|
26
|
+
]
|
|
27
|
+
dist = [
|
|
28
|
+
"ase>=3.22",
|
|
29
|
+
"e3nn-jax>=0.20",
|
|
30
|
+
# jax 0.11.2 segfaults compiling ghost_exchange.redistribute on CPU; 0.11.1 passes.
|
|
31
|
+
"jax!=0.11.2",
|
|
32
|
+
"jax-md>=0.2.27",
|
|
33
|
+
"nequix>=0.4",
|
|
34
|
+
]
|
|
35
|
+
test = [
|
|
36
|
+
"pytest>=7",
|
|
37
|
+
"numpy>=1.24",
|
|
38
|
+
]
|
|
39
|
+
|
|
40
|
+
[tool.setuptools]
|
|
41
|
+
package-dir = {"" = "python"}
|
|
42
|
+
|
|
43
|
+
[tool.setuptools.packages.find]
|
|
44
|
+
where = ["python"]
|
|
45
|
+
|
|
46
|
+
[tool.pytest.ini_options]
|
|
47
|
+
pythonpath = ["python"]
|
|
48
|
+
testpaths = ["tests"]
|
|
49
|
+
|
|
50
|
+
[tool.basedpyright]
|
|
51
|
+
venvPath = "."
|
|
52
|
+
venv = ".venv"
|
|
53
|
+
extraPaths = ["python", "tests"]
|
|
54
|
+
|
|
55
|
+
[tool.ty.environment]
|
|
56
|
+
python = "./.venv"
|
|
57
|
+
root = ["python", "tests"]
|
|
58
|
+
|
|
59
|
+
[[tool.ty.overrides]]
|
|
60
|
+
include = ["tests/**"]
|
|
61
|
+
|
|
62
|
+
[tool.ty.overrides.rules]
|
|
63
|
+
invalid-argument-type = "ignore"
|
|
64
|
+
invalid-assignment = "ignore"
|
|
65
|
+
unsupported-operator = "ignore"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""LAMMPS-JAX package."""
|