Skip to content

refactor(ofdft): reduce solver global state dependencies - #8157

Closed
zzlinpku wants to merge 1 commit into
deepmodeling:developfrom
zzlinpku:ofdft-global-config-refactor
Closed

zzlinpku wants to merge 1 commit into
deepmodeling:developfrom
zzlinpku:ofdft-global-config-refactor

Conversation

@zzlinpku

Copy link
Copy Markdown
Collaborator

Summary

Reduce ESolver_OF's direct dependence on global runtime state while preserving the existing initialization and numerical behavior.

  • Snapshot the six PARAM.globalv settings used by OFDFT into OFDFTRuntimeConfig at the solver initialization boundary, then use that configuration for charge initialization, output paths, force, and stress calculations.
  • Pass the warning stream explicitly through the OFDFT convergence, direction-check, and line-search methods. The base OFDFT and OFDFT-TDDFT runners provide the stream at their orchestration boundary.
  • Keep initialization stage markers and XC static-state access unchanged. XC lifecycle and mutation behavior remain a separate follow-up evaluation.

Validation

  • cmake --build build --target abacus_basic_para -j2 — passed.
  • ctest --test-dir build -R '^MODULE_PW_OfDFT$' --output-on-failure — passed (1/1).
  • ctest --test-dir build -R '^07_OFDFT$' --output-on-failure — 169 of 173 cases passed. Four cases require optional build support unavailable in this configuration: 04_OF_KE_CPN5 and 06_OF_KE_MPN require ENABLE_MLALGO; 22_OF_LibxcPBE and 26_OF_MD_LibxcPBE require LibXC support.
  • git diff --check — passed.

@mohanchen

Copy link
Copy Markdown
Collaborator

@ABACUS-PR-BOT could you review the PR?

@mohanchen mohanchen added the Refactor Refactor ABACUS codes label Oct 17, 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 4193ee4: I found no correctness issue in the snapshot and warning-stream changes, including the OF-TDDFT callers. Two non-blocking follow-ups are below. Whitespace and trusted governance checks completed without errors; no builds or runtime tests were run, and CI diagnostics were unavailable.

#define ESOLVER_OF_H

#include <string>
#include <ostream>

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 use <iosfwd> here, since this header only declares std::ostream& parameters and does not need the complete stream definition. The output operations are implemented in the .cpp files. This can be handled in a follow-up.

ESolver_FP::before_all_runners(ucell, inp);

// Snapshot the global settings needed by OFDFT at the solver boundary.
this->of_runtime_config_.global_readin_dir = PARAM.globalv.global_readin_dir;

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: Could you add a focused regression test for the captured settings and an injected std::ostringstream warning sink? MODULE_PW_OfDFT only compiles KEDF code, and the calculation cases do not distinguish the supplied sink from GlobalV::ofs_warning or a retained snapshot from later global reads. The existing integration coverage is useful; this additional coverage can follow after merge.

@mohanchen

Copy link
Copy Markdown
Collaborator

This PR may not be the best solution, I will close it.

@mohanchen mohanchen closed this Oct 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Refactor Refactor ABACUS codes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants