Skip to content

[Refactor] Rename module_base to source_base #6308

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ set(ABACUS_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/source)
set(ABACUS_TEST_DIR ${CMAKE_CURRENT_SOURCE_DIR}/tests)
set(ABACUS_BIN_PATH ${CMAKE_CURRENT_BINARY_DIR}/${ABACUS_BIN_NAME})
include_directories(${ABACUS_SOURCE_DIR})
include_directories(${ABACUS_SOURCE_DIR}/module_base/module_container)
include_directories(${ABACUS_SOURCE_DIR}/source_base/module_container)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
Expand Down
4 changes: 2 additions & 2 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ The source code of ABACUS is based on several modules. Under the ABACUS root dir
For those who are interested in the source code, the following figure shows the structure of the source code.

```text
|-- module_base A basic module including
|-- source_base A basic module including
| | (1) Mathematical library interface functions: BLAS, LAPACK, Scalapack;
| | (2) Custom data classes: matrix, vector definitions and related functions;
| | (3) Parallelization functions: MPI, OpenMP;
Expand Down Expand Up @@ -183,7 +183,7 @@ pre-commit install

## Adding a unit test

We use [GoogleTest](https://github.com/google/googletest) as our test framework. Write your test under the corresponding module folder at `abacus-develop/tests`, then append the test to `tests/CMakeLists.txt`. If there are currently no unit tests provided for the module, do as follows. `module_base` provides a simple demonstration.
We use [GoogleTest](https://github.com/google/googletest) as our test framework. Write your test under the corresponding module folder at `abacus-develop/tests`, then append the test to `tests/CMakeLists.txt`. If there are currently no unit tests provided for the module, do as follows. `source_base` provides a simple demonstration.

- Add a folder named `test` under the module.
- Append the content below to `CMakeLists.txt` of the module:
Expand Down
6 changes: 3 additions & 3 deletions python/pyabacus/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ 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(BASE_PATH "${ABACUS_SOURCE_DIR}/source_base")
set(NAO_PATH "${ABACUS_SOURCE_DIR}/module_basis/module_nao")
set(HSOLVER_PATH "${ABACUS_SOURCE_DIR}/source_hsolver")
set(PSI_PATH "${ABACUS_SOURCE_DIR}/module_psi")
Expand Down Expand Up @@ -69,14 +69,14 @@ endif()
include_directories(
${BASE_PATH}
${ABACUS_SOURCE_DIR}
${ABACUS_SOURCE_DIR}/module_base/module_container
${ABACUS_SOURCE_DIR}/source_base/module_container
)

# add basic libraries
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_subdirectory(${ABACUS_SOURCE_DIR}/source_base ${BASE_BINARY_DIR})
# add parameter
set(PARAMETER_BINARY_DIR "${PROJECT_SOURCE_DIR}/build/parameter")
add_subdirectory(${ABACUS_SOURCE_DIR}/module_parameter ${PARAMETER_BINARY_DIR})
Expand Down
6 changes: 3 additions & 3 deletions python/pyabacus/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ find_package(pybind11 CONFIG REQUIRED)
```cmake
# Set source path
set(ABACUS_SOURCE_DIR "${PROJECT_SOURCE_DIR}/../../source")
set(BASE_PATH "${ABACUS_SOURCE_DIR}/module_base")
set(BASE_PATH "${ABACUS_SOURCE_DIR}/source_base")
set(NAO_PATH "${ABACUS_SOURCE_DIR}/module_basis/module_nao")
set(HSOLVER_PATH "${ABACUS_SOURCE_DIR}/source_hsolver")
set(PSI_PATH "${ABACUS_SOURCE_DIR}/module_psi")
Expand Down Expand Up @@ -131,7 +131,7 @@ endif()
include_directories(
${BASE_PATH}
${ABACUS_SOURCE_DIR}
${ABACUS_SOURCE_DIR}/module_base/module_container
${ABACUS_SOURCE_DIR}/source_base/module_container
)
```
- This section adds the necessary include directories for the project.
Expand All @@ -141,7 +141,7 @@ include_directories(
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_subdirectory(${ABACUS_SOURCE_DIR}/source_base ${BASE_BINARY_DIR})
# Add parameter
set(PARAMETER_BINARY_DIR "${PROJECT_SOURCE_DIR}/build/parameter")
add_subdirectory(${ABACUS_SOURCE_DIR}/module_parameter ${PARAMETER_BINARY_DIR})
Expand Down
2 changes: 1 addition & 1 deletion python/pyabacus/examples/indexmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def _index_map(ntype, natom, lmax, nzeta=None):

0, 1, -1, 2, -2, 3, -3, ..., l, -l

(see module_base/ylm.cpp and module_base/math_ylmreal.cpp
(see source_base/ylm.cpp and source_base/math_ylmreal.cpp
for details)

'''
Expand Down
317 changes: 161 additions & 156 deletions python/pyabacus/src/ModuleBase/py_base_math.cpp

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions python/pyabacus/src/ModuleNAO/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ list(APPEND _naos
${NAO_PATH}/two_center_integrator.cpp
${NAO_PATH}/two_center_table.cpp
# dependency
${ABACUS_SOURCE_DIR}/module_base/kernels/math_ylm_op.cpp
${ABACUS_SOURCE_DIR}/module_base/kernels/math_kernel_op.cpp
${ABACUS_SOURCE_DIR}/module_base/kernels/math_kernel_op_vec.cpp
${ABACUS_SOURCE_DIR}/source_base/kernels/math_ylm_op.cpp
${ABACUS_SOURCE_DIR}/source_base/kernels/math_kernel_op.cpp
${ABACUS_SOURCE_DIR}/source_base/kernels/math_kernel_op_vec.cpp
# ${ABACUS_SOURCE_DIR}/module_psi/kernels/psi_memory_op.cpp
${ABACUS_SOURCE_DIR}/module_base/module_device/memory_op.cpp
${ABACUS_SOURCE_DIR}/module_base/module_device/device.cpp
${ABACUS_SOURCE_DIR}/source_base/module_device/memory_op.cpp
${ABACUS_SOURCE_DIR}/source_base/module_device/device.cpp
)
add_library(naopack SHARED
${_naos}
Expand Down
8 changes: 4 additions & 4 deletions python/pyabacus/src/ModuleNAO/py_m_nao.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#include "module_basis/module_nao/radial_collection.h"
#include "module_basis/module_nao/two_center_integrator.h"
#include "source_base/vector3.h"

#include <pybind11/numpy.h>
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>

#include "module_base/vector3.h"
#include "module_basis/module_nao/radial_collection.h"
#include "module_basis/module_nao/two_center_integrator.h"

namespace py = pybind11;
using namespace pybind11::literals;
template <typename... Args>
Expand Down
97 changes: 45 additions & 52 deletions python/pyabacus/src/hsolver/py_diago_cg.hpp
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
#ifndef PYTHON_PYABACUS_SRC_PY_DIAGO_CG_HPP
#define PYTHON_PYABACUS_SRC_PY_DIAGO_CG_HPP

#include "source_base/module_device/memory_op.h"
#include "source_hsolver/diago_cg.h"

#include <ATen/core/tensor.h>
#include <ATen/core/tensor_map.h>
#include <ATen/core/tensor_types.h>
#include <complex>
#include <functional>

#include <pybind11/pybind11.h>
#include <pybind11/complex.h>
#include <pybind11/functional.h>
#include <pybind11/numpy.h>
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>

#include <ATen/core/tensor.h>
#include <ATen/core/tensor_map.h>
#include <ATen/core/tensor_types.h>

#include "source_hsolver/diago_cg.h"
#include "module_base/module_device/memory_op.h"

namespace py = pybind11;

namespace py_hsolver
{

class PyDiagoCG
{
public:
PyDiagoCG(int dim, int num_eigs) : dim{dim}, num_eigs{num_eigs} { }
public:
PyDiagoCG(int dim, int num_eigs) : dim{dim}, num_eigs{num_eigs}
{
}
PyDiagoCG(const PyDiagoCG&) = delete;
PyDiagoCG& operator=(const PyDiagoCG&) = delete;
PyDiagoCG(PyDiagoCG&& other)
Expand All @@ -37,9 +37,9 @@ class PyDiagoCG
other.eig = nullptr;
}

~PyDiagoCG()
~PyDiagoCG()
{
if (psi != nullptr)
if (psi != nullptr)
{
delete psi;
psi = nullptr;
Expand All @@ -52,19 +52,20 @@ class PyDiagoCG
}
}

void init_eig()
void init_eig()
{
eig = new ct::Tensor(ct::DataType::DT_DOUBLE, {num_eigs});
eig->zero();
}

py::array_t<double> get_eig()
py::array_t<double> get_eig()
{
py::array_t<double> eig_out(eig->NumElements());
py::buffer_info eig_buf = eig_out.request();
double* eig_out_ptr = static_cast<double*>(eig_buf.ptr);

if (eig == nullptr) {
if (eig == nullptr)
{
throw std::runtime_error("eig is not initialized");
}
double* eig_ptr = eig->data<double>();
Expand All @@ -78,12 +79,10 @@ class PyDiagoCG
py::buffer_info psi_buf = psi_in.request();
std::complex<double>* psi_ptr = static_cast<std::complex<double>*>(psi_buf.ptr);

psi = new ct::TensorMap(
psi_ptr,
ct::DataType::DT_COMPLEX_DOUBLE,
ct::DeviceType::CpuDevice,
ct::TensorShape({num_eigs, dim})
);
psi = new ct::TensorMap(psi_ptr,
ct::DataType::DT_COMPLEX_DOUBLE,
ct::DeviceType::CpuDevice,
ct::TensorShape({num_eigs, dim}));
}

py::array_t<std::complex<double>> get_psi()
Expand All @@ -92,7 +91,8 @@ class PyDiagoCG
py::buffer_info psi_buf = psi_out.request();
std::complex<double>* psi_out_ptr = static_cast<std::complex<double>*>(psi_buf.ptr);

if (psi == nullptr) {
if (psi == nullptr)
{
throw std::runtime_error("psi is not initialized");
}
std::complex<double>* psi_ptr = psi->data<std::complex<double>>();
Expand All @@ -106,12 +106,7 @@ class PyDiagoCG
py::buffer_info prec_buf = prec_in.request();
double* prec_ptr = static_cast<double*>(prec_buf.ptr);

prec = new ct::TensorMap(
prec_ptr,
ct::DataType::DT_DOUBLE,
ct::DeviceType::CpuDevice,
ct::TensorShape({dim})
);
prec = new ct::TensorMap(prec_ptr, ct::DataType::DT_DOUBLE, ct::DeviceType::CpuDevice, ct::TensorShape({dim}));
}

void diag(std::function<py::array_t<std::complex<double>>(py::array_t<std::complex<double>>)> mm_op,
Expand All @@ -120,23 +115,25 @@ class PyDiagoCG
const std::vector<double>& diag_ethr,
bool need_subspace,
bool scf_type,
int nproc_in_pool = 1
) {
int nproc_in_pool = 1)
{
const std::string basis_type = "pw";
const std::string calculation = scf_type ? "scf" : "nscf";

auto hpsi_func = [mm_op] (const ct::Tensor& psi_in, ct::Tensor& hpsi_out) {
auto hpsi_func = [mm_op](const ct::Tensor& psi_in, ct::Tensor& hpsi_out) {
const auto ndim = psi_in.shape().ndim();
REQUIRES_OK(ndim <= 2, "dims of psi_in should be less than or equal to 2");
const int nvec = ndim == 1 ? 1 : psi_in.shape().dim_size(0);
const int nvec = ndim == 1 ? 1 : psi_in.shape().dim_size(0);
const int ld_psi = ndim == 1 ? psi_in.NumElements() : psi_in.shape().dim_size(1);

// Note: numpy's py::array_t is row-major, and
// our tensor-array is row-major
py::array_t<std::complex<double>> psi({ld_psi, nvec});
py::buffer_info psi_buf = psi.request();
std::complex<double>* psi_ptr = static_cast<std::complex<double>*>(psi_buf.ptr);
std::copy(psi_in.data<std::complex<double>>(), psi_in.data<std::complex<double>>() + nvec * ld_psi, psi_ptr);
std::copy(psi_in.data<std::complex<double>>(),
psi_in.data<std::complex<double>>() + nvec * ld_psi,
psi_ptr);

py::array_t<std::complex<double>> hpsi = mm_op(psi);

Expand All @@ -145,34 +142,30 @@ class PyDiagoCG
std::copy(hpsi_ptr, hpsi_ptr + nvec * ld_psi, hpsi_out.data<std::complex<double>>());
};

auto subspace_func = [] (const ct::Tensor& psi_in, ct::Tensor& psi_out) { /*do nothing*/ };
auto subspace_func = [](const ct::Tensor& psi_in, ct::Tensor& psi_out) { /*do nothing*/ };

auto spsi_func = [this] (const ct::Tensor& psi_in, ct::Tensor& spsi_out) {
auto spsi_func = [this](const ct::Tensor& psi_in, ct::Tensor& spsi_out) {
const auto ndim = psi_in.shape().ndim();
REQUIRES_OK(ndim <= 2, "dims of psi_in should be less than or equal to 2");
const int nrow = ndim == 1 ? psi_in.NumElements() : psi_in.shape().dim_size(1);
const int nrow = ndim == 1 ? psi_in.NumElements() : psi_in.shape().dim_size(1);
const int nbands = ndim == 1 ? 1 : psi_in.shape().dim_size(0);
syncmem_z2z_h2h_op()(
spsi_out.data<std::complex<double>>(),
psi_in.data<std::complex<double>>(),
static_cast<size_t>(nrow * nbands)
);
syncmem_z2z_h2h_op()(spsi_out.data<std::complex<double>>(),
psi_in.data<std::complex<double>>(),
static_cast<size_t>(nrow * nbands));
};

cg = std::make_unique<hsolver::DiagoCG<std::complex<double>, base_device::DEVICE_CPU>>(
basis_type,
calculation,
need_subspace,
subspace_func,
tol,
diag_ndim,
nproc_in_pool
);
cg = std::make_unique<hsolver::DiagoCG<std::complex<double>, base_device::DEVICE_CPU>>(basis_type,
calculation,
need_subspace,
subspace_func,
tol,
diag_ndim,
nproc_in_pool);

cg->diag(hpsi_func, spsi_func, *psi, *eig, diag_ethr, *prec);
}

private:
private:
base_device::DEVICE_CPU* ctx = {};

int dim;
Expand Down
Loading
Loading