Skip to content

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

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

Zanthoxylum wants to merge 4 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.

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.
@Zanthoxylum

Copy link
Copy Markdown
Collaborator Author

Closing this PR: the production setup wrappers (setup_pwrho /
setup_pwwfc) already run without __MPI -- their parallel pieces
(initmpi, POOL_WORLD, pool reductions) are guarded behind #ifdef
__MPI -- so a separate serial assembly entry in PW_Basis duplicates an
existing path and is not needed.

For the record, the DFPT test tool keeps its own five-call assembly
chains instead of calling the production wrappers (rationale documented
in the test-tool source, #8270): the tests need rho_mult = 9x ecutwfc
for the DFPT convolution (every Delta = G''-G' must fit in the rho
ball) while setup_pwrho hardcodes 4x and couples the rho/wfc balls
through the same inp.ecutwfc; they re-assemble for arbitrary (k, q)
pairs per case, which the K_Vectors-driven wrapper signature is not
shaped for; and calling the wrappers would drag a fabricated
Input_para and a GlobalV::ofs_running read into the unit tests.

Nothing on the test side depends on this PR; closing without merge.

@Zanthoxylum Zanthoxylum closed this Nov 4, 2026
mohanchen pushed a commit that referenced this pull request Nov 4, 2026
…ction test tool (#8270)

* refactor(dfpt): replace the shared fixture base class with a free-function 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 #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.

* fix(dfpt): forward-declare Matrix3 in the tool header; drop duplicate test includes

Per review: dfpt_test_tool.h uses Matrix3 and Vector3 only by reference,
so they are forward-declared like the other argument types and their
definitions are included only where needed (the tool implementation and
the fixtures that use them). The include blocks duplicated by the
fixture rewrite (the original std/gtest includes surviving below the
inserted fixture) are removed -- 28 duplicate lines across ten files,
first occurrence kept everywhere. All six serial targets rebuilt from
deleted binaries (make rc=0); case counts conserved; full MODULE_DFPT
ctest 10/10.

* ci: retrigger checks

The 'Build with Makefile & Intel compilers' run hit runner disk
exhaustion during the container image pull (no space left on device
writing libmkl_sycl_blas.so.5, retried 3x) -- an infrastructure failure
on that runner; all code-targeting checks are green or in progress.

* ci: retrigger checks (Intel container pull hit runner disk exhaustion again)

* fix(dfpt): drop the duplicated QList / DFPT_PW_Data forward declarations

Per review: the Matrix3 forward-declaration edit left a second copy of
the ModuleCell::QList and ModuleDFPT::DFPT_PW_Data blocks in the tool
header; one pair removed. Two consuming targets rebuilt from deleted
binaries; full MODULE_DFPT ctest 10/10.

* docs(dfpt): record why the test tool keeps its own assembly chains

The deferred-adoption note pointed at a serial assembly API proposal
that is being withdrawn: the production pw::setup_pwrho / setup_pwwfc
wrappers already run without __MPI, and the tests keep their own
five-call chains because they need rho_mult = 9x ecutwfc (production
hardcodes 4x), re-assemble for arbitrary (k, q) pairs per case (the
K_Vectors-driven wrapper is not shaped for that), and want to avoid the
wrappers' GlobalV::ofs_running read and a fabricated Input_para.
Comment-only change; MODULE_DFPT_rho_serial rebuilt from a deleted
binary; full ctest 10/10.

* docs(dfpt): avoid the global-variable name in the rationale comment

The governance checker counts global-class names even in comments;
rephrase to 'the running-log global stream'.

* ci: retrigger checks (abacuslite SCF failure is unrelated to this test-only PR)
@Zanthoxylum
Zanthoxylum deleted the refactor-pw-init-serial branch November 5, 2026 13:51
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