Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions docs/advanced/elec_properties/dfpt_convergence.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# DFPT response convergence

A converged ground state is followed by separate response calculations.
`dfpt_conv_thr` controls the outer density or screening-potential fixed-point
residual; `dfpt_max_iter` caps that response iteration. The Sternheimer
controls `dfpt_lin_conv_thr` and `dfpt_lin_max_iter` specify the inner linear
solve and should be set explicitly when diagnosing either level separately.

An atomic-displacement or ordinary electric-field response that still fails
its outer criterion at the limit terminates ABACUS with exit status 1, before
that incomplete response is cached or used for force constants, dielectric
response or LO-TO results. A response that first satisfies the criterion on
the final allowed iteration succeeds. Failed solves are not restarted as
another identical full displacement pass.

The failure diagnostic records the response stage, q index and fractional
coordinates, direction, atom for displacement responses, actual iterations,
limit, final residual and threshold. It is available in stdout and
`OUT.<suffix>/warning.log`. q indices retain the existing zero-based output
convention; the diagnostic atom index is one-based.

Every required inner solve must also satisfy its effective linear threshold.
The returned projected solution is checked against the true residual
`||P_c(b - A*dpsi)|| / ||P_c b||`. An iteration limit, invalid dimensions or
effective parameters, non-finite numerical data, or operator breakdown stops
the response before consumption. A valid homogeneous projected system may
converge in zero steps. Position responses use the same checks before the
related dielectric tensor and Born charges are computed.

The checks described here concern outer response self-consistency. They do
not establish convergence with respect to basis cutoffs or sampling. A
converged imaginary phonon frequency can describe structural instability and
is not itself a response-convergence failure.

Each production invocation establishes a new `run_id` and
`OUT.<suffix>/dfpt.status` before ground-state setup. Only `Complete` for
that invocation qualifies its product list. `Running`, `Verified` and
`Failed` do not establish completed output. The ordinary response failures
record `Failed`; an abrupt exit can leave an incomplete marker.

New dyn files are written inside a private `.dfpt-run-*` generation directory
and published to their existing `dyn.q<N>` names only after results have been
verified. The completion marker is committed last. Per-file publication is
not an atomic commit of the entire product set: an interrupted publication
may leave partial files, which must be rejected without a matching `Complete`.

When reusing a suffix, numbered dyn files with the ABACUS DFPT ownership
header are preserved in the new generation's `previous/` directory, together
with the previous status. Other files remain untouched. Unknown or symlinked
numbered dyn paths, and an earlier active/incomplete generation, are rejected;
use a fresh output suffix in those cases. Do not run concurrent calculations
in the same output directory. These records provide output validity, not
checkpoint/restart support. Input or process failures before the DFPT solver
entry still require checking the invocation's exit status; an older run_id
must never be treated as a new invocation.
1 change: 1 addition & 0 deletions docs/advanced/elec_properties/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Electronic Properties and Outputs
dos
Mulliken
potential
dfpt_convergence
wfc
charge
hs_matrix
Expand Down
1 change: 1 addition & 0 deletions source/Makefile.Objects
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,7 @@ OBJS_DFPT=dfpt_symm.o\
dfpt_q0_pos.o\
dfpt_rho.o\
dfpt_rho_mix.o\
dfpt_run_session.o\
dfpt_stern.o\
dfpt_write_dyn.o\
dfpt_xc_analytic.o
Expand Down
25 changes: 22 additions & 3 deletions source/source_esolver/esolver_dfpt_pw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ void ESolver_DFPT_PW::before_all_runners(BaseCell &basecell, const Input_para &i

ModuleBase::TITLE("ESolver_DFPT_PW", "before_all_runners");

const std::string output_directory = "OUT." + inp.suffix;
const int output_rank = ModuleBase::world_comm_domain().rank();
dfpt_session_.begin(output_directory, output_rank, &GlobalV::ofs_running);

ESolver_KS_PW<std::complex<double>, base_device::DEVICE_CPU>::before_all_runners(ucell, inp);

// capture the (possibly autoset) ground-state scalars once; inp aliases
Expand All @@ -231,6 +235,7 @@ void ESolver_DFPT_PW::before_all_runners(BaseCell &basecell, const Input_para &i
// static DFPT configuration from INPUT (explicit passing, rule 1); the
// ground-state data wiring happens in init_dfpt after the SCF converges
dfpt_ = new ModuleDFPT::DFPT_PW();
dfpt_->set_run_session(dfpt_session_);
dfpt_->set_qmesh(inp.dfpt_qmesh[0], inp.dfpt_qmesh[1], inp.dfpt_qmesh[2]);
dfpt_->set_qfile(inp.dfpt_qfile);
dfpt_->set_conv_thr(inp.dfpt_conv_thr);
Expand All @@ -256,6 +261,10 @@ void ESolver_DFPT_PW::runner(BaseCell &basecell, const int istep)
if (!gs_done_)
{
run_gs(ucell);
if (!this->conv_esolver)
{
dfpt_session_.fail("DFPT response requires a converged ground state");
}
gs_done_ = true;
}

Expand Down Expand Up @@ -287,7 +296,8 @@ void ESolver_DFPT_PW::run_gs(UnitCell &ucell)
ModuleBase::TITLE("ESolver_DFPT_PW", "run_gs");

ESolver_KS_PW<std::complex<double>, base_device::DEVICE_CPU>::runner(ucell, 0);
ModuleDFPT::validate_scf_convergence(this->conv_esolver);
// An unconverged ground state is rejected via the session-fail path in
// runner(); a direct guard here would exit before the session records it.
}

void ESolver_DFPT_PW::init_dfpt(UnitCell &ucell)
Expand Down Expand Up @@ -489,6 +499,9 @@ void ESolver_DFPT_PW::run_post_process(UnitCell &ucell)
{
return;
}
dfpt_->require_results();
dfpt_session_.verify();

// multi-q frequency report (one block per q of the list, plus the LO-TO
// corrected Gamma block along the data-layer direction when enabled);
// the tensor blocks below stay design-phase std::cout until the io
Expand Down Expand Up @@ -542,9 +555,15 @@ void ESolver_DFPT_PW::run_post_process(UnitCell &ucell)
// is offset by the two global-record domag reads removed above).
if (this->inp_->dfpt_out_dyn)
{
const std::string out_dir = "OUT." + this->inp_->suffix + "/";
ModuleDFPT::DFPT_Write_Dyn(ucell, dfpt_->get_data(), nq, out_dir, dfpt_->get_myrank(), &GlobalV::ofs_running);
const std::string out_dir = dfpt_session_.staging_directory();
const bool written = ModuleDFPT::DFPT_Write_Dyn(
ucell, dfpt_->get_data(), nq, out_dir, dfpt_->get_myrank(), dfpt_session_.running_log());
if (!written)
{
dfpt_session_.fail("DFPT dynamical-matrix staging failed");
}
}
dfpt_session_.commit(nq, this->inp_->dfpt_out_dyn);
}

} // namespace ModuleESolver
3 changes: 3 additions & 0 deletions source/source_esolver/esolver_dfpt_pw.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "esolver_ks_pw.h"
#include "source_pw/module_dfpt/dfpt_pw.h"
#include "source_pw/module_dfpt/dfpt_run_session.h"

namespace ModuleDFPT
{
Expand All @@ -33,6 +34,8 @@ class ESolver_DFPT_PW : public ESolver_KS_PW<std::complex<double>, base_device::
protected:
ModuleDFPT::DFPT_PW *dfpt_ = nullptr;

ModuleDFPT::DFPT_RunSession dfpt_session_;

///< first-order XC kernel adapter over elecstate::PotXC_FDM (C7),
///< owned here so module_dfpt stays free of pot_xc_fdm.h dependencies
ModuleDFPT::XC_First_Order *xc_adapter_ = nullptr;
Expand Down
54 changes: 23 additions & 31 deletions source/source_io/module_parameter/read_inp_dfpt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ void ReadInput::item_dfpt()
"(potential mixing is permitted).";
item.default_value = "1.0e-8";
read_sync_double(input.dfpt_conv_thr);
item.description += " An unconverged displacement or electric-field response stops "
"the calculation before its results are cached or assembled.";
item.check_value = [](const Input_Item &item, const Parameter &para)
{
if (para.input.dfpt_conv_thr <= 0.0)
Expand All @@ -183,32 +185,26 @@ void ReadInput::item_dfpt()
"joint history and one limit.";
item.default_value = "100";
read_sync_int(input.dfpt_max_iter);
item.description += " The same cap applies to each ordinary electric-field direction. "
"An unconverged response stops with a nonzero exit status; "
"convergence on the final allowed iteration is successful.";
this->add_item(item);
}
{
Input_Item item("dfpt_lin_conv_thr");
item.annotation = "convergence threshold of the inner Sternheimer linear solve";
item.category = category;
item.type = "Real";
item.description = "Dedicated convergence threshold of the projected CG solve of the "
"Sternheimer equation inside every DFPT response iteration, as the "
"relative residual ||P_c r|| / ||P_c b|| of the projected system "
"(r: CG residual, b: projected right-hand side, P_c: complement of "
"the occupied subspace at k+q). Non-positive values (the default) "
"inherit dfpt_conv_thr, which reproduces the historical "
"single-knob behavior. Accuracy tradeoff of truncating the inner "
"solve: the outer mixing residual does NOT check the achieved "
"Sternheimer residual, so a loose inner threshold or a small "
"dfpt_lin_max_iter can shift converged observables; the same "
"controls also affect the one-shot Gamma position response (the "
"bare q = 0 operator legs inherit them as well). When the knobs "
"are tightened for a hard response, validate the phonons, "
"dielectric tensor and Born charges against tighter inner "
"settings to quantify the truncation error. Decouple them when a "
"flat semicore band system needs a loose inner solve to keep the "
"outer mixing stable: the shifted operator is then near-singular "
"and a very deep inner solve amplifies the response beyond what "
"the outer mixing can damp.";
item.description = "Required relative residual threshold of the projected Sternheimer "
"linear solve, ||P_c(b-A*dpsi)|| / ||P_c b||, checked on the final "
"projected solution. Finite non-positive values (the default) "
"inherit dfpt_conv_thr. Every required displacement, electric-field "
"and Gamma position response must satisfy its effective threshold; "
"an unsuccessful inner solve terminates before its response is "
"consumed, even if the outer density or potential changes little. "
"Convergence of observables with respect to this threshold remains "
"a separate accuracy check. No automatic threshold relaxation or "
"retry is performed.";
item.default_value = "-1.0 (inherit dfpt_conv_thr)";
read_sync_double(input.dfpt_lin_conv_thr);
this->add_item(item);
Expand All @@ -218,18 +214,14 @@ void ReadInput::item_dfpt()
item.annotation = "iteration cap of the inner Sternheimer linear solve";
item.category = category;
item.type = "Integer";
item.description = "Dedicated iteration cap of the projected CG solve of the "
"Sternheimer equation inside every DFPT response iteration. "
"Non-positive values (the default) inherit dfpt_max_iter, which "
"reproduces the historical single-knob behavior. Lower it to "
"truncate the CG before it drives into near-singular directions of "
"a flat-band system; raise it for otherwise unconverged inner "
"solves without enlarging the outer mixing budget. The cap has the "
"same accuracy tradeoff as dfpt_lin_conv_thr: the outer mixing "
"residual does not check the achieved Sternheimer residual, the "
"one-shot Gamma position response shares the cap, and truncated "
"inner solves should be validated against tighter settings on the "
"phonons, dielectric tensor and Born charges.";
item.description = "Iteration budget of each projected Sternheimer linear solve, "
"including the Gamma position response. Non-positive values (the "
"default) inherit dfpt_max_iter. A required inner solve that does "
"not satisfy dfpt_lin_conv_thr within this budget terminates with "
"a nonzero exit status before response consumption. Success on "
"the final allowed iteration is valid; the iteration count alone "
"does not determine failure. This budget is distinct from outer "
"response iterations and is not multiplied by implicit retries.";
item.default_value = "0 (inherit dfpt_max_iter)";
read_sync_int(input.dfpt_lin_max_iter);
this->add_item(item);
Expand Down
3 changes: 3 additions & 0 deletions source/source_pw/module_dfpt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ set(SOURCES
dfpt_pert.cpp
dfpt_pert_vkb.cpp
dfpt_pert_nl.cpp
dfpt_run_session.cpp
dfpt_stern.cpp
dfpt_symm.cpp
dfpt_validation.cpp
Expand All @@ -34,6 +35,8 @@ set(HEADERS
dfpt_pw_data.h
dfpt_kq_basis.h
dfpt_pert.h
dfpt_convergence.h
dfpt_run_session.h
dfpt_stern.h
dfpt_nscf.h
dfpt_rho.h
Expand Down
24 changes: 24 additions & 0 deletions source/source_pw/module_dfpt/dfpt_convergence.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#ifndef DFPT_CONVERGENCE_H
#define DFPT_CONVERGENCE_H

#include <cmath>
#include <limits>

namespace ModuleDFPT
{
/// Relative fixed-point defect; absent or invalid norms never mean success.
inline double response_relative_residual(double defect_squared, double output_squared)
{
if (!std::isfinite(defect_squared) || !std::isfinite(output_squared) || defect_squared < 0.0 ||
output_squared < 0.0)
{
return std::numeric_limits<double>::infinity();
}
if (output_squared == 0.0)
{
return defect_squared == 0.0 ? 0.0 : std::numeric_limits<double>::infinity();
}
return std::sqrt(defect_squared / output_squared);
}
} // namespace ModuleDFPT
#endif
Loading
Loading