Skip to content

Conversation

@PhilipDeegan
Copy link
Member

@PhilipDeegan PhilipDeegan commented Jun 6, 2025

roch is using this on his close branch so we might aswell get it in separately

allow conditional runtime resource allocation via variants

@coderabbitai
Copy link

coderabbitai bot commented Jun 6, 2025

📝 Walkthrough

Walkthrough

Added a public static helper handle_sub_resources to ResourcesManager to uniformly traverse compile-time (tuple) and runtime (variant) sub-resources and applied it in registerResources, allocate, and getIDs_. Introduced variant utility helpers for extracting references/tuples from std::variants and tests validating variant-backed resources. Minor include reorder in a tensorfield header.

Changes

Cohort / File(s) Change Summary
Resources manager
src/amr/resources_manager/resources_manager.hpp
Added public static handle_sub_resources(auto fn, auto& obj, auto&&... args) to traverse runtime (std::variant) and compile-time (std::tuple) sub-resources; refactored registerResources, allocate, and getIDs_ to call it; added <tuple> include; removed prior duplicate/private recursion.
Variant utilities
src/core/utilities/variants.hpp
New header with utilities: decay_to_ptr, varient_visitor_overloads, unique-type tuple helpers, visit_ptr_overloads, get_as_ref_or_throw, get_as_tuple_or_throw, and get_from_variants for type-safe extraction from std::variant collections.
Tests: resources manager
tests/amr/resources_manager/test_resources_manager.cpp
Added FieldResource, VecFieldResource, ResourceUser (uses std::variant), and tests for variant helpers, variant resource retrieval (get_from_variants, get_as_*_or_throw), and ResourcesManager integration (allocation, mutation, persistence across patches).
Include reorder
src/core/data/tensorfield/tensorfield.hpp
Reordered standard library includes relative to project includes; no behavioral changes.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant Test as TestCase
    participant RU as ResourceUser
    participant RM as ResourcesManager
    participant Var as VariantHelpers
    participant Patch as PatchStore

    Note over Test,RU: Prepare ResourceUser with vector<std::variant<...>>

    Test->>RM: registerResources(RU)
    RM->>RM: handle_sub_resources(registerResources, RU)
    RM->>Var: (for runtime entries) get_as_tuple_or_throw / get_as_ref_or_throw
    Var-->>RM: references to concrete sub-resources

    loop For each Patch
        Test->>RM: allocate(RU, Patch)
        RM->>RM: handle_sub_resources(allocate, RU, Patch)
        RM->>Var: extract variant element(s) for allocation
        Var-->>RM: allocated sub-resources
        Test->>RM: getIDs_(RU, Patch)
        RM->>RM: handle_sub_resources(getIDs_, RU, Patch)
    end

    Note over Test,RM: Tests modify resource on one patch and verify persistence across patches
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20–30 minutes

  • Pay extra attention to:
    • src/amr/resources_manager/resources_manager.hpp: correctness of traversal order, forwarding of args, and handling of variant/tuple mixes.
    • src/core/utilities/variants.hpp: correctness of visitor construction, pointer-decay approach, exception messages, and safety of conversions.
    • New tests in tests/amr/resources_manager/test_resources_manager.cpp for correctness and realistic coverage.

Possibly related PRs

Suggested reviewers

  • nicolasaunai

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 4.55% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: introducing variants handling in the resource manager to support conditional runtime resource allocation.
Description check ✅ Passed The description is related to the changeset, explaining the intent to enable conditional runtime resource allocation via variants, though it is brief and mentions context about another contributor.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6cbddf1 and 0f9b875.

📒 Files selected for processing (4)
  • src/amr/resources_manager/resources_manager.hpp (5 hunks)
  • src/core/data/tensorfield/tensorfield.hpp (1 hunks)
  • src/core/utilities/variants.hpp (1 hunks)
  • tests/amr/resources_manager/test_resources_manager.cpp (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • src/core/data/tensorfield/tensorfield.hpp
👮 Files not reviewed due to content moderation or server errors (3)
  • src/amr/resources_manager/resources_manager.hpp
  • tests/amr/resources_manager/test_resources_manager.cpp
  • src/core/utilities/variants.hpp
🧰 Additional context used
📓 Path-based instructions (1)
**/*.hpp

⚙️ CodeRabbit configuration file

Review the C++ code, point out issues relative to principles of clean code, expressiveness, and performance.

Files:

  • src/core/utilities/variants.hpp
  • src/amr/resources_manager/resources_manager.hpp
🧠 Learnings (2)
📓 Common learnings
Learnt from: PhilipDeegan
Repo: PHAREHUB/PHARE PR: 888
File: pyphare/pyphare/pharesee/hierarchy/hierarchy_utils.py:566-568
Timestamp: 2024-09-09T13:57:02.285Z
Learning: Avoid commenting on draft PRs for PhilipDeegan unless explicitly requested.
Learnt from: PhilipDeegan
Repo: PHAREHUB/PHARE PR: 888
File: src/hdf5/detail/h5/h5_file.hpp:78-79
Timestamp: 2024-10-09T08:32:15.667Z
Learning: Avoid commenting on draft PRs for the user PhilipDeegan.
Learnt from: PhilipDeegan
Repo: PHAREHUB/PHARE PR: 888
File: src/hdf5/detail/h5/h5_file.hpp:78-79
Timestamp: 2024-09-05T17:02:58.784Z
Learning: Avoid commenting on draft PRs for the user PhilipDeegan.
Learnt from: PhilipDeegan
Repo: PHAREHUB/PHARE PR: 784
File: tests/simulator/test_restarts.py:333-339
Timestamp: 2024-10-09T08:32:15.667Z
Learning: PhilipDeegan has indicated a preference for minimal and efficient code, even after making changes to get a function working. There may be opportunities to remove or optimize parts of the code such as sleep/wait/advances.
Learnt from: PhilipDeegan
Repo: PHAREHUB/PHARE PR: 784
File: tests/simulator/test_restarts.py:333-339
Timestamp: 2024-07-26T22:04:34.160Z
Learning: PhilipDeegan has indicated a preference for minimal and efficient code, even after making changes to get a function working. There may be opportunities to remove or optimize parts of the code such as sleep/wait/advances.
Learnt from: PhilipDeegan
Repo: PHAREHUB/PHARE PR: 1068
File: src/amr/data/field/coarsening/electric_field_coarsener.hpp:1-2
Timestamp: 2025-09-17T13:35:11.533Z
Learning: PhilipDeegan prefers header guard names that include the full directory path structure, following the pattern PHARE_[PATH_WITH_UNDERSCORES]_HPP. For example, a file at src/amr/data/field/coarsening/electric_field_coarsener.hpp should use PHARE_AMR_DATA_FIELD_COARSENING_ELECTRIC_FIELD_COARSENER_HPP as the header guard.
📚 Learning: 2025-09-01T09:41:40.618Z
Learnt from: PhilipDeegan
Repo: PHAREHUB/PHARE PR: 1056
File: tests/core/numerics/interpolator/test_main.cpp:314-318
Timestamp: 2025-09-01T09:41:40.618Z
Learning: The PHARE project uses C++20, which makes the typename keyword optional for dependent types in obvious contexts. The project prefers minimal code without unnecessary keywords, so typename suggestions for dependent types should be avoided when the code compiles successfully in C++20.

Applied to files:

  • src/core/utilities/variants.hpp
  • src/amr/resources_manager/resources_manager.hpp
🧬 Code graph analysis (3)
src/core/utilities/variants.hpp (3)
src/amr/solvers/solver_ppc_model_view.hpp (1)
  • tuple_size (262-277)
src/core/data/tensorfield/tensorfield.hpp (6)
  • i (183-183)
  • i (183-183)
  • i (184-184)
  • i (184-184)
  • ptr (86-89)
  • ptr (86-86)
tests/amr/resources_manager/test_resources_manager.cpp (2)
  • forward_as_tuple (284-284)
  • forward_as_tuple (291-291)
tests/amr/resources_manager/test_resources_manager.cpp (1)
src/core/utilities/variants.hpp (8)
  • get_as_tuple_or_throw (75-101)
  • get_as_tuple_or_throw (75-75)
  • get_as_ref_or_throw (63-70)
  • get_as_ref_or_throw (63-63)
  • get_from_variants (104-117)
  • get_from_variants (104-104)
  • get_from_variants (121-125)
  • get_from_variants (121-122)
src/amr/resources_manager/resources_manager.hpp (4)
src/amr/messengers/mhd_hybrid_messenger_strategy.hpp (2)
  • patch (41-46)
  • patch (41-41)
src/amr/physical_models/mhd_model.hpp (4)
  • patch (46-50)
  • patch (46-46)
  • patch (59-62)
  • patch (59-59)
src/amr/physical_models/hybrid_model.hpp (4)
  • patch (59-62)
  • patch (59-59)
  • patch (74-77)
  • patch (74-74)
src/amr/messengers/hybrid_hybrid_messenger_strategy.hpp (2)
  • patch (146-154)
  • patch (146-146)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
  • GitHub Check: build (macos-latest)
  • GitHub Check: build (macos-13)
  • GitHub Check: build (macos-14)
  • GitHub Check: Analyze (cpp)
  • GitHub Check: Analyze (python)
  • GitHub Check: build (ubuntu-latest, clang)
  • GitHub Check: build (ubuntu-latest, gcc)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (2)
tests/amr/resources_manager/test_resources_manager.cpp (2)

257-283: Test structures look good but consider adding validation.

The test structures properly implement the required interfaces for variant-based resource management. However:

  1. The FieldResource initializes Field1D with nullptr which might cause issues if the field's data pointer is accessed during tests.
  2. The ResourceUser::get() method assumes exactly 2 FieldResource items but doesn't validate this assumption.

Consider adding validation:

 auto get() { 
+    if (resources.size() != 2) {
+        throw std::runtime_error("Expected exactly 2 resources");
+    }
     return get_as_tuple_or_throw<FieldResource, FieldResource>(resources); 
 }

302-340: Well-structured integration test for variant resources.

The test properly exercises the variant-based resource management through the full lifecycle. Consider adding a comment to explain the significance of the test values.

 auto dataOnPatch = resourcesManager.setOnPatch(*patch, resourceUser);
 auto&& [r0, r1]  = resourceUser.get();
+// Set a test value at a specific index to verify data persistence
 r1.rho.data()[4] = 5;
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 49d3b04 and d0736b8.

📒 Files selected for processing (2)
  • src/amr/resources_manager/resources_manager.hpp (7 hunks)
  • tests/amr/resources_manager/test_resources_manager.cpp (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.hpp`: Review the C++ code, point out issues relative to principles of clean code, expressiveness, and performance.

**/*.hpp: Review the C++ code, point out issues relative to principles of clean code, expressiveness, and performance.

  • src/amr/resources_manager/resources_manager.hpp
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: build (ubuntu-latest, clang)
  • GitHub Check: build (ubuntu-latest, gcc)
  • GitHub Check: Analyze (cpp)
  • GitHub Check: Analyze (python)
  • GitHub Check: build (macos-14)
  • GitHub Check: build (macos-latest)
  • GitHub Check: build (macos-13)
🔇 Additional comments (4)
src/amr/resources_manager/resources_manager.hpp (3)

22-22: Include addition looks good.

The tuple header is required for the std::apply usage in the new handle_sub_resources function.


168-170: Excellent refactoring to eliminate code duplication.

The replacement of inline recursive logic with calls to handle_sub_resources in registerResources, allocate, getIDs_, and setResources_ improves code maintainability and consistency. All lambda captures and parameter forwarding are correctly implemented.

Also applies to: 194-196, 339-339, 397-400


412-412: Minor formatting improvement.

tests/amr/resources_manager/test_resources_manager.cpp (1)

11-14: Required includes for variant-based testing.

The new includes are appropriate for the variant-based resource management tests.

Also applies to: 21-22

* unpacked elements
*/

void static handle_sub_resources(auto fn, auto& obj, auto&&... args)

Check notice

Code scanning / CodeQL

Unused static variable Note

Static variable args is never read.
* unpacked elements
*/

void static handle_sub_resources(auto fn, auto& obj, auto&&... args)

Check notice

Code scanning / CodeQL

Unused local variable Note

Variable args is not used.
std::vector<Resources> resources{FieldResource{}, VecFieldResource{}};

{
auto const&& [rho, B] = get_as_tuple_or_throw<FieldResource, VecFieldResource>(resources);

Check notice

Code scanning / CodeQL

Unused local variable Note test

Variable rho is not used.
std::vector<Resources> resources{FieldResource{}, VecFieldResource{}};

{
auto const&& [rho, B] = get_as_tuple_or_throw<FieldResource, VecFieldResource>(resources);

Check notice

Code scanning / CodeQL

Unused local variable Note test

Variable B is not used.
for (auto const& patch : *hierarchy->getPatchLevel(iLevel))
{
auto dataOnPatch = resourcesManager.setOnPatch(*patch, resourceUser);
auto&& [r0, r1] = resourceUser.get();

Check notice

Code scanning / CodeQL

Unused local variable Note test

Variable r0 is not used.
for (auto const& patch : *hierarchy->getPatchLevel(iLevel))
{
auto dataOnPatch = resourcesManager.setOnPatch(*patch, resourceUser);
auto&& [r0, r1] = resourceUser.get();

Check notice

Code scanning / CodeQL

Unused local variable Note test

Variable r0 is not used.
@PhilipDeegan PhilipDeegan marked this pull request as draft June 7, 2025 10:08
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (3)
src/core/utilities/variants.hpp (3)

68-68: Improve error message with type information.

The generic error message makes debugging difficult when the function throws.

-    throw std::runtime_error("No element in variant for type");
+    throw std::runtime_error("No element in variant for type: " + std::string(typeid(Type).name()));

94-95: Enhance error message to indicate which type was not found.

The generic error message doesn't help identify which type extraction failed.

-    for_N<tuple_size>([&](auto i) {
-        if (std::get<i>(pointer_tuple) == nullptr)
-            throw std::runtime_error("No element in variant for type");
-    });
+    for_N<tuple_size>([&](auto i) {
+        if (std::get<i>(pointer_tuple) == nullptr)
+        {
+            using Type = std::tuple_element_t<i, Tuple>;
+            throw std::runtime_error("No element in variant for type at index " + std::to_string(i) + 
+                                   ": " + std::string(typeid(Type).name()));
+        }
+    });

72-73: Document the ordering requirement and algorithm complexity.

The comment emphasizes order requirements but doesn't explain the consequences or the algorithm's complexity.

-// ARGS MUST BE IN THE SAME ORDER AS VARIANT LIST TYPES!!!!!
+// ARGS MUST BE IN THE SAME ORDER AS VARIANT LIST TYPES!!!!!
+// The function assumes types appear in the same order in both the template arguments
+// and the variant collection. Violating this assumption will result in runtime errors.
+// Complexity: O(n×m) where n = variants.size() and m = sizeof...(Args)
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d0736b8 and a27ed4e.

📒 Files selected for processing (3)
  • src/amr/resources_manager/resources_manager.hpp (6 hunks)
  • src/core/utilities/variants.hpp (1 hunks)
  • tests/amr/resources_manager/test_resources_manager.cpp (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • tests/amr/resources_manager/test_resources_manager.cpp
  • src/amr/resources_manager/resources_manager.hpp
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.hpp`: Review the C++ code, point out issues relative to principles of clean code, expressiveness, and performance.

**/*.hpp: Review the C++ code, point out issues relative to principles of clean code, expressiveness, and performance.

⚙️ Source: CodeRabbit Configuration File

List of files the instruction was applied to:

  • src/core/utilities/variants.hpp
🧠 Learnings (2)
📓 Common learnings
Learnt from: PhilipDeegan
PR: PHAREHUB/PHARE#888
File: src/hdf5/detail/h5/h5_file.hpp:78-79
Timestamp: 2024-10-09T08:32:15.667Z
Learning: Avoid commenting on draft PRs for the user PhilipDeegan.
Learnt from: PhilipDeegan
PR: PHAREHUB/PHARE#888
File: src/hdf5/detail/h5/h5_file.hpp:78-79
Timestamp: 2024-09-05T17:02:58.784Z
Learning: Avoid commenting on draft PRs for the user PhilipDeegan.
Learnt from: PhilipDeegan
PR: PHAREHUB/PHARE#888
File: pyphare/pyphare/pharesee/hierarchy/hierarchy_utils.py:566-568
Timestamp: 2024-09-09T13:57:02.285Z
Learning: Avoid commenting on draft PRs for PhilipDeegan unless explicitly requested.
Learnt from: PhilipDeegan
PR: PHAREHUB/PHARE#784
File: tests/simulator/test_restarts.py:333-339
Timestamp: 2024-07-26T22:04:34.160Z
Learning: PhilipDeegan has indicated a preference for minimal and efficient code, even after making changes to get a function working. There may be opportunities to remove or optimize parts of the code such as sleep/wait/advances.
Learnt from: PhilipDeegan
PR: PHAREHUB/PHARE#784
File: tests/simulator/test_restarts.py:333-339
Timestamp: 2024-10-09T08:32:15.667Z
Learning: PhilipDeegan has indicated a preference for minimal and efficient code, even after making changes to get a function working. There may be opportunities to remove or optimize parts of the code such as sleep/wait/advances.
src/core/utilities/variants.hpp (2)
Learnt from: PhilipDeegan
PR: PHAREHUB/PHARE#998
File: src/core/utilities/point/point.hpp:195-210
Timestamp: 2025-04-17T14:41:53.643Z
Learning: In `src/core/utilities/point/point.hpp`, the `as_signed()` and `as_unsigned()` methods are intentionally designed to cause compilation errors for unsupported types (only 4-byte types are supported). This forces developers to implement proper conversions themselves when extending the functionality to new types. The comment "else no return cause not yet handled" indicates this is a deliberate design choice.
Learnt from: PhilipDeegan
PR: PHAREHUB/PHARE#898
File: src/amr/data/particles/refine/particles_data_split.hpp:181-182
Timestamp: 2024-10-16T09:54:01.455Z
Learning: The codebase uses C++17 features such as class template argument deduction, allowing template arguments to be omitted in declarations like `std::array`.
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: build (ubuntu-latest, clang)
  • GitHub Check: build (ubuntu-latest, gcc)
  • GitHub Check: build (macos-latest)
  • GitHub Check: Analyze (cpp)
  • GitHub Check: build (macos-13)
  • GitHub Check: build (macos-14)

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (3)
src/core/utilities/variants.hpp (2)

13-17: Remove unsafe const_cast in ptr_or_null_for_type.


83-98: get_as_tuple_or_throw: error message & performance refinements

tests/amr/resources_manager/test_resources_manager.cpp (1)

310-325: Add assertions to verify the helper functions work correctly.

Additionally, to address the static analysis warnings about unused variables, consider using the extracted references or adding explicit assertions:

     {
         auto const&& [rho, B] = get_as_tuple_or_throw<FieldResource, VecFieldResource>(resources);
+        // Verify extraction succeeded - accessing members would fail if wrong type
+        static_cast<void>(rho.rho);
+        static_cast<void>(B.B);
     }
     {
         auto& rho = get_as_ref_or_throw<FieldResource>(resources);
+        EXPECT_EQ(&rho, &std::get<FieldResource>(resources[0]));
     }
     {
         auto& B = get_as_ref_or_throw<VecFieldResource>(resources);
+        EXPECT_EQ(&B, &std::get<VecFieldResource>(resources[1]));
     }
🧹 Nitpick comments (4)
src/core/utilities/variants.hpp (3)

20-26: Fix typo in struct name: varientvariant.

The struct name contains a typo that should be corrected for consistency with standard C++ terminology.

-template<typename... Ts>
-struct varient_visitor_overloads : Ts...
+template<typename... Ts>
+struct variant_visitor_overloads : Ts...
 {
     using Ts::operator()...;
 };

 template<typename... Ts>
-varient_visitor_overloads(Ts&&...) -> varient_visitor_overloads<std::decay_t<Ts>...>;
+variant_visitor_overloads(Ts&&...) -> variant_visitor_overloads<std::decay_t<Ts>...>;

32-32: Update to use corrected struct name.

-    return varient_visitor_overloads{ptr_or_null_for_type<Args>()...,
+    return variant_visitor_overloads{ptr_or_null_for_type<Args>()...,

70-70: Enhance error message with type information.

The error message should include the type name for better debugging.

-    throw std::runtime_error("No element in variant for type");
+    throw std::runtime_error("No element in variant for type: " + std::string(typeid(Type).name()));
tests/amr/resources_manager/test_resources_manager.cpp (1)

372-372: Remove or use the unused variable r0.

The variable r0 is extracted but never used, triggering static analysis warnings.

-            auto&& [r0, r1]  = resourceUser.get();
+            auto&& [_, r1]  = resourceUser.get();

Or if you need both resources:

             auto&& [r0, r1]  = resourceUser.get();
+            static_cast<void>(r0); // Explicitly mark as unused
             r1.rho.data()[4] = 5;

Also applies to: 382-382

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between da99c68 and 720ecf2.

📒 Files selected for processing (4)
  • src/amr/resources_manager/resources_manager.hpp (5 hunks)
  • src/core/data/tensorfield/tensorfield.hpp (1 hunks)
  • src/core/utilities/variants.hpp (1 hunks)
  • tests/amr/resources_manager/test_resources_manager.cpp (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • src/core/data/tensorfield/tensorfield.hpp
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/amr/resources_manager/resources_manager.hpp
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.hpp`: Review the C++ code, point out issues relative to principles of clean code, expressiveness, and performance.

**/*.hpp: Review the C++ code, point out issues relative to principles of clean code, expressiveness, and performance.

⚙️ Source: CodeRabbit Configuration File

List of files the instruction was applied to:

  • src/core/utilities/variants.hpp
🧠 Learnings (3)
📓 Common learnings
Learnt from: PhilipDeegan
PR: PHAREHUB/PHARE#888
File: pyphare/pyphare/pharesee/hierarchy/hierarchy_utils.py:566-568
Timestamp: 2024-09-09T13:57:02.285Z
Learning: Avoid commenting on draft PRs for PhilipDeegan unless explicitly requested.
Learnt from: PhilipDeegan
PR: PHAREHUB/PHARE#888
File: src/hdf5/detail/h5/h5_file.hpp:78-79
Timestamp: 2024-09-05T17:02:58.784Z
Learning: Avoid commenting on draft PRs for the user PhilipDeegan.
Learnt from: PhilipDeegan
PR: PHAREHUB/PHARE#888
File: src/hdf5/detail/h5/h5_file.hpp:78-79
Timestamp: 2024-10-09T08:32:15.667Z
Learning: Avoid commenting on draft PRs for the user PhilipDeegan.
Learnt from: PhilipDeegan
PR: PHAREHUB/PHARE#784
File: tests/simulator/test_restarts.py:333-339
Timestamp: 2024-07-26T22:04:34.160Z
Learning: PhilipDeegan has indicated a preference for minimal and efficient code, even after making changes to get a function working. There may be opportunities to remove or optimize parts of the code such as sleep/wait/advances.
Learnt from: PhilipDeegan
PR: PHAREHUB/PHARE#784
File: tests/simulator/test_restarts.py:333-339
Timestamp: 2024-10-09T08:32:15.667Z
Learning: PhilipDeegan has indicated a preference for minimal and efficient code, even after making changes to get a function working. There may be opportunities to remove or optimize parts of the code such as sleep/wait/advances.
tests/amr/resources_manager/test_resources_manager.cpp (3)
Learnt from: PhilipDeegan
PR: PHAREHUB/PHARE#998
File: src/core/utilities/point/point.hpp:195-210
Timestamp: 2025-04-17T14:41:53.643Z
Learning: In `src/core/utilities/point/point.hpp`, the `as_signed()` and `as_unsigned()` methods are intentionally designed to cause compilation errors for unsupported types (only 4-byte types are supported). This forces developers to implement proper conversions themselves when extending the functionality to new types. The comment "else no return cause not yet handled" indicates this is a deliberate design choice.
Learnt from: rochSmets
PR: PHAREHUB/PHARE#921
File: src/core/data/ions/ions.hpp:138-142
Timestamp: 2025-02-06T10:52:56.461Z
Learning: In PHARE simulations, velocity calculations must account for per-population densities that can be strictly zero in given cells. Simple zero-return solutions for division by zero are inadequate as they don't reflect the correct physics.
Learnt from: nicolasaunai
PR: PHAREHUB/PHARE#591
File: res/cmake/options.cmake:73-75
Timestamp: 2025-02-07T14:35:14.630Z
Learning: In CMake configuration for PHARE, `lowResourceTests` and `highResourceTests` options must be mutually exclusive and cannot be enabled simultaneously.
src/core/utilities/variants.hpp (2)
Learnt from: PhilipDeegan
PR: PHAREHUB/PHARE#998
File: src/core/utilities/point/point.hpp:195-210
Timestamp: 2025-04-17T14:41:53.643Z
Learning: In `src/core/utilities/point/point.hpp`, the `as_signed()` and `as_unsigned()` methods are intentionally designed to cause compilation errors for unsupported types (only 4-byte types are supported). This forces developers to implement proper conversions themselves when extending the functionality to new types. The comment "else no return cause not yet handled" indicates this is a deliberate design choice.
Learnt from: PhilipDeegan
PR: PHAREHUB/PHARE#898
File: src/amr/data/particles/refine/particles_data_split.hpp:181-182
Timestamp: 2024-10-16T09:54:01.455Z
Learning: The codebase uses C++17 features such as class template argument deduction, allowing template arguments to be omitted in declarations like `std::array`.
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
  • GitHub Check: build (ubuntu-latest, gcc)
  • GitHub Check: build (ubuntu-latest, clang)
  • GitHub Check: build (macos-latest)
  • GitHub Check: build (macos-14)
  • GitHub Check: build (macos-13)
  • GitHub Check: Analyze (python)
  • GitHub Check: Analyze (cpp)
🔇 Additional comments (1)
tests/amr/resources_manager/test_resources_manager.cpp (1)

328-349: Well-structured test with proper assertions.

The test correctly validates the get_from_variants helper function with appropriate assertions.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (2)
src/core/utilities/variants.hpp (2)

13-17: Remove unsafe const_cast in decay_to_ptr.

The unconditional use of const_cast can lead to undefined behavior if used on const objects. This violates const-correctness and could cause subtle bugs or crashes.


103-117: Missing throw statement causes undefined behavior.

The function constructs an error message but never throws it, leading to undefined behavior when the required name is not found.

🧹 Nitpick comments (4)
src/core/utilities/variants.hpp (4)

19-27: Fix typo in struct name.

The struct name varient_visitor_overloads contains a typo - it should be variant_visitor_overloads.

-template<typename... Ts>
-struct varient_visitor_overloads : Ts...
-{
-    using Ts::operator()...;
-};
-
-template<typename... Ts>
-varient_visitor_overloads(Ts&&...) -> varient_visitor_overloads<std::decay_t<Ts>...>;
+template<typename... Ts>
+struct variant_visitor_overloads : Ts...
+{
+    using Ts::operator()...;
+};
+
+template<typename... Ts>
+variant_visitor_overloads(Ts&&...) -> variant_visitor_overloads<std::decay_t<Ts>...>;

29-34: Update function to use corrected struct name.

This function references the misspelled varient_visitor_overloads struct. Update it to use the corrected name variant_visitor_overloads.

 template<typename... Args>
 auto constexpr _visit_ptr_overloads(std::tuple<Args...>*)
 {
-    return varient_visitor_overloads{decay_to_ptr<Args>()...,
+    return variant_visitor_overloads{decay_to_ptr<Args>()...,
                                      [](auto&) mutable -> void* { return nullptr; }};
 }

62-70: Improve error message for better debugging.

The generic error message makes debugging difficult. Consider including more specific information about the failed type lookup.

-    throw std::runtime_error("No element in variant for type");
+    throw std::runtime_error("No element in variant for type: " + std::string(typeid(Type).name()));

74-101: Consider performance optimization for large variant collections.

The nested loops in this function result in O(N × M) complexity. For large variant lists, consider optimizing the type lookup mechanism.

Additionally, improve the error message to include more context:

-            throw std::runtime_error("No element in variant for type");
+            throw std::runtime_error("No element in variant for type at tuple position " + std::to_string(i));
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 720ecf2 and 9a25324.

📒 Files selected for processing (2)
  • src/core/utilities/variants.hpp (1 hunks)
  • tests/amr/resources_manager/test_resources_manager.cpp (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/amr/resources_manager/test_resources_manager.cpp
🧰 Additional context used
📓 Path-based instructions (1)
**/*.hpp

Instructions used from:

Sources:
⚙️ CodeRabbit Configuration File

🧠 Learnings (2)
📓 Common learnings
Learnt from: PhilipDeegan
PR: PHAREHUB/PHARE#888
File: pyphare/pyphare/pharesee/hierarchy/hierarchy_utils.py:566-568
Timestamp: 2024-09-09T13:57:02.285Z
Learning: Avoid commenting on draft PRs for PhilipDeegan unless explicitly requested.
Learnt from: PhilipDeegan
PR: PHAREHUB/PHARE#888
File: src/hdf5/detail/h5/h5_file.hpp:78-79
Timestamp: 2024-10-09T08:32:15.667Z
Learning: Avoid commenting on draft PRs for the user PhilipDeegan.
Learnt from: PhilipDeegan
PR: PHAREHUB/PHARE#888
File: src/hdf5/detail/h5/h5_file.hpp:78-79
Timestamp: 2024-09-05T17:02:58.784Z
Learning: Avoid commenting on draft PRs for the user PhilipDeegan.
Learnt from: PhilipDeegan
PR: PHAREHUB/PHARE#784
File: tests/simulator/test_restarts.py:333-339
Timestamp: 2024-07-26T22:04:34.160Z
Learning: PhilipDeegan has indicated a preference for minimal and efficient code, even after making changes to get a function working. There may be opportunities to remove or optimize parts of the code such as sleep/wait/advances.
Learnt from: PhilipDeegan
PR: PHAREHUB/PHARE#784
File: tests/simulator/test_restarts.py:333-339
Timestamp: 2024-10-09T08:32:15.667Z
Learning: PhilipDeegan has indicated a preference for minimal and efficient code, even after making changes to get a function working. There may be opportunities to remove or optimize parts of the code such as sleep/wait/advances.
src/core/utilities/variants.hpp (2)
Learnt from: PhilipDeegan
PR: PHAREHUB/PHARE#898
File: src/amr/data/particles/refine/particles_data_split.hpp:181-182
Timestamp: 2024-10-16T09:54:01.455Z
Learning: The codebase uses C++17 features such as class template argument deduction, allowing template arguments to be omitted in declarations like `std::array`.
Learnt from: PhilipDeegan
PR: PHAREHUB/PHARE#998
File: src/core/utilities/point/point.hpp:195-210
Timestamp: 2025-04-17T14:41:53.643Z
Learning: In `src/core/utilities/point/point.hpp`, the `as_signed()` and `as_unsigned()` methods are intentionally designed to cause compilation errors for unsupported types (only 4-byte types are supported). This forces developers to implement proper conversions themselves when extending the functionality to new types. The comment "else no return cause not yet handled" indicates this is a deliberate design choice.
🧬 Code Graph Analysis (1)
src/core/utilities/variants.hpp (2)
src/core/data/tensorfield/tensorfield.hpp (6)
  • for_N (84-88)
  • for_N (89-93)
  • i (179-179)
  • i (179-179)
  • i (180-180)
  • i (180-180)
tests/amr/resources_manager/test_resources_manager.cpp (2)
  • forward_as_tuple (284-284)
  • forward_as_tuple (291-291)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
  • GitHub Check: Analyze (cpp)
  • GitHub Check: build (macos-14)
  • GitHub Check: Analyze (python)
  • GitHub Check: build (macos-latest)
  • GitHub Check: build (macos-13)
  • GitHub Check: build (ubuntu-latest, gcc)
  • GitHub Check: build (ubuntu-latest, clang)
🔇 Additional comments (5)
src/core/utilities/variants.hpp (5)

1-10: Header structure looks good.

The header guards follow proper naming conventions and all necessary includes are present for the variant utilities functionality.


37-51: Well-implemented template metafunction.

The unique template struct and unique_tuple alias provide a clean way to filter duplicate types from template parameter packs. The implementation follows modern C++ best practices.


54-58: Clean implementation of visitor creation.

The visit_ptr_overloads function effectively combines the unique type filtering with visitor creation. The use of unique_tuple ensures type safety.


120-125: Good use of modern C++ features.

The variadic overload with the requires clause is well-implemented and provides a clean interface for extracting multiple elements.


130-134: Proper file structure closing.

The namespace and header guard are properly closed.

@PHAREHUB PHAREHUB deleted a comment from coderabbitai bot Oct 31, 2025
@PHAREHUB PHAREHUB deleted a comment from coderabbitai bot Nov 5, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (1)
src/core/utilities/variants.hpp (1)

115-117: Throw when a name is missing in get_from_variants.

Falling off the end here just constructs a std::runtime_error and returns without a value, which is UB. Please actually throw.

-    if (start == variants.size())
-        std::runtime_error("Required name not found in variants: " + arg.name());
+    if (start == variants.size())
+        throw std::runtime_error("Required name not found in variants: " + arg.name());
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9a25324 and 6cbddf1.

📒 Files selected for processing (4)
  • src/amr/resources_manager/resources_manager.hpp (5 hunks)
  • src/core/data/tensorfield/tensorfield.hpp (1 hunks)
  • src/core/utilities/variants.hpp (1 hunks)
  • tests/amr/resources_manager/test_resources_manager.cpp (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/core/data/tensorfield/tensorfield.hpp
🧰 Additional context used
📓 Path-based instructions (1)
**/*.hpp

⚙️ CodeRabbit configuration file

Review the C++ code, point out issues relative to principles of clean code, expressiveness, and performance.

Files:

  • src/amr/resources_manager/resources_manager.hpp
  • src/core/utilities/variants.hpp
🧠 Learnings (3)
📓 Common learnings
Learnt from: PhilipDeegan
Repo: PHAREHUB/PHARE PR: 888
File: pyphare/pyphare/pharesee/hierarchy/hierarchy_utils.py:566-568
Timestamp: 2024-09-09T13:57:02.285Z
Learning: Avoid commenting on draft PRs for PhilipDeegan unless explicitly requested.
Learnt from: PhilipDeegan
Repo: PHAREHUB/PHARE PR: 888
File: src/hdf5/detail/h5/h5_file.hpp:78-79
Timestamp: 2024-10-09T08:32:15.667Z
Learning: Avoid commenting on draft PRs for the user PhilipDeegan.
Learnt from: PhilipDeegan
Repo: PHAREHUB/PHARE PR: 888
File: src/hdf5/detail/h5/h5_file.hpp:78-79
Timestamp: 2024-09-05T17:02:58.784Z
Learning: Avoid commenting on draft PRs for the user PhilipDeegan.
Learnt from: PhilipDeegan
Repo: PHAREHUB/PHARE PR: 784
File: tests/simulator/test_restarts.py:333-339
Timestamp: 2024-10-09T08:32:15.667Z
Learning: PhilipDeegan has indicated a preference for minimal and efficient code, even after making changes to get a function working. There may be opportunities to remove or optimize parts of the code such as sleep/wait/advances.
Learnt from: PhilipDeegan
Repo: PHAREHUB/PHARE PR: 784
File: tests/simulator/test_restarts.py:333-339
Timestamp: 2024-07-26T22:04:34.160Z
Learning: PhilipDeegan has indicated a preference for minimal and efficient code, even after making changes to get a function working. There may be opportunities to remove or optimize parts of the code such as sleep/wait/advances.
Learnt from: PhilipDeegan
Repo: PHAREHUB/PHARE PR: 1068
File: src/amr/data/field/coarsening/electric_field_coarsener.hpp:1-2
Timestamp: 2025-09-17T13:35:11.533Z
Learning: PhilipDeegan prefers header guard names that include the full directory path structure, following the pattern PHARE_[PATH_WITH_UNDERSCORES]_HPP. For example, a file at src/amr/data/field/coarsening/electric_field_coarsener.hpp should use PHARE_AMR_DATA_FIELD_COARSENING_ELECTRIC_FIELD_COARSENER_HPP as the header guard.
📚 Learning: 2025-09-01T09:41:40.618Z
Learnt from: PhilipDeegan
Repo: PHAREHUB/PHARE PR: 1056
File: tests/core/numerics/interpolator/test_main.cpp:314-318
Timestamp: 2025-09-01T09:41:40.618Z
Learning: The PHARE project uses C++20, which makes the typename keyword optional for dependent types in obvious contexts. The project prefers minimal code without unnecessary keywords, so typename suggestions for dependent types should be avoided when the code compiles successfully in C++20.

Applied to files:

  • src/amr/resources_manager/resources_manager.hpp
  • src/core/utilities/variants.hpp
📚 Learning: 2025-04-17T14:41:53.643Z
Learnt from: PhilipDeegan
Repo: PHAREHUB/PHARE PR: 998
File: src/core/utilities/point/point.hpp:195-210
Timestamp: 2025-04-17T14:41:53.643Z
Learning: In `src/core/utilities/point/point.hpp`, the `as_signed()` and `as_unsigned()` methods are intentionally designed to cause compilation errors for unsupported types (only 4-byte types are supported). This forces developers to implement proper conversions themselves when extending the functionality to new types. The comment "else no return cause not yet handled" indicates this is a deliberate design choice.

Applied to files:

  • src/core/utilities/variants.hpp
🧬 Code graph analysis (1)
tests/amr/resources_manager/test_resources_manager.cpp (1)
src/core/utilities/variants.hpp (8)
  • get_as_tuple_or_throw (75-101)
  • get_as_tuple_or_throw (75-75)
  • get_as_ref_or_throw (63-70)
  • get_as_ref_or_throw (63-63)
  • get_from_variants (104-117)
  • get_from_variants (104-104)
  • get_from_variants (121-125)
  • get_from_variants (121-122)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
  • GitHub Check: build (macos-14)
  • GitHub Check: build (macos-13)
  • GitHub Check: build (macos-latest)
  • GitHub Check: build (ubuntu-latest, clang)
  • GitHub Check: Analyze (python)
  • GitHub Check: Analyze (cpp)
  • GitHub Check: build (ubuntu-latest, gcc)

@PHAREHUB PHAREHUB deleted a comment from coderabbitai bot Nov 6, 2025
@PHAREHUB PHAREHUB deleted a comment from coderabbitai bot Nov 6, 2025
@PhilipDeegan PhilipDeegan marked this pull request as ready for review November 6, 2025 12:14
@PHAREHUB PHAREHUB deleted a comment from coderabbitai bot Nov 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants