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!: Remove MagneticFieldProvider::getFieldGradient #3983

Merged
merged 3 commits into from
Jan 8, 2025

Conversation

andiwand
Copy link
Contributor

@andiwand andiwand commented Dec 13, 2024

Remove MagneticFieldProvider::getFieldGradient after discussions as it is not used anywhere.


previously:

  • Remove output param
  • Return Result<std::pair<Vector3, SquareMatrix3>> instead of Result<Vector3>
  • Actually implement this function correctly

pulled out of #3951

Summary by CodeRabbit

Release Notes

  • Refactor

    • Removed getFieldGradient method from multiple magnetic field classes, streamlining their interfaces.
    • Updated destructor implementation in MagneticFieldProvider for simplification.
  • Chores

    • Cleaned up unused header file inclusions.
    • Removed unimplemented gradient calculation methods.

The changes primarily focus on enhancing the clarity and usability of the magnetic field-related code by eliminating incomplete functionality.

@andiwand andiwand added this to the v39.0.0 milestone Dec 13, 2024
Copy link

coderabbitai bot commented Dec 13, 2024

## Walkthrough

In this pull request, the Acts library undergoes a systematic removal of the `getFieldGradient` method across multiple magnetic field classes. The changes span several files in the Core, Plugins, and Examples directories, focusing on simplifying the magnetic field provider interfaces. The modifications primarily involve eliminating an unimplemented method that was intended to calculate magnetic field gradients but was not fully developed.

## Changes

| File | Change Summary |
|------|----------------|
| `Core/include/Acts/MagneticField/*.hpp` | Removed `getFieldGradient` method from `ConstantBField`, `InterpolatedBFieldMap`, `MagneticFieldProvider`, `MultiRangeBField`, `NullBField`, `SolenoidBField` |
| `Plugins/DD4hep/include/Acts/Plugins/DD4hep/DD4hepFieldAdapter.hpp` | Removed `getFieldGradient` method |
| `Examples/Detectors/MagneticField/include/ActsExamples/MagneticField/ScalableBField.hpp` | Removed `getFieldGradient` method |
| `Tests/UnitTests/Core/MagneticField/InterpolatedBFieldMapTests.cpp` | Removed related test checks for gradient |

## Possibly related PRs

- **#3927**: Removal of `getFieldGradient` method from multiple classes.
- **#3982**: Cleanup of `InterpolatedBFieldMap` class.

## Suggested labels

`automerge`, `Vertexing`

## Suggested reviewers

- paulgessinger

## Poem

> Magnetic fields, once complex and grand,  
> Gradients vanish like sand through hand.  
> Simplicity calls, methods fade away,  
> Code becomes clearer with each passing day.  
> 🧲✨ Farewell, unused gradient, be free!

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 98b5f3b and b0a3f96.

📒 Files selected for processing (3)
  • Core/include/Acts/MagneticField/ConstantBField.hpp (0 hunks)
  • Core/include/Acts/MagneticField/NullBField.hpp (2 hunks)
  • Tests/UnitTests/Core/MagneticField/InterpolatedBFieldMapTests.cpp (0 hunks)
💤 Files with no reviewable changes (2)
  • Core/include/Acts/MagneticField/ConstantBField.hpp
  • Tests/UnitTests/Core/MagneticField/InterpolatedBFieldMapTests.cpp
🚧 Files skipped from review as they are similar to previous changes (1)
  • Core/include/Acts/MagneticField/NullBField.hpp
⏰ Context from checks skipped due to timeout of 90000ms (14)
  • GitHub Check: CI Bridge / linux_ubuntu_2204
  • GitHub Check: CI Bridge / build_linux_ubuntu
  • GitHub Check: CI Bridge / build_exatrkx
  • GitHub Check: CI Bridge / build_exatrkx_cpu
  • GitHub Check: merge-sentinel
  • GitHub Check: CI Bridge / clang_tidy
  • GitHub Check: unused_files
  • GitHub Check: linux_ubuntu_extra (ubuntu2204_clang, 20)
  • GitHub Check: linux_ubuntu_extra (ubuntu2204, 20)
  • GitHub Check: macos
  • GitHub Check: build_debug
  • GitHub Check: linux_ubuntu
  • GitHub Check: missing_includes
  • GitHub Check: docs

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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 Component - Core Affects the Core module Component - Examples Affects the Examples module Component - Plugins Affects one or more Plugins labels Dec 13, 2024
@andiwand
Copy link
Contributor Author

alternatively we could drop this function as it is not used anywhere

@andiwand andiwand changed the title refactor!: Remove output parameter from `MagneticFieldProvider::getFi… refactor!: Remove output parameter from MagneticFieldProvider::getFieldGradient Dec 13, 2024
Copy link

github-actions bot commented Dec 13, 2024

📊: Physics performance monitoring for b0a3f96

Full contents

physmon summary

@andiwand andiwand marked this pull request as ready for review December 17, 2024 14:40
@paulgessinger
Copy link
Member

@andiwand I'm wondering if dropping might be the better idea for now.

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 comments (1)
Core/src/MagneticField/SolenoidBField.cpp (1)

Incomplete test coverage for mathematical formulas, I sense. Hmmmm.

Missing, crucial test cases are:

  • Validation of k2 function behavior, there must be
  • Mathematical accuracy against known solutions, we need
  • Tests for extreme values of z and r, essential they are
  • Edge case r = 0, though handled in code, explicit tests require we do
🔗 Analysis chain

Line range hint 89-156: Test the mathematical implementation thoroughly, we must.

Complex mathematical formulas, these functions contain. Yet, unit tests for edge cases, I see not.

Run this script to check for existing tests:

Consider adding tests for:

  • Edge case r = 0
  • Large z values
  • Various combinations of r and z

Help you write comprehensive test cases, shall I?

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for test cases covering mathematical edge cases
rg -l "SolenoidBField.*test" 
rg "B_r|B_z|k2.*test" 

Length of output: 7234


Script:

#!/bin/bash
# Extract test ranges and specific test cases
echo "=== Test Ranges and Cases ==="
rg "for.*r.*=|for.*z.*=" Tests/UnitTests/Core/MagneticField/SolenoidBFieldTests.cpp -A 2
echo -e "\n=== Edge Case Tests ==="
rg "r.*=.*0|z.*=.*0" Tests/UnitTests/Core/MagneticField/SolenoidBFieldTests.cpp
echo -e "\n=== k2 Function Tests ==="
rg "k2.*test|CHECK.*k2" Tests/UnitTests/Core/MagneticField/SolenoidBFieldTests.cpp

Length of output: 1380

🧹 Nitpick comments (3)
Core/include/Acts/MagneticField/NullBField.hpp (1)

36-36: Elegant simplification, achieved you have!

Direct return of Zero vector, more efficient it is. Removed the need for member variable, you have. Strong with the Force, this change is.

Consider marking method as [[nodiscard]] you should:

-  Result<Vector3> getField(const Vector3& position,
+  [[nodiscard]] Result<Vector3> getField(const Vector3& position,
Core/include/Acts/MagneticField/MultiRangeBField.hpp (1)

Line range hint 1-60: Complete removal of getFieldGradient, consider we must!

Unused in the codebase, this function remains. If no plans for gradient calculations exist, remove all traces of it, we should. Create new PR for this purpose, you could.

Create GitHub issue for complete removal, shall I? Track remaining references and ensure clean deletion, we must.

Core/src/MagneticField/MultiRangeBField.cpp (1)

Line range hint 32-67: Document the caching mechanism better, we should.

Complex, this caching mechanism is. Help future Padawans understand it better, additional documentation would. Consider adding:

  • Performance characteristics
  • Cache invalidation scenarios
  • Example of cache hit/miss scenarios
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2d5ed72 and 98b5f3b.

📒 Files selected for processing (12)
  • Core/include/Acts/MagneticField/ConstantBField.hpp (0 hunks)
  • Core/include/Acts/MagneticField/InterpolatedBFieldMap.hpp (0 hunks)
  • Core/include/Acts/MagneticField/MagneticFieldProvider.hpp (1 hunks)
  • Core/include/Acts/MagneticField/MultiRangeBField.hpp (2 hunks)
  • Core/include/Acts/MagneticField/NullBField.hpp (1 hunks)
  • Core/include/Acts/MagneticField/SolenoidBField.hpp (0 hunks)
  • Core/src/MagneticField/MultiRangeBField.cpp (1 hunks)
  • Core/src/MagneticField/SolenoidBField.cpp (1 hunks)
  • Examples/Detectors/MagneticField/include/ActsExamples/MagneticField/ScalableBField.hpp (1 hunks)
  • Plugins/DD4hep/include/Acts/Plugins/DD4hep/DD4hepFieldAdapter.hpp (1 hunks)
  • Plugins/DD4hep/src/DD4hepFieldAdapter.cpp (0 hunks)
  • Tests/UnitTests/Core/MagneticField/InterpolatedBFieldMapTests.cpp (0 hunks)
💤 Files with no reviewable changes (5)
  • Plugins/DD4hep/src/DD4hepFieldAdapter.cpp
  • Core/include/Acts/MagneticField/SolenoidBField.hpp
  • Tests/UnitTests/Core/MagneticField/InterpolatedBFieldMapTests.cpp
  • Core/include/Acts/MagneticField/ConstantBField.hpp
  • Core/include/Acts/MagneticField/InterpolatedBFieldMap.hpp
⏰ Context from checks skipped due to timeout of 90000ms (11)
  • GitHub Check: CI Bridge / lcg_106a: [alma9, gcc14]
  • GitHub Check: CI Bridge / lcg_106a: [alma9, clang16]
  • GitHub Check: CI Bridge / lcg_106a: [alma9, gcc13]
  • GitHub Check: CI Bridge / lcg_105: [alma9, clang16]
  • GitHub Check: CI Bridge / lcg_105: [alma9, gcc13]
  • GitHub Check: CI Bridge / linux_ubuntu_2204_clang
  • GitHub Check: CI Bridge / linux_ubuntu_2204
  • GitHub Check: CI Bridge / build_linux_ubuntu
  • GitHub Check: CI Bridge / build_exatrkx
  • GitHub Check: CI Bridge / build_exatrkx_cpu
  • GitHub Check: CI Bridge / clang_tidy
🔇 Additional comments (7)
Plugins/DD4hep/include/Acts/Plugins/DD4hep/DD4hepFieldAdapter.hpp (1)

11-11: Approve, I do, the addition of Algebra header!

Necessary for Vector3 usage, this inclusion is. Clean and proper, the dependency management appears.

Core/include/Acts/MagneticField/MagneticFieldProvider.hpp (1)

45-45: Simplified the destructor has become, hmmmm!

Wise choice it is, to use default destructor. Virtual remains it does, protecting derived classes still. Clean and efficient, the way of the Force this is.

Run this command to ensure no custom destructors in derived classes rely on this:

✅ Verification successful

Safe the default destructor is, hmmmm! Verified this change has been.

All derived classes, using default destructors they are. No custom cleanup needed, the Force is balanced. Final classes, most of them are - wisdom in design, this shows.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for custom destructors in magnetic field providers
rg "~\w+BField\b.*\{" --type cpp

Length of output: 34


Script:

#!/bin/bash
# Search for classes inheriting from MagneticFieldProvider
ast-grep --pattern 'class $_ : $$$MagneticFieldProvider$$$'

# Also search for potential destructors with different naming patterns
rg "~\w+(?:Field|Map|Provider)\b.*\{" --type cpp -A 2

Length of output: 117


Script:

#!/bin/bash
# Search for virtual destructors in Acts headers
fd '\.hpp$' Core/include/Acts | xargs rg "virtual\s+~.*\{" -A 2

# Also search for class declarations with MagneticFieldProvider
fd '\.hpp$' Core/include/Acts | xargs rg "class.*MagneticFieldProvider" -A 5

Length of output: 3362

Core/include/Acts/MagneticField/MultiRangeBField.hpp (1)

10-14: Balanced the Force is, in these header changes!

Removed MagneticFieldError.hpp, added Algebra.hpp you have. Clean dependencies, maintain we must.

Verify the header dependencies, we should:

✅ Verification successful

Correct these header changes are, hmmmm!

In balance with the Force, these modifications stand:

  • MagneticFieldError.hpp, to implementation file moved it was, where it belongs
  • Algebra.hpp, required it is, for Vector3 in public interface
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if MagneticFieldError.hpp is still needed
rg "MagneticFieldError" --type cpp

# Verify Vector3 usage requiring Algebra.hpp
rg "Vector3" "Core/include/Acts/MagneticField/MultiRangeBField.hpp"

Length of output: 2181

Core/src/MagneticField/MultiRangeBField.cpp (1)

11-11: Proper error handling, you have added! Hmmmm.

A wise addition this include is, enabling proper error reporting when field bounds are exceeded.

Examples/Detectors/MagneticField/include/ActsExamples/MagneticField/ScalableBField.hpp (1)

90-90: Clean and focused, this interface has become.

Removed the unused gradient functionality, we have. Simpler and more maintainable, the code now is.

Core/src/MagneticField/SolenoidBField.cpp (2)

11-11: Proper error handling, added you have.

Wise decision to include error handling capabilities, this is.


Line range hint 1-1: Verify unused status of removed functionality, we must.

Removed getFieldGradient has been, but verify its unused status throughout the codebase, we should.

Run this script to confirm no remaining usage:

✅ Verification successful

Confirmed, the removal of getFieldGradient is, hmm!

Through the Force, searched the entire codebase we have. No remaining traces of the field gradient functionality exist. Other gradient functions, different purposes they serve - material gradients and color gradients, separate paths they follow.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining references to getFieldGradient
rg "getFieldGradient"

# Search for potential method calls that might have used this functionality
ast-grep --pattern 'getFieldGradient($$$)'

Length of output: 66


Script:

#!/bin/bash
# Search with case variations and partial matches
rg -i "field.*gradient"
rg -i "gradient.*field"

# Search specifically in header files
fd -e h -e hpp -x rg -i "gradient" {}

# Look for potential field gradient calculations
ast-grep --pattern 'gradient($$$)'
ast-grep --pattern 'field($$$gradient$$$)'

Length of output: 614

@andiwand andiwand requested a review from paulgessinger January 8, 2025 08:45
@andiwand andiwand changed the title refactor!: Remove output parameter from MagneticFieldProvider::getFieldGradient refactor!: Remove MagneticFieldProvider::getFieldGradient Jan 8, 2025
@acts-project-service acts-project-service added the Breaks Athena build This PR breaks the Athena build label Jan 8, 2025
@andiwand andiwand added automerge and removed Breaks Athena build This PR breaks the Athena build labels Jan 8, 2025
@kodiakhq kodiakhq bot merged commit 31388e4 into acts-project:main Jan 8, 2025
53 of 54 checks passed
@github-actions github-actions bot removed the automerge label Jan 8, 2025
@andiwand andiwand deleted the refactor-magfield-return-grad branch January 8, 2025 10:27
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 Component - Examples Affects the Examples module Component - Plugins Affects one or more Plugins
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants