Skip to content

Commit

Permalink
Merge branch 'develop' into warning
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhuxuegang2022 authored Mar 7, 2024
2 parents a3b6408 + 0bd0ba7 commit d1b3017
Show file tree
Hide file tree
Showing 97 changed files with 2,612 additions and 1,835 deletions.
1 change: 1 addition & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ jobs:
if: ${{ ! cancelled() }}
with:
gcov: true
token: ${{ secrets.CODECOV_TOKEN }}
23 changes: 16 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ You can install Git first and reinstall abacus.")
RESULT_VARIABLE GIT_COMMIT_DATE_RESULT
)
if(GIT_COMMIT_HASH_RESULT EQUAL 0 AND GIT_COMMIT_DATE_RESULT EQUAL 0)
set(COMMIT "${GIT_COMMIT_HASH} (${GIT_COMMIT_DATE})")
add_definitions("-DCOMMIT=\"${COMMIT}\"")
add_definitions(-DCOMMIT_INFO)
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/commit.h" "#define COMMIT \"${GIT_COMMIT_HASH} (${GIT_COMMIT_DATE})\"\n")
include_directories(${CMAKE_CURRENT_BINARY_DIR})
message(STATUS "Current commit hash: ${GIT_COMMIT_HASH}")
message(STATUS "Last commit date: ${GIT_COMMIT_DATE}")
else()
Expand Down Expand Up @@ -320,9 +321,6 @@ endif()
# Warning: CMake add support to HIP in version 3.21. This is rather a new version.
# Use cmake with AMD-ROCm: https://rocmdocs.amd.com/en/latest/Installation_Guide/Using-CMake-with-AMD-ROCm.html
if(USE_ROCM)
if(COMMIT_INFO)
message(FATAL_ERROR "Commit info is not supported on ROCm. Try to recompile with cmake command -DCOMMIT_INFO=OFF.")
endif()
if(NOT DEFINED ROCM_PATH )
set (ROCM_PATH "/opt/rocm" CACHE STRING "Default ROCM installation directory." )
endif ()
Expand Down Expand Up @@ -396,10 +394,21 @@ if(MKLROOT)
list(APPEND math_libs -lifcore)
endif()
else()
# In compatibility to builtin FindLAPACK.cmake before v3.5.4
if(DEFINED LAPACK_DIR)
string(APPEND CMAKE_PREFIX_PATH ";${LAPACK_DIR}")
endif()
if(DEFINED LAPACK_LIBRARY)
set(LAPACK_LIBRARIES ${LAPACK_LIBRARY})
endif()
if(DEFINED BLAS_DIR)
string(APPEND CMAKE_PREFIX_PATH ";${BLAS_DIR}")
endif()

find_package(FFTW3 REQUIRED)
find_package(LAPACK REQUIRED)
include_directories(${FFTW3_INCLUDE_DIRS})
list(APPEND math_libs FFTW3::FFTW3 LAPACK::LAPACK)
list(APPEND math_libs FFTW3::FFTW3 LAPACK::LAPACK BLAS::BLAS)

if(ENABLE_LCAO)
find_package(ScaLAPACK REQUIRED)
Expand Down Expand Up @@ -733,4 +742,4 @@ endif()
if(ENABLE_RAPIDJSON)
target_link_libraries(${ABACUS_BIN_NAME}
json_output)
endif()
endif()
19 changes: 19 additions & 0 deletions cmake/FindELPA.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,27 @@

find_package(PkgConfig)

# Compatible layer towards old manual routines
if(DEFINED ELPA_INCLUDE_DIR)
set(ELPA_INCLUDE_DIRS ${ELPA_INCLUDE_DIR})
endif()
if(DEFINED ELPA_LIBRARIES)
set(ELPA_LINK_LIBRARIES ${ELPA_LIBRARIES})
endif()

find_path(ELPA_INCLUDE_DIRS
elpa/elpa.h
HINTS ${ELPA_DIR}
PATH_SUFFIXES "include" "include/elpa"
)
# Fix #3589
# First if judges if ELPA dir specified
if(ELPA_INCLUDE_DIRS MATCHES "^/usr/include/elpa/.*")
# Second if judges if global visible ELPA header found
if(DEFINED ELPA_DIR OR CMAKE_PREFIX_PATH MATCHES ".*elpa.*")
unset(ELPA_INCLUDE_DIRS)
endif()
endif()
if(USE_OPENMP)
find_library(ELPA_LINK_LIBRARIES
NAMES elpa_openmp elpa
Expand All @@ -28,6 +44,9 @@ else()
)
endif()

# Incompatible with ELPA earlier than 2021.11.001
# Before ELPA 2021.11.001, its pkg-config file
# is named like "elpa-2021.05.002.pc".
if(NOT ELPA_INCLUDE_DIRS AND PKG_CONFIG_FOUND)
if(DEFINED ELPA_DIR)
string(APPEND CMAKE_PREFIX_PATH ";${ELPA_DIR}")
Expand Down
31 changes: 0 additions & 31 deletions cmake/FindLAPACK.cmake

This file was deleted.

17 changes: 10 additions & 7 deletions cmake/FindLibxc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,24 @@ include(FindPackageHandleStandardArgs)
if(DEFINED Libxc_DIR)
string(APPEND CMAKE_PREFIX_PATH ";${Libxc_DIR}")
endif()
# Using CMake interface as default.
# Using pkg-config interface as default, to
# avoid linking to wrong global visible Libxc instead of
# specified one.
# NO REQUIRED here, otherwhile it would throw error
# with no LibXC found.
find_package(Libxc HINTS
find_package(PkgConfig)
if(PKG_CONFIG_FOUND)
pkg_search_module(Libxc IMPORTED_TARGET GLOBAL libxc)
find_package_handle_standard_args(Libxc DEFAULT_MSG Libxc_LINK_LIBRARIES Libxc_INCLUDE_DIRS)
endif()
if(NOT Libxc_FOUND)
find_package(Libxc REQUIRED HINTS
${Libxc_DIR}/share/cmake/Libxc
${Libxc_DIR}/lib/cmake/Libxc
${Libxc_DIR}/lib64/cmake/Libxc
)
if(NOT TARGET Libxc::xc)
find_package(PkgConfig REQUIRED)
pkg_search_module(Libxc REQUIRED IMPORTED_TARGET GLOBAL libxc)
find_package_handle_standard_args(Libxc DEFAULT_MSG Libxc_LINK_LIBRARIES Libxc_INCLUDE_DIRS)
endif()


# Copy the results to the output variables and target.
# if find_package() above works, Libxc::xc would be present and
# below would be skipped.
Expand Down
17 changes: 11 additions & 6 deletions docs/advanced/input_files/input-main.md
Original file line number Diff line number Diff line change
Expand Up @@ -1019,16 +1019,16 @@ Note that `mixing_beta_mag` is not euqal to `mixing_beta` means that $\rho_{up}$

### mixing_restart

- **Type**: Integer
- **Description**: At `mixing_restart`-th iteration, SCF will restart by using output charge density from perivos iteration as input charge density directly, and start a new mixing. `mixing_restart=0|1` means SCF starts from scratch.
- **Type**: double
- **Description**: If the density difference between input and output `drho` is smaller than `mixing_restart`, SCF will restart at next step which means SCF will restart by using output charge density from perivos iteration as input charge density directly, and start a new mixing. Notice that `mixing_restart` will only take effect once in one SCF.

- **Default**: 0

### mixing_dmr

- **Type**: bool
- **Availability**: Only for `mixing_restart>=2`
- **Description**: At `mixing_restart`-th iteration, SCF will start a mixing for real-space density matrix by using the same coefficiences as the mixing of charge density.
- **Availability**: Only for `mixing_restart>=0.0`
- **Description**: At n-th iteration which is calculated by `drho<mixing_restart`, SCF will start a mixing for real-space density matrix by using the same coefficiences as the mixing of charge density.

- **Default**: false

Expand Down Expand Up @@ -3546,8 +3546,13 @@ These variables are used to control the usage of QO analysis. Please note presen
### qo_screening_coeff

- **Type**: Real \[Real...\](optional)
- **Availability**: for `qo_basis pswfc` only.
- **Description**: for each atom type, screening factor $e^{-\eta|\mathbf{r}|}$ is multiplied to the pswfc to mimic the behavior of some kind of electron. $\eta$ is the screening coefficient. If only one value is given, then will apply to each atom type. If not enough values are given, will apply default value to rest of atom types. This parameter plays important role in controlling the spread of QO orbitals together with `qo_thr`.
- **Description**: rescale the shape of radial orbitals, available for both `qo_basis hydrogen` and `qo_basis pswfc`. cases but has different meaning.

For `qo_basis pswfc`
For each atom type, screening factor $e^{-\eta|\mathbf{r}|}$ is multiplied to the pswfc to mimic the behavior of some kind of electron. $\eta$ is the screening coefficient. If only one value is given, then will apply to each atom type. If not enough values are given, will apply default value to rest of atom types. This parameter plays important role in controlling the spread of QO orbitals together with `qo_thr`.

For `qo_basis hydrogen`
If any float number is given, will apply Slater screening to all atom types. Slater screening is a classic and empirical method roughly taking many-electron effect into account for obtaining more accurate results when evaluating electron affinity and ionization energy. The Coulomb potential then becomes $V(r) = -\frac{Z-\sigma}{r}$. For example the effective nuclear charge for Cu 3d electrons now reduces from 29 to 7.85, 4s from 29 to 3.70, which means Slater screening will bring about longer tailing effect. If no value is given, will not apply Slater screening.
- **Default**: 0.1
- **Unit**: Bohr^-1

Expand Down
112 changes: 99 additions & 13 deletions python/pyabacus/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,106 @@ find_package(Python REQUIRED COMPONENTS Interpreter Development.Module)
find_package(pybind11 CONFIG REQUIRED)

set(ABACUS_SOURCE_DIR "${PROJECT_SOURCE_DIR}/../../source")
include_directories(${BASE_PATH} ${ABACUS_SOURCE_DIR})
set(BASE_PATH "${ABACUS_SOURCE_DIR}/module_base")
set(NAO_PATH "${ABACUS_SOURCE_DIR}/module_basis/module_nao")
set(ENABLE_LCAO ON)
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/../../cmake")

# add math_libs
if(DEFINED ENV{MKLROOT} AND NOT DEFINED MKLROOT)
set(MKLROOT "$ENV{MKLROOT}")
endif()
if(MKLROOT)
find_package(IntelMKL REQUIRED)
add_definitions(-D__MKL)
include_directories(${MKL_INCLUDE_DIRS} ${MKL_INCLUDE_DIRS}/fftw)

# Since libtorch will find its own MKL, the fftw part conflicts with the original one.
# When enable deepks, mkl will be linked within ${TORCH_LIBRARIES}.
if(NOT ENABLE_DEEPKS)
list(APPEND math_libs IntelMKL::MKL)
endif()

if(CMAKE_CXX_COMPILER_ID MATCHES Intel)
list(APPEND math_libs -lifcore)
endif()
else()
find_package(FFTW3 REQUIRED)
add_compile_definitions(__FFTW3)
find_package(LAPACK REQUIRED)
include_directories(${FFTW3_INCLUDE_DIRS})
message(STATUS "FFTW3_INCLUDE_DIRS: ${FFTW3_INCLUDE_DIRS}")
list(APPEND math_libs FFTW3::FFTW3 LAPACK::LAPACK)

if(ENABLE_LCAO)
find_package(ScaLAPACK REQUIRED)
list(APPEND math_libs ScaLAPACK::ScaLAPACK)
endif()
endif()

include_directories(${BASE_PATH}
${ABACUS_SOURCE_DIR}
${ABACUS_SOURCE_DIR}/module_base/module_container)

# add library
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# add base
set(BASE_BINARY_DIR "${PROJECT_SOURCE_DIR}/build/base")
add_subdirectory(${ABACUS_SOURCE_DIR}/module_base ${BASE_BINARY_DIR})
# add orb
set(ORB_BINARY_DIR "${PROJECT_SOURCE_DIR}/build/orb")
add_subdirectory(${ABACUS_SOURCE_DIR}/module_basis/module_ao ${ORB_BINARY_DIR})
# set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)

# add nao shared library
list(APPEND _naos
${NAO_PATH}/atomic_radials.cpp
${NAO_PATH}/beta_radials.cpp
${NAO_PATH}/hydrogen_radials.cpp
${NAO_PATH}/numerical_radial.cpp
${NAO_PATH}/pswfc_radials.cpp
${NAO_PATH}/radial_collection.cpp
${NAO_PATH}/radial_set.cpp
${NAO_PATH}/real_gaunt_table.cpp
${NAO_PATH}/sphbes_radials.cpp
${NAO_PATH}/two_center_bundle.cpp
${NAO_PATH}/two_center_integrator.cpp
${NAO_PATH}/two_center_table.cpp
# dependency
${ABACUS_SOURCE_DIR}/module_base/kernels/math_op.cpp
${ABACUS_SOURCE_DIR}/module_psi/kernels/psi_memory_op.cpp
${ABACUS_SOURCE_DIR}/module_io/output_radial.cpp
)
add_library(naopack SHARED
${_naos}
)
# link math_libs
target_link_libraries(naopack
base
container
orb
${math_libs}
)
# list(APPEND _sources ${_naos} ${_bases})
list(APPEND _sources
#${ABACUS_SOURCE_DIR}/module_basis/module_nao/numerical_radial.h
#${ABACUS_SOURCE_DIR}/module_basis/module_nao/numerical_radial.cpp
${ABACUS_SOURCE_DIR}/module_base/constants.h
${ABACUS_SOURCE_DIR}/module_base/math_sphbes.h
${ABACUS_SOURCE_DIR}/module_base/math_sphbes.cpp
${ABACUS_SOURCE_DIR}/module_base/math_integral.h
${ABACUS_SOURCE_DIR}/module_base/math_integral.cpp
${PROJECT_SOURCE_DIR}/src/py_abacus.cpp
#${PROJECT_SOURCE_DIR}/src/py_numerical_radial.cpp
${PROJECT_SOURCE_DIR}/src/py_math_base.cpp)
python_add_library(_core MODULE ${_sources} WITH_SOABI)
target_link_libraries(_core PRIVATE pybind11::headers)
${PROJECT_SOURCE_DIR}/src/py_base_math.cpp
${PROJECT_SOURCE_DIR}/src/py_m_nao.cpp
)
pybind11_add_module(_core MODULE ${_sources})
target_link_libraries(_core PRIVATE pybind11::headers naopack)
target_compile_definitions(_core PRIVATE VERSION_INFO=${PROJECT_VERSION})
# set RPATH
execute_process(
COMMAND "${PYTHON_EXECUTABLE}" -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"
OUTPUT_VARIABLE PYTHON_SITE_PACKAGES
OUTPUT_STRIP_TRAILING_WHITESPACE
)

# set package name to pyabacus
set(TARGET_PACK pyabacus)
set(CMAKE_INSTALL_RPATH "${PYTHON_SITE_PACKAGES}/${TARGET_PACK}")
set_target_properties(_core PROPERTIES INSTALL_RPATH "$ORIGIN")
set_target_properties(naopack PROPERTIES INSTALL_RPATH "$ORIGIN")
install(TARGETS _core naopack DESTINATION ${TARGET_PACK})

install(TARGETS _core DESTINATION pyabacus)
20 changes: 15 additions & 5 deletions python/pyabacus/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ Python).
Installation
------------

- install pybind11 and scikit-build-core by `pip install pybind11 scikit-build-core`
- clone this repository
- `pip install ./pyabacus`
- Create and activate a new conda env, e.g. `conda create -n myenv python=3.8 & conda activate myenv`.
- Clone ABACUS main repository and `cd abacus-develop/python/pyabacus`.
- Build pyabacus by `pip install -v .` or install test dependencies & build pyabacus by `pip install .[test]`. (Use `pip install -r .[test] -i https://pypi.tuna.tsinghua.edu.cn/simple` to accelerate installation process.)


CI Examples
Expand All @@ -21,6 +21,15 @@ There are examples for CI in `.github/workflows`. A simple way to produces
binary "wheels" for all platforms is illustrated in the "wheels.yml" file,
using [`cibuildwheel`][].

Use `pytest` to run all the unit tests for pyabacus in the local machine.

Run `python test_m_nao.py` in `tests` to check the S matrix.

```shell
$ python test_m_nao.py
norm(S_e3 - S_numer) = 3.341208104032616e-15
```

License
-------

Expand All @@ -33,8 +42,9 @@ Test call

```python
import pyabacus as m

chi = m.NumericalRadial()
s = m.ModuleBase.Sphbes()
s.sphbesj(1, 0.0)
0.0
```

[`cibuildwheel`]: https://cibuildwheel.readthedocs.io
4 changes: 3 additions & 1 deletion python/pyabacus/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ classifiers = [
]

[project.optional-dependencies]
test = ["pytest", "numpy"]
test = ["contourpy","cycler","exceptiongroup","fonttools","importlib-metadata","importlib-resources","iniconfig","kiwisolver","matplotlib","mpmath","numpy","packaging","pillow","platformdirs","pluggy","pyparsing","pytest","python-dateutil","six","stylize","sympy","tomli","yapf","zipp"]


[tool.scikit-build]
wheel.expand-macos-universal-tags = true
cmake.verbose = true
logging.level = "INFO"


[tool.pytest.ini_options]
Expand Down
8 changes: 4 additions & 4 deletions python/pyabacus/src/py_abacus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

namespace py = pybind11;

void bind_numerical_radial(py::module& m);
void bind_math_base(py::module& m);
void bind_base_math(py::module& m);
void bind_m_nao(py::module& m);

PYBIND11_MODULE(_core, m)
{
// bind_numerical_radial(m);
bind_math_base(m);
bind_base_math(m);
bind_m_nao(m);
}
Loading

0 comments on commit d1b3017

Please sign in to comment.