Skip to content

Commit ee03f01

Browse files
Fix(input): reject esolver_type=lr with a self-consistent calculation (#7779)
esolver_type=lr reads the ground state wave function from a separate SCF run, so it cannot be combined with calculation=scf. Previously the reset hook silently rewrote calculation to nscf, hiding an invalid user input. Remove the reset hook and reject the contradictory combination in check_value with an explicit diagnostic that states the required value. Co-authored-by: Stardust0831 <169599847+Stardust0831@users.noreply.github.com> Co-authored-by: Mohan Chen <mohanchen@pku.edu.cn>
1 parent d923b08 commit ee03f01

3 files changed

Lines changed: 30 additions & 7 deletions

File tree

source/source_io/module_parameter/read_input_item_system.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,15 @@ void ReadInput::item_system()
168168
ModuleBase::WARNING_QUIT("ReadInput", "Can not find `pot_file` !");
169169
}
170170
}
171-
};
172-
item.reset_value = [](const Input_Item& item, Parameter& para) {
171+
// LR reads the ground state wave function from a separate SCF run,
172+
// so it cannot be combined with a self-consistent calculation.
173173
if (para.input.esolver_type == "lr" && para.input.calculation == "scf")
174-
{ // for LR-only calculation based on the ground-state, set calculation to "nscf"
175-
para.input.calculation = "nscf";
174+
{
175+
ModuleBase::WARNING_QUIT("ReadInput",
176+
"esolver_type=lr requires calculation=nscf (it reads the ground state "
177+
"wave function computed by a separate SCF run); please set calculation=nscf.");
176178
}
177-
};
179+
};
178180
this->add_item(item);
179181
}
180182
{

source/source_io/test_serial/read_input_item_test.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,10 @@ TEST_F(InputTest, Item_test)
132132
param.input.esolver_type = "lr";
133133
param.input.calculation = "scf";
134134
it = find_label("esolver_type", readinput.input_lists);
135-
it->second.reset_value(it->second, param);
136-
EXPECT_EQ(param.input.calculation, "nscf");
135+
testing::internal::CaptureStdout();
136+
EXPECT_EXIT(it->second.check_value(it->second, param), ::testing::ExitedWithCode(1), "");
137+
output = testing::internal::GetCapturedStdout();
138+
EXPECT_THAT(output, testing::HasSubstr("esolver_type=lr requires calculation=nscf"));
137139
}
138140
{ // nspin
139141
auto it = find_label("nspin", readinput.input_lists);

source/source_io/test_serial/read_input_test.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,25 @@ TEST_F(InputTest, ValidateBandParallelization)
306306
"bndpar can not exceed the number of MPI processes");
307307
}
308308

309+
TEST_F(InputTest, ValidateLrRequiresNscf)
310+
{
311+
// esolver_type=lr reads the ground state wave function from a separate SCF run,
312+
// so it cannot be combined with a self-consistent calculation.
313+
expect_invalid_input("lr_scf_INPUT",
314+
"esolver_type lr\n",
315+
"esolver_type=lr requires calculation=nscf");
316+
expect_invalid_input("lr_explicit_scf_INPUT",
317+
"esolver_type lr\ncalculation scf\n",
318+
"esolver_type=lr requires calculation=nscf");
319+
320+
Parameter valid_param;
321+
EXPECT_NO_THROW(read_parameters("lr_nscf_INPUT",
322+
"esolver_type lr\ncalculation nscf\n",
323+
valid_param));
324+
EXPECT_EQ(valid_param.inp.esolver_type, "lr");
325+
EXPECT_EQ(valid_param.inp.calculation, "nscf");
326+
}
327+
309328
TEST_F(InputTest, ValidateDeepksOutputFrequency)
310329
{
311330
Parameter default_param;

0 commit comments

Comments
 (0)