Skip to content

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

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

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

Conversation

@LiYuqiii

@LiYuqiii LiYuqiii commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

C++14 test-build correction (2026-12-04)

Directly initialize the nonmovable StoHSolverPW fixture member with braces. The former temporary-object initialization required a deleted move constructor in CI's C++14 configuration, while local GoogleTest forced C++17 and masked it through guaranteed copy elision. No production algorithm, reference, or tolerance changed.

Reproduced the old failure locally using GCC 12, official GoogleTest v1.14.0 headers, and -std=c++14 -fsyntax-only; all 9 PR-touched test source files pass the same C++14 compile check after the fix. Rebuilt and linked MODULE_PW_Sto_HSolver_UTs; this historical target has zero active tests, so this is compilation/link/startup coverage only. CPU/MPI small suites rerun: PR2 8/8 (15.15 s), PR3 8/8 (14.99 s). Production binaries are reused because only test initialization changed. Governance and diff checks passed. Commands/results are recorded in verification/pr-ci-followup-20261204/status-check/.

The separate PR2 pre-commit failure was an upstream downloader-test false positive: assertNotIn("618", stdout) matched the random localhost port 36181 despite a successful HTTP 302/200 download and checksum. No downloader or numerical checks were disabled; the new push reruns CI.

CI follow-up and latest upstream verification (2026-12-04)

Merged develop 274927085 and retained explicit input/output context while passing the new fixed-atoms/lattice arguments to MD initialization. This resolves the new driver merge conflict.

The remaining CPU/CUDA test-build failure was in test_sto_nonlocal_bounds.cpp: initializer-list std::min/max lacked a direct <algorithm> include. GCC 11 indirectly exposed the implementation through <functional>; CI GCC 13 did not. Added <algorithm> and <utility> explicitly. The previous float-template and Intel-link fixes are confirmed successful by the preceding CI runs. No numerical references or tolerances changed.

After this merge: CPU/CUDA builds passed; the formerly failing nonlocal-bound CTest passed; PR2 CPU/MPI 8/8, PR3 8/8 plus DOS-quality 4/4, GPU 1/2 MPI 2/2, PR1 output 5/5, and combined small suite 13/13 (17.92 s). OMP_NUM_THREADS=OPENBLAS_NUM_THREADS=1. GCC 12 also compiled the corrected test; GCC 13 is unavailable locally and its result still requires CI. Runtime test binaries were rebuilt after the upstream merge; PR3/combined use checked incremental object builds. Governance, changed CMake formatting, and diff whitespace checks passed.

Workspace commands: cmake --build verification/pr-upload/cmake-upstream --target abacus_pw_para MODULE_PW_STO_NONLOCAL_BOUNDS_UTs -j 8; ctest --test-dir verification/pr-upload/cmake-upstream -R '^MODULE_PW_STO_NONLOCAL_BOUNDS_UTs$' --output-on-failure; ctest --test-dir verification/pr-ci-followup-20261204/ctest-combined --output-on-failure -j 1. Individual suite logs are in verification/pr-ci-followup-20261204/ctest-merged-*.log.

Earlier CI fix and verification — 2026-12-04

The CPU/CUDA test jobs failed during compilation, before numerical tests: float instantiations passed mixed float/double arguments to std::min/max. Intel CMake and Makefile builds also failed to link spectral_bounds, because class-template explicit instantiations preceded the new member definitions. Comparisons now use a common double type, and CPU/GPU explicit instantiations follow all member definitions. Added focused float-checker and cross-translation-unit float/double spectral-bound regressions. Merged develop f61bbeb89, adapting the MD endpoint and nonlocal-projector interfaces. No numerical references, tolerances, or new global state were introduced.

Fresh local CPU and CUDA builds explicitly enable ENABLE_FLOAT_FFTW=ON. With OMP/BLAS threads fixed to 1:

  • PR2 CPU/MPI small suite: 8/8, 15.00 s; CUDA 1/2 MPI on one RTX 3090: 2/2, 5.65 s.
  • Related CTest units: 8/8, including the new float/link tests and two-rank spectral tests.
  • PR3 independent CPU/MPI suite: 8/8, 14.62 s; DOS-quality gtests: 4/4.
  • Combined three-PR CPU/MPI/output suite: 13/13, 17.73 s.

Exact workspace commands: ctest --test-dir verification/pr-ci-20261204/ctest-pr2 --output-on-failure -j 1, the corresponding ctest-gpu, ctest-pr3, and ctest-combined directories, and ctest --test-dir verification/pr-upload/cmake-upstream --output-on-failure -j 1 -R '^MODULE_PW_(Sto_Tool_UTs|Sto_Hamilt_UTs|STO_SPECTRAL_BOUNDS.*UTs|STO_NONLOCAL_BOUNDS_UTs|STO_MATH_UTs|sto_func)$'.

PR3 uses freshly rebuilt DOS objects after verifying all other production sources/headers match the fresh PR2 build; the combined build recompiles dependency-affected objects. These are incremental builds, not additional full clean builds. Governance has zero blockers and global-reference delta −17; CMake formatting and whitespace checks passed. Intel is unavailable locally, so its final result still requires remote CI. The previous Read the Docs failure was a SciPy inventory-download timeout, not a numerical failure. Ne/TS total-error-estimator redesign remains outside this PR.

Original description and earlier verification

Linked Issue

This follows PR #8382 and updates the existing DOS-quality PR. No separate issue
is needed. The local branch includes the revised #8382 commits.

What's changed?

DOS window and dimension calculations are extracted into pure helpers. Diagnostics
report insufficient polynomial order, coarse energy grids, visible negative DOS
and non-finite results. Quality checks do not clip Gaussian tails, reset a positive
spectral lower bound, or replace operator evidence by a cutoff heuristic. No new
INPUT parameter or global dependency is added. Narrowing the requested output
window does not lower the polynomial order required to resolve a fixed Gaussian.

Unit Tests and/or Case Tests for my changes

ctest --test-dir verification/pr-review-fixes/ctest-pr8383 --output-on-failure -j1:
eight CPU/MPI entries passed on the independent PR binary. In the clean combined
CMake build, MODULE_PW_STO_DOS_QUALITY_UTs passed four tests, including analytic
Gaussian tails evaluated at a common energy on different requested windows for
methods 1/2, automatic-window padding, matrix limits and diagnostics.

Governance Notes

Dependencies are passed through OutputContext and explicit numerical arguments.
The Driver adapts existing application globals once; this does not claim to remove
all historical globals from ABACUS. No new mutable process-global RNG state,
direct MPI calls, or default arguments are introduced. Header additions provide
the actual context, Psi/device, and callable types used by these interfaces; no
circular dependency is introduced. ESolver schedules owning-module operations.
No governance exception is requested.

No documentation update required beyond the updated Input_Item metadata and
checked-in test-suite README files. Generated parameter YAML/Markdown are build
artifacts and are not committed. CMake and Makefile source lists are updated.
Standalone test helpers cover file records, expected failures, and DOS curves
that Autotest scalar references cannot express; ordinary scalar checks still
use Autotest. Fixtures are immutable, use scratch directories and timeouts, and
forward MPI launcher flags.

The combined implementation passed a clean GNU/CMake CPU build and 27 scoped
CTest entries (two are existing deferred TS counterexamples; one old HSolver
target has zero active gtests and provides compile/link/startup coverage only).
GPU evidence uses a CUDA build on one device, including two MPI ranks sharing
that device. No new Intel, Makefile, ROCm, multiple-device or full MPI-off build
was run locally. GitHub CI must run on the pushed revisions. The Ne/TS total
error estimator is outside this change.

Upload verification (2026-12-03): reran the combined scope (25/25) and the independent PR suites (5/5, 8/8, 8/8), using the unchanged binary hashes recorded locally. Commands: ctest --test-dir verification/pr-review-fixes/ctest-pr8383 --output-on-failure -j1; combined selection excludes the separate LOW_TS/TS_UNDERESTIMATE counterexamples.

Latest develop synchronization (67d6746c4): resolved output-layout and unit-test
migration conflicts without changing interval/entropy algorithms. The scalar
entropy tests retain upstream coverage but compare tails against the smooth
analytic expression instead of requiring the removed |x| > 36 cutoff.
A GNU/CMake CPU build of PR 8382 and 11 scoped unit-test entries passed (the old
HSolver target still has no active gtests). The independent eight-entry PR 8383
fast suite and four DOS-quality gtests passed. PR 8383 was built incrementally
from those fresh PR 8382 objects after checking all other production sources and
headers are identical; its two changed production objects were rebuilt.
The method-1 two-rank fixture now covers out_app_flag=2; it exposed and fixed
Autotest's text-DOS collector reading the old directory. The failed case passed
again with unchanged numerical references. The new PR 8382 sKG smoke also passed
with five finite Onsager rows and a logged DOS/Chebycoef.txt.

Commands: ctest --test-dir verification/pr-upload/cmake-upstream --output-on-failure -R 'MODULE_PW_(STO_|sto_func|Sto_)|MODULE_BASE_(chebyshev_final_vector|filename)' -j1;
ctest --test-dir verification/pr-upload/ctest-upstream-8383 --output-on-failure -j1.
Changed CMake files pass cmake-format; governance against the fetched develop
reports zero blockers, with a global-reference net delta of -17. Existing
ESolver output-directory reads are passed explicitly to the lower-level routines.
The numerical/GPU measurements recorded before this upstream synchronization
remain labeled with their original code hashes; this synchronization has fresh
CPU/MPI verification and will also be checked by GitHub CI.

The three-PR combined tree with current develop additionally passed 13/13 CPU/MPI
fast and wavefunction-output entries (18.67 s). Remote Governance now passes for
all three PRs. Read the Docs currently fails because Sphinx cannot connect to
docs.scipy.org/doc/scipy/objects.inv; all four failing build logs report this
single external-inventory warning as an error. The input dumper compilation and
parameter generation succeeded. Those documentation builds still need a retry;
other CI jobs are in progress. No warning suppression or numerical change was
made to hide that infrastructure failure.

Four defects made SDFT/DOS unreliable at high electronic temperature:

* Math_Chebyshev::checkconverge() treats tmin == 0 as its "uninitialized"
  sentinel, so a positive trial Rayleigh quotient can leave Emin > 0 and exclude
  every bound state; the upper bound is underestimated in the same path.
* the DOS stage re-derived the range from the input defaults instead of keeping
  the converged SCF range, and Stochastic_WF::nchi was never initialized, so the
  range probe always used random vectors even for MDFT.
* dos_scale widened the reported window by 0.5% per side without any relation to
  the Chebyshev interval, so a grid point could sit outside the spectral range.
* the entropy density formed 1 - f by subtraction and returned 0 for |x| > 36,
  which lifted the sqrt(g) coefficient tail from ~1e-19 to ~1e-12, and
  Stochastic_Iter::dot() ignored the arrays it was given, so the printed
  Chebyshev "precision" of the stochastic trace was not the quantity it claimed.

Fixes: keep the converged SCF range in the DOS stage, initialize nchi, repair a
positive automatic lower bound and an underestimated upper bound at the call
sites (an explicitly given emin_sto is preserved, since a positive spectrum is
valid), clip the requested output window to the spectral interval instead of
widening the interval, evaluate the entropy density with s = min(f, 1-f) and
log1p(-s), and make dot() contract the arrays that the caller passes.

The range probe now also carries one independent random vector next to the real
stochastic orbitals: with `nbands_sto all` those orbitals are coordinate
vectors, so a handful of them can miss a diagonal state of another invariant
subspace. The new unit test for the entropy kernels fails on the unpatched
sto_func.cpp and passes here; dos_nche >= 2 is documented in its INPUT metadata.
Move the Chebyshev-window repair and the DOS diagnostics of the SDFT solver into
one small, global-state-free module (`module_stodft/sto_dos_quality`) and cover
it with unit tests:

* `sanitize_che_range()` repairs the window so that it covers the known
  deterministic eigenvalues and the plane-wave spectrum top (`1.05*ecutwfc`),
  replaces a pathological positive lower bound and enforces a minimum width.
  Healthy input is returned bit for bit unchanged and the function is
  idempotent.  It replaces the two inline copies of the heuristic in
  `Sto_Tool::check_che_op` and `Sto_DOS::decide_param` and takes the cutoff and
  the eigenvalues as arguments instead of reading them from the caller's
  globals.  The interval is deliberately *not* widened to fit a requested DOS
  output grid: at a fixed Chebyshev order that lowers the resolution, so the
  output window is clipped to the spectrum instead (part 2/3).

* `check_dos_parameters()` reports `dos_edelta_ev` vs `dos_sigma` mismatches and
  a `dos_nche` that cannot resolve `range/dos_sigma` (with the estimated order);
  `check_dos_result()` reports a curve that goes visibly negative or an output
  energy outside the interval.  Both only return messages: the caller logs them
  as `WARNING: DOS: ...` and never aborts a long run.

Adds `unittests/test_sto_dos_quality.cpp` (13 cases).

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

Refactor Refactor ABACUS codes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants