Skip to content

SDFT DOS: pure-function window guard, runtime quality warnings, unit tests - #8383

Draft
LiYuqiii wants to merge 4 commits into
deepmodeling:developfrom
LiYuqiii:sdft-dos-quality
Draft

LiYuqiii wants to merge 4 commits into
deepmodeling:developfrom
LiYuqiii:sdft-dos-quality

Conversation

@LiYuqiii

@LiYuqiii LiYuqiii commented Nov 24, 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.
  • I have requested any needed governance exception below.

Linked Issue

Addresses #8379 (part 3/3). Depends on #8382 (this branch currently contains part 2 as well; after
#8382 is merged the diff of this PR reduces to the 4 files listed below).

Unit Tests and/or Case Tests for my changes

  • Commands run:
    • ctest -R MODULE_PW_STO --output-on-failure (two targets, 18 TEST cases:
      test_sto_func.cpp and the new test_sto_dos_quality.cpp with 14 cases)
    • tests/06_SDFT through tests/integrate/Autotest.sh (24 cases, 116 checks)
    • mpirun -np 4 abacus on the 1-atom 348 eV DOS case of SDFT: DOS values of 1e52 at high electronic temperature #8379 with healthy and with deliberately
      bad DOS parameters
    • cmake --build --target abacus_pw_para on top of the current develop
  • Result summary:
    • ctest -R MODULE_PW_STO: 2/2 targets, 18/18 cases pass
    • tests/06_SDFT: 116/116 checks pass; the two existing DOS cases emit no new warnings
    • healthy 348 eV case: no warning, unchanged numbers; bad parameters
      (dos_sigma 0.05 eV, dos_edelta_ev 5, dos_nche 50): 4 warnings, the run still completes
  • Checks not run, with reason: no new case test is added under tests/; the two behaviour groups are
    pure functions covered by the new unit test, and the end-to-end effect is covered by
    tests/06_SDFT.

What's changed?

New module ModuleIO::sto_dos_quality with pure (global-state free, unit-tested) helpers:

  • sanitize_che_range() repairs the Chebyshev window so that it covers the known deterministic
    eigenvalues, the plane-wave spectrum top (1.05*ecutwfc) and the requested DOS output grid
    (|t| <= 1 by construction). Healthy input is returned bit for bit unchanged and the function is
    idempotent. It replaces two copies of an inline heuristic (Sto_Tool::check_che_op,
    Sto_DOS::decide_param) and takes ecutwfc, the eigenvalues and the output window as arguments
    instead of reading PARAM.
  • check_dos_parameters() / check_dos_result() emit warnings only (never abort):
    dos_edelta_ev vs dos_sigma mismatch, dos_nche insufficient for range/sigma (with the
    estimated order), prohibitive range/sigma, DOS integral not reproducing the number of states,
    visibly negative DOS, and an output energy that left the Chebyshev interval. The integral check is
    skipped when the window truncates the spectrum on purpose and for spin-polarized runs.

Files: new module_stodft/sto_dos_quality.{h,cpp} and module_stodft/unittests/test_sto_dos_quality.cpp,
plus the wiring in sto_dos.{h,cpp}, sto_tool.cpp, module_stodft/CMakeLists.txt and
module_stodft/unittests/CMakeLists.txt.

Governance Notes

  • INPUT/docs changes: no new keyword and no default change; the new messages are runtime warnings.
    There is no documentation update required for this change.
  • Core module impact: module_stodft only. The new module is dependency-free (no PARAM, no
    GlobalV), which is also what makes it unit-testable.
  • Exceptions requested: Global dependency budget (+3 references on top of SDFT: fix the high-temperature DOS blow-up and the Ne/TS precision asymmetry #8382, in the reporting
    path), see below.

Governance Exception

  • Rule: Global dependency budget
  • Reason: the diagnostics are written through GlobalV::ofs_running, the channel the SDFT stage
    already uses. The guarded calls run once per DOS calculation.
  • Scope: source/source_pw/module_stodft/sto_dos.cpp only; sto_dos_quality.* adds no global
    reference.
  • User or maintenance risk: low. Warnings only, no control flow change; all checks are no-ops for
    healthy parameter sets.
  • Why the normal rule cannot be followed now: same interface argument as part 2/3 - no output stream
    is passed into module_stodft.
  • Follow-up cleanup plan: same as parts 1-2 (pass an output stream / logging context from the
    esolver).
  • Requested approver: ABACUS maintainer

…ymmetry

Four defects made SDFT/DOS unusable at high temperature:

* checkconverge() uses tmin == 0 as its "uninitialized" sentinel, so a positive
  trial Rayleigh quotient leaves Emin > 0 and excludes every bound state; the
  upper bound is underestimated in the same path.
* the DOS stage re-derived the range from (0, 0) instead of inheriting the
  converged SCF range, and Stochastic_WF::nchi was never initialized, so the
  range probe always used random vectors.
* dos_scale widened the reported window by 0.5% per side without widening the
  Chebyshev interval, so T_n(|x| > 1) grew exponentially: DOS values of
  1e26--1e64 instead of the 2*N_pw integral.
* the entropy density computed 1 - f by subtraction, and returned 0 for
  |x| > 36: the sqrt(g) coefficient tail was lifted from ~1e-19 to ~1e-12,
  which made E_entropy(-TS) two orders of magnitude too large while Ne stayed
  exact. Stochastic_Iter::dot() also ignored its arguments, so the reported
  precision was meaningless.

Fixes: repair the range at the call sites, inherit the SCF range in the DOS
stage, initialize nchi, expand the Chebyshev interval to contain the output
grid, evaluate the entropy density with s = min(f, 1-f) and log1p(-s), and make
dot() use the passed arrays. Adds a unit test for the entropy kernels.
…tests

Add ModuleIO::sto_dos_quality with two groups of pure (global-state free,
unit-tested) helpers:

* sanitize_che_range(): repairs the Chebyshev window so that it covers the known
  deterministic eigenvalues, the plane-wave spectrum top (1.05*ecutwfc) and the
  requested DOS output grid. Healthy input is returned bit for bit unchanged.
  Used by both the SCF range check (Sto_Tool::check_che_op) and the DOS stage
  (Sto_DOS::decide_param), replacing two copies of an inline heuristic that read
  PARAM directly.

* check_dos_parameters() / check_dos_result(): warn (never abort) when
  dos_edelta_ev and dos_sigma are mismatched, dos_nche cannot resolve
  range/sigma (reporting the estimated order), the range/sigma ratio is
  prohibitive, the DOS integral does not reproduce 2*sum_k npwk, the curve goes
  visibly negative, or an output energy left the Chebyshev interval. The
  integral check is skipped when the window truncates the spectrum on purpose.

Adds unittests/test_sto_dos_quality.cpp (14 cases).
Sto_Tool::check_che_op() now calls ModuleIO::sanitize_che_range(), so the
pre-existing MODULE_PW_Sto_Tool_UTs target (which compiles ../sto_tool.cpp)
needs ../sto_dos_quality.cpp as well; otherwise the target fails to link in
the BUILD_TESTING configuration.
The Makefile-based build (source/Makefile.Objects) lists its objects explicitly,
so the new quality-guard translation unit has to be registered there too;
otherwise `make -f ../Makefile` fails with an undefined reference to
ModuleIO::sanitize_che_range().

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant