Skip to content

refactor(dfpt): replace the shared fixture base class with a free-function test tool - #8270

Merged
mohanchen merged 9 commits into
deepmodeling:developfrom
Zanthoxylum:refactor-dfpt-test-tool
Nov 4, 2026
Merged

mohanchen merged 9 commits into
deepmodeling:developfrom
Zanthoxylum:refactor-dfpt-test-tool

Conversation

@Zanthoxylum

@Zanthoxylum Zanthoxylum commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

DFPTSerialBase (the shared gtest fixture base class and its header,
dfpt_serial_fixture.{h,cpp}) is replaced by a free-function test tool,
following the established module_pw test/test_tool.{h,cpp} pattern:
small declaration-only header + one implementation TU compiled into
every test target.

  • dfpt_test_tool.{h,cpp} provides the shared utilities as 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 — plus 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 (ucell_, pw_rho_, pw_wfc_,
    qlist_, data_, q_cart_, ...) as members and calls exactly the
    utilities it needs. There is no shared fixture base class and no
    fixture header anywhere in the module.
  • The rho files keep their file-local RNG (single-TU determinism).
  • CMakeLists.txt swaps dfpt_serial_fixture.cpp for
    dfpt_test_tool.cpp in every test target.

setup_bases keeps its own five-call assembly chains instead of
calling the production pw::setup_pwrho / pw::setup_pwwfc wrappers
(which also run without __MPI): the tests need rho_mult = 9x ecutwfc for the DFPT convolution (every Delta = G''-G' must fit in
the rho ball) while production hardcodes 4x ecutwfc 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 running-log global-stream read
into the unit tests. The rationale is documented in the tool source.

Verification

cmake --build build-gcc13 --target MODULE_DFPT_pert_serial \
  MODULE_DFPT_rho_serial MODULE_DFPT_phon_serial MODULE_DFPT_q0_serial \
  MODULE_DFPT_xc_analytic_serial MODULE_DFPT_write_dyn_serial -j 20
ctest --test-dir build-gcc13 -R "MODULE_DFPT"      # 10/10 targets Passed
  • All six reworked targets rebuilt from deleted binaries (make exit
    code 0 per target).
  • Case counts conserved: pert 7 / phon 20 / rho 11 / q0 6 / xc 6 /
    write_dyn 6 (identical case names, none added or lost).
  • Full MODULE_DFPT suite: 10/10, re-run after every review round
    (fixture inline / include dedup / forward declarations / develop
    merge).
  • agent_governance_check.py --base origin/develop --head HEAD:
    no errors.

Documentation

No docs change needed: test-only refactor with no INPUT, interface, or
behavior change.

…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.
@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 3, 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.

Static review of 68d7f3fd5 found no functional regression in the fixture extraction; two include cleanups are noted below. Builds and tests were not run.

… 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.
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.
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.
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.
@mohanchen
mohanchen merged commit a76b67d into deepmodeling:develop Nov 4, 2026
19 checks passed
@Zanthoxylum
Zanthoxylum deleted the refactor-dfpt-test-tool 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.

3 participants