Skip to content

Add Deep Potential plugin for CP2K#1620

Closed
Cloudac7 wants to merge 2 commits intocp2k:masterfrom
Cloudac7:deepmd_latest
Closed

Add Deep Potential plugin for CP2K#1620
Cloudac7 wants to merge 2 commits intocp2k:masterfrom
Cloudac7:deepmd_latest

Conversation

@Cloudac7
Copy link
Contributor

@Cloudac7 Cloudac7 commented Aug 9, 2021

Deep Potential (DP) is a machine learning potential based on deep neural network, first proposed by Zhang L. et al. (Doi: 10.1016/j.cpc.2018.03.016) By learning from coordinates as well as energy and forces of different structures from DFT calculations, a potential describing the whole system could be frozen to a file. By reading the file, program could yield energy, forces etc. from structures, and then MD simulation with DFT accuracy could be fastened greatly. This PR add Deep Potential support for CP2K, with potential file (e.g. graph.pb) supplied, CP2K could run MD simulation.

Only DeePMD-kit >= 2.0.0 is supportted.

To enable the DeePMD-kit feature, --with-deepmd as well as --with-tfcc flag in toolchain should not be set to no. The following ways installing has been added.

  • Please set --deepmd-mode to gpu if GPU support is needed, and load CUDA environment before installing.
  • From exist DeePMD-kit C++ interface, with$deepmd_root and $tensorflow_root (Described here in detail), by setting --with-deepmd=$deepmd_root and --with-tfcc=$tensorflow_root.
  • From source code and library from Github and Anaconda Cloud, by setting the both flags to install. For now, DeePMD-kit v2.0.0.b1 and Tensorflow C++ interface 2.3.0 will be installed, and only CUDA Toolkit 10.1 is OK from this way.
  • From system, by adding the header files and library to where ld command could read directly.

The result from CP2K has been tested to be the same with which from Lammps, supportted by Deepmodeling.

@oschuett
Copy link
Member

oschuett commented Aug 9, 2021

Thanks for the PR. This is certainly impressive work!

As a first step, I'd ask you to remove any merge commits from your git history, ie. make it linear.

Furthermore, I'd suggest you squash the git history to a single (or few) commit(s).

Copy link
Member

@oschuett oschuett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing the git history. I left a couple of comments. Once everything is up and running it would also be good to add some regression tests.

echo "libtensorflow_cc-${tfcc_ver}.tar.bz2 is found"
else
download_pkg ${DOWNLOADER_FLAGS} ${deepmd_sha256} \
https://anaconda.org/deepmodeling/libtensorflow_cc/2.3.0/download/linux-64/libtensorflow_cc-${tfcc_ver}.tar.bz2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Installing Tensorflow via Conda is a nice solution given how painful it is to build from source. However, I'm wondering why are you not using the "official" package from conda forge?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Installing Tensorflow via Conda is a nice solution given how painful it is to build from source. However, I'm wondering why are you not using the "official" package from conda forge?

The packages used here are provided by Deep Modeling, the main developer group of DeePMD-kit. I will also try the package on conda-forge.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The packages used here are provided by Deep Modeling, the main developer group of DeePMD-kit. I will also try the package on conda-forge.

Failed because of the lost of include/google/protobuf/type.pb.h. The package on conda-forge seems not include some headers needed by DeePMD-kit.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That header file is probably part of libprotobuf. So, I guess installing Conda packages by hand is not a very robust solution after all.

I think, then we should keep Tensorflow out of the toolchain for now. It's actually not that hard to install via pip and most HPC centers also provide it.

I've opened #1622 to make Tensorflow available in the CI. Once it's merged you can rebase this PR and continue testing.

;;
esac

cub_link="https://github.com/NVlabs/cub/archive/c3cceac115c072fb63df1836ff46d8c60d9eb304.zip"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe CUB is now included in the regular CUDA Toolkit. So, there is no need to install it separately anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, in DeePMD-kit repository, they just use the very fork of CUB as submodule, while removing it error would be raised when compiling. So here I tried to add it to DeePMD-kit code by downloading code archive file directly. According to your description, it might be OK building without it, and I will have a try.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe CUB is now included in the regular CUDA Toolkit. So, there is no need to install it separately anymore.

In their latest commits, they remove extra CUB requirement for CUDA>=11, shown here, as it has been included in CUDA Toolkit. However, for former CUDA versions, it might still be needed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, then let's keep it for a year or so until everybody has upgrade to CUDA >= 11.

!> \param nonbonded ...
!> \param section ...
!> \param start ...
!> \author teo
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can put your own name here or remove the \author tag as you prefer.

dcoord => dpmd_coord
dbox => dpmd_box
datype => dpmd_atype
! IF (do_parallel) THEN
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left overs copied from QUIP? See also remainder of this routine.

#
FCDEBFLAGS = ${FCDEBFLAGS}
CFLAGS = ${CFLAGS}
CXXFLAGS = ${CXXFLAGS}
Copy link
Member

@oschuett oschuett Aug 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does DeePMD-kit also offer a C API or would it be easy to add? So, far we've managed to keep C++ out of CP2K and I'd really like to keep it that way.

* \brief A minimal wrapper for DeepMD-kit C++ interface.
* \author Yongbin Zhuang and Yunpei Liu
******************************************************************************/

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

include guard #ifndef DEEPMOD_C_WRAPPER_H ... missing

END DO
c_model(N + 1) = C_NULL_CHAR
#if(__DEEPMD)
create_nnp%ptr = create_nnp_c(c_model)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should be able to simply pass along TRIM(model) // C_NULL_CHAR directly without having to copy, see for example src/pw/pw_fpga.F

dener, dforce, dvirial, datom_ener, &
datom_virial, dcoord, datype, dbox) BIND(C, name="compute_nnp")
USE ISO_C_BINDING
TYPE(C_PTR), INTENT(IN), VALUE :: nnp, vecsize, dener, dforce, dvirial, &
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you declare the proper types rather than simply declare everything as a C_PTR?
Also, I somehow doubt that everything is INTENT(IN).

#if(__DEEPMD)
CALL compute_nnp_c(pot, C_LOC(vecsize), C_LOC(dener), C_LOC(dforce(1)), &
C_LOC(dvirial(1)), C_LOC(datom_ener(1)), C_LOC(datom_virial(1)), &
C_LOC(dcoord(1)), C_LOC(datype(1)), C_LOC(dbox(1)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't C_LOC work on the arrays directly rather than taking the first argument first?
Also, it should be possible to drop POINTER but they should likely to be declared CONTIGUOUS instead.

TYPE(deepmd_data_type), POINTER :: deepmd_data
TYPE(deepmd_pot_type), POINTER :: deepmd
TYPE(nnp), SAVE :: deepmd_tmp_pot1, &
deepmd_tmp_pot2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. If you have to preserve data you have to add it to a suitable env. No global vars or shared state.


PRIVATE
LOGICAL, SAVE, PRIVATE :: do_create(2) = .TRUE.
INTEGER, SAVE, PRIVATE :: do_count = 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, see further down below.

@Cloudac7
Copy link
Contributor Author

Thanks for reviewing. We will check our code and modify then.

@oschuett
Copy link
Member

Tensorflow is now readily available within the CI containers (#1622). So, please rebase your branch and adopt install_deepmd.sh.

@oschuett
Copy link
Member

Gentle ping, is this PR still being worked on?

@oschuett
Copy link
Member

@deepmodeling, does anybody know if there is still any interest in this PR?

@oschuett
Copy link
Member

I'm going to close this PR now. Personally, I think it's a really pity because obviously a lot of work went into it. But I'm afraid this wouldn't be useful to anybody without further support from the authors.

@oschuett oschuett closed this Mar 13, 2022
@robinzyb
Copy link
Contributor

I'm going to close this PR now. Personally, I think it's a really pity because obviously a lot of work went into it. But I'm afraid this wouldn't be useful to anybody without further support from the authors.

hi, @oschuett,
@Cloudac7 and me are the contributors to this pr. I will make a new pr since my colleagues have developed relevant FEP methods based on DPMD(https://aip.scitation.org/doi/10.1063/5.0098330) and we are planning to reorganize these codes in a more pretty format.

@robinzyb
Copy link
Contributor

@oschuett is it ok for opening a new subsection named DPNN/DPMD under FORCE_EVAL or nest the section in FORCE_EVAL/NNP

@oschuett
Copy link
Member

Hi @robinzyb, this is great news!

is it ok for opening a new subsection named DPNN/DPMD under FORCE_EVAL or nest the section in

Yes, please create new subsections below FORCE_EVAL, MOTION/MD, and MOTION/FREE_ENERGY as you see fit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants