MLAIP - AttributeError: 'mliap_unified_couple_kokkos.MLIAPDataPy' object has no attribute 'forward_exchange'

Hi, I am trying to run MACE neural-network potential via the MLIAP library. My system is a simple box of Al atoms at 300K, here’s my code:

units         metal
atom_style    atomic
atom_modify   map yes
boundary      p p p
newton        on
variable inputfile string "uob/Al_wide_box.lmp"
variable outputfile1 string "lammps-output/Al_wide_minimize.data"
variable outputfile2 string "lammps-output/Al_wide_final.data"
variable modelfile string "models-uob/GPU_Models/BCC/mace01_64channel_stagetwo.model-mliap_lammps.pt"
read_data ${inputfile}
pair_style mliap unified ${modelfile} 0
pair_coeff * * Al
neighbor        1.0 bin
neigh_modify    every 1 delay 5 check yes
fix             nvt1 all nvt temp 300.0 300.0 1.0
timestep        0.001
thermo          1
run             1000
write_data      ${outputfile2}

At run 1000 I get the following error:

Traceback (most recent call last):
  File "mliap_unified_couple_kokkos.pyx", line 418, in mliap_unified_couple_kokkos.compute_forces_python_kokkos
  File "mliap_unified_couple_kokkos.pyx", line 400, in mliap_unified_couple_kokkos.MLIAPUnifiedInterfaceKokkos.compute_forces
  File "/home/michele/mambaforge/envs/benchmark-mace/lib/python3.12/site-packages/mace/calculators/lammps_mliap_mace.py", line 160, in compute_forces
    _, atom_energies, pair_forces = self.model(batch)
                                    ^^^^^^^^^^^^^^^^^
  File "/home/michele/mambaforge/envs/benchmark-mace/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1751, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/michele/mambaforge/envs/benchmark-mace/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1762, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/michele/mambaforge/envs/benchmark-mace/lib/python3.12/site-packages/mace/calculators/lammps_mliap_mace.py", line 84, in forward
    out = self.model(
          ^^^^^^^^^^^
  File "/home/michele/mambaforge/envs/benchmark-mace/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1751, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/michele/mambaforge/envs/benchmark-mace/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1762, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/michele/mambaforge/envs/benchmark-mace/lib/python3.12/site-packages/mace/modules/models.py", line 418, in forward
    node_feats, sc = interaction(
                     ^^^^^^^^^^^^
  File "/home/michele/mambaforge/envs/benchmark-mace/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1751, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/michele/mambaforge/envs/benchmark-mace/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1762, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/michele/mambaforge/envs/benchmark-mace/lib/python3.12/site-packages/mace/modules/blocks.py", line 545, in forward
    node_feats = self.handle_lammps(
                 ^^^^^^^^^^^^^^^^^^^
  File "/home/michele/mambaforge/envs/benchmark-mace/lib/python3.12/site-packages/mace/modules/blocks.py", line 355, in handle_lammps
    node_feats = LAMMPS_MP.apply(node_feats, lammps_class)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/michele/mambaforge/envs/benchmark-mace/lib/python3.12/site-packages/torch/autograd/function.py", line 575, in apply
    return super().apply(*args, **kwargs)  # type: ignore[misc]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/michele/mambaforge/envs/benchmark-mace/lib/python3.12/site-packages/mace/tools/utils.py", line 158, in forward
    data.forward_exchange(feats, out, ctx.vec_len)
    ^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'mliap_unified_couple_kokkos.MLIAPDataPy' object has no attribute 'forward_exchange'
ERROR: Running mliappy unified compute_forces failure. (src/KOKKOS/mliap_unified_kokkos.cpp:82)

And I really have no clue what’s going on. I could not find anyone else having the same problem and I cannot really determine if it’s a MLAIP issue or a MACE issue (in the latter case I am preventively sorry for spamming on this forum).

What is your LAMMPS version?

It’s not official release, I am building from GitHub - ACEsuit/lammps: Public development project of the LAMMPS MD software package, develop branch.

I asked the maintainers of that repo for help: they could help me for some things, but not this error in particular.

I cannot help you either. I am not involved in the development done in this repo and when the people maintaining it don’t know, then there is not much hope.

I can only note that that repository is substantially behind the develop branch in the upstream repository and that the mliap_unified_couple_kokkos.pyx has had some changes since. Just compare:

with

I am also wondering, why you are using the “develop” branch, which is just tracking upstream (you could just follow the official repo and develop) and not one of the “mace” specific branches.

I am also wondering, why you are using the “develop” branch, which is just tracking upstream (you could just follow the official repo and develop) and not one of the “mace” specific branches.

That’s a great question, and probably the reason why I am getting this error. I was 100% sure MACE documentation indicated to clone their develop branch, it turns out I had to clone LAMMPS official repo instead! The fact that MACE develop branch is so much behind is most probably the reason why I am getting the error. Thanks!

Please let me remind you that the MACE development is done outside of LAMMPS and it is not part of LAMMPS, so you are really looking for help in the wrong place.

Please let me remind you that the MACE development is done outside of LAMMPS and it is not part of LAMMPS, so you are really looking for help in the wrong place.

Might be, but at the end of the day here is where I found the missing piece of solution to my problem (now the ML-IAP interface works like a charm). I understand that it can get frustrating having to skim through dozen of off-topic posts (and I wouldn’t have posted, if I hadn’t spent an entire afternoon debugging, to no avail), but please try not to be too patronizing when people just thank you for you help.

Hello,
I am encountering the same problem, cloning the last stable version doesn’t cut it, I still get:
File “mliap_unified_couple_kokkos.pyx”, line 431, in mliap_unified_couple_kokkos.mliap_unified_connect_kokkos
AttributeError: map_location
ERROR: Running mliappy unified module failure. (src/KOKKOS/mliap_unified_kokkos.cpp:248)

How did you compile LAMMPS to work with mliap?

@podgaetsky are you calling LAMMPS from Python?
Are you using the latest LAMMPS feature release?

My brain needs some AI booster so I cannot tell for sure (AIs always act if they know), but I vaguely recall that somebody else had some issues and needed to call some activation python function. For details, please see the corresponding note in the pair style mliap documentation.

No, I am not calling LAMMPS from PYTHON, but rather using the MLIAP package in a regular LAMMPS run. I tried both the stable and development branches, but had no luck.
I indeed read about the activation function, but it’s irrelevant as I am using LAMMPS input.

Then I don’t know how to help you with this. You have to contact the mliappy authors.

I have no problems with the following test input with either KOKKOS enabled or disabled, with 1 or more MPI tasks.

# create LJ potential for use with mliappy
python create_pickle here """
import lammps
import lammps.mliap
from lammps.mliap.mliap_unified_lj import MLIAPUnifiedLJ
def create_pickle():
    unified = MLIAPUnifiedLJ(['Ar'])
    unified.pickle('mliap_unified_lj_Ar.pkl')
    print('created LJ Ar pickle')
"""
if "$(is_file(mliap_unified_lj_Ar.pkl)) == 0" then "python create_pickle invoke"

units           lj
atom_style      atomic
lattice         fcc 0.8442
region          box block 0 20 0 20 0 20
create_box      1 box
create_atoms    1 box
mass            1 1.0
velocity        all create 3.0 87287 loop geom

pair_style mliap unified mliap_unified_lj_Ar.pkl 0
pair_coeff * * Ar

neighbor        0.3 bin
neigh_modify    every 20 delay 0 check no
fix             1 all nve
thermo          10
run 100 post no