-
Notifications
You must be signed in to change notification settings - Fork 0
restructuring consistency check for grids version and restart results file #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -23,6 +23,9 @@ | |||||||||
|
|
||||||||||
| #include <green/ndarray/ndarray.h> | ||||||||||
| #include <green/params/params.h> | ||||||||||
| #include <green/grids/common_defs.h> | ||||||||||
| #include <green/h5pp/archive.h> | ||||||||||
| #include "except.h" | ||||||||||
|
|
||||||||||
| namespace green::sc { | ||||||||||
| /** | ||||||||||
|
|
@@ -113,5 +116,51 @@ namespace green::sc { | |||||||||
|
|
||||||||||
| return 0; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * @brief Checks consistency between grid-file version used in current run vs. the version | ||||||||||
| * used to generate the results file that is being (re-)started from. | ||||||||||
| * This is to prevent users from accidentally restarting from a results file that was generated with | ||||||||||
| * an older version of green-grids, which can lead to silent errors in the results. | ||||||||||
| * | ||||||||||
| * 1. If the results file does not have a green-grids version attribute, treat it as having been | ||||||||||
| * generated with the baseline grids version (GRIDS_MIN_VERSION, currently 0.2.4) and check | ||||||||||
| * that the current grid-file version is not newer; otherwise an error is raised. | ||||||||||
| * 2. If the results file has a green-grids version attribute, compare that version with the current | ||||||||||
| * grid-file version and distinguish older, equal, and newer cases, allowing only compatible | ||||||||||
| * combinations and throwing specific errors when there is a mismatch. | ||||||||||
| * | ||||||||||
| * @param results_file - path to the results file that is being restarted from | ||||||||||
| * @param grid_file_version - version of green-grids used in the current run (can be obtained from DysonSolver::get_grids_version()) | ||||||||||
| */ | ||||||||||
| void check_grids_version_consistency(std::string results_file, const std::string grid_file_version) { | ||||||||||
|
||||||||||
| void check_grids_version_consistency(std::string results_file, const std::string grid_file_version) { | |
| void check_grids_version_consistency(const std::string& results_file, const std::string& grid_file_version) { |
Copilot
AI
Feb 25, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The second parameter name grid_file_version is inconsistent with how it's documented. The documentation says "version of green-grids used in the current run" but the parameter is named grid_file_version. Consider renaming to grids_version or current_grids_version for clarity and consistency with the terminology used throughout the function (e.g., "green-grids version").
Copilot
AI
Feb 25, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function is defined in a header file but is not marked as inline. This can lead to multiple definition linker errors if the header is included in multiple translation units. Following the pattern of other functions in this file (like define_parameters and compare_version_strings), this function should be marked as inline.
| void check_grids_version_consistency(std::string results_file, const std::string grid_file_version) { | |
| inline void check_grids_version_consistency(std::string results_file, const std::string grid_file_version) { |
Copilot
AI
Feb 25, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a control flow bug: when the file has a grids_version attribute and the versions are equal (compatible case), the archive is closed at line 144, then execution falls through to line 156. If the condition at line 156 is also false, execution reaches line 162 which attempts to close the archive again. This double-close could cause errors depending on the h5pp::archive implementation. The function should return after line 155 when versions are compatible, or restructure the logic to avoid attempting to close an already-closed archive.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -634,6 +634,24 @@ TEST_CASE("FockSigmaVectorSpace") { test_vector_space<green::opt::vector_space_f | |
|
|
||
| TEST_CASE("CyclicFockSigmaVectorSpace") { test_vector_space<green::opt::cyclic_vector_space_fock_sigma>(); } | ||
|
|
||
| TEST_CASE("Grids Version Consistency") { | ||
| // 1. Starting with new file (does not exist). | ||
| // Version check should pass because there's nothing to check / no inconsistency | ||
| std::string res_file_1 = random_name(); | ||
| REQUIRE_NOTHROW(green::sc::check_grids_version_consistency(res_file_1, "0.2.4")); | ||
|
|
||
| // 2. Open the file and add __grids_version__ attribute | ||
| green::h5pp::archive ar_res_1(res_file_1, "w"); | ||
| ar_res_1.set_attribute<std::string>("__grids_version__", "0.2.4"); | ||
| ar_res_1.close(); | ||
| REQUIRE_NOTHROW(green::sc::check_grids_version_consistency(res_file_1, green::grids::GRIDS_MIN_VERSION)); | ||
| REQUIRE_THROWS_AS(green::sc::check_grids_version_consistency(res_file_1, "0.2.3"), | ||
| green::grids::outdated_grids_file_error); | ||
| REQUIRE_THROWS_AS(green::sc::check_grids_version_consistency(res_file_1, "0.2.5"), | ||
| green::sc::outdated_results_file_error); | ||
| std::filesystem::remove(res_file_1); | ||
| } | ||
|
Comment on lines
+637
to
+653
|
||
|
|
||
| int main(int argc, char** argv) { | ||
| MPI_Init(&argc, &argv); | ||
| int result = Catch::Session().run(argc, argv); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function uses std::filesystem::exists but there is no #include directive in this file. While this may work due to transitive includes from other headers, it creates a fragile dependency. The file should explicitly include to ensure portability and make dependencies clear.