Repository navigation
Build kokkos-cpu LAMMPS as a shared library usable from Python - #13
Merged
Merged
Conversation
Build LAMMPS against the libtorch of the pip torch wheel (instead of a separate libtorch 2.5.1 zip), as a shared library with the lammps Python module installed, so it can run in-process from Python (e.g. matcalc's MATCALC_BACKEND=LAMMPS) with one libtorch shared by Python and LAMMPS. Pin torch in the runtime and derived images to the build version via /opt/lammps/torch-constraint.txt, and add ML-SNAP. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The derived image builds FROM the published matgl:latest-kokkos-cpu, which lacks /opt/lammps/torch-constraint.txt until this change is published. Freeze the base image's torch instead, which works with both the old and the new base. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
materialyzeai/matgl:latest-kokkos-cpucurrently can't drive LAMMPS from Python:lmp. There is noliblammps.soand nolammpsPython module.libc10.so,libtorch_cpu.so).matcalc's new LAMMPS backend (
MATCALC_BACKEND=LAMMPS) runs LAMMPS in-process through the Python module, and its CI is meant to use this image. This PR makes the image support that.Changes
Dockerfile.matgl.kokkos-cpughcr.io/astral-sh/uv:python3.12-bookworm, the same Python layout as the runtime image.matglwith the CPU torch wheel and builds LAMMPS against the wheel's libtorch.CMAKE_CXX_STANDARD=20is needed because torch 2.15 headers require C++20.BUILD_SHARED_LIBS=ON. ThelammpsPython package is copied into site-packages, and/opt/lammps/libis registered withldconfig. The RPATH coversliblammps.soand the torchlib/directory./opt/lammps/torch-constraint.txt. The runtime image installs against it, so Python and LAMMPS share one libtorch.PKG_ML-SNAP.lmpnow loads TorchScript models with the same torch that exported them. Before, models exported with 2.15 were loaded by libtorch 2.5.1.Dockerfile.matml.kokkos-cpu: pins torch to the version already in the base image (uv pip freeze), so adding matcalc/matpes can't change torch. Freezing, rather than reading/opt/lammps/torch-constraint.txt, also works with the currently published base, which this image is built FROM in CI until the new base is pushed.from lammps import lammps(with Kokkos) and thatpair_style matgl,matgl/kkandsnapare present.Derived images must keep torch fixed with
uv pip install --system -c /opt/lammps/torch-constraint.txt ....Testing
BUILD_JOBS=8): torch 2.15.0+cpu, Kokkos backends OpenMP and Serial. Installed packages: EXTRA-COMPUTE, EXTRA-DUMP, EXTRA-FIX, KOKKOS, MANYBODY, ML-SNAP, MOLECULE, plus ML-MATGL.tests/test_backend_lammps.pywith failures instead of skips when LAMMPS pieces are missing. 35/35 passed withpair_style matgl, and 35/35 withmatgl/kk(-k on t 2 -sf kk -pk kokkos newton on neigh half).from lammps import lammpswithmatgl/kkworks alongside matcalc.🤖 Generated with Claude Code