Skip to content

Commit

Permalink
Refactor: Organize code structure to improve maintainability in pyaba…
Browse files Browse the repository at this point in the history
…cus (#5346)

* fix some typos in `_hsolver.py`

* fix some bugs caused by #5134

* Refactor hsolver module and remove unused code

* refactor the structure of pythonization source code

* fix some bug

* Refactor __getattr__ function in __init__.py to handle attribute errors

* fix some bugs

* Add CONTRIBUTING.md to facilitate contributing to pyabacus project

* fix typos

* Update CONTRIBUTING.md

* Update CONTRIBUTING.md

* update README.md and CONTRIBUTING.md

* update README.md

* update CONTRIBUTING.md

* update CONTRIBUTING.md

* fix a bug caused by tuple in python3.8

* update
  • Loading branch information
a1henu authored Oct 25, 2024
1 parent e4044a4 commit 729059f
Show file tree
Hide file tree
Showing 20 changed files with 1,034 additions and 188 deletions.
100 changes: 14 additions & 86 deletions python/pyabacus/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
cmake_minimum_required(VERSION 3.15...3.26)

# project settings
project(
${SKBUILD_PROJECT_NAME}
VERSION ${SKBUILD_PROJECT_VERSION}
LANGUAGES CXX)

# find python and pybind11
find_package(Python REQUIRED COMPONENTS Interpreter Development.Module)
find_package(pybind11 CONFIG REQUIRED)

# set source path
set(ABACUS_SOURCE_DIR "${PROJECT_SOURCE_DIR}/../../source")
set(BASE_PATH "${ABACUS_SOURCE_DIR}/module_base")
set(NAO_PATH "${ABACUS_SOURCE_DIR}/module_basis/module_nao")
set(HSOLVER_PATH "${ABACUS_SOURCE_DIR}/module_hsolver")
set(HAMILT_PATH "${ABACUS_SOURCE_DIR}/module_hamilt_general")
set(PSI_PATH "${ABACUS_SOURCE_DIR}/module_psi")
set(ENABLE_LCAO ON)
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/../../cmake")
Expand Down Expand Up @@ -63,11 +65,14 @@ else()
endif()
endif()

include_directories(${BASE_PATH}
# add include directories
include_directories(
${BASE_PATH}
${ABACUS_SOURCE_DIR}
${ABACUS_SOURCE_DIR}/module_base/module_container)
${ABACUS_SOURCE_DIR}/module_base/module_container
)

# add library
# add basic libraries
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# add base
set(BASE_BINARY_DIR "${PROJECT_SOURCE_DIR}/build/base")
Expand All @@ -80,83 +85,6 @@ 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
${NAO_PATH}/projgen.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_base/module_device/memory_op.cpp
)
add_library(naopack SHARED
${_naos}
)
# add diago shared library
list(APPEND _diago
${HSOLVER_PATH}/diago_dav_subspace.cpp
${HSOLVER_PATH}/diago_david.cpp
${HSOLVER_PATH}/diag_const_nums.cpp
${HSOLVER_PATH}/diago_iter_assist.cpp

${HSOLVER_PATH}/kernels/dngvd_op.cpp
${HSOLVER_PATH}/kernels/math_kernel_op.cpp
# dependency
${BASE_PATH}/module_device/device.cpp
${BASE_PATH}/module_device/memory_op.cpp

${HAMILT_PATH}/operator.cpp
${PSI_PATH}/psi.cpp
)
add_library(diagopack SHARED
${_diago}
)
target_link_libraries(diagopack
PRIVATE
${OpenBLAS_LIBRARIES}
${LAPACK_LIBRARIES}
)
# link math_libs
if(MKLROOT)
target_link_libraries(naopack
base
parameter
container
orb
${math_libs}
MPI::MPI_CXX
OpenMP::OpenMP_CXX
)
else()
target_link_libraries(naopack
base
parameter
container
orb
${math_libs}
)
endif()
# list(APPEND _sources ${_naos} ${_bases})
list(APPEND _sources
${PROJECT_SOURCE_DIR}/src/py_abacus.cpp
${PROJECT_SOURCE_DIR}/src/py_base_math.cpp
${PROJECT_SOURCE_DIR}/src/py_m_nao.cpp
${PROJECT_SOURCE_DIR}/src/py_hsolver.cpp
)
pybind11_add_module(_core MODULE ${_sources})
target_link_libraries(_core PRIVATE pybind11::headers naopack diagopack)
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())"
Expand All @@ -167,9 +95,9 @@ execute_process(
# 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")
set_target_properties(diagopack PROPERTIES INSTALL_RPATH "$ORIGIN")
install(TARGETS _core naopack DESTINATION ${TARGET_PACK})
install(TARGETS _core diagopack DESTINATION ${TARGET_PACK})

# add subdirectories for submodules
add_subdirectory(${PROJECT_SOURCE_DIR}/src/hsolver)
add_subdirectory(${PROJECT_SOURCE_DIR}/src/ModuleBase)
add_subdirectory(${PROJECT_SOURCE_DIR}/src/ModuleNAO)

Loading

0 comments on commit 729059f

Please sign in to comment.