Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Paddle support to Deepmd and Lammps #1699

Open
wants to merge 11 commits into
base: paddle-backup
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "source/lib/src/cuda/cub"]
path = source/lib/src/cuda/cub
url = git://github.com/NVIDIA/cub.git
url = https://github.com/NVIDIA/cub.git
122 changes: 122 additions & 0 deletions README_Paddle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# 1.Introduction
This repo is based on the PaddlePaddle deep learning framework including training and inference parts,DeepMD-kit package,LAMMPS software. The target is, basing on PaddlePaddle framework, to accomplish molecular dynamics simulation with deep learning method.
- PaddlePaddle (PArallel Distributed Deep LEarning) is a simple, efficient and extensible deep learning framework.
- DeePMD-kit is a package written in Python/C++, designed to minimize the effort required to build deep learning based model of interatomic potential energy and force field and to perform molecular dynamics (MD).
- LAMMPS is a classical molecular dynamics code with a focus on materials modeling. It's an acronym for Large-scale Atomic/Molecular Massively Parallel Simulator.

# 2.Progress&Features
- Based on Intel CPU, the pipline of training and inference runs smoothly
- Support traditional molecular dynamics software LAMMPS
- Support se_a desciptor model

# 3.Compiling&Building&Installation
- prepare docker and python environment
```
docker pull paddlepaddle/paddle:latest-dev-cuda11.0-cudnn8-gcc82
docker run -it --name {name} -v 绝对路径开发目录:绝对路径开发目录 -v /root/.cache:/root/.cache -v /root/.ccache:/root/.ccache {image_id} bash
rm -f /usr/bin/python3
ln -s /usr/bin/python3.8 /usr/bin/python3
wget https://github.com/Kitware/CMake/releases/download/v3.21.0/cmake-3.21.0-linux-x86_64.tar.gz && tar -xf cmake-3.21.0-linux-x86_64.tar.gz
add ~/.bashrc:export PATH=/home/cmake-3.21.0-linux-x86_64/bin:$PATH
```

- compile Paddle
```
git clone https://github.com/PaddlePaddle/Paddle.git
cd Paddle
git reset --hard eca6638c599591c69fe40aa196f5fd42db7efbe2
rm -rf build && mkdir build && cd build
cmake .. -DPY_VERSION=3.8 -DPYTHON_INCLUDE_DIR=$(python3 -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") -DPYTHON_LIBRARY=$(python3 -c "import distutils.sysconfig as sysconfig; print(sysconfig.get_config_var('LIBDIR'))") -DWITH_GPU=OFF -DWITH_AVX=ON -DON_INFER=ON -DCMAKE_BUILD_TYPE=Release
# cmake .. -DPY_VERSION=3.8 -DPYTHON_INCLUDE_DIR=$(python3 -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") -DPYTHON_LIBRARY=$(python3 -c "import distutils.sysconfig as sysconfig; print(sysconfig.get_config_var('LIBDIR'))") -DWITH_GPU=On -DWITH_AVX=ON -DON_INFER=ON -DCUDA_ARCH_NAME=Auto -DCMAKE_BUILD_TYPE=Release
make -j 32
make -j 32 inference_lib_dist
python3 -m pip install python/dist/paddlepaddle-0.0.0-cp38-cp38-linux_x86_64.whl --no-cache-dir
PADDLE_ROOT=/home/Paddle/build/paddle_inference_install_dir(or add in bashrc with export)
```
- compile Paddle_DeepMD-kit --training part
```
cd /home
git clone https://github.com/X4Science/paddle-deepmd.git
cd /home/paddle-deepmd
python3 -m pip install tensorflow-cpu==2.5.0
# python3 -m pip install tensorflow-gpu==2.5.0
python3 -m pip install scikit-build
python3 setup.py install
find the package name of deepmd-kit in the location of installation and add in bashrc
export LD_LIBRARY_PATH=/usr/local/lib/python3.8/dist-packages/**{deepmd_name}**/deepmd/op:$LD_LIBRARY_PATH
export LIBRARY_PATH=/usr/local/lib/python3.8/dist-packages/**{deepmd_name}**/deepmd/op:$LIBRARY_PATH
export DEEP_MD_PATH=/usr/local/lib/python3.8/dist-packages/**{deepmd_name}**/deepmd/op
source ~/.bashrc
cd deepmd && python3 load_paddle_op.py install
```

- compile Paddle_DeepMD-kit --inference part
```
rm -rf /home/deepmdroot/ && mkdir /home/deepmdroot && DEEPMD_ROOT=/home/deepmdroot(or add in bashrc with export)
cd /home/paddle-deepmd/source && rm -rf build && mkdir build && cd build
cmake -DCMAKE_INSTALL_PREFIX=$DEEPMD_ROOT -DPADDLE_ROOT=$paddle_root -DUSE_CUDA_TOOLKIT=FALSE -DFLOAT_PREC=low ..
make -j 4 && make install
make lammps
```
- compile LAMMPS
```
cd /home
wget https://download.open-mpi.org/release/open-mpi/v4.0/openmpi-4.0.7.tar.gz
tar xf openmpi-4.0.7.tar.gz
cd openmpi-4.0.7
./configure
make all install
add bashrc: export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
#apt install libc-dev
cd /home
wget https://github.com/lammps/lammps/archive/stable_29Oct2020.tar.gz
rm -rf lammps-stable_29Oct2020/
tar -xzvf stable_29Oct2020.tar.gz
cd lammps-stable_29Oct2020/src/
cp -r /home/paddle-deepmd/source/build/USER-DEEPMD .
make yes-kspace yes-user-deepmd
#make serial -j 20
make mpi -j 20
add in bashrc by
export LD_LIBRARY_PATH=/home/Paddle/build/paddle_inference_install_dir/paddle/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/home/Paddle/build/paddle_inference_install_dir/third_party/install/mkldnn/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/home/Paddle/build/paddle_inference_install_dir/third_party/install/mklml/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/home/Paddle/build/paddle/fluid/pybind/:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/home/deepmd-kit/source/build:$LD_LIBRARY_PATH
source ~/.bashrc
```
# 4.Using Guide
example: water
- training
```
cd /paddle_deepmd-kit_PATH/example/water/train/
dp train water_se_a.json
cp ./model.ckpt/model.pd* ../lmp/ -r
cd ../lmp
```
- inference
```
mpirun -np 10 lmp_mpi -in in.lammps
```


# 5.Performance
- The performance of inference based on the LAMMPS with PaddlePaddle framework,comparing with TensorFlow framework, about single core and multi-threads
![截屏2022-05-25 23 08 11](https://user-images.githubusercontent.com/50223303/170295703-32e18058-aff9-4368-93cd-38a1ed787e8a.png)
- single thread performance
```
TF_INTRA_OP_PARALLELISM_THREADS=8 TF_INTER_OP_PARALLELISM_THREADS=1 numactl -c 0 -m 0 lmp_serial -in in.lammps
```
- multithreads performance
```
OMP_NUM_THREADS=1 TF_INTRA_OP_PARALLELISM_THREADS=1 TF_INTER_OP_PARALLELISM_THREADS=1 mpirun --allow-run-as-root -np 4 lmp_mpi -in in.lammps
```
# 6.Future Plans
- fix training precision
- support Gromacs
- support more descriptor and fitting net model
- support GPU trainning

# 7.Cooperation
Welcome to join us to develop this program together.
Please contact us from [X4Science](https://github.com/X4Science) [PaddlePaddle](https://www.paddlepaddle.org.cn) [PPSIG](https://www.paddlepaddle.org.cn/sig) [PaddleAIforScience](https://www.paddlepaddle.org.cn/science) [PaddleScience](https://github.com/PaddlePaddle/PaddleScience).
9 changes: 3 additions & 6 deletions deepmd/load_paddle_op.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
from paddle.utils.cpp_extension import CppExtension, CUDAExtension, setup
from paddle.utils.cpp_extension import CppExtension, setup
import site

site_package_dir = site.getsitepackages()[0]

setup(
name='paddle_ops',
ext_modules=CUDAExtension(
ext_modules=CppExtension(
sources=['../source/op/paddle_ops/srcs/pd_prod_env_mat_multi_devices_cpu.cc',
'../source/op/paddle_ops/srcs/pd_prod_env_mat_multi_devices_cuda.cc',
'../source/op/paddle_ops/srcs/pd_prod_force_se_a_multi_devices_cpu.cc',
'../source/op/paddle_ops/srcs/pd_prod_force_se_a_multi_devices_cuda.cc',
'../source/op/paddle_ops/srcs/pd_prod_virial_se_a_multi_devices_cpu.cc',
'../source/op/paddle_ops/srcs/pd_prod_virial_se_a_multi_devices_cuda.cc'],
'../source/op/paddle_ops/srcs/pd_prod_virial_se_a_multi_devices_cpu.cc'],
include_dirs=["../source/lib/include/"],
library_dirs=[site_package_dir+"/deepmd/op"],
extra_link_args=["-ldeepmd"]
Expand Down
13 changes: 0 additions & 13 deletions examples/water/ipi/water.json

This file was deleted.

6 changes: 4 additions & 2 deletions examples/water/lmp/in.lammps
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# bulk water

echo screen
units metal
boundary p p p
atom_style atomic
Expand All @@ -11,11 +11,13 @@ read_data water.lmp
mass 1 16
mass 2 2

pair_style deepmd frozen_model.pb
pair_style deepmd model.ckpt/model.pdmodel model.ckpt/model.pdiparams
pair_coeff

velocity all create 330.0 23456789
duplicate 10 10 10

write_data init.data
fix 1 all nvt temp 330.0 330.0 0.5
timestep 0.0005
thermo_style custom step pe ke etotal temp press vol
Expand Down
19 changes: 19 additions & 0 deletions examples/water/lmp/log.cite
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
This LAMMPS simulation made specific use of work described in the
following references. See https://lammps.sandia.gov/cite.html
for details.

USER-DEEPMD package:

based on PaddlePaddle framework and inference@article{Wang_ComputPhysCommun_2018_v228_p178,
author = {Wang, Han and Zhang, Linfeng and Han, Jiequn and E, Weinan},
doi = {10.1016/j.cpc.2018.03.016},
url = {https://doi.org/10.1016/j.cpc.2018.03.016},
year = 2018,
month = {jul},
publisher = {Elsevier {BV}},
volume = 228,
journal = {Comput. Phys. Commun.},
title = {{DeePMD-kit: A deep learning package for many-body potential energy representation and molecular dynamics}},
pages = {178--184}
}

Binary file added examples/water/lmp/model.ckpt/model.pdiparams
Binary file not shown.
Binary file not shown.
Binary file added examples/water/lmp/model.ckpt/model.pdmodel
Binary file not shown.
88 changes: 88 additions & 0 deletions examples/water/train/out.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
{
"model": {
"type_map": [
"O",
"H"
],
"descriptor": {
"type": "se_a",
"sel": [
46,
92
],
"rcut_smth": 5.8,
"rcut": 6.0,
"neuron": [
25,
50,
100
],
"resnet_dt": false,
"axis_neuron": 16,
"seed": 1,
"activation_function": "tanh",
"type_one_side": false,
"precision": "float64",
"trainable": true,
"exclude_types": [],
"set_davg_zero": false
},
"fitting_net": {
"neuron": [
240,
240,
240
],
"resnet_dt": true,
"seed": 1,
"type": "ener",
"numb_fparam": 0,
"numb_aparam": 0,
"activation_function": "tanh",
"precision": "float64",
"trainable": true,
"rcond": 0.001,
"atom_ener": []
},
"data_stat_nbatch": 10,
"data_stat_protect": 0.01
},
"learning_rate": {
"type": "exp",
"decay_steps": 5000,
"start_lr": 0.001,
"stop_lr": 3.51e-08
},
"loss": {
"start_pref_e": 0.02,
"limit_pref_e": 1,
"start_pref_f": 1000,
"limit_pref_f": 1,
"start_pref_v": 0,
"limit_pref_v": 0,
"type": "ener",
"start_pref_ae": 0.0,
"limit_pref_ae": 0.0
},
"training": {
"systems": [
"../data/"
],
"set_prefix": "set",
"stop_batch": 1000000,
"batch_size": 1,
"seed": 1,
"disp_file": "lcurve.out",
"disp_freq": 100,
"numb_test": 10,
"save_ckpt": "model.ckpt",
"load_ckpt": "model.ckpt",
"disp_training": true,
"time_training": true,
"tensorboard": false,
"tensorboard_log_dir": "log",
"profiling": false,
"profiling_file": "timeline.json",
"save_freq": 10000
}
}
64 changes: 0 additions & 64 deletions examples/water/train/polar.json

This file was deleted.

Loading