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

refactor!: material: double for pathCorrection #3920

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

AJPfleger
Copy link
Contributor

@AJPfleger AJPfleger commented Nov 29, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced precision in material accumulation calculations by updating the pathCorrection parameter type to double.
  • Bug Fixes

    • Improved clarity in calculations by using explicit floating-point division.
  • Refactor

    • Updated method signatures to ensure consistent use of double for related computations, enhancing overall accuracy.

@AJPfleger AJPfleger added this to the next milestone Nov 29, 2024
Copy link

coderabbitai bot commented Nov 29, 2024

Walkthrough

Changes made to the AccumulatedMaterialSlab class involve updating the pathCorrection parameter type from float to double in both the header and implementation files. This adjustment enhances precision in calculations related to material accumulation. The default value for pathCorrection is also modified to 1. from 1. Additionally, related methods now utilize double for calculations involving weights and variances, ensuring consistency in precision across the class.

Changes

File Path Change Summary
Core/include/Acts/Material/AccumulatedMaterialSlab.hpp Method signature updated: void accumulate(MaterialSlab slabAlongTrack, float pathCorrection = 1)void accumulate(MaterialSlab slabAlongTrack, double pathCorrection = 1.)
Core/src/Material/AccumulatedMaterialSlab.cpp Method signatures updated for accumulate and totalVariance to use double instead of float; explicit floating-point division updated.

Poem

In the depths of code, a change did arise,
Precision enhanced, to the coder's surprise.
From float to double, the numbers now dance,
In the realm of math, they take a new stance.
Accumulated wisdom, in every line,
A journey of clarity, oh how divine! ✨


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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

@github-actions github-actions bot added the Component - Core Affects the Core module label Nov 29, 2024
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

🧹 Outside diff range and nitpick comments (3)
Core/src/Material/AccumulatedMaterialSlab.cpp (2)

Line range hint 26-35: Consistency in precision types, maintain we must.

Mixed use of float and double in calculations, I sense. For variance calculation, float you use, but for weights, double you choose. Harmonize these types, we should.

-    float variance = ((1 / m_trackAverage.material().X0()) -
+    double variance = ((1 / m_trackAverage.material().X0()) -
                      (1 / slabReference.material().X0())) *
                     ((1 / m_trackAverage.material().X0()) -
                      (1 / slabReference.material().X0()));

Line range hint 67-71: Return type alignment, crucial it is.

Hmmmm... Return float from method that uses double internally, unwise it is. Precision loss at boundaries, this may cause.

-std::pair<float, unsigned int> Acts::AccumulatedMaterialSlab::totalVariance()
+std::pair<double, unsigned int> Acts::AccumulatedMaterialSlab::totalVariance()
     const {
   return {m_totalVariance, m_totalCount};
 }
Core/include/Acts/Material/AccumulatedMaterialSlab.hpp (1)

49-49: Consider float to double for variance calculations as well, you should.

Notice I do, that while pathCorrection now uses double precision, m_totalVariance still uses float. For consistency in precision throughout calculations, suggest changing m_totalVariance to double as well, I do.

Apply this change, you should:

  /// Averaged properties over multiple tracks.
  MaterialSlab m_totalAverage;
  /// Averaged variance over multiple tracks.
- float m_totalVariance = 0.0;
+ double m_totalVariance = 0.0;

And update the return type in totalVariance():

- std::pair<float, unsigned int> totalVariance() const;
+ std::pair<double, unsigned int> totalVariance() const;

Also applies to: 94-94

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 9c9444e and 4537996.

📒 Files selected for processing (2)
  • Core/include/Acts/Material/AccumulatedMaterialSlab.hpp (1 hunks)
  • Core/src/Material/AccumulatedMaterialSlab.cpp (1 hunks)
🔇 Additional comments (2)
Core/include/Acts/Material/AccumulatedMaterialSlab.hpp (2)

49-49: Approve the path correction parameter type change, I do!

Wise decision it is, to use double precision for pathCorrection. In physics calculations, more precise we must be! Hmmmm.


49-49: Verify impact on dependent code, we must.

Changed parameter type may affect code that calls this method. Check we must, that all callers handle double precision correctly.

✅ Verification successful

Hmm, safe the change is. Verified our concerns are.

Through the Force, searched the codebase I have. Found many calls to accumulate, but all pass MaterialSlab as first parameter they do. The second parameter pathCorrection, optional it remains with default value of 1.

In AccumulatedMaterialSlab.hpp, changed parameter type affects not the interface - double precision already used it was:

void accumulate(MaterialSlab slabAlongTrack, double pathCorrection = 1.);

All callers throughout codebase, proper double precision they use:

  • In AccumulatedSurfaceMaterial.cpp, correct double pathCorrection passed it is
  • In test files like AccumulatedMaterialSlabTests.cpp, proper usage shown it is
  • In material mapping code, correctly handled the types are

Clear it is, that change breaks nothing. Safe to proceed, we are.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for calls to accumulate method
rg -A 2 "accumulate\s*\([^)]*\)" --type cpp

Length of output: 17062

Core/src/Material/AccumulatedMaterialSlab.cpp Show resolved Hide resolved
Copy link

github-actions bot commented Nov 29, 2024

📊: Physics performance monitoring for decff69

Full contents

physmon summary

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 (2)
Core/src/Material/AccumulatedMaterialSlab.cpp (2)

Line range hint 67-70: Return type, change it we must.

Still returning float for variance, but calculations in double we do. Consistency in the force, maintain we shall.

Apply this change:

-std::pair<float, unsigned int> Acts::AccumulatedMaterialSlab::totalVariance()
+std::pair<double, unsigned int> Acts::AccumulatedMaterialSlab::totalVariance()

Line range hint 1-70: Path to consistent precision, clear it must be.

Throughout the codebase, a systematic approach to floating-point precision, needed it is. Consider these steps:

  1. Document precision requirements in coding guidelines
  2. Create migration plan for remaining float usage
  3. Add static analysis rules to prevent mixing precisions

Strong with the Force this change is, but complete the journey we must.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 4537996 and 7d9919a.

📒 Files selected for processing (1)
  • Core/src/Material/AccumulatedMaterialSlab.cpp (1 hunks)
🔇 Additional comments (3)
Core/src/Material/AccumulatedMaterialSlab.cpp (3)

Line range hint 24-36: Mixed precision calculations, troubling they are.

Float for X0 calculations but double for weights, confusion this brings. Consistent precision throughout the force, maintain we must.

Suggest these changes, I do:

-    float variance = ((1 / m_trackAverage.material().X0()) -
+    double variance = ((1. / m_trackAverage.material().X0()) -
                      (1 / slabReference.material().X0())) *
                     ((1 / m_trackAverage.material().X0()) -
                      (1 / slabReference.material().X0()));

Line range hint 44-61: Wise implementation, this is.

Consistent use of double precision for weights, good practices it follows. Approve this part, I do.


15-15: ⚠️ Potential issue

Precision loss in the force, I sense.

Converting pathCorrection to float in scaleThickness, defeats the purpose of double precision it does. Maintain consistent precision throughout the calculations, we must.

Apply this change, you should:

-  slab.scaleThickness(static_cast<float>(1. / pathCorrection));
+  slab.scaleThickness(1. / pathCorrection);

Hmmmm, but first verify MaterialSlab's thickness type, we must.

Also applies to: 18-18

@AJPfleger AJPfleger modified the milestones: next, v39.0.0 Nov 30, 2024
@github-actions github-actions bot added the Stale label Jan 3, 2025
@github-actions github-actions bot removed the Stale label Jan 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component - Core Affects the Core module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants