fix_setup_etot - #7489
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors the setup_etot helpers in the lattice and ion relaxation modules by simplifying their APIs and standardizing how current/previous total energies are tracked, then updates call sites and unit tests accordingly.
Changes:
- Simplified
Lattice_Change_Basic::setup_etotandIons_Move_Basic::setup_etotsignatures (removedjudgementand stream parameters) and aligned implementations to a consistent “previous = last current” update rule. - Updated relaxation drivers (CG/SD/BFGS paths) to call the new
setup_etotAPIs. - Collapsed/updated unit tests for
setup_etotto match the new signatures.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| source/source_relax/test/lattice_change_basic_test.cpp | Updates setup_etot unit tests for lattice relaxation after API change. |
| source/source_relax/test/ions_move_basic_test.cpp | Updates setup_etot unit tests for ionic relaxation after API change. |
| source/source_relax/lattice_change_cg.cpp | Adjusts CG lattice relaxation to call the new setup_etot signature. |
| source/source_relax/lattice_change_basic.h | Updates setup_etot declaration (doc needs alignment with new signature). |
| source/source_relax/lattice_change_basic.cpp | Simplifies setup_etot implementation for lattice energy bookkeeping. |
| source/source_relax/ions_move_sd.cpp | Updates SD ionic relaxation to call the new setup_etot signature. |
| source/source_relax/ions_move_cg.cpp | Adjusts CG ionic relaxation to call the new setup_etot signature. |
| source/source_relax/ions_move_bfgs.cpp | Adjusts BFGS ionic relaxation to call the new setup_etot signature. |
| source/source_relax/ions_move_basic.h | Updates setup_etot declaration (doc needs alignment with new signature). |
| source/source_relax/ions_move_basic.cpp | Simplifies setup_etot implementation for ionic energy bookkeeping. |
Comments suppressed due to low confidence (2)
source/source_relax/test/lattice_change_basic_test.cpp:490
- The updated SetupEtot test no longer covers the
stress_step == 1branch (initialization of etot/etot_p), so the behavior introduced/retained in setup_etot() for the first stress step is now untested. This is a regression in unit coverage for setup_etot().
TEST_F(LatticeChangeBasicTest, SetupEtot)
{
Lattice_Change_Basic::stress_step = 2;
double energy_in = 80.0;
std::vector<double> etot_info = {100.0, 90.0};
Lattice_Change_Basic::setup_etot(energy_in, etot_info);
EXPECT_DOUBLE_EQ(100.0, etot_info[1]);
EXPECT_DOUBLE_EQ(80.0, etot_info[0]);
EXPECT_DOUBLE_EQ(-20.0, etot_info[0] - etot_info[1]);
}
source/source_relax/test/ions_move_basic_test.cpp:285
- The updated SetupEtot test only covers
istep > 1and no longer exercises theistep == 1initialization branch in Ions_Move_Basic::setup_etot(). Since that branch is still part of the function’s behavior, it should remain covered by unit tests.
// Test the setup_etot() function
TEST_F(IonsMoveBasicTest, SetupEtot)
{
// Initialize data
const int istep = 2;
std::vector<double> etot_info = {2.0, 1.0};
double energy_in = 3.0;
// Call the function being tested
std::ofstream ofs("/dev/null");
Ions_Move_Basic::setup_etot(energy_in, istep, etot_info);
ofs.close();
// Check the results
EXPECT_DOUBLE_EQ(etot_info[1], 2.0);
EXPECT_DOUBLE_EQ(etot_info[0], 3.0);
EXPECT_DOUBLE_EQ(etot_info[0] - etot_info[1], 1.0);
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reminder
Linked Issue
Fix #...
Unit Tests and/or Case Tests for my changes
What's changed?
Any changes of core modules? (ignore if not applicable)