Skip to content

feat(pw): expose the serial basis assembly as PW_Basis::init_serial - #8268

Open
Zanthoxylum wants to merge 3 commits into
deepmodeling:developfrom
Zanthoxylum:refactor-pw-init-serial
Open

Zanthoxylum wants to merge 3 commits into
deepmodeling:developfrom
Zanthoxylum:refactor-pw-init-serial

Conversation

@Zanthoxylum

Copy link
Copy Markdown
Collaborator

Summary

The plain serial basis assembly chain

initgrids -> initparameters -> fft_bundle.initfftmode(0) -> setuptransform -> collect_local_pw

was mirrored by every serial test scaffolding, because the production
wrappers setup_pwrho / setup_pwwfc bundle it with global parallel
state (GlobalV::NPROC_IN_POOL / RANK_IN_POOL, GlobalV::ofs_running
logging), the full Input_para, K_Vectors, and GPU/double-grid
branches — unreachable from a serial unit test. This PR exposes the
chain as a public source API so heavily-used test setup references the
source instead of duplicating it:

  • PW_Basis::init_serial(lat0, latvec, gridecut) (pw_basis.h /
    pw_init.cpp): the five-call sequence above, no parallel/device
    context, default distribution.
  • PW_Basis_K::init_serial(lat0, latvec, nx, ny, nz, ecut, nk, kvec_d)
    (pw_basis_k.h / .cpp): the FFT-box + k-list variant, for a wfc basis
    sharing the rho grid's box.
  • The DFPT serial fixture's SetupBases — the single most-shared test
    helper (every serial DFPT test file reaches it) — shrinks to the two
    init_serial calls plus its (k, q) data wiring.

The parallel production path (setup_pwrho / setup_pwwfc) is
untouched: it interleaves initmpi and device/precision branches
between the same calls, so unifying it onto init_serial is a separate
decision; this PR only removes the test-side mirror.

Scope and dependency on #8259

Verification

cmake --build build-gcc13 --target abacus_basic_para -j 20
cmake --build build-gcc13 --target MODULE_DFPT_rho_serial -j 20   # etc. per target
ctest --test-dir build-gcc13 -R "MODULE_DFPT"      # 10/10 targets Passed
  • All DFPT serial test binaries rebuilt from deleted binaries (make
    exit code 0 per target); full MODULE_DFPT suite 10/10 — the
    fixture output is byte-identical by construction (the chain is the
    same five calls).
  • The local 11_PW_GPU integration failure is a pre-existing no-CUDA
    environment issue: verified identical on the unmodified baseline
    (stash + rebuild + rerun).

Documentation

No docs change needed: additive internal API, no INPUT or user-facing
behavior change.

The plain serial assembly chain (initgrids -> initparameters -> default
FFT mode -> setuptransform -> collect_local_pw) was duplicated in every
serial test scaffolding because the production wrappers setup_pwrho /
setup_pwwfc bundle it with global parallel state (GlobalV::NPROC_IN_
POOL / RANK_IN_POOL / ofs_running), the full Input_para, K_Vectors and
GPU branches -- unreachable from a serial unit test. Expose the chain
as public PW_Basis::init_serial and PW_Basis_K::init_serial (FFT-box +
k-list variant) so heavily-used test setup references the source API
instead of mirroring it; the DFPT serial fixture's SetupBases shrinks
to the two init_serial calls plus its (k, q) data wiring. The parallel
production path is untouched. All DFPT serial test binaries rebuilt
from deleted binaries; full MODULE_DFPT ctest 10/10 (the local
11_PW_GPU integration failure is a pre-existing no-CUDA environment
issue, identical on the unmodified baseline).
@Zanthoxylum Zanthoxylum added Refactor Refactor ABACUS codes Tests/Examples Issues/PR related to unit tests and integrate tests DFPT Density Functional Perturbation Theory labels Nov 2, 2026

@ABACUS-PR-BOT ABACUS-PR-BOT left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The migrated fixture preserves its original basis initialization sequence. One API-contract clarification is below. Static review at 292c3d0; the reported build and runtime results were not independently verified.


//Serial basis assembly: the plain production sequence (initgrids ->
//initparameters -> default FFT mode -> setuptransform -> collect_local_pw)
//without any parallel/device context (no initmpi, default distribution).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking: Please state that the advertised no-initmpi use requires PW sources compiled without __MPI. Both initgrids overloads otherwise reach MPI_Allreduce with a fresh object's MPI_COMM_NULL; the migrated DFPT fixture avoids this by recompiling those sources with __MPI disabled.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 883b21d: both init_serial declarations (PW_Basis and
PW_Basis_K) now carry the requirement explicitly -- the no-initmpi use
requires the PW sources compiled without __MPI, because with __MPI the
initgrids overloads reduce over the object communicator, which is
MPI_COMM_NULL on a fresh basis that never called initmpi. The note also
points at the working pattern: the DFPT serial test targets compile the
PW sources with __MPI disabled (abacus_disable_feature_definitions),
which is exactly why the migrated fixture is safe. Comment-only change;
abacus_basic_para rebuilt clean (make rc=0).

Zanthoxylum added a commit to Zanthoxylum/abacus-develop that referenced this pull request Nov 3, 2026
…ction test tool

The DFPTSerialBase base class and its header are removed in favor of
dfpt_test_tool.{h,cpp} (the module_pw test/test_tool pattern): shared
declarations plus one implementation TU of free functions -- setup_cell,
make_coulomb_atom, make_nc_atom, make_two_atom_cell, make_nlcc_two_atom_
cell, setup_bases, vloc_coulomb, analytic_dvloc, fkey, gkey -- and the
shared test-world constants (lat0 / ecutwfc / rho_mult / cubic_edge).
Every test file now derives its own fixture directly from ::testing::Test,
owns its objects as members and calls the utilities it needs; there is no
shared fixture base class and no fixture header. The rho files keep their
file-local RNG. CMakeLists swaps dfpt_serial_fixture.cpp for
dfpt_test_tool.cpp in every target. setup_bases keeps the raw assembly
chains and adopts PW_Basis::init_serial once deepmodeling#8268 lands. All six serial
targets rebuilt from deleted binaries (make rc=0); case counts conserved
(pert 7 / phon 20 / rho 11 / q0 6 / xc 6 / write_dyn 6); full MODULE_DFPT
ctest 10/10.
Per review: the no-initmpi use advertised by init_serial requires the PW
sources compiled without __MPI -- with __MPI the initgrids overloads
reduce over the object communicator, which is MPI_COMM_NULL on a fresh
basis. Both init_serial declarations now state this; the DFPT fixture
works because its test targets compile the PW sources with __MPI
disabled.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

DFPT Density Functional Perturbation Theory Refactor Refactor ABACUS codes Tests/Examples Issues/PR related to unit tests and integrate tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants