Skip to content

fix(dfpt): enforce response convergence before publishing results - #8514

Open
Zanthoxylum wants to merge 5 commits into
deepmodeling:developfrom
Zanthoxylum:fix-dfpt-response-nonconvergence
Open

Zanthoxylum wants to merge 5 commits into
deepmodeling:developfrom
Zanthoxylum:fix-dfpt-response-nonconvergence

Conversation

@Zanthoxylum

Copy link
Copy Markdown
Collaborator

Summary

An outer DFPT mixing criterion could be satisfied while required inner linear
solves were still unconverged. Ordinary outer failures could also populate
response caches, assemble phonons and exit successfully. Reusing an output
suffix could leave old dyn files looking like results of the latest run.

Require valid ground-state and response results before formal consumption,
and commit an output generation only after its products have been published.

Changes

  • Add explicit projected-CG results for convergence, iteration limit, invalid
    input, non-finite data and breakdown. Verify the true residual of the final
    projected solution. Preserve legitimate zero-step homogeneous solves and
    success on the final allowed iteration; reject squared-norm underflow as
    evidence of a zero RHS.
  • Check required displacement, position and electric-field solves before
    consuming their responses. Missing required legs/projectors cannot be
    silently skipped, and the legacy solver adapter cannot lose a failed
    status. Ordinary outer failures exit 1 before final response storage and
    cannot return to identical repeated full displacement passes.
  • Check response qualification before assembly and verify complete finite raw
    matrices, spectra and requested polar products before publication. Retain
    working caches needed by the iteration.
  • Start a unique run identity and status before ground-state setup. Preserve
    owned previous dyn files and status under a private generation directory;
    reject unknown or symlinked numbered dyn paths without altering them.
    Stage new dyn files, propagate writer errors, publish without overwriting
    foreign destination files, and commit the current Complete manifest last.
    Per-file publication is not an atomic transaction of the whole file set;
    incomplete generations must be rejected.
  • Route the ground-state convergence rejection through the session-fail
    path instead of a direct validator call: the session records the Failed
    state and exits 1, so a failed ground state is observable in the run
    status rather than terminating before the bookkeeping runs.
  • Update INPUT help and the convergence guide. Finite non-positive linear
    thresholds keep their inheritance behavior. Successful dyn format and
    filenames remain compatible.

Verification

Used the existing GCC13/OpenMPI toolchain with one OpenMP/OpenBLAS thread for
runtime checks. Rebuilt the executable and all twelve DFPT test targets:

cmake --build build-gcc13 --target abacus_basic_para \
  MODULE_DFPT_pert_serial MODULE_DFPT_rho_serial MODULE_DFPT_phon_serial \
  MODULE_DFPT_q0_serial MODULE_DFPT_write_dyn_serial MODULE_DFPT_xc_analytic_serial \
  MODULE_DFPT_pw_data_test MODULE_DFPT_kq_basis_test MODULE_DFPT_stern_test \
  MODULE_DFPT_pw_run_test MODULE_DFPT_symm_serial MODULE_DFPT_session_serial -j6
ctest --test-dir build-gcc13 --output-on-failure \
  -R 'MODULE_DFPT|dfpt_freq_collector|dfpt_failure_|dfpt_session_'
  • 25/25 CTest entries (module, session and failure fixtures) pass; the six
    printed Gamma frequencies and the dfpt_si_g anchor are unchanged. Three
    distinct converged controls retain byte-identical full dyn files.
  • Seven real-process failures cover ordinary outer and inner response limits.
    Each checks the expected task, converged GS, precise exit 1 and absence of
    fresh formal products. Three one-step inner cases that previously exited 0
    and wrote dyn files are rejected at the first failed linear solve.
  • Actual success-then-failure runs in the same suffix cover outer, inner and
    GS failures: new Failed identity, preserved prior dyn bytes, no current dyn,
    unchanged unrelated files. Foreign-file protection also passes.
  • Nine session unit tests cover ownership, symlinks, lifecycle, partial
    publication, interruption and foreign destination collisions. Analytic
    linear tests cover final-step/zero-step success, budget exhaustion, invalid
    dimensions/parameters, non-finite data, breakdown, adapter propagation and
    norm underflow. Audit helpers reject stale identities and mismatched products.
  • An integration tree that additionally carries the pending symmetry
    branches (finite-q response support, antiunitary reduction and q-star
    reconstruction) passes 27 CTest entries, 48 symmetry tests and 13 Autotest
    calculations / 203 checked attributes; all 20 dyn files match their
    reference byte for byte. Joint failures and an actual representative-q
    failure also stop publication: Gamma completes before representative q Merge recent abacus changes to deepmodeling #1
    fails, and target q Merge recent changes on master #2 is blocked. The adaptations those branches require
    are not part of this branch.
  • Version, INPUT help and --check-input passed. DFPT/CMake formatting and
    governance checks passed without ERROR. Outside DFPT, only changed code
    snippets were formatted. Header dependencies serve actual types and finite
    checks; the running-log dependency moves from writer to session startup,
    with zero net growth in global references.

Integration test driver rationale

Autotest cannot express expected nonzero exits or a success-then-failure
sequence with historical-byte and identity checks. Dedicated drivers use fixed
fixtures copied unchanged into temporary directories and stage their named
pseudopotentials. Crashes, unrelated exits or wrong failure stages cannot pass.
Python discovery is optional; normal successful regressions remain Autotest
cases.

Scope

This covers correctness and output validity for the current single-rank PW
DFPT path. Retry policies, warm starts and persistent restart remain separate
work. A completion must match the current invocation's run identity and exit
status; older files or an older Complete marker are insufficient. Concurrent
calculations in one output directory are unsupported. No new QE comparison,
material convergence study or multi-rank validation is claimed.

Summary
Stop ordinary displacement and electric-field outer solves with WARNING_QUIT
when their response budget is exhausted. Report the failed task, physical q,
iteration budget and residual before any completed-response cache is populated.

Design
Use the existing fatal exit path. A failing producer can no longer return to
the legacy driver's identical repeated passes. Successful solves keep the
same arithmetic and output. Inner-solver reports and stale-output ownership
remain separate follow-ups.

Verification
Rebuilt the main executable and all eleven DFPT unit-test targets. The four
new real-process negative cases reject the old executable (exit 0 with a dyn
file) and accept the candidate (exit 1 without formal output). A three-step
budget stops after three traces rather than the old 54. Three successful
controls retain byte-identical dyn files; all six default Gamma frequencies
are unchanged. INPUT help and --check-input pass.

Tests
CTest: 17/17; default Gamma Autotest: 8/8 attributes; governance: no findings.
The finite-q fixture uses an explicit one-point Direct list to retain the
ordinary solve path when the uniform-mesh planner is present; the physical
k point and weight are unchanged. All four process checks were rerun on the
preserved independent binary after this fixture refinement.

DFPT C++ and CMake formatting pass. Only new description statements outside
DFPT were formatted. Expected nonzero exits cannot be expressed by Autotest,
so focused process drivers check the exit, converged GS, exact failed task,
finite residual, iteration count and absence of fresh formal output.
Summary
Return explicit projected linear-solve status and verify the true residual of
the returned solution. Distinguish homogeneous zero-step success from invalid
sizes, non-finite values, iteration limits, breakdown and norm underflow.

Design
Every required displacement, position and electric-field solve is checked
before response consumption. The legacy adapter also rejects failures instead
of losing status. Missing response legs/projectors cannot be silently skipped.
Keep nonpositive finite threshold inheritance; non-finite settings remain
invalid. Missing mixing residuals cannot imply convergence. No retry is added.

Verification
Rebuilt main and all eleven DFPT unit targets. CTest 20/20, default Gamma
Autotest 8/8, all six exact anchor strings unchanged. Three independent
successful control dyn files remain byte-identical to the C1 archive. Seven
real failure cases stop at their expected inner/outer stage without formal
products. CLI help and --check-input pass. DFPT/CMake formatting passes; only
changed INPUT description snippets outside DFPT were formatted.

Tests
Analytic final-step success, zero projected RHS, insufficient budget, malformed
dimensions/parameters, nonfinite data, negative curvature, adapter propagation
and norm underflow. Governance has no ERROR; four standard-header warnings
are required by the public string API and inline finite/norm checks.
Summary
Begin a unique DFPT output generation before ground-state setup. Reject
unconverged GS and unverified response/matrix/tensor consumers. Record ordinary
response failures, preserve owned previous dyn files and publish staged files
before committing a matching Complete manifest.

Design
A Failed/Running/Verified generation is not complete. Preserve old owned
products and previous status under a private generation directory. Reject
unknown or symlinked numbered dyn paths; leave unrelated files intact. Check
dyn writer success and publish without overwriting new foreign files. A
partial publication never commits Complete. The session is not a checkpoint.
The running-log dependency moves from the writer to session initialization;
new GlobalV references are offset by removed references (net zero).

Verification
Main executable and all twelve DFPT unit targets rebuilt. CTest 26/26; default
Gamma Autotest 8/8 and all six exact frequencies unchanged. Three converged
control dyn files remain byte-identical to C2. Seven inner/outer failure cases
and real success-then-outer/inner/GS-failure runs pass, preserving old output
bytes and unrelated files. Foreign-file protection passes. All seven frozen
branch combinations merge without textual conflict.

Tests
Nine session unit tests cover lifecycle, legacy ownership, symlinks, partial
publication, interrupted generations and foreign destination collisions; the
dyn writer reports missing matrices. Manifest auditing rejects stale identities
and incomplete/mismatched product sets. DFPT/CMake and only new outside-DFPT
snippets are format-clean. Governance has no ERROR; header dependencies serve
actual session ownership and public types. No retry or warm start is added.
…ession

Merging develop brought the direct validate_scf_convergence call into
run_gs; it WARNING_QUITs before runner()'s session-fail bookkeeping
runs, leaving the session state stale at 'Running' when the ground
state fails (the ground_state failure fixture catches this after the
sync). The session-fail path performs the same rejection with state
recording and exit code 1, so the direct call is removed and the guard
deliberately routes through the session. The validator itself and its
unit test are unchanged.

25/25 ctest targets (module + session + failure fixtures) and the
dfpt_si_g anchor frequencies are unchanged after the fix.
@Zanthoxylum Zanthoxylum added Refactor Refactor ABACUS codes DFPT Density Functional Perturbation Theory labels Dec 4, 2026

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

DFPT Density Functional Perturbation Theory Refactor Refactor ABACUS codes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant