Repository navigation
fix(dfpt): enforce response convergence before publishing results - #8514
Zanthoxylum wants to merge 9 commits into
Conversation
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.
…pw-guarded rotation)
…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.
| dos | ||
| Mulliken | ||
| potential | ||
| dfpt_convergence |
There was a problem hiding this comment.
the phrase 'dfpt_convergence' is not at the same level compared to other phrases like "dos" "potential"
| dfpt_session_.fail("DFPT dynamical-matrix staging failed"); | ||
| } | ||
| } | ||
| dfpt_session_.commit(nq, this->inp_->dfpt_out_dyn); |
There was a problem hiding this comment.
be careful, the file may be too large, maybe you can consider moving some details to the dfpt module
| protected: | ||
| ModuleDFPT::DFPT_PW *dfpt_ = nullptr; | ||
|
|
||
| ModuleDFPT::DFPT_RunSession dfpt_session_; |
There was a problem hiding this comment.
some notes need here for dfpt_session_
| namespace ModuleDFPT | ||
| { | ||
| /// Relative fixed-point defect; absent or invalid norms never mean success. | ||
| inline double response_relative_residual(double defect_squared, double output_squared) |
There was a problem hiding this comment.
I think some notes are needed here to explain the function
|
|
||
| void run(); | ||
| void set_run_session(DFPT_RunSession &session); | ||
| void require_results() const; |
There was a problem hiding this comment.
the name 'require_results' is very confusing,
| << "residual target within " << lin_max << " outer iterations (last pass " << it | ||
| << "); raise dfpt_conv_thr precision handling or inspect the spectrum"; | ||
| ModuleBase::WARNING_QUIT("DFPT_PW::build_occ_kq", oss.str()); | ||
| fail_response("DFPT_PW::build_occ_kq", oss.str()); |
|
|
||
| namespace ModuleDFPT | ||
| { | ||
| /// One production invocation owns its output generation. An incomplete or |
There was a problem hiding this comment.
I think background need to be introduced here, let readers know the functions and classes
There was a problem hiding this comment.
the file is not allowed in this directory, try not adding any new functions/scripts in the tests/integrate directory
Six of the eight review comments on deepmodeling#8514: 1. index.rst: move dfpt_convergence out of the atomic property list into its own DFPT toctree group (comment on toctree ordering). 2. esolver_dfpt_pw.h: add the lifecycle doc comment on dfpt_session_ (output-generation state machine; comment on missing member note). 3. dfpt_convergence.h: add the file-level and function-level doc on response_relative_residual and its convergence contract (comment on missing function explanation). 4. dfpt_pw.h/cpp: rename require_results to verify_response_qualification with a doc comment describing the convergence/spectrum/finiteness gates (comment on confusing name). 5. dfpt_pw_impl.h: add the bridge doc comment on fail_response (session state recording + WARNING_QUIT; comment on what it is). 6. dfpt_run_session.h: add the class-level background paragraph covering the begin/verify/fail/commit lifecycle and the no-stale-Complete guarantee (comment on missing background). The remaining two comments (deepmodeling#2 file size, deepmodeling#8 tests/integrate layout) are scope-level decisions: they are acknowledged in the PR reply rather than rushed into this round. 26/26 ctest entries pass; the dfpt_si_g anchor is unchanged.
Move the three ground-state extraction blocks from
ESolver_DFPT_PW::init_dfpt into a new module_dfpt translation
unit (dfpt_gs_extract.{h,cpp}):
- extract_veff_smooth: smooth-grid potential to contiguous vector
- validate_xc_functional: LDA/GGA-only functional guard
- build_xc_first_order: first-order XC kernel construction (libxc
analytic or FDM fallback, including the valence+core linearization
point and the libxc parameter/weight forwarding)
- build_nlcc_vxc: ground-state XC potential for the nlcc diagonal
term (valence+core density, same linearization point)
The removed VKB debug probes (VKBCHK/VKBEL console output) were
development leftovers and are not carried over. The ESolver method
shrinks from 191 to ~40 lines; the file from 569 to 422 lines
(-26%). The ESolver layer now only validates ground-state readiness,
extracts dependencies from its members, and forwards them through
the DFPT_PW_InitContext.
Registration: Makefile.Objects + module_dfpt/CMakeLists.txt.
26/26 ctest entries pass and the dfpt_si_g anchor is unchanged.
Addresses review comment on file size (comment deepmodeling#2 on deepmodeling#8514).
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
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.
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.
matrices, spectra and requested polar products before publication. Retain
working caches needed by the iteration.
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.
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.
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_'printed Gamma frequencies and the dfpt_si_g anchor are unchanged. Three
distinct converged controls retain byte-identical full dyn files.
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.
GS failures: new Failed identity, preserved prior dyn bytes, no current dyn,
unchanged unrelated files. Foreign-file protection also passes.
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.
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.
--check-inputpassed. DFPT/CMake formatting andgovernance 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.