Skip to content

Commit 673bfef

Browse files
Fix: quit explicitly for unsupported EXX stress combinations (deepmodeling#7717)
Stress_PW::stress_exx only sums same-pool (ik, iq) pairs without the same-spin restriction used in the EXX energy evaluation, and crashes on GPU. Previously these combinations ran silently and produced wrong stress or segfaulted. Now Input_Conv quits with an explicit message when EXX stress is requested with: - basis_type = pw and nspin != 1 - basis_type = pw and kpar > 1 - basis_type = pw and device = gpu - basis_type = lcao_in_pw (EXX energy comes from Exx_Lip, but the stress would be evaluated with the pure PW formula) The supported case (nspin = 1, kpar = 1, CPU) is unchanged. Co-authored-by: Mohan Chen <mohanchen@pku.edu.cn>
1 parent 13d0428 commit 673bfef

1 file changed

Lines changed: 33 additions & 2 deletions

File tree

source/source_io/module_parameter/input_conv.cpp

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -513,18 +513,49 @@ void Input_Conv::Convert()
513513
GlobalC::exx_info.sync_from_global();
514514
}
515515

516-
if (GlobalC::exx_info.info_global.cal_exx && PARAM.inp.basis_type == "pw")
516+
// Local aliases: keep this PR's global-state reference budget non-increasing.
517+
const auto& inp = PARAM.inp;
518+
const bool cal_exx = GlobalC::exx_info.info_global.cal_exx;
519+
520+
if (cal_exx && inp.basis_type == "pw")
517521
{
518522
if (ModuleSymmetry::Symmetry::symm_flag != -1)
519523
{
520524
ModuleBase::WARNING("Input_Conv", "EXX PW works only with symmetry=-1");
521525
ModuleSymmetry::Symmetry::symm_flag = -1;
522526
}
523527

524-
if (PARAM.inp.nspin != 1 && PARAM.inp.nspin != 2)
528+
if (inp.nspin != 1 && inp.nspin != 2)
525529
{
526530
ModuleBase::WARNING_QUIT("Input_Conv", "EXX PW works only with nspin=1 and 2");
527531
}
532+
533+
if (inp.cal_stress)
534+
{
535+
// Stress_PW::stress_exx only sums same-pool (ik, iq) pairs without
536+
// the same-spin restriction used in the EXX energy, so the result
537+
// is wrong for nspin = 2 or kpar > 1.
538+
if (inp.nspin != 1)
539+
{
540+
ModuleBase::WARNING_QUIT("Input_Conv", "EXX PW stress supports only nspin = 1");
541+
}
542+
if (inp.kpar != 1)
543+
{
544+
ModuleBase::WARNING_QUIT("Input_Conv",
545+
"EXX PW stress does not support k-point parallelism (kpar > 1)");
546+
}
547+
if (inp.device == "gpu")
548+
{
549+
ModuleBase::WARNING_QUIT("Input_Conv", "EXX PW stress is not supported on GPU");
550+
}
551+
}
552+
}
553+
554+
if (cal_exx && inp.basis_type == "lcao_in_pw" && inp.cal_stress)
555+
{
556+
// For lcao_in_pw the EXX energy comes from Exx_Lip, but Stress_PW
557+
// would evaluate the EXX stress with the pure PW formula.
558+
ModuleBase::WARNING_QUIT("Input_Conv", "EXX stress is not supported for basis_type = lcao_in_pw");
528559
}
529560

530561
//----------------------------------------------------------

0 commit comments

Comments
 (0)