pair_nequip icon indicating copy to clipboard operation
pair_nequip copied to clipboard

Error when link Lammps to python after Nequip complied

Open Dio2k opened this issue 3 years ago • 1 comments

I have pytorch==1.11.0+cu113 and cuda 11.3 on my system. After I complied Lammps with Nequip, I want to link Lammps to python. but when I input make serial mode=shlib in terminal in the path/to/src, the following error accurred:

g++ -g -O3 -std=c++11 -fPIC -DLAMMPS_GZIP -DLAMMPS_MEMALIGN=64    -I../STUBS     -c ../lammps.cpp
In file included from ../style_pair.h:16,
                 from ../lammps.cpp:29:
../pair_nequip.h:25:10: fatal error: torch/torch.h: No such file or directory
   25 | #include <torch/torch.h>;
      |          ^~~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [Makefile:109: lammps.o] Error 1
make[2]: Leaving directory '/home/ubuntu/software/lammps/lammps/src/Obj_shared_serial'
make[1]: *** [Makefile:390: serial] Error 2
make[1]: Leaving directory '/home/ubuntu/software/lammps/lammps/src'
make: *** [Makefile:390: serial] Error 2

I can easily link a new Lammps with nothing complied to python by:

make serial mode=shlib
make install-python

but I can't make it when Nequip is complied. I wonder if it is possible to link Lammps with Nequip implied to python or does someone manage it?

Dio2k avatar Nov 11 '22 09:11 Dio2k

This should be possible, but you need to do everything within CMake, since we use it to find Torch.

See the documentation, but you should essentially add something like -DPKG_PYTHON=ON -DBUILD_SHARED_LIBS=ON.

You can try to set -DCMAKE_INSTALL_PREFIX=/somewhere/in/path and run make install and pray that you can then run import lammps; l = lammps.lammps(), although this is somewhat unreliable. A safer option is to set the environment variables PYTHONPATH=$PYTHONPATH:/path/to/lammps/python LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/lammps/build

anjohan avatar Nov 11 '22 15:11 anjohan