Skip to content

Commit a71dd61

Browse files
committed
Merge branch 'develop' of https://github.com/deepmodeling/abacus-develop into hotfix
2 parents 31cad58 + 60c1f77 commit a71dd61

File tree

164 files changed

+2428
-2806
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

164 files changed

+2428
-2806
lines changed

.github/workflows/coverage.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ jobs:
1515
uses: actions/checkout@v4
1616
- name: Install Requirements for Coverage Testing
1717
run: |
18-
apt update && apt install -y lcov
18+
apt update && apt install -y lcov gpg
1919
- name: Building
2020
run: |
21-
cmake -B build -DENABLE_DEEPKS=ON -DENABLE_LIBXC=ON -DBUILD_TESTING=ON -DENABLE_COVERAGE=ON
21+
cmake -B build -DENABLE_COVERAGE=ON -DBUILD_TESTING=ON -DENABLE_DEEPKS=ON -DENABLE_LIBXC=ON -DENABLE_LIBRI=ON -DENABLE_PAW=ON -DENABLE_GOOGLEBENCH=ON -DENABLE_RAPIDJSON=ON
2222
cmake --build build -j`nproc`
2323
cmake --install build
2424
- name: Testing

CMakeLists.txt

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -436,22 +436,6 @@ if(ENABLE_FLOAT_FFTW)
436436
endif()
437437

438438
if(ENABLE_DEEPKS)
439-
# Torch uses outdated components to detect CUDA arch, causing failure on
440-
# latest CUDA kits. Set CMake variable TORCH_CUDA_ARCH_LIST in the form of
441-
# "major.minor" if required.
442-
find_package(Torch REQUIRED)
443-
if(NOT Torch_VERSION VERSION_LESS "2.1.0")
444-
set_if_higher(CMAKE_CXX_STANDARD 17)
445-
elseif(NOT Torch_VERSION VERSION_LESS "1.5.0")
446-
set_if_higher(CMAKE_CXX_STANDARD 14)
447-
endif()
448-
include_directories(${TORCH_INCLUDE_DIRS})
449-
if(MKL_FOUND)
450-
list(PREPEND math_libs ${TORCH_LIBRARIES})
451-
else()
452-
list(APPEND math_libs ${TORCH_LIBRARIES})
453-
endif()
454-
add_compile_options(${TORCH_CXX_FLAGS})
455439
target_link_libraries(${ABACUS_BIN_NAME} deepks)
456440

457441
find_path(libnpy_SOURCE_DIR npy.hpp HINTS ${libnpy_INCLUDE_DIR})
@@ -470,6 +454,25 @@ if(ENABLE_DEEPKS)
470454
add_compile_definitions(__DEEPKS)
471455
endif()
472456

457+
# Torch uses outdated components to detect CUDA arch, causing failure on
458+
# latest CUDA kits. Set CMake variable TORCH_CUDA_ARCH_LIST in the form of
459+
# "major.minor" if required.
460+
if(ENABLE_DEEPKS OR DEFINED Torch_DIR)
461+
find_package(Torch REQUIRED)
462+
if(NOT Torch_VERSION VERSION_LESS "2.1.0")
463+
set_if_higher(CMAKE_CXX_STANDARD 17)
464+
elseif(NOT Torch_VERSION VERSION_LESS "1.5.0")
465+
set_if_higher(CMAKE_CXX_STANDARD 14)
466+
endif()
467+
include_directories(${TORCH_INCLUDE_DIRS})
468+
if(MKL_FOUND)
469+
list(PREPEND math_libs ${TORCH_LIBRARIES})
470+
else()
471+
list(APPEND math_libs ${TORCH_LIBRARIES})
472+
endif()
473+
add_compile_options(${TORCH_CXX_FLAGS})
474+
endif()
475+
473476
if (ENABLE_CNPY)
474477
find_path(cnpy_SOURCE_DIR
475478
cnpy.h
@@ -590,13 +593,14 @@ if(DEFINED DeePMD_DIR)
590593
add_compile_definitions(__DPMDC)
591594
else()
592595
target_link_libraries(${ABACUS_BIN_NAME} DeePMD::deepmd_cc)
593-
if(NOT DEFINED TensorFlow_DIR)
594-
set(TensorFlow_DIR ${DeePMD_DIR})
595-
endif()
596-
find_package(TensorFlow REQUIRED)
597-
if(TensorFlow_FOUND)
598-
target_link_libraries(${ABACUS_BIN_NAME} TensorFlow::tensorflow_cc)
599-
endif()
596+
endif()
597+
endif()
598+
599+
if(DEFINED TensorFlow_DIR)
600+
find_package(TensorFlow REQUIRED)
601+
include_directories(${TensorFlow_DIR}/include)
602+
if(TensorFlow_FOUND)
603+
target_link_libraries(${ABACUS_BIN_NAME} TensorFlow::tensorflow_cc)
600604
endif()
601605
endif()
602606

docs/advanced/input_files/input-main.md

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
- [pw\_diag\_thr](#pw_diag_thr)
4040
- [pw\_diag\_nmax](#pw_diag_nmax)
4141
- [pw\_diag\_ndim](#pw_diag_ndim)
42-
- [diago\_full\_acc](#diago_full_acc)
4342
- [erf\_ecut](#erf_ecut)
4443
- [fft\_mode](#fft_mode)
4544
- [erf\_height](#erf_height)
@@ -779,12 +778,6 @@ These variables are used to control the plane wave related parameters.
779778
- **Description**: Only useful when you use `ks_solver = dav` or `ks_solver = dav_subspace`. It indicates dimension of workspace(number of wavefunction packets, at least 2 needed) for the Davidson method. A larger value may yield a smaller number of iterations in the algorithm but uses more memory and more CPU time in subspace diagonalization.
780779
- **Default**: 4
781780

782-
### diago_full_acc
783-
784-
- **Type**: bool
785-
- **Description**: Only useful when you use `ks_solver = dav_subspace`. If `TRUE`, all the empty states are diagonalized at the same level of accuracy of the occupied ones. Otherwise the empty states are diagonalized using a larger threshold (10-5) (this should not affect total energy, forces, and other ground-state properties).
786-
- **Default**: false
787-
788781
### erf_ecut
789782

790783
- **Type**: Real
@@ -925,7 +918,7 @@ calculations.
925918
- **cg**: cg method.
926919
- **bpcg**: bpcg method, which is a block-parallel Conjugate Gradient (CG) method, typically exhibits higher acceleration in a GPU environment.
927920
- **dav**: the Davidson algorithm.
928-
- **dav_subspace**: subspace Davidson algorithm
921+
- **dav_subspace**: Davidson algorithm without orthogonalization operation, this method is the most recommended for efficiency. `pw_diag_ndim` can be set to 2 for this method.
929922

930923
For atomic orbitals basis,
931924

docs/advanced/install.md

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,22 @@ cmake -B build -DENABLE_DEEPKS=1 -DTorch_DIR=~/libtorch/share/cmake/Torch/ -Dlib
3838
If the Deep Potential model is employed in Molecule Dynamics calculations, the following prerequisites and steps are needed:
3939

4040
- [DeePMD-kit](https://github.com/deepmodeling/deepmd-kit)
41-
- [TensorFlow](https://www.tensorflow.org/)
41+
- [TensorFlow](https://www.tensorflow.org/) (optional)
42+
- [LibTorch](https://pytorch.org/) (optional)
4243

44+
In the simplest case, the `tensorflow_cc` and `torch` libraries are in the same directory as the `deepmd_c`/`deepmd_cc` libraries, then
4345
```bash
44-
cmake -B build -DDeePMD_DIR=~/deepmd-kit -DTensorFlow_DIR=~/tensorflow
46+
cmake -B build -DDeePMD_DIR=/dir_to_deepmd-kit
4547
```
48+
DeePMD-kit supports TensorFlow backend but its libraries are placed at another directory, then
4649

47-
> `deepmd_c`/`deepmd_cc` and `tensorflow_cc` libraries would be called according to `DeePMD_DIR` and `TensorFlow_DIR`, which is showed in detail in [this page](https://github.com/deepmodeling/deepmd-kit/blob/master/doc/inference/cxx.md). If `TensorFlow_DIR` is not defined, it will be the same as `DeePMD_DIR`. Note that `tensorflow_cc` is not required if `deepmd_c` is found.
50+
```bash
51+
cmake -B build -DDeePMD_DIR=/dir_to_deepmd-kit -DTensorFlow_DIR=/dir_to_tensorflow
52+
```
53+
Similarly, DeePMD-kit supports PyTorch backend but its libraries are placed at another directory, then
54+
```bash
55+
cmake -B build -DDeePMD_DIR=/dir_to_deepmd-kit -DTorch_DIR=/dir_to_pytorch
56+
```
4857

4958
## Build with LibRI and LibComm
5059

@@ -93,9 +102,9 @@ cmake -B build -DUSE_CUDA=1 -DCMAKE_CUDA_COMPILER=${path to cuda toolkit}/bin/nv
93102

94103
## Build math library from source
95104

96-
> Note: This flag is **enabled by default**. It will get better performance than the standard implementation on `gcc` and `clang`. But it **will be disabled** when using `Intel Compiler` since the math functions will get wrong results and the performance is also unexpectly poor.
105+
> Note: We recommend using the latest available compiler sets, since they offer faster implementations of math functions.
97106
98-
To build math functions from source code, instead of using c++ standard implementation, define `USE_ABACUS_LIBM` flag.
107+
This flag is disabled by default. To build math functions from source code, define `USE_ABACUS_LIBM` flag. It is expected to get a better performance on legacy versions of `gcc` and `clang`.
99108

100109
Currently supported math functions:
101110
`sin`, `cos`, `sincos`, `exp`, `cexp`
@@ -282,15 +291,21 @@ directly.
282291

283292
> Note: This part is only required if you want to load a trained DeeP Potential and run molecular dynamics with that. To train the DeeP Potential with DP-GEN, no extra prerequisite is needed and please refer to [this page](http://abacus.deepmodeling.com/en/latest/advanced/interface/dpgen.html) for ABACUS interface with DP-GEN.
284293
285-
To compile ABACUS with DeePMD-kit, you need to define `DeePMD_DIR` and `TensorFlow_DIR` in the file `Makefile.vars` or use
294+
To compile ABACUS with DeePMD-kit, you need to define `DeePMD_DIR` and `TensorFlow_DIR` (TensorFlow Backend, optional) and/or `LIBTORCH_DIR` (PyTorch Backend, optional) in the file `Makefile.vars`.
286295

296+
Or the `tensorflow_cc` and `torch` libraries are in the same directory as the `deepmd_c`/`deepmd_cc` libraries, then
287297
```makefile
288-
make DeePMD_DIR=~/deepmd-kit TensorFlow_DIR=~/tensorflow
298+
make DeePMD_DIR=/dir_to_deepmd-kit
289299
```
300+
DeePMD-kit supports TensorFlow backend but its libraries are placed at another directory, then
290301

291-
directly.
292-
293-
> `deepmd_c`/`deepmd_cc` and `tensorflow_cc` libraries would be called according to `DeePMD_DIR` and `TensorFlow_DIR`, which is showed in detail in [this page](https://github.com/deepmodeling/deepmd-kit/blob/master/doc/inference/cxx.md). If `TensorFlow_DIR` is not defined, it will be the same as `DeePMD_DIR`. Note that `tensorflow_cc` is not required if `deepmd_c` is found.
302+
```makefile
303+
make DeePMD_DIR=/dir_to_deepmd-kit TensorFlow_DIR=/dir_to_tensorflow
304+
```
305+
Similarly, DeePMD-kit supports PyTorch backend but its libraries are placed at another directory, then
306+
```makefile
307+
make DeePMD_DIR=/dir_to_deepmd-kit Torch_DIR=/dir_to_pytorch
308+
```
294309

295310
### Add LibRI Support
296311
To use new EXX, you need two libraries: [LibRI](https://github.com/abacusmodeling/LibRI) and [LibComm](https://github.com/abacusmodeling/LibComm) and need to define `LIBRI_DIR` and `LIBCOMM_DIR` in the file `Makefile.vars` or use

examples/lr-tddft/lcao_Si2/INPUT

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,3 @@ out_alllog 1
3737

3838
nvirt 19
3939
abs_wavelen_range 100 175
40-
#diago_full_acc 1

python/pyabacus/src/py_diago_dav_subspace.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class PyDiagoDavSubspace
106106
double tol,
107107
int max_iter,
108108
bool need_subspace,
109-
std::vector<bool> is_occupied,
109+
std::vector<double> diag_ethr,
110110
bool scf_type,
111111
hsolver::diag_comm_info comm_info
112112
) {
@@ -141,7 +141,7 @@ class PyDiagoDavSubspace
141141
comm_info
142142
);
143143

144-
return obj->diag(hpsi_func, psi, nbasis, eigenvalue, is_occupied, scf_type);
144+
return obj->diag(hpsi_func, psi, nbasis, eigenvalue, diag_ethr.data(), scf_type);
145145
}
146146

147147
private:

python/pyabacus/src/py_diago_david.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ class PyDiagoDavid
132132
const std::complex<double> *psi_in,
133133
std::complex<double> *spsi_out,
134134
const int nrow,
135-
const int npw,
136135
const int nbands
137136
) {
138137
syncmem_op()(this->ctx, this->ctx, spsi_out, psi_in, static_cast<size_t>(nbands * nrow));

python/pyabacus/src/py_hsolver.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ void bind_hsolver(py::module& m)
5959
The maximum number of iterations.
6060
need_subspace : bool
6161
Whether to use the subspace function.
62-
is_occupied : list[bool]
63-
A list of boolean values indicating whether the band is occupied,
62+
diag_ethr : list[float]
63+
A list of float values indicating the thresholds of each band for the diagonalization,
6464
meaning that the corresponding eigenvalue is to be calculated.
6565
scf_type : bool
6666
Whether to use the SCF type, which is used to determine the
@@ -76,7 +76,7 @@ void bind_hsolver(py::module& m)
7676
"tol"_a,
7777
"max_iter"_a,
7878
"need_subspace"_a,
79-
"is_occupied"_a,
79+
"diag_ethr"_a,
8080
"scf_type"_a,
8181
"comm_info"_a)
8282
.def("set_psi", &py_hsolver::PyDiagoDavSubspace::set_psi, R"pbdoc(

python/pyabacus/src/pyabacus/hsolver/_hsolver.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def dav_subspace(
2525
tol: float = 1e-2,
2626
max_iter: int = 1000,
2727
need_subspace: bool = False,
28-
is_occupied: Union[List[bool], None] = None,
28+
diag_ethr: Union[List[float], None] = None,
2929
scf_type: bool = False
3030
) -> Tuple[NDArray[np.float64], NDArray[np.complex128]]:
3131
""" A function to diagonalize a matrix using the Davidson-Subspace method.
@@ -52,10 +52,8 @@ def dav_subspace(
5252
The maximum number of iterations, by default 1000.
5353
need_subspace : bool, optional
5454
Whether to use subspace function, by default False.
55-
is_occupied : List[bool] | None, optional
56-
The list of occupied bands, by default None. This indicates how many eigenvalues
57-
need to be calculated, starting from the smallest eigenvalue. Only the energy levels
58-
occupied by electrons (occupied) need to be calculated.
55+
diag_ethr : List[float] | None, optional
56+
The list of thresholds of bands, by default None.
5957
scf_type : bool, optional
6058
Indicates whether the calculation is a self-consistent field (SCF) calculation.
6159
If True, the initial precision of eigenvalue calculation can be coarse.
@@ -72,8 +70,8 @@ def dav_subspace(
7270
if not callable(mvv_op):
7371
raise TypeError("mvv_op must be a callable object.")
7472

75-
if is_occupied is None:
76-
is_occupied = [True] * num_eigs
73+
if diag_ethr is None:
74+
diag_ethr = [tol] * num_eigs
7775

7876
if init_v.ndim != 1 or init_v.dtype != np.complex128:
7977
init_v = init_v.flatten().astype(np.complex128, order='C')
@@ -93,7 +91,7 @@ def dav_subspace(
9391
tol,
9492
max_iter,
9593
need_subspace,
96-
is_occupied,
94+
diag_ethr,
9795
scf_type,
9896
comm_info
9997
)
@@ -113,7 +111,6 @@ def davidson(
113111
tol: float = 1e-2,
114112
max_iter: int = 1000,
115113
use_paw: bool = False,
116-
# is_occupied: Union[List[bool], None] = None,
117114
# scf_type: bool = False
118115
) -> Tuple[NDArray[np.float64], NDArray[np.complex128]]:
119116
""" A function to diagonalize a matrix using the Davidson-Subspace method.

source/Makefile

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -135,16 +135,17 @@ ifdef LIBRI_DIR
135135
HONG += -D__EXX -DEXX_H_COMM=2 -DEXX_DM=3 -DTEST_EXX_LCAO=0 -DTEST_EXX_RADIAL=1
136136
endif
137137

138+
ifdef LIBNPY_DIR
139+
CNPY_INCLUDE_DIR = -I${LIBNPY_DIR}/include
140+
HONG += -D__DEEPKS
141+
INCLUDES += $(CNPY_INCLUDE_DIR)
142+
endif
143+
138144
ifdef LIBTORCH_DIR
139-
ifdef LIBNPY_DIR
140-
LIBTORCH_INCLUDE_DIR = -I${LIBTORCH_DIR}/include -I${LIBTORCH_DIR}/include/torch/csrc/api/include
141-
LIBTORCH_LIB_DIR= ${LIBTORCH_DIR}/lib
142-
LIBTORCH_LIB = -L${LIBTORCH_LIB_DIR} -ltorch -lc10 -Wl,-rpath,${LIBTORCH_LIB_DIR} -Wl,--no-as-needed,"${LIBTORCH_LIB_DIR}/libtorch_cpu.so" -Wl,--as-needed ${LIBTORCH_LIB_DIR}/libc10.so -lpthread -Wl,--no-as-needed,"${LIBTORCH_LIB_DIR}/libtorch.so" -Wl,--as-needed
143-
CNPY_INCLUDE_DIR = -I${LIBNPY_DIR}/include
144-
HONG += -D__DEEPKS
145-
INCLUDES += $(LIBTORCH_INCLUDE_DIR) $(CNPY_INCLUDE_DIR)
146-
LIBS += $(LIBTORCH_LIB)
147-
endif
145+
LIBTORCH_INCLUDE_DIR = -I${LIBTORCH_DIR}/include -I${LIBTORCH_DIR}/include/torch/csrc/api/include
146+
INCLUDES += $(LIBTORCH_INCLUDE_DIR)
147+
LIBTORCH_LIB_DIR= ${LIBTORCH_DIR}/lib
148+
LIBS += -L${LIBTORCH_LIB_DIR} -ltorch -lc10 -Wl,-rpath,${LIBTORCH_LIB_DIR} -Wl,--no-as-needed,"${LIBTORCH_LIB_DIR}/libtorch_cpu.so" -Wl,--as-needed ${LIBTORCH_LIB_DIR}/libc10.so -lpthread -Wl,--no-as-needed,"${LIBTORCH_LIB_DIR}/libtorch.so" -Wl,--as-needed
148149
endif
149150

150151
ifdef DeePMD_DIR
@@ -162,20 +163,19 @@ ifdef DeePMD_DIR
162163
LIBS += -L${DeeP_LIB_DIR} -ldeepmd_c -Wl,-rpath=${DeeP_LIB_DIR}
163164
else
164165
LIBS += -L${DeeP_LIB_DIR} -ldeepmd_cc -Wl,-rpath=${DeeP_LIB_DIR}
165-
166-
#==========================
167-
# TensorFlow package
168-
#==========================
169-
ifndef TensorFlow_DIR
170-
TensorFlow_DIR = ${DeePMD_DIR}
171-
endif
172-
TensorFlow_LIB_DIR = ${TensorFlow_DIR}/lib
173-
LIBS += -L${TensorFlow_LIB_DIR} -ltensorflow_cc -Wl,-rpath=${TensorFlow_LIB_DIR}
174-
TensorFlow_INCLUDE_DIR = ${TensorFlow_DIR}/include
175-
INCLUDES += -I${TensorFlow_INCLUDE_DIR}
176166
endif
177167
endif
178168

169+
ifdef TensorFlow_DIR
170+
#==========================
171+
# TensorFlow package
172+
#==========================
173+
TensorFlow_LIB_DIR = ${TensorFlow_DIR}/lib
174+
LIBS += -L${TensorFlow_LIB_DIR} -ltensorflow_cc -Wl,-rpath=${TensorFlow_LIB_DIR}
175+
TensorFlow_INCLUDE_DIR = ${TensorFlow_DIR}/include
176+
INCLUDES += -I${TensorFlow_INCLUDE_DIR}
177+
endif
178+
179179
ifdef PEXSI_DIR
180180
OBJS_ABACUS += ${OBJS_HSOLVER_PEXSI}
181181
INCLUDES += -I${PEXSI_DIR}/include -I${PARMETIS_DIR}/include -I${DSUPERLU_DIR}/include

0 commit comments

Comments
 (0)