Skip to content
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

tagging better #903

Merged
merged 5 commits into from
Oct 18, 2024
Merged

tagging better #903

merged 5 commits into from
Oct 18, 2024

Conversation

nicolasaunai
Copy link
Member

@nicolasaunai nicolasaunai commented Oct 12, 2024

This PR fixes the tagging formula by adding the missing absolute value at the denominator.

Results below were obtained with this diff on top of #893

current master formula (also in the paper) leads to this refinement if increasing the threshold

image

clearly the two current layers being similar in terms of scales and magnetic jump they should be refined the same way.
This comes from the absolute value missing in the denominator that makes the positive and negative derivatives of B leading to different values of tagging formula hence difference response to the thresholding.

adding the absolute value and testing it for different tagging thresholds leads to

image

Which behaves better, see the pic above that tested the same configuration as above for different thresholds:

  • at 0.8 there is no refinement
  • at 0.6 there is L1 but no L2
  • at 0.4 there is an L2 mapping the 2 current layers
  • at 0.1, things are a bit similar to 0.4
  • at 0.05 L1 remains about the same, but L2 grows a bit, there are more patches
  • at 0.01, L1 becomes wider, there is almost no space in between the two current sheets that is not refined
  • at 0.001 L2 is larger and L1 occupies all space in between the current layers.

Summary by CodeRabbit

  • Bug Fixes

    • Improved stability of magnetic field calculations in the tagging process, reducing the risk of division by zero.
  • New Features

    • Enhanced logic for tagging in 2D scenarios, ensuring more accurate results based on field differences.
    • Updated build configuration for improved optimization in the SAMRAI project, including changes to build type and compiler flags.

Copy link

coderabbitai bot commented Oct 12, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The changes in this pull request focus on the DefaultHybridTaggerStrategy class within the src/amr/tagging/default_hybrid_tagger_strategy.hpp file. The primary modification involves the field_diff lambda function in the tag method, specifically adjusting the return statement to compute absolute differences for the magnetic field components separately and normalize them. The overall structure of the tag method and its handling of tagging criteria remain unchanged.

Changes

File Path Change Summary
src/amr/tagging/default_hybrid_tagger_strategy.hpp Updated the field_diff lambda function in the tag method to explicitly calculate absolute differences for 2D magnetic field components. No changes to method signatures or public entities.
.github/workflows/cmake_ubuntu.yml Modified GitHub Actions workflow to change CMake build type from RelWithDebInfo to Debug and updated compiler flags to include -O3.

Possibly related PRs

  • tagging thresholds from python #879: The changes in the DefaultHybridTaggerStrategy class regarding the handling of thresholds are related to the modifications in the tagging functionality introduced in the simulation.py file, which also involves tagging thresholds.

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 3a96bbd and 072909d.

📒 Files selected for processing (2)
  • .github/workflows/cmake_ubuntu.yml (1 hunks)
  • src/amr/tagging/default_hybrid_tagger_strategy.hpp (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • .github/workflows/cmake_ubuntu.yml
  • src/amr/tagging/default_hybrid_tagger_strategy.hpp

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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

🧹 Outside diff range and nitpick comments (1)
src/amr/tagging/default_hybrid_tagger_strategy.hpp (1)

111-114: Consider refactoring field_diff for better readability

To improve code readability, consider assigning intermediate calculations to named variables within the field_diff lambda function. This will make the code easier to understand and maintain.

Apply the following diff to refactor the code:

 auto field_diff = [&](auto const& F) //
 {
+    auto delta_x = F(ix + 2, iy) - F(ix, iy);
+    auto delta_x_prev = F(ix + 1, iy) - F(ix, iy);
+    auto criter_x = std::abs(delta_x) / (1 + std::abs(delta_x_prev));
+
+    auto delta_y = F(ix, iy + 2) - F(ix, iy);
+    auto delta_y_prev = F(ix, iy + 1) - F(ix, iy);
+    auto criter_y = std::abs(delta_y) / (1 + std::abs(delta_y_prev));
+
-    return std::make_tuple(std::abs((F(ix + 2, iy) - F(ix, iy))
-                                    / (1 + std::abs(F(ix + 1, iy) - F(ix, iy)))),
-                           std::abs(F(ix, iy + 2) - F(ix, iy))
-                               / (std::abs(F(ix, iy + 1) - F(ix, iy)) + 1));
+    return std::make_tuple(criter_x, criter_y);
 };
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 356720a and d16001e.

📒 Files selected for processing (1)
  • src/amr/tagging/default_hybrid_tagger_strategy.hpp (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
src/amr/tagging/default_hybrid_tagger_strategy.hpp (1)

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

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

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 7c3cd75 and 3a96bbd.

📒 Files selected for processing (2)
  • .github/workflows/cmake_ubuntu.yml (1 hunks)
  • src/amr/tagging/default_hybrid_tagger_strategy.hpp (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/amr/tagging/default_hybrid_tagger_strategy.hpp
🧰 Additional context used
📓 Learnings (1)
.github/workflows/cmake_ubuntu.yml (1)
Learnt from: PhilipDeegan
PR: PHAREHUB/PHARE#898
File: .github/workflows/cmake_ubuntu.yml:81-85
Timestamp: 2024-10-15T16:27:04.609Z
Learning: In this project, the `RelWithDebInfo` build type includes `-DNDEBUG`, which disables asserts. To keep asserts enabled while having some optimizations, the `Debug` build type is used with the `-O3` optimization flag.
🔇 Additional comments (1)
.github/workflows/cmake_ubuntu.yml (1)

77-77: Approved: SAMRAI build type change to Debug

Changing the SAMRAI build type from RelWithDebInfo to Debug aligns with the project's goal of keeping asserts enabled. This is beneficial for debugging and catching potential issues during development.

However, it's important to monitor the performance impact of this change. Consider running the following command to compare build times:

make -j2 && sudo make install && cd ../.. && rm -rf samrai
cd ${{runner.workspace}}/build && rm -rf *
cmake $GITHUB_WORKSPACE -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON --fresh \
-DCMAKE_BUILD_TYPE=RelWithDebInfo -Dasan=OFF \
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
-DlowResourceTests=ON -DdevMode=ON -Dbench=ON \
-DCMAKE_CXX_FLAGS="-DPHARE_DIAG_DOUBLES=1 " -Dphare_configurator=ON
-DCMAKE_CXX_FLAGS="-O3 -DPHARE_DIAG_DOUBLES=1 " -Dphare_configurator=ON
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Reconsider the combination of Debug build type with -O3 optimization

The addition of the -O3 flag to CMAKE_CXX_FLAGS while using Debug build type is unusual and potentially problematic. This combination can lead to unexpected behavior as Debug builds typically include minimal optimizations to aid in debugging, while -O3 applies aggressive optimizations.

Consider one of the following alternatives:

  1. Remove the -O3 flag to maintain a true Debug build:
-              -DCMAKE_CXX_FLAGS="-O3 -DPHARE_DIAG_DOUBLES=1 " -Dphare_configurator=ON
+              -DCMAKE_CXX_FLAGS="-DPHARE_DIAG_DOUBLES=1 " -Dphare_configurator=ON
  1. Create a custom build type that enables both debugging symbols and optimizations:
-              -DCMAKE_BUILD_TYPE=RelWithDebInfo -Dasan=OFF \
+              -DCMAKE_BUILD_TYPE=CustomDebug -Dasan=OFF \
+              -DCMAKE_CXX_FLAGS_CUSTOMDEBUG="-g -O2 -DPHARE_DIAG_DOUBLES=1" \

This approach allows you to define a build type that suits your specific needs.

Committable suggestion was skipped due to low confidence.

@nicolasaunai nicolasaunai merged commit a69bcf0 into PHAREHUB:master Oct 18, 2024
12 checks passed
UCaromel pushed a commit to UCaromel/PHARE that referenced this pull request Jan 6, 2025
fix tagging (missing absolute value)
UCaromel pushed a commit to UCaromel/PHARE that referenced this pull request Jan 13, 2025
fix tagging (missing absolute value)
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