[Patch] Follow up to #1531 - Layers: Add layers in layout, and replace it in scheduler#1701
[Patch] Follow up to #1531 - Layers: Add layers in layout, and replace it in scheduler#1701aserhani wants to merge 23 commits into
Conversation
|
Thanks @aserhani for opening this PR! You can do multiple things directly here: Once the workflow completes a message will appear displaying informations related to the run. Also the PR gets automatically reviewed by gemini, you can: |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a significant architectural change by implementing a multi-layered data layout system. The new Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a PatchDataLayout to manage multiple data layers, which is a good step towards more complex simulations. The changes correctly replace the old PatchDataLayerLayout in most places. My review focuses on improving consistency and leveraging modern C++ features.
A recurring point is the access to the default layer. In some places, it's accessed by index 0, while in others by name "main". Using the name is more robust and readable. I've suggested changes to consistently use "main".
I've also pointed out opportunities to simplify code by removing redundant checks and using helper functions, and to modernize some C++ constructs for better maintainability.
| PatchDataLayout(const std::vector<std::string> &layer_names) | ||
| : layer_layouts{layer_names.size()} { | ||
| for (size_t i = 0; i < layer_layouts.size(); i++) { | ||
| layer_layouts[i].name = layer_names[i]; | ||
| layer_layouts[i].layout = std::make_shared<PatchDataLayerLayout>(); | ||
| } | ||
| } |
There was a problem hiding this comment.
This constructor can be implemented more idiomatically using modern C++ features like reserve and push_back with an initializer list. This avoids default-constructing LayerEntry objects and then re-assigning their members, which is slightly more efficient and readable.
PatchDataLayout(const std::vector<std::string> &layer_names) {
layer_layouts.reserve(layer_names.size());
for (const auto &name : layer_names) {
layer_layouts.push_back({std::make_shared<PatchDataLayerLayout>(), name});
}
}| size_t get_layer_index(const std::string &name) const { | ||
| for (size_t i = 0; i < layer_layouts.size(); i++) { | ||
| if (layer_layouts[i].name == name) { | ||
| return i; | ||
| } | ||
| } | ||
| throw shambase::make_except_with_loc<std::invalid_argument>( | ||
| "the requested layer does not exists"); | ||
| } |
There was a problem hiding this comment.
This loop can be replaced with std::find_if from the <algorithm> header for a more idiomatic C++ implementation. You will need to include <algorithm> and <iterator>.
size_t get_layer_index(const std::string &name) const {
auto it = std::find_if(layer_layouts.begin(), layer_layouts.end(),
[&name](const LayerEntry &entry) {
return entry.name == name;
});
if (it != layer_layouts.end()) {
return std::distance(layer_layouts.begin(), it);
}
throw shambase::make_except_with_loc<std::invalid_argument>(
"the requested layer does not exists");
}| auto &pdl = *pdl_ptr; | ||
| std::shared_ptr<shamrock::patch::PatchDataLayout> pdl_ptr | ||
| = std::make_shared<shamrock::patch::PatchDataLayout>(std::vector<std::string>{"main"}); | ||
| auto &pdl = pdl_ptr->get_layer_ref(0); |
| auto &layer1 = pdl.get_layer_ref(0); | ||
| auto &layer2 = pdl.get_layer_ref(1); | ||
| auto &layer3 = pdl.get_layer_ref(2); |
| PatchDataLayout pdl_ref = PatchDataLayout(); | ||
| pdl_ref.layer_layouts.push_back( | ||
| PatchDataLayout::LayerEntry{std::make_shared<PatchDataLayerLayout>(pdl_layer), "main"}); |
There was a problem hiding this comment.
It's better to use the public API to construct the reference object for the test. This makes the test clearer and also tests the class's public interface.
PatchDataLayout pdl_ref({"main"});
pdl_ref.get_layer_ref("main") = pdl_layer;References
- In tests, prefer programmatic construction of expected data collections over manual, verbose initialization to improve maintainability and robustness.
| auto &layout = *layout_ptr; | ||
| std::shared_ptr<PatchDataLayout> layout_ptr | ||
| = std::make_shared<PatchDataLayout>(std::vector<std::string>{"main"}); | ||
| auto &layout = layout_ptr->get_layer_ref(0); |
Workflow reportworkflow report corresponding to commit d042116 Light CI is enabled. This will only run the basic tests and not the full tests. Pre-commit check reportPre-commit check: ✅ Test pipeline can run. Doxygen diff with
|
No description provided.