Skip to content

Conversation

@Guo-astro
Copy link
Contributor

Summary

Use existing SerialPatchTreeRefEdge from shamrock/solvergraph/ to register the serial patch tree in the solver graph for explicit data dependency tracking.

Part of GSPH solvergraph migration (1 object per PR per maintainer request).

Changes:

  • Add solver_graph and serial_patch_tree_ref edge to SolverStorage
  • Register edge in init_solver_graph()
  • Set reference in gen_serial_patch_tree() after tree is built
  • Clear reference in reset_serial_patch_tree()

The tree storage remains as Component<SerialPatchTree<Tvec>> while the solvergraph edge holds a reference for dependency tracking.

Test plan

  • Build passes
  • GSPH Sod shock tube test passes

Use existing SerialPatchTreeRefEdge from shamrock/solvergraph/
to register the serial patch tree in the solver graph for explicit
data dependency tracking.

Changes:
- Add solver_graph and serial_patch_tree_ref edge to SolverStorage
- Register edge in init_solver_graph()
- Set reference in gen_serial_patch_tree() after tree is built
- Clear reference in reset_serial_patch_tree()

The tree storage remains as Component<SerialPatchTree<Tvec>> while
the solvergraph edge holds a reference for dependency tracking.
@github-actions
Copy link
Contributor

Thanks @Guo-astro for opening this PR!

You can do multiple things directly here:
1 - Comment pre-commit.ci run to run pre-commit checks.
2 - Comment pre-commit.ci autofix to apply fixes.
3 - Add label autofix.ci to fix authorship & pre-commit for every commit made.
4 - Add label light-ci to only trigger a reduced & faster version of the CI (need the full one before merge).
5 - Add label trigger-ci to create an empty commit to trigger the CI.

Once the workflow completes a message will appear displaying informations related to the run.

Also the PR gets automatically reviewed by gemini, you can:
1 - Comment /gemini review to trigger a review
2 - Comment /gemini summary for a summary
3 - Tag it using @gemini-code-assist either in the PR or in review comments on files

@gemini-code-assist
Copy link

Summary of Changes

Hello @Guo-astro, 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 integrates the serial patch tree into the solver graph framework, a crucial step in the GSPH solvergraph migration. By introducing a dedicated reference edge, the system can now explicitly track data dependencies related to the serial patch tree, enhancing the overall data flow management and consistency within the solver. This change lays the groundwork for more robust and transparent data handling in future solver operations.

Highlights

  • SolverGraph Integration: The SerialPatchTreeRefEdge from shamrock/solvergraph/ is now used to register the serial patch tree within the solver graph, enabling explicit data dependency tracking.
  • SolverStorage Updates: The SolverStorage class has been extended to include a solver_graph instance and a serial_patch_tree_ref edge for managing the serial patch tree's lifecycle within the graph.
  • Lifecycle Management: The init_solver_graph() method now registers the serial_patch_tree_ref edge, gen_serial_patch_tree() sets the reference to the newly built tree, and reset_serial_patch_tree() clears this reference, ensuring proper resource management.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions
Copy link
Contributor

Workflow report

workflow report corresponding to commit 30a341a
Commiter email is guo.yansong.ngy@gmail.com

Pre-commit check report

Some failures were detected in base source checks checks.
Check the On PR / Linting / Base source checks (pull_request) job in the tests for more detailled output

Suggested changes

Detailed changes :
diff --git a/src/shammodels/gsph/src/Solver.cpp b/src/shammodels/gsph/src/Solver.cpp
index bdc7d8df..99f8c91a 100644
--- a/src/shammodels/gsph/src/Solver.cpp
+++ b/src/shammodels/gsph/src/Solver.cpp
@@ -129,7 +129,8 @@ void shammodels::gsph::Solver<Tvec, Kern>::gen_serial_patch_tree() {
     storage.serial_patch_tree.set(std::move(_sptree));
 
     // Set solvergraph edge reference to the stored tree
-    shambase::get_check_ref(storage.serial_patch_tree_ref).patch_tree = storage.serial_patch_tree.get();
+    shambase::get_check_ref(storage.serial_patch_tree_ref).patch_tree
+        = storage.serial_patch_tree.get();
 }
 
 template<class Tvec, template<class> class Kern>

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request integrates the SerialPatchTree with the solvergraph for dependency tracking by introducing a SerialPatchTreeRefEdge. The changes correctly add the new solvergraph edge, register it, and manage its lifecycle by setting the reference after tree creation and clearing it before destruction. A critical concern has been raised regarding a potential memory management bug. The method free_alloc() is called on a non-owning reference wrapper, which could lead to a double-free if it deallocates the raw pointer it holds. A detailed comment has been provided on this potential issue. Apart from this concern, the changes look correct and align with the PR's objective.

Comment on lines +92 to +95
inline void reset_serial_patch_tree() {
shambase::get_check_ref(storage.serial_patch_tree_ref).free_alloc();
storage.serial_patch_tree.reset();
}

Choose a reason for hiding this comment

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

critical

The use of free_alloc() on serial_patch_tree_ref is concerning. SerialPatchTreeRefEdge holds a non-owning raw pointer (patch_tree) to an object managed by storage.serial_patch_tree. The name free_alloc strongly implies deallocation. If this method attempts to delete the raw pointer, it will lead to a double-free when storage.serial_patch_tree is reset, which is a critical memory corruption bug.

If the intention of free_alloc() is simply to nullify the internal pointer (e.g., patch_tree = nullptr;), the method is dangerously misnamed and should be renamed to something like clear_reference() or reset() to avoid confusion and prevent future misuse.

Given the potential for a critical bug, please verify the implementation of SerialPatchTreeRefEdge::free_alloc() and consider renaming it for clarity and safety.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants