Skip to content

Title: test(md): relocate LCAO RT-TDDFT hybrid-gauge coverage out of source _md unit tests #8297

Closed

Description

@mohanchen

Describe the Code Quality Issue

Summary

source/source_ md/unittests/test _md_ base.cpp is presented as a unit test for MD_base , but it contains a complete hybrid-gauge LCAO RT-TDDFT folding model
and asserts on module_rt::reset_matrix_boundary and module_rt::folding_HR_td .

Neither MD_base nor MDCell has any notion of k-points, Bloch phases, or a
vector potential A . The only MD-side state involved is boundary_shift , which module_rt consumes through UnitCell . Putting the RT assertions here creates
an inverted dependency: source_md (a lower layer) now depends on source_lcao/module_rt plus module_hcontainer and module_ao . ## Evidence Source file: source/source_md/unittests/test_md_base.cpp - L9-L10 include source_lcao/module_rt/boundary_fix.h and td_folding.h . - L178-L226 define the helper fold_hybrid(...) , which builds a hamilt::HContainer<std::complex<double>> , inserts atom pairs with
translations, computes exp(i * A * R_cart) phases, and calls module_rt::folding_HR_td . - L228-L319 define expect_hybrid_fold_correction(...) , which compares folded
matrices at saved_A versus next_A and asserts the saved-field-time
behaviour of module_rt::reset_matrix_boundary . - L321-L411 define expect_phase_correction(...) , which asserts H/S/coefficient
phase covariance from reset_matrix_boundary . - L492-L508 HybridBoundaryMatchesFreshFoldingAtSavedFieldTime is a pure
hybrid-gauge RT test that only calls MD_base::first_half to produce the
boundary shifts.

The hybrid-gauge physics lives entirely in the RT layer: - source/source_lcao/module_rt/boundary_fix.cpp L49-L52: exp(i * (2*pi*k.R + A.R_cart)) , with the parameter documented as
"Saved hybrid-gauge Cartesian A in Hartree atomic units; zero in other gauges"
in boundary_fix.h L21. - source/source_lcao/module_rt/td_folding.h and force_rt_overlap.cpp L154
use the same hybrid-gauge phase map.

The MD side only produces the boundary shift: - source/source_md/md_base.cpp L123-L141 sets atom.boundary_shift in MD_base::update_pos . - source/source_cell/mdcell.cpp L180-L274 copies it into the backing UnitCell . - source/source_lcao/module_rt/boundary_fix.cpp L40-L52 is the consumer.

Build-level proof of the inversion, source/source_md/unittests/CMakeLists.txt L16-L31: the MODULE_MD_base_mpi target compiles ../md_base.cpp
../../source_lcao/module_rt/boundary_fix.cpp
../../source_lcao/module_rt/td_folding.cpp
../../source_hamilt/module_hcontainer/base_matrix.cpp
../../source_hamilt/module_hcontainer/atom_pair.cpp
../../source_hamilt/module_hcontainer/hcontainer.cpp
../../source_basis/module_ao/parallel_orbitals.cpp
../../source_base/parallel_2d.cpp so an MD unit-test target pulls in the LCAO, Hamiltonian-container, and
atomic-orbital layers.

Finally, source/source_lcao/module_rt/test/CMakeLists.txt has targets for evolve_psi , middle_hamilt , band_energy , norm_psi , upsi , propagator ,
SNAP, and radial interpolation, but none for boundary_fix.cpp or td_folding.cpp . This MD test is currently the only coverage of reset_matrix_boundary (including its hybrid-gauge branch), which is exactly
why the test belongs with module_rt . ## Why this matters - Ownership: hybrid gauge is RT-TDDFT physics. A file named test_md_base.cpp should assert MD behaviour, not LCAO RT folding. - Dependency direction: a test should not make the module under test depend on
a module that depends on it in production. Any change to Parallel_Orbitals , HContainer , or TD folding can break the MD test target. - Discoverability: a reader looking for boundary_fix tests will not search
under source_md . ## Proposed refactor 1. Keep only MD-owned cases in source/source_md/unittests/test_md_base.cpp :
position wrapping and boundary_shift generation, setup() flag semantics
(initial/restarted force evaluation), and MDCell::sync_backing_unitcell state preservation. 2. Add source/source_lcao/module_rt/test/test_boundary_fix.cpp covering reset_matrix_boundary directly: - distributed and gathered matrix layouts (the len_hs branch); - hybrid gauge with saved A versus a different next-step A ; - non-orthogonal lattice and lat0 != 1 Cartesian/unit conversion; - the OpenMP path and the shared Psi cursor invariant.
This test only needs source_cell and Parallel_Orbitals ; it does not need source_md . 3. Add source/source_lcao/module_rt/test/test_td_folding.cpp for folding_HR_td phases, which currently has no test either. 4. Move the MD -> RT end-to-end contract (wrap during first_half , then
correct the saved H/S/psi) to an integration test that legitimately spans
both modules, registered through CTest/Autotest rather than an MD unit
target. 5. Remove module_rt , module_hcontainer , and module_ao sources from MODULE_MD_base_mpi , and delete fold_hybrid , expect_hybrid_fold_correction , and expect_phase_correction from the MD
test. ## Acceptance criteria - MODULE_MD_base_mpi compiles only MD, cell, and base sources; its dependency
list no longer contains source_lcao , source_hamilt/module_hcontainer , or source_basis/module_ao . - boundary_fix.cpp and td_folding.cpp have dedicated unit tests under source_lcao/module_rt/test , including the hybrid-gauge saved-field timing. - The existing regression coverage is preserved: every assertion moved, none
silently dropped. - The MD/RT integration case is registered as a CTest/Autotest case and passes
with 1 and 4 MPI ranks.

Additional Context

No response

Task list for Issue attackers (only for developers)

  • Identify the specific code file or section with the code quality issue.
  • Investigate the issue and determine the root cause.
  • Research best practices and potential solutions for the identified issue.
  • Refactor the code to improve code quality, following the suggested solution.
  • Ensure the refactored code adheres to the project's coding standards.
  • Test the refactored code to ensure it functions as expected.
  • Update any relevant documentation, if necessary.
  • Submit a pull request with the refactored code and a description of the changes made.

Activity

  1. ABACUS-PR-BOT commented on Nov 8, 2026

    @ABACUS-PR-BOT
    Collaborator

    The test-ownership concern is supported. Before relocating coverage, account for the existing integration cases and the overlapping work in #8295.

    • The RT/HContainer/AO dependency is in MODULE_MD_base_mpi. The production md object does not compile those RT sources. Removing them also leaves shared IO/LJ fixture dependencies, so “only MD/cell/base” needs a separately agreed scope.
    • Preserve the current 1/4-rank and OpenMP=4 registrations, repeated backing-cell synchronization, saved-field behavior and Psi cursor assertions. Exercise the gathered len_hs branch with more than one rank; a one-rank layout cannot distinguish it from the local layout.
    • 18_NO_hyb_TDDFT already targets saved-field timing across a periodic boundary with two electronic steps per MD step; it and 10_NO_MD_boundary_shift are registered in the CPU/GPU case lists. Map the moved assertions to this existing coverage before adding another integration case.
    • A dedicated folding test should independently construct the expected Fourier sum: folding_HR_td consumes the supplied phase_hybrid map; its cart_At argument does not itself generate the field phase.

    #8295 already lists a new test_boundary_fix.cpp and an MPI wrapper; its coverage equivalence is not assessed here. Also settle the destination alongside the open unittests/ proposal in #8245. RT’s test directory is LCAO-gated while the original MD MPI target is not; preserve or explicitly account for that change in test availability.

    Static source/build-list inspection at 27c3e1065bfe0ca6be2d9b90a93da91bfea1ffe0; no build or runtime tests were run.

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

Metadata

Metadata

Assignees

Labels

RefactorRefactor ABACUS codesrt-TDDFTReal-time Time-Dependent DFT

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions