Skip to content

Move the dV/dR sparse conversion out of module_gint and narrow three header includes - #8230

Merged
mohanchen merged 2 commits into
deepmodeling:developfrom
Critsium-xy:refactor/hamilt-drop-lcao-pw-includes
Oct 29, 2026
Merged

mohanchen merged 2 commits into
deepmodeling:developfrom
Critsium-xy:refactor/hamilt-drop-lcao-pw-includes

Conversation

@Critsium-xy

@Critsium-xy Critsium-xy commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

Reminder

  • I have read AGENTS.md and docs/developers_guide/agent_governance.md.
  • I have linked an issue or explained why this PR does not need one.
  • I have added adequate unit tests and/or case tests, or explained why not.
  • I have listed the exact verification commands run and their results.
  • I have described user-visible behavior changes, including INPUT parameter changes.
  • I have explained core-module impact for ESolver, HSolver, ElecState, Hamilt, Operator, Psi, or other source/ changes.
  • I have requested any needed governance exception below.

Linked Issue

Fixes #8232. Part of #7599 and #7604. This removes two of the includes from source_hamilt into source_lcao and source_pw, and one from source_pw into source_lcao. The remaining source_hamilt ones (exx_info_ri.h, cal_pseudo.cpp) overlap open PRs #8176 and #8222 and are left for later.

Unit Tests and/or Case Tests for my changes

  • Commands run:
    • python3 tools/03_code_analysis/agent_governance_check.py --staged --format text: warnings only, listed under Governance Notes.
    • A static include-closure comparison against develop @ e5ad53046 for every file that reaches one of the changed headers. No file loses a header whose classes, aliases or macros it uses.
  • Result summary: all 18 CI checks pass on 733ff65b3, including the builds and the unit and integration tests.
  • Checks not run, with reason:
    • No local build or tests: the remote build machine I normally use was unavailable, so CI is the only build.
    • The relocated conversion only runs with out_mat_dh 1, nspin 2 and gamma_only 0. The two existing out_mat_dh cases do not reach it: 02_NAO_Gamma/scf_out_dh uses gamma_only 1, and 03_NAO_multik/scf_out_dh_t uses nspin 1. CI therefore compiles this path but does not run it. The function bodies are moved unchanged; the only edits are the parameter changes listed under "What's changed?". Adding an nspin 2 case, and a spin-2 comparison in props_mat.sh, is a separate test gap tracked in [Dependency] module_gint includes source_lcao for the dH sparse output; two headers include more than they use #8232 and left out of this PR.

What's changed?

Two commits, no intended behavior change:

  1. Narrow three header includes to what the header actually uses.
    • source_hamilt/module_xc/kernels/xc_functional_op.h: source_psi/psi.h → source_base/module_device/types.h. The kernel only needs GetTypeReal (already included from source_base/macros.h) and the base_device tags.
    • source_hamilt/module_vdw/vdwd2_parameters.h: source_io/module_parameter/parameter.h → input_parameter.h. Only Input_para is used; none of its includers touch PARAM.
    • source_pw/module_pwdft/op_pw_exx.h: source_lcao/module_ri/conv_coulomb_pot_k.h → source_hamilt/module_xc/coulomb_config.h. Only Conv_Coulomb_Pot_K::Coulomb_Type is used, and it is defined there. The two files that call conv_coulomb_pot_k.h functions (ewald_vq.hpp, exx_lri.hpp) include it directly.
  2. Move the dV/dR sparse conversion from module_gint to source_lcao.
    • Gint_dvlocal::cal_dvlocal() integrates ⟨φ|V|∇φ⟩ on the grid into three HContainers; that part stays.
    • Its other two members, cal_dvlocal_R_sparse and distribute_pvdpR_sparse, only converted that result into the LCAO_HS_Arrays format of the dH output. They were why module_gint included source_lcao/lcao_hs_arrays.h and source_lcao/module_ri/abfs_vector3_order.h.
    • Both are now file-local functions in source_lcao/spar_dh.cpp, next to their only caller sparse_format::cal_dH, and take the HContainers from the existing get_pvdpR*() getters.
    • The bodies are unchanged. The only edits: dead locals and the unused nspin/Grid_Driver parameters are dropped, and trace_lo is read through the public Gint::get_gint_info() instead of the protected member.
    • The wrapper ModuleGint::cal_dvlocal_R_sparse and the LCAO_HS_Arrays forward declaration in gint_interface.h are removed. veff_dh.cpp, the other user of Gint_dvlocal, only calls cal_dvlocal() and the getters and is untouched.

Governance Notes

  • INPUT/docs changes: none; no INPUT parameter or output format changes.
  • Core module impact: source_hamilt/module_gint, module_xc (kernel header), module_vdw (one header), source_pw/module_pwdft/op_pw_exx.h, source_lcao/spar_dh.cpp. No new files, so no CMake or Makefile changes.
  • Exceptions requested:
    • Global dependency budget: net 0. The one PARAM.globalv.nlocal line in spar_dh.cpp is the existing call site, reformatted.
    • Header include warnings (three): each one replaces an include with a narrower one.

🤖 Generated with Claude Code

Critsium-xy and others added 2 commits October 28, 2026 17:14
- xc_functional_op.h only needs GetTypeReal (source_base/macros.h) and the
  base_device tags its instantiations use; it no longer pulls source_psi/psi.h
  into the XC kernel.
- vdwd2_parameters.h only names Input_para, so it includes input_parameter.h
  instead of parameter.h and the global PARAM object.
- op_pw_exx.h only uses Conv_Coulomb_Pot_K::Coulomb_Type, which is defined in
  source_hamilt/module_xc/coulomb_config.h; it no longer includes the LCAO RI
  header conv_coulomb_pot_k.h.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Gint_dvlocal::cal_dvlocal() integrates <phi|V|dphi> on the real-space grid.
Its other two members only converted that result into the LCAO_HS_Arrays
sparse format used by the dH output, which made module_gint include
source_lcao/lcao_hs_arrays.h and source_lcao/module_ri/abfs_vector3_order.h.

The conversion now lives next to its only caller, sparse_format::cal_dH in
source_lcao/spar_dh.cpp, as file-local functions that take the three
HContainers from Gint_dvlocal's existing getters. The bodies are unchanged;
the dead locals and unused nspin/Grid_Driver parameters are dropped, and the
wrapper ModuleGint::cal_dvlocal_R_sparse is removed. source_hamilt no longer
includes source_lcao from module_gint.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Critsium-xy
Critsium-xy marked this pull request as ready for review October 28, 2026 13:48

@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 found no implementation defect in the relocation or narrowed headers. git diff --check passed; build, runtime, and CI results were not verified.

Comment thread source/source_lcao/spar_dh.cpp Resolved

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

LGTM

@mohanchen
mohanchen merged commit 14c224d into deepmodeling:develop Oct 29, 2026
21 checks passed
@mohanchen mohanchen added Refactor Refactor ABACUS codes The Absolute Zero Reduce the "entropy" of the code to 0 labels Oct 29, 2026
mohanchen pushed a commit to mohanchen/abacus-mc that referenced this pull request Oct 29, 2026
Resolve conflicts with upstream/develop (PR deepmodeling#8225, deepmodeling#8214, deepmodeling#8230, deepmodeling#8223):

- write_dipole.cpp grid validation: take upstream version, which rejects
  only the inconsistent state (nplane == 0 && nrxx != 0) while allowing
  legitimate empty partitions; a superset of our nplane fix (13b21fb).
- write_dipole.cpp file write: keep our MY_RANK == 0 guard (fixes UB of
  writing to an unopened stream on non-root ranks) wrapping upstream's
  new setw/scientific output format.
- source_io/unittests/CMakeLists.txt: adopt upstream's test/ -> unittests/
  rename and test_<module>.cpp file naming (rule 11), while keeping our
  stru_frame_io.cpp link additions; read_set_globalv.cpp still calls
  stru_frame_io::extract_last_frame, so the dependency remains.

Verification: conflict markers cleared, no stale references to old test
file names, all SOURCES entries point to existing files; build not rerun
locally.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Refactor Refactor ABACUS codes The Absolute Zero Reduce the "entropy" of the code to 0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Dependency] module_gint includes source_lcao for the dH sparse output; two headers include more than they use

3 participants