Skip to content

Deep potential plugin for CP2K implemented from C interface#3145

Merged
oschuett merged 19 commits intocp2k:masterfrom
Cloudac7:deepmd-c-interface
Jan 4, 2024
Merged

Deep potential plugin for CP2K implemented from C interface#3145
oschuett merged 19 commits intocp2k:masterfrom
Cloudac7:deepmd-c-interface

Conversation

@Cloudac7
Copy link
Contributor

@Cloudac7 Cloudac7 commented Dec 6, 2023

Enhanced based on #1620
For the implementation is fully changed, I think it would be better to just open a new PR instead of former old one.

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.

As mentioned in #1620 , it was not a good practice to introduce C++ flags in CP2K, while at that time DeePMD-kit does not supply C interface. But now everything has changed. Since v2.2.x, DeePMD-kit C Interface is directly released together with each DeePMD-kit release, making it no need to install libtensorflow_cc any more. In this way, C wrapper has been rewritten and now only necessary parameters are added to arch file.

We also support download from toolchain. To enable the DeePMD-kit feature, --with-deepmd 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, by setting --with-deepmd=/path/to/libdeepmd_c.
  • From source code and library from Github, by setting it to install. For now, DeePMD-kit v2.2.7 will be installed.
  • From system, by adding the header files and library to where ld command could read directly.

DEALLOCATE (fist_nonbond_env%deepmd_data%force)
END IF
IF (ASSOCIATED(fist_nonbond_env%deepmd_data%use_indices)) THEN
DEALLOCATE (fist_nonbond_env%deepmd_data%use_indices)
Copy link
Contributor

Choose a reason for hiding this comment

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

I would refactor that into a routine in the DeepMD module

ALLOCATE (use_atom(n_atoms))
ALLOCATE (use_atom_type(n_atoms))
use_atom = .FALSE.
use_atom_type = 100 ! just initial the array
Copy link
Contributor

Choose a reason for hiding this comment

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

initialize

SUBROUTINE pair_potential_deepmd_copy(deepmd_source, deepmd_dest)
TYPE(deepmd_pot_type), POINTER :: deepmd_source, deepmd_dest

IF (.NOT. ASSOCIATED(deepmd_source)) RETURN
Copy link
Contributor

Choose a reason for hiding this comment

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

I would rather nullify deepmd_dest

@oschuett
Copy link
Member

oschuett commented Dec 7, 2023

It's so nice to see DeePMD land after all :-)

This PR looks very good to me. My only concern is with the H2O-DPLR-model.pb file because its 10.3 MB. Is there maybe a smaller model we could use for testing?

@Cloudac7
Copy link
Contributor Author

Cloudac7 commented Dec 8, 2023

It's so nice to see DeePMD land after all :-)

This PR looks very good to me. My only concern is with the H2O-DPLR-model.pb file because its 10.3 MB. Is there maybe a smaller model we could use for testing?

I just replaced the model as one of 1.6 MB in AISSquare. It could be a rather small one to reproduce results just similar to calculation result for a W cell as shown in materials project.

@Cloudac7 Cloudac7 force-pushed the deepmd-c-interface branch from 8d1452d to bc6def1 Compare January 4, 2024 07:04
@oschuett
Copy link
Member

oschuett commented Jan 4, 2024

Seems like there is a memory leak. Can you fix this in DeepMD? Otherwise you could add a suppression.

@Cloudac7
Copy link
Contributor Author

Cloudac7 commented Jan 4, 2024

Seems like there is a memory leak. Can you fix this in DeepMD? Otherwise you could add a suppression.

As discussed in deepmodeling/deepmd-kit#3045, there is memory leak in Tensorflow and Protobuf, which could not be so easily fixed, while @njzjz has fixed a possible leak in DeePMD-kit (deepmodeling/deepmd-kit#3062, thanks a lot.)

At this moment, I think just adding suppression might be OK while the leak is not so severe that might cause the program crashing.

@robinzyb
Copy link
Contributor

robinzyb commented Jan 4, 2024

It is nice to see this interface land!

@oschuett oschuett merged commit 969d126 into cp2k:master Jan 4, 2024
@oschuett
Copy link
Member

oschuett commented Jan 4, 2024

I'm also very happy to finally merge this. Great work!

Btw, we now have a section on machine learning in our manual ;-)

@njzjz
Copy link

njzjz commented Jan 4, 2024

Thanks, @Cloudac7.

DeePMD-kit also has a documentation page for all external interfaces.

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.

5 participants