mliap_unified_couple_kokkos module not accessible when driving LAMMPS through python interface

I’ve built LAMMPS for use with MACE MLIAP on GPU. It works totally fine when run directly, i.e:

mpirun -np 1 lmp -k on g 1 -sf kk -pk kokkos newton on neigh half -in input.in 

But when driven through the python library interface, i.e:

import lammps
import mpi4py

args = [
    "-k", "on", "g","1",
    "-sf", "kk",
    "-pk", "kokkos", "newton", "on", "neigh", "half"
    ]
lmps = lammps.lammps(cmdargs=args)

lmps.file("input.in")

I get this error:

Reading data file ...
  orthogonal box = (0 0 0) to (27.337164 27.337164 27.337164)
  1 by 1 by 1 MPI processor grid
  reading atoms ...
  1000 atoms
  read_data CPU = 0.011 seconds
ModuleNotFoundError: No module named 'mliap_unified_couple_kokkos'
ERROR: Loading mliappy unified module failure. (src/KOKKOS/mliap_unified_kokkos.cpp:236)
Last input line: pair_style mliap unified mace-mpa-0-medium.model-mliap_lammps.pt 0
Traceback (most recent call last):
  File "/gpfs/home/f/fraser/test_mliap_mace_plugin/test_python_interface/input.py", line 11, in <module>
    lmps.file("input.in")
  File "/gpfs/home/f/fraser/PythonVirtualEnvs/MaceVenv_py312/lib/python3.12/site-packages/lammps/core.py", line 793, in file
    with ExceptionCheck(self):
  File "/gpfs/home/f/fraser/PythonVirtualEnvs/MaceVenv_py312/lib/python3.12/site-packages/lammps/core.py", line 57, in __exit__
    raise self.lmp._lammps_exception
Exception: ERROR: Loading mliappy unified module failure. (src/KOKKOS/mliap_unified_kokkos.cpp:236)
Last input line: pair_style mliap unified mace-mpa-0-medium.model-mliap_lammps.pt 0

Looking at src/KOKKOS/mliap_unified_kokkos.cpp the offending line seems to be:

 PyImport_ImportModule("mliap_unified_couple_kokkos");

Here is my input script:

units         metal
atom_style    atomic
atom_modify   map yes

read_data small_cell.lj

mass 1 28.0855
pair_style mliap unified mace-mpa-0-medium.model-mliap_lammps.pt 0


# pair_style mliap unified 2023-12-03-mace-128-L1_epoch-199.model-mliap_lammps.pt 0
pair_coeff * * Si


fix 1 all nve

thermo 1
dump mydump all custom 1 dump0.lammpstrj id type mass xs ys zs vx vy vz fx fy fz

run 1

and my build script:

cmake ../cmake \
  -D CMAKE_CXX_COMPILER=/path/to/lammps_develop/lib/kokkos/bin/nvcc_wrapper \
  -D BUILD_KOKKOS=on \
  -D BUILD_MPI=on \
  -D PKG_KOKKOS=yes \
  -D Kokkos_ARCH_AMPERE80=yes \
  -D Kokkos_ENABLE_OPENMP=yes \
  -D BUILD_SHARED_LIBS=yes \
  -D PKG_PYTHON=yes \
  -D PKG_ML-SNAP=yes \
  -D PKG_ML-IAP=yes \
  -D PKG_OPENMP=yes \
  -D Kokkos_ENABLE_CUDA=yes \
  -D MLIAP_ENABLE_PYTHON=ON


cmake --build . -j 42

cmake --install .

make install-python

Edit: I was using a version of the develop branch from a couple of weeks ago. I’m just rebuilding and trying it again with the current version.

Edit 2: I have reproduced this error on the current version of the LAMMPS develop branch (as of 6th May 2025)

I don’t think there much that any LAMMPS developer can do for you, since MACE is developed and maintained externally. Also the MLIAP Python interface is maintained by developers at Los Alamos and they have chose a different path of interfacing LAMMPS to Python.

That said there is an mliap subpackage in the LAMMPS python package. Perhaps you need to look through that.

Bottom line, look at the source files for the authors and contact them or use the MACE discussion forum, or both.

Thanks for the pointers Axel - I’ll get in contact with the relevant developers.

The solution, for future reference to anybody with this issue, is this:

import lammps.mliap
lammps.mliap.activate_mliappy_kokkos(lmp)

See this example: lammps/examples/mliap/mliap_pytorch_Ta06A_kokkos.py at 750cfbedd3750df3b0ebf3c3d7bd499f55e3b227 · lammps/lammps · GitHub

1 Like