Skip to content
Draft
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
  •  
  •  
  •  
7 changes: 4 additions & 3 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
---
Language: Cpp
BasedOnStyle: Microsoft
BasedOnStyle: GNU

AlwaysBreakTemplateDeclarations: Yes

ColumnLimit: 120
AllowAllArgumentsOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
BinPackArguments: false
Expand All @@ -18,7 +19,7 @@ FixNamespaceComments: true
# InsertBraces: true # only for clang-format version15.0.0 or later

# About include
IncludeBlocks: Regroup
IncludeBlocks: Preserve
IncludeIsMainRegex: '([-_](test|unittest))?$'
IncludeIsMainSourceRegex: ''

Expand All @@ -30,7 +31,7 @@ DerivePointerAlignment: false
PointerAlignment: Left

ReflowComments: true
SortIncludes: true
SortIncludes: false
SortUsingDeclarations: true

# About space
Expand Down
12 changes: 9 additions & 3 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
---
Checks: '
-*,
modernize-deprecated-headers,
modernize-redundant-void-arg,
modernize-use-bool-literals,
modernize-use-nullptr,
readability-avoid-return-with-void-value,
readability-braces-around-statements
readability-avoid-return-with-void-value

# TODO: Find out why the two checks would cause fatal regression
# modernize-redundant-void-arg,
# readability-braces-around-statements

# llvm-header-guard,
# bugprone-*,
Expand Down Expand Up @@ -40,4 +43,7 @@ Checks: '
# -google-build-using-namespace,
# -bugprone-narrowing-conversions,
'

ExcludeHeaderFilterRegex: '^(/usr|/opt|/lib|/include)'
SystemHeaders: false
...
50 changes: 50 additions & 0 deletions .github/workflows/precommit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Precommit

on:
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
test:
name: Precommit
runs-on: X64
if: github.repository_owner == 'deepmodeling'
container:
image: ghcr.io/deepmodeling/abacus-gnu
volumes:
- /tmp/ccache:/github/home/.ccache
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
fetch-depth: 0
# We will handle submodules manually after fixing ownership
submodules: 'false'

- name: Take ownership of the workspace and update submodules
run: |
sudo chown -R $(whoami) .
git submodule update --init --recursive

- name: Install CI tools
run: |
sudo apt-get update
sudo apt-get install -y ccache ca-certificates python-is-python3 python3-pip
sudo pip install --upgrade pip
sudo pip install clang-format clang-tidy

- name: Configure
run: |
cmake -B build -DBUILD_TESTING=ON -DENABLE_MLALGO=ON -DENABLE_LIBXC=ON -DENABLE_LIBRI=ON -DENABLE_GOOGLEBENCH=ON -DENABLE_RAPIDJSON=ON -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DENABLE_FLOAT_FFTW=ON

- uses: pre-commit/action@v3.0.1
with:
extra_args:
--from-ref ${{ github.event.pull_request.base.sha }}
--to-ref ${{ github.event.pull_request.head.sha }}
continue-on-error: true
- uses: pre-commit-ci/lite-action@v1.0.3

11 changes: 0 additions & 11 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,6 @@ jobs:
run: |
cmake -B build -DBUILD_TESTING=ON -DENABLE_MLALGO=ON -DENABLE_LIBXC=ON -DENABLE_LIBRI=ON -DENABLE_GOOGLEBENCH=ON -DENABLE_RAPIDJSON=ON -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DENABLE_FLOAT_FFTW=ON

# Temporarily removed because no one maintains this now.
# And it will break the CI test workflow.

# - uses: pre-commit/action@v3.0.1
# with:
# extra_args:
# --from-ref ${{ github.event.pull_request.base.sha }}
# --to-ref ${{ github.event.pull_request.head.sha }}
# continue-on-error: true
# - uses: pre-commit-ci/lite-action@v1.0.3

- name: Build
run: |
cmake --build build -j8
Expand Down
210 changes: 108 additions & 102 deletions python/pyabacus/src/ModuleBase/py_base_math.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,116 +14,122 @@ using namespace pyabacus::utils;
template <typename... Args>
using overload_cast_ = pybind11::detail::overload_cast_impl<Args...>;

void bind_base_math(py::module& m)
void
bind_base_math (py::module& m)
{
// python binding for class Sphbes
py::class_<ModuleBase::Sphbes>(m, "Sphbes")
.def(py::init<>())
.def_static("sphbesj", overload_cast_<const int, const double>()(&ModuleBase::Sphbes::sphbesj), "l"_a, "x"_a)
.def_static("dsphbesj", overload_cast_<const int, const double>()(&ModuleBase::Sphbes::dsphbesj), "l"_a, "x"_a)
.def_static("sphbesj",
[](const int n, py::array_t<double> r, const double q, const int l, py::array_t<double> jl) {
check_1d_array(r, "r");
check_1d_array(jl, "jl");
ModuleBase::Sphbes::sphbesj(n,
get_array_ptr(r),
q,
l,
get_array_ptr(jl));
})
.def_static("dsphbesj",
[](const int n, py::array_t<double> r, const double q, const int l, py::array_t<double> djl) {
check_1d_array(r, "r");
check_1d_array(djl, "djl");
ModuleBase::Sphbes::dsphbesj(n,
get_array_ptr(r),
q,
l,
get_array_ptr(djl));
})
.def_static("sphbes_zeros", [](const int l, const int n, py::array_t<double> zeros) {
check_1d_array(zeros, "zeros");
ModuleBase::Sphbes::sphbes_zeros(l, n, get_array_ptr(zeros));
});
py::class_<ModuleBase::Sphbes> (m, "Sphbes")
.def (py::init<> ())
.def_static ("sphbesj", overload_cast_<const int, const double> () (&ModuleBase::Sphbes::sphbesj), "l"_a, "x"_a)
.def_static ("dsphbesj",
overload_cast_<const int, const double> () (&ModuleBase::Sphbes::dsphbesj),
"l"_a,
"x"_a)
.def_static ("sphbesj",
[] (const int n, py::array_t<double> r, const double q, const int l, py::array_t<double> jl)
{
check_1d_array (r, "r");
check_1d_array (jl, "jl");
ModuleBase::Sphbes::sphbesj (n, get_array_ptr (r), q, l, get_array_ptr (jl));
})
.def_static ("dsphbesj",
[] (const int n, py::array_t<double> r, const double q, const int l, py::array_t<double> djl)
{
check_1d_array (r, "r");
check_1d_array (djl, "djl");
ModuleBase::Sphbes::dsphbesj (n, get_array_ptr (r), q, l, get_array_ptr (djl));
})
.def_static ("sphbes_zeros",
[] (const int l, const int n, py::array_t<double> zeros)
{
check_1d_array (zeros, "zeros");
ModuleBase::Sphbes::sphbes_zeros (l, n, get_array_ptr (zeros));
});

// python binding for class Integral
py::class_<ModuleBase::Integral>(m, "Integral")
.def(py::init<>())
.def_static("Simpson_Integral", [](const int mesh, py::array_t<double> func, py::array_t<double> rab, double asum) {
check_1d_array(func, "func");
check_1d_array(rab, "rab");
py::class_<ModuleBase::Integral> (m, "Integral")
.def (py::init<> ())
.def_static (
"Simpson_Integral",
[] (const int mesh, py::array_t<double> func, py::array_t<double> rab, double asum)
{
check_1d_array (func, "func");
check_1d_array (rab, "rab");

double isum = asum;
ModuleBase::Integral::Simpson_Integral(mesh,
get_array_ptr(func),
get_array_ptr(rab),
isum);
return isum;
})
.def_static("Simpson_Integral", [](const int mesh, py::array_t<double> func, const double dr, double asum){
check_1d_array(func, "func");
double isum = asum;
ModuleBase::Integral::Simpson_Integral (mesh, get_array_ptr (func), get_array_ptr (rab), isum);
return isum;
})
.def_static ("Simpson_Integral",
[] (const int mesh, py::array_t<double> func, const double dr, double asum)
{
check_1d_array (func, "func");

double isum = asum;
ModuleBase::Integral::Simpson_Integral(mesh,
get_array_ptr(func),
dr,
isum);
return isum;
})
.def_static("Simpson_Integral_0toall", [](const int mesh, py::array_t<double> func, py::array_t<double> rab, py::array_t<double> asum){
check_1d_array(func, "func");
check_1d_array(rab, "rab");
check_1d_array(asum, "asum");
ModuleBase::Integral::Simpson_Integral_0toall(mesh,
get_array_ptr(func),
get_array_ptr(rab),
get_array_ptr(asum));
})
.def_static("Simpson_Integral_alltoinf", [](const int mesh, py::array_t<double> func, py::array_t<double> rab, py::array_t<double> asum){
check_1d_array(func, "func");
check_1d_array(rab, "rab");
check_1d_array(asum, "asum");
ModuleBase::Integral::Simpson_Integral_alltoinf(mesh,
get_array_ptr(func),
get_array_ptr(rab),
get_array_ptr(asum));
})
.def_static("simpson", [](const int n, py::array_t<double> f, const double dx){
check_1d_array(f, "f");
return ModuleBase::Integral::simpson(n,
get_array_ptr(f),
dx);
})
.def_static("simpson", [](const int n, py::array_t<double> f, py::array_t<double> h){
check_1d_array(f, "f");
check_1d_array(h, "h");
return ModuleBase::Integral::simpson(n,
get_array_ptr(f),
get_array_ptr(h));
})
.def_static("Gauss_Legendre_grid_and_weight", [](const int n, py::array_t<double> x, py::array_t<double> w){
check_1d_array(x, "x");
check_1d_array(w, "w");
ModuleBase::Integral::Gauss_Legendre_grid_and_weight(n,
get_array_ptr(x),
get_array_ptr(w));
})
.def_static("Gauss_Legendre_grid_and_weight", [](const double xmin, const double xmax, const int n, py::array_t<double> x, py::array_t<double> w){
check_1d_array(x, "x");
check_1d_array(w, "w");
ModuleBase::Integral::Gauss_Legendre_grid_and_weight(xmin,
xmax,
n,
get_array_ptr(x),
get_array_ptr(w));
});
py::class_<ModuleBase::SphericalBesselTransformer>(m, "SphericalBesselTransformer")
.def(py::init<>());
double isum = asum;
ModuleBase::Integral::Simpson_Integral (mesh, get_array_ptr (func), dr, isum);
return isum;
})
.def_static ("Simpson_Integral_0toall",
[] (const int mesh, py::array_t<double> func, py::array_t<double> rab, py::array_t<double> asum)
{
check_1d_array (func, "func");
check_1d_array (rab, "rab");
check_1d_array (asum, "asum");
ModuleBase::Integral::Simpson_Integral_0toall (mesh,
get_array_ptr (func),
get_array_ptr (rab),
get_array_ptr (asum));
})
.def_static ("Simpson_Integral_alltoinf",
[] (const int mesh, py::array_t<double> func, py::array_t<double> rab, py::array_t<double> asum)
{
check_1d_array (func, "func");
check_1d_array (rab, "rab");
check_1d_array (asum, "asum");
ModuleBase::Integral::Simpson_Integral_alltoinf (mesh,
get_array_ptr (func),
get_array_ptr (rab),
get_array_ptr (asum));
})
.def_static ("simpson",
[] (const int n, py::array_t<double> f, const double dx)
{
check_1d_array (f, "f");
return ModuleBase::Integral::simpson (n, get_array_ptr (f), dx);
})
.def_static ("simpson",
[] (const int n, py::array_t<double> f, py::array_t<double> h)
{
check_1d_array (f, "f");
check_1d_array (h, "h");
return ModuleBase::Integral::simpson (n, get_array_ptr (f), get_array_ptr (h));
})
.def_static (
"Gauss_Legendre_grid_and_weight",
[] (const int n, py::array_t<double> x, py::array_t<double> w)
{
check_1d_array (x, "x");
check_1d_array (w, "w");
ModuleBase::Integral::Gauss_Legendre_grid_and_weight (n, get_array_ptr (x), get_array_ptr (w));
})
.def_static (
"Gauss_Legendre_grid_and_weight",
[] (const double xmin, const double xmax, const int n, py::array_t<double> x, py::array_t<double> w)
{
check_1d_array (x, "x");
check_1d_array (w, "w");
ModuleBase::Integral::Gauss_Legendre_grid_and_weight (xmin,
xmax,
n,
get_array_ptr (x),
get_array_ptr (w));
});
py::class_<ModuleBase::SphericalBesselTransformer> (m, "SphericalBesselTransformer").def (py::init<> ());
}

PYBIND11_MODULE(_base_pack, m)
PYBIND11_MODULE (_base_pack, m)
{
m.doc() = "Submodule for pyabacus: ModuleBase";
m.doc () = "Submodule for pyabacus: ModuleBase";

bind_base_math(m);
bind_base_math (m);
}
Loading
Loading