VASPml library: Difference between revisions

From VASP Wiki
No edit summary
No edit summary
Line 1: Line 1:
VASPml is a C++ library accompanying {{VASP}}, providing functionality related to machine-learned force fields. It is supposed to extend, and eventually replace, the original Fortran machine learning code inside {{VASP}}. Currently, it does not yet offer any training capabilities but rather focuses on inference. At this point VASPml is in a beta-testing stage and provides its first application, an interface to the popular molecular dynamics (MD) software [https://www.lammps.org LAMMPS]. This allows users to combine {{VASP}}-generated machine-learned force fields with the large amount of MD-related features provided by LAMMPS, some of which may not be offered in {{VASP}} directly.
VASPml is a C++ library accompanying {{VASP}}, providing functionality related to machine-learned force fields. It is supposed to extend, and eventually replace, the original Fortran machine learning code inside {{VASP}}. Currently, it does not yet offer any training capabilities but rather focuses on inference. At this point VASPml is in a beta-testing stage and provides its first application, an interface to the popular molecular dynamics (MD) software [https://www.lammps.org LAMMPS]. This allows users to combine {{VASP}}-generated machine-learned force fields with the large amount of MD-related features provided by LAMMPS, some of which may not be offered in {{VASP}} directly.
{{NB|warning|As of {{VASP}} 6.5.0 the VASPml library is experimental and results should be carefully checked against the standard Fortran code (compile without <code>-Dlibvaspml</code> or set {{TAGO|ML_LIB|.FALSE.}}).}}


= Build instructions =
= Supported features =


In future the source of VASPml will be distributed as part of the official {{VASP}} release. The build process of {{VASP}} will include the steps necessary to compile and link also the VASPml library and interfaces. However, at this point (and most likely even when integrated into {{VASP}}) it is possible to build VASPml completely independent of {{VASP}}. The following sections describe details of such an independent build of VASPml.
* Fast prediction-only mode in {{VASP}} ({{TAGO|ML_MODE|run}})
* Running {{VASP}} machine-learned force fields in LAMMPS


=== Prerequisites ===
If {{VASP}} is compiled with the VASPml library and a requested feature is supported by both, the original Fortran code '''and''' the C++ VASPml implementation, then the latter code path is used by default. To override this behavior and explicitly avoid the use of the VASPml library set {{TAGO|ML_LIB|.FALSE.}} in the {{FILE|INCAR}} file.


# VASPml requires a C++ compiler conforming to the C++17 language standard, for example compilers which are part of:
= Build instructions =
#* GNU Compiler Collection
#* Intel oneAPI Base Toolkit
#* NVIDIA HPC SDK
#* NEC SDK
# Numerical libraries: LAPACK and BLAS, which are distributed for example as part of:
#* OpenBLAS
#* Intel oneAPI Math Kernel Library (part of Base Toolkit)
#* NVIDIA HPC SDK
#* NEC NLC (NEC Numeric Library Collection)
# An MPI (Message Passing Interface) implementation, e.g. in
#* OpenMPI
#* Intel MPI (part of Intel oneAPI HPC Toolkit)
#* NVIDIA HPC SDK (OpenMPI)
#* NEC MPI
 
=== Build library and applications ===
 
Similar to {{VASP}} also VASPml requires to enter compiler details and library paths into a file named <code>makefile.include</code> before the build process can be started. Template files for this file can be found in the <code>arch</code> subdirectory. Usually it is convenient to start from one of these files. Hence, first copy it to the base directory and rename it to <code>makefile.include</code>, e.g.
 
<pre>cp arch/makefile.include.gnu makefile.include</pre>
Then modify the contents to reflect the compiler and library settings on your machine, for details see the [[#compiler-and-linker-options|compiler and linker options]] section below. Once done, the VASPml library can be built by executing this command in the top directory:
 
<pre>make -j </pre>
This will automatically build the two ''targets'' <code>libvaspml</code> and <code>applications</code>, and is equivalent of running two make commands explicitly in this order:
 
<pre>make libvaspml -j
make applications -j</pre>
The <code>libvaspml</code> target builds the library with same name and places it in the <code>lib</code> folder. The <code>applications</code> target compiles and links standalone applications present in <code>src/applications</code>. At the moment there is only one application named <code>vaspml-predict</code> which predicts energy, forces and stress for one <code>POSCAR</code> file with a given <code>ML_FF</code> force field file. The executable will be copied to the <code>bin</code> directory.
 
With the <code>-j</code> flag present <code>make</code> will run the build process in parallel, starting as many parallel jobs as possible. You can limit the maximum load the build process is allowed to cause with the <code>-l</code> flag, please review the documentation of GNU <code>make</code>.
 
==== Compiler and linker options ====
 
The following compiler and linker options in the <code>makefile.include</code> should be reviewed and eventually modified before starting the build process:
 
* <code>CXX</code>: This should be a C++17-compatible C++ compiler with MPI support.
* <code>CXXFLAGS</code>: Specifies the flags for the C++ compiler.
* <code>INCLUDE</code>: Paths in which to look for headers of required libraries. Here the include directory of BLAS should be listed.
* <code>FC</code> (deprecated)
* <code>FFLAGS</code> (deprecated)
 
==== Compile-time options ====
 
* <code>-DVASPML_DEBUG_LEVEL</code>: If set to 1, 2 or 3 enables various sanity checks during runtime with low, medium and high impact on performance, respectively.
* <code>-DVASPML_USE_CBLAS</code>: Use CBLAS (C interface for BLAS routines) for linear algebra. This is the default and should always be used.
* <code>-DVASPML_USE_MKL</code>: Use Intel MKL for linear algebra.
* <code>-DVASPML_FORTRAN_MATH</code> (deprecated): Enable legacy Fortran math routines.
 
==== Makefile options ====
 
* <code>--no-color</code>: Disables colored output of makefiles.
* <code>--no-logo</code>: Disables the logo VASPml logo output.
 
=== Automatic patching and compilations of LAMMPS ===


<pre>make lammps -j</pre>
The VASPml library is automatically built alongside {{VASP}} if <code>-Dlibvaspml</code> is added to the <code>CPP_OPTIONS</code> [[Precompiler options|precompiler option]] in the [[makefile.include]] file. In addition, a few more compiler settings regarding the C++ compiler, include paths and VASPml options may be required. The [[makefile.include#Archetypical files|makefile.include templates]] provided in {{VASP}}'s <code>arch</code> directory contain pre-filled blocks corresponding to the VASPml build. Uncomment the VASPml-related lines and fill  and This may look like this:
==== Technical details ====


From a technical standpoint LAMMPS and VASPml interact in the following way: on the LAMMPS side a new class <code>PairVASP</code> (inheriting from <code>Pair</code>) is implemented in <code>pair_vasp.cpp/h</code>. Its purpose is to transfer the neighbor lists to VASPml, trigger processing, and receive back the energy and force contributions. VASPml enters the received neighbor list data into its own structures and computes energy and force predictions according to the pre-trained machine-learned force field. A typical build for the combination of the two codes requires to first compile the <code>libvaspml</code> library. Then, LAMMPS is patched with the additional <code>pair_vasp.cpp/h</code> files, which are automatically compiled during the LAMMPS build. In the final stage, LAMMPS is linked to the <code>libvaspml</code> library, resulting in a patched executable. This can be done manually but VASPml also offers a convenient automated way covering all steps (<code>make lammps</code>).
...
# For machine learning library vaspml (experimental)
#CPP_OPTIONS += -Dlibvaspml
#CPP_OPTIONS += -DVASPML_USE_CBLAS
#CPP_OPTIONS += -DVASPML_DEBUG_LEVEL=3
#CXX_ML      = mpic++
#CXXFLAGS_ML = -O3 -std=c++17 -pedantic-errors -Wall -Wextra
#INCLUDE_ML  = -I$(OPENBLAS_ROOT)/include
...

Revision as of 14:53, 22 January 2025

VASPml is a C++ library accompanying VASP, providing functionality related to machine-learned force fields. It is supposed to extend, and eventually replace, the original Fortran machine learning code inside VASP. Currently, it does not yet offer any training capabilities but rather focuses on inference. At this point VASPml is in a beta-testing stage and provides its first application, an interface to the popular molecular dynamics (MD) software LAMMPS. This allows users to combine VASP-generated machine-learned force fields with the large amount of MD-related features provided by LAMMPS, some of which may not be offered in VASP directly.

Warning: As of VASP 6.5.0 the VASPml library is experimental and results should be carefully checked against the standard Fortran code (compile without -Dlibvaspml or set ML_LIB = .FALSE.).

Supported features

  • Fast prediction-only mode in VASP (ML_MODE = run)
  • Running VASP machine-learned force fields in LAMMPS

If VASP is compiled with the VASPml library and a requested feature is supported by both, the original Fortran code and the C++ VASPml implementation, then the latter code path is used by default. To override this behavior and explicitly avoid the use of the VASPml library set ML_LIB = .FALSE. in the INCAR file.

Build instructions

The VASPml library is automatically built alongside VASP if -Dlibvaspml is added to the CPP_OPTIONS precompiler option in the makefile.include file. In addition, a few more compiler settings regarding the C++ compiler, include paths and VASPml options may be required. The makefile.include templates provided in VASP's arch directory contain pre-filled blocks corresponding to the VASPml build. Uncomment the VASPml-related lines and fill and This may look like this:

...
# For machine learning library vaspml (experimental)
#CPP_OPTIONS += -Dlibvaspml
#CPP_OPTIONS += -DVASPML_USE_CBLAS
#CPP_OPTIONS += -DVASPML_DEBUG_LEVEL=3
#CXX_ML      = mpic++
#CXXFLAGS_ML = -O3 -std=c++17 -pedantic-errors -Wall -Wextra
#INCLUDE_ML  = -I$(OPENBLAS_ROOT)/include
...