VASPml library

From VASP Wiki
Revision as of 09:36, 23 January 2025 by Singraber (talk | contribs)

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

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.

Restrictions

Since the VASPml library is still under development some features available in the original Fortran code are not yet available:

  • No machine learning related file output (e.g. ML_LOGFILE)
Tip: For running the fast prediction-only mode in VASP there is currently only negligible performance gains from the VASPml library. Hence, if file output is important (e.g. when monitoring the spilling factor) we recommend using the original Fortran code (ML_LIB = .FALSE.).

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 with values according to your toolchain. For example, when using the GCC toolchain with OpenBLAS the makefile.include section 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
...

Apart from the mandatory -Dlibvaspml flag there are the following possible CPP_OPTIONS:

  • -DVASPML_DEBUG_LEVEL=[0|1|2|3]: If set to 1, 2 or 3 enables various sanity checks during runtime with low, medium and high impact on performance, respectively.
Mind: Do not use this flag for production runs as it may impact performance.
  • -DVASPML_USE_CBLAS: Use CBLAS (C interface for BLAS routines) for linear algebra. This is the default and should always be used.
  • -DVASPML_USE_MKL: Use Intel MKL for linear algebra.

In addition, VASPml requires to set its own compiler, flags and include path:

  • CXX_ML: This should be a C++17-compatible C++ compiler with MPI support.
  • CXXFLAGS_ML: Specifies the flags for the C++ compiler.
  • INCLUDE_ML: Paths in which to look for headers of required libraries. Here the include directory of BLAS should be listed.

The VASPml project (source code and related files) is located