Skip to content

Commit ca6e17b

Browse files
authored
Merge branch 'develop' into test/source-base-coverage
2 parents a60912d + 3df3bb4 commit ca6e17b

76 files changed

Lines changed: 3950 additions & 2331 deletions

Some content is hidden

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

docs/advanced/acceleration/cuda.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ The ABACUS program will automatically determine whether the current ELPA support
4444
## Run with the GPU support by editing the INPUT script:
4545

4646
In `INPUT` file we need to set the input parameter [device](../input_files/input-main.md#device) to `gpu`. If this parameter is not set, ABACUS will try to determine if there are available GPUs.
47-
- Set `ks_solver`: For the PW basis, CG, BPCG and Davidson methods are supported on GPU; set the input parameter [ks_solver](../input_files/input-main.md#ks_solver) to `cg`, `bpcg` or `dav`. For the LCAO basis, `cusolver`, `cusolvermp` and `elpa` is supported on GPU.
47+
- Set `ks_solver`: For the PW basis, CG, BPCG, Davidson, and Davidson subspace methods are supported on GPU; set the input parameter [ks_solver](../input_files/input-main.md#ks_solver) to `cg`, `bpcg`, `dav`, or `dav_subspace`. For the LCAO basis, `cusolver`, `cusolvermp`, and `elpa` are supported on GPU.
4848
- **single-card**: ABACUS allows for single-GPU acceleration. You can run ABACUS without any MPI process by command `abacus`, and `ks_solver cusolver` is recommended for the LCAO basis. *note: avoid using `mpirun -n 1 abacus`*.
4949
- **multi-cards**: ABACUS allows for multi-GPU acceleration. If you have multiple GPU cards, you can run ABACUS with several MPI processes, and each process will utilize one GPU card. For example, the command `mpirun -n 2 abacus` will by default launch two GPUs for computation. If you only have one card, this command will only start one GPU. *note: the number of MPI processes SHOULD be equal to the number of GPU cards, unless you are using MPS in your computer.*
5050

@@ -58,4 +58,4 @@ PW basis:
5858

5959
LCAO basis:
6060
- Unless there is a specific reason, avoid using multiple GPUs, as it can be slower than using a single GPU. This is because the generalized eigenvalue solution of the LCAO basis set will incur additional communication overhead when calculated on multiple cards. When the memory limit of a GPU card makes it insufficient to complete the task, it is recommended to use multiple cards for calculation.
61-
- When using elpa on GPUs, some ELPA internal logs will be output.
61+
- When using elpa on GPUs, some ELPA internal logs will be output.

docs/advanced/input_files/input-main.md

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- [System variables](#system-variables)
99
- [suffix](#suffix)
1010
- [ntype](#ntype)
11+
- [cell\_replica](#cell_replica)
1112
- [calculation](#calculation)
1213
- [esolver\_type](#esolver_type)
1314
- [symmetry](#symmetry)
@@ -356,6 +357,8 @@
356357
- [md\_restart](#md_restart)
357358
- [md\_restartfreq](#md_restartfreq)
358359
- [md\_dumpfreq](#md_dumpfreq)
360+
- [md\_neighbor\_skin](#md_neighbor_skin)
361+
- [md\_out\_force](#md_out_force)
359362
- [dump\_force](#dump_force)
360363
- [dump\_vel](#dump_vel)
361364
- [dump\_virial](#dump_virial)
@@ -601,6 +604,12 @@
601604
- **Description**: Number of different atom species in the calculation.
602605
- **Default**: 0
603606

607+
### cell_replica
608+
609+
- **Type**: Three Integers
610+
- **Description**: Replicate the input STRU by Na, Nb, and Nc along its lattice vectors for distributed MDCell workflows. This parameter is only used for classical potentials or machine-learned interatomic potentials. The default is 1 1 1, which preserves the input structure.
611+
- **Default**: 1 1 1
612+
604613
### calculation
605614

606615
- **Type**: String
@@ -3504,15 +3513,28 @@
35043513
### md_restartfreq
35053514

35063515
- **Type**: Integer
3507-
- **Description**: The output frequency of OUT.{suffix}/STRIU/, which are used to restart molecular dynamics calculations, see md_restart in detail.
3516+
- **Description**: The output frequency of OUT.{suffix}/STRU_MD_*, which are used to restart molecular dynamics calculations, see md_restart in detail. Set to 0 to disable MD restart output.
35083517
- **Default**: 5
35093518

35103519
### md_dumpfreq
35113520

35123521
- **Type**: Integer
3513-
- **Description**: The output frequency of OUT.${suffix}/MD_dump in molecular dynamics calculations, which including the information of lattices and atoms.
3522+
- **Description**: The output frequency of OUT.${suffix}/MD_dump in molecular dynamics calculations, which includes lattice and atomic information. Set to 0 to disable MD_dump output.
35143523
- **Default**: 1
35153524

3525+
### md_neighbor_skin
3526+
3527+
- **Type**: Real
3528+
- **Description**: The extra neighbor-list radius in Angstrom for MDCell molecular dynamics. This parameter is only used for classical potentials or machine-learned interatomic potentials. A positive value reuses the cutoff-plus-skin candidate list until an atom has moved by half this distance; 0 rebuilds the list every force evaluation.
3529+
- **Default**: 0.0
3530+
- **Unit**: Angstrom
3531+
3532+
### md_out_force
3533+
3534+
- **Type**: Boolean
3535+
- **Description**: Whether to output the TOTAL-FORCE table in OUT.${suffix}/running_md.log for MDCell molecular dynamics. This does not affect force calculation or molecular dynamics integration.
3536+
- **Default**: True
3537+
35163538
### dump_force
35173539

35183540
- **Type**: Boolean
@@ -3535,8 +3557,8 @@
35353557

35363558
- **Type**: Integer
35373559
- **Description**: The random seed to initialize random numbers used in molecular dynamics calculations.
3538-
- < 0: No srand() function is called.
3539-
- >= 0: The function srand(md_seed) is called.
3560+
- < 0: Each MPI rank uses the default seed 1 plus its rank.
3561+
- >= 0: Each MPI rank uses md_seed plus its rank.
35403562
- **Default**: -1
35413563

35423564
### md_tfreq

docs/parameters.yaml

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ parameters:
1717
default_value: "0"
1818
unit: ""
1919
availability: ""
20+
- name: cell_replica
21+
category: System variables
22+
type: Three Integers
23+
description: |
24+
Replicate the input STRU by Na, Nb, and Nc along its lattice vectors for distributed MDCell workflows. This parameter is only used for classical potentials or machine-learned interatomic potentials. The default is 1 1 1, which preserves the input structure.
25+
default_value: 1 1 1
26+
unit: ""
27+
availability: ""
2028
- name: calculation
2129
category: System variables
2230
type: String
@@ -1449,18 +1457,34 @@ parameters:
14491457
category: Molecular dynamics
14501458
type: Integer
14511459
description: |
1452-
The output frequency of OUT.{suffix}/STRIU/, which are used to restart molecular dynamics calculations, see md_restart in detail.
1460+
The output frequency of OUT.{suffix}/STRU_MD_*, which are used to restart molecular dynamics calculations, see md_restart in detail. Set to 0 to disable MD restart output.
14531461
default_value: "5"
14541462
unit: ""
14551463
availability: ""
14561464
- name: md_dumpfreq
14571465
category: Molecular dynamics
14581466
type: Integer
14591467
description: |
1460-
The output frequency of OUT.${suffix}/MD_dump in molecular dynamics calculations, which including the information of lattices and atoms.
1468+
The output frequency of OUT.${suffix}/MD_dump in molecular dynamics calculations, which includes lattice and atomic information. Set to 0 to disable MD_dump output.
14611469
default_value: "1"
14621470
unit: ""
14631471
availability: ""
1472+
- name: md_neighbor_skin
1473+
category: Molecular dynamics
1474+
type: Real
1475+
description: |
1476+
The extra neighbor-list radius in Angstrom for MDCell molecular dynamics. This parameter is only used for classical potentials or machine-learned interatomic potentials. A positive value reuses the cutoff-plus-skin candidate list until an atom has moved by half this distance; 0 rebuilds the list every force evaluation.
1477+
default_value: "0.0"
1478+
unit: Angstrom
1479+
availability: ""
1480+
- name: md_out_force
1481+
category: Molecular dynamics
1482+
type: Boolean
1483+
description: |
1484+
Whether to output the TOTAL-FORCE table in OUT.${suffix}/running_md.log for MDCell molecular dynamics. This does not affect force calculation or molecular dynamics integration.
1485+
default_value: "True"
1486+
unit: ""
1487+
availability: ""
14641488
- name: dump_force
14651489
category: Molecular dynamics
14661490
type: Boolean
@@ -1490,8 +1514,8 @@ parameters:
14901514
type: Integer
14911515
description: |
14921516
The random seed to initialize random numbers used in molecular dynamics calculations.
1493-
* < 0: No srand() function is called.
1494-
* >= 0: The function srand(md_seed) is called.
1517+
* < 0: Each MPI rank uses the default seed 1 plus its rank.
1518+
* >= 0: Each MPI rank uses md_seed plus its rank.
14951519
default_value: "-1"
14961520
unit: ""
14971521
availability: ""

python/pyabacus/CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ To contribute to the `pyabacus` project, follow these steps:
375375

376376
@staticmethod
377377
def sphbes_zeros(l: int, n: int, zeros: NDArray[np.float64]) -> None:
378-
super().sphbes_zeros(l, n, zeros)
378+
_Sphbes.sphbes_zeros(l, n, zeros)
379379
```
380380

381381
## Conclusion

python/pyabacus/src/pyabacus/ModuleBase/_module_base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def dsphbesj(self, *args, **kwargs):
4848

4949
@staticmethod
5050
def sphbes_zeros(l: int, n: int, zeros: NDArray[np.float64]) -> None:
51-
super().sphbes_zeros(l, n, zeros)
51+
_Sphbes.sphbes_zeros(l, n, zeros)
5252

5353
class Integral(_Integral):
5454
def __init__(self) -> None:
@@ -81,7 +81,7 @@ def Simpson_Integral_0toall(
8181
rab: NDArray[np.float64],
8282
asum: NDArray[np.float64]
8383
) -> None:
84-
super().Simpson_Integral_0toall(mesh, func, rab, asum)
84+
_Integral.Simpson_Integral_0toall(mesh, func, rab, asum)
8585

8686
@staticmethod
8787
def Simpson_Integral_alltoinf(
@@ -90,7 +90,7 @@ def Simpson_Integral_alltoinf(
9090
rab: NDArray[np.float64],
9191
asum: NDArray[np.float64]
9292
) -> None:
93-
super().Simpson_Integral_alltoinf(mesh, func, rab, asum)
93+
_Integral.Simpson_Integral_alltoinf(mesh, func, rab, asum)
9494

9595
@overload
9696
@staticmethod

python/pyabacus/tests/test_base_math.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,23 @@ def test_sphbes():
1313
assert s.sphbesj(0, 0.0) == 1.0
1414
assert s.sphbesj(1, np.array([0.0]), 1, 1, np.zeros(1)) == None
1515

16+
def test_static_array_wrappers():
17+
zeros = np.zeros(2)
18+
base.Sphbes.sphbes_zeros(0, 2, zeros)
19+
np.testing.assert_allclose(zeros, [np.pi, 2 * np.pi])
20+
21+
mesh = 3
22+
func = np.ones(mesh)
23+
rab = np.ones(mesh)
24+
integral_from_zero = np.zeros(mesh)
25+
integral_to_infinity = np.zeros(mesh)
26+
27+
base.Integral.Simpson_Integral_0toall(mesh, func, rab, integral_from_zero)
28+
base.Integral.Simpson_Integral_alltoinf(mesh, func, rab, integral_to_infinity)
29+
30+
np.testing.assert_allclose(integral_from_zero, [0.0, 1.0, 2.0])
31+
np.testing.assert_allclose(integral_to_infinity, [2.0, 1.0, 0.0])
32+
1633
def test_sbt():
1734
sbt = base.SphericalBesselTransformer()
1835

source/Makefile.Objects

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,7 @@ OBJS_MODULE_RI=conv_coulomb_pot_k.o\
772772
singular_value.o\
773773

774774
OBJS_PARALLEL=parallel_common.o\
775-
communication_domain.o\
775+
parallel_cell.o\
776776
parallel_global.o\
777777
parallel_comm.o\
778778
parallel_grid.o\

source/source_base/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ add_library(
5151
tool_title.cpp
5252
ylm.cpp
5353
parallel_common.cpp
54-
communication_domain.cpp
54+
parallel_cell.cpp
5555
parallel_global.cpp
5656
parallel_comm.cpp
5757
parallel_reduce.cpp

source/source_base/module_container/ATen/core/tensor.h

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -390,25 +390,30 @@ class Tensor {
390390
*
391391
* @return The pointer to the specified row.
392392
*
393-
* @note This function assumes the tensor is treated as a matrix, where each row
394-
* is a contiguous block of memory.
395-
* If the row index is out of bounds, the behavior is undefined.
393+
* @note This function supports rank-1 and rank-2 tensors. For a rank-1 tensor,
394+
* the index selects an element. For a rank-2 tensor, the index selects a row.
395+
* An invalid rank or index throws std::invalid_argument.
396396
*/
397397
template <typename T>
398-
T* inner_most_ptr(const int &index) const {
399-
if (shape_.ndim() > 2) {
400-
throw std::invalid_argument("Invalid call, inner_most_ptr only support tensor rank <= 2!");
398+
T* inner_most_ptr(const int& index) const
399+
{
400+
const unsigned int rank = shape_.ndim();
401+
if (rank == 0 || rank > 2)
402+
{
403+
throw std::invalid_argument("Invalid call, inner_most_ptr only supports tensor ranks 1 and 2!");
401404
}
402-
if (index > shape_.dim_size(static_cast<int>(shape_.ndim() - 2))) {
403-
throw std::invalid_argument("Invalid index, index of the inner-most must less than the inner-most shape size!");
405+
const int64_t outer_size = shape_.dim_size(0);
406+
if (index < 0 || static_cast<int64_t>(index) >= outer_size)
407+
{
408+
throw std::invalid_argument("Invalid index, inner_most_ptr index is out of bounds!");
404409
}
405-
if (shape_.ndim() == 1) {
410+
if (rank == 1)
411+
{
406412
return data<T>() + index;
407413
}
408-
return data<T>() + index * shape_.dim_size(static_cast<int>(shape_.ndim()) - 1);
414+
return data<T>() + index * shape_.dim_size(1);
409415
}
410416

411-
412417
/**
413418
* @brief Equality comparison operator for tensors.
414419
*

source/source_base/module_container/test/tensor_test.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,27 @@ TEST(Tensor, GetValueAndInnerMostPtr) {
230230
EXPECT_EQ(row_ptr[3], 12);
231231
}
232232

233+
TEST(Tensor, InnerMostPtrBounds)
234+
{
235+
container::Tensor vector(container::DataType::DT_INT, container::DeviceType::CpuDevice, {4});
236+
std::vector<int> values = {1, 2, 3, 4};
237+
memcpy(vector.data<int>(), values.data(), sizeof(int) * values.size());
238+
239+
auto element_ptr = vector.inner_most_ptr<int>(2);
240+
EXPECT_EQ(*element_ptr, 3);
241+
EXPECT_THROW(vector.inner_most_ptr<int>(-1), std::invalid_argument);
242+
EXPECT_THROW(vector.inner_most_ptr<int>(4), std::invalid_argument);
243+
244+
container::Tensor matrix(container::DataType::DT_INT, container::DeviceType::CpuDevice, {2, 2});
245+
EXPECT_THROW(matrix.inner_most_ptr<int>(2), std::invalid_argument);
246+
247+
container::Tensor empty(container::DataType::DT_INT, container::DeviceType::CpuDevice, container::TensorShape());
248+
EXPECT_THROW(empty.inner_most_ptr<int>(0), std::invalid_argument);
249+
250+
container::Tensor rank_three(container::DataType::DT_INT, container::DeviceType::CpuDevice, {1, 1, 1});
251+
EXPECT_THROW(rank_three.inner_most_ptr<int>(0), std::invalid_argument);
252+
}
253+
233254
TEST(Tensor, ReshapeDeathTest) {
234255
::testing::FLAGS_gtest_death_test_style = "threadsafe";
235256
container::Tensor t(container::DataType::DT_FLOAT, container::DeviceType::CpuDevice, {2, 3, 4});
@@ -545,4 +566,4 @@ TEST(Tensor, Accessor) {
545566
}
546567
}
547568

548-
} // namespace container
569+
} // namespace container

0 commit comments

Comments
 (0)