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(gx2f): put parts into separate compile units #3946

Merged
merged 6 commits into from
Dec 6, 2024

Conversation

AJPfleger
Copy link
Contributor

@AJPfleger AJPfleger commented Dec 4, 2024

This reduces the memory impact of the GX2F during compilation by:

  • extracting heavy parts to a separate compile unit
  • removing the templating from the extracted parts (to make them moveable in the first place)

Impact

main:

[    6.03M, max:  1072.02M] [    9.74s] - Core/src/TrackFitting/GlobalChiSquareFitter.cpp
[    7.05M, max:  3364.18M] [   52.19s] - Examples/Algorithms/TrackFitting/src/GlobalChiSquareFitterFunction.cpp
[    6.93M, max:  4196.06M] [   85.36s] - Tests/UnitTests/Core/TrackFitting/Gx2fTests.cpp

after addMeasurementToGx2fSumsBackend:

[    6.04M, max:  1408.93M] [   16.37s] - Core/src/TrackFitting/GlobalChiSquareFitter.cpp
[    6.91M, max:  2299.42M] [   29.93s] - Examples/Algorithms/TrackFitting/src/GlobalChiSquareFitterFunction.cpp
[    6.94M, max:  3269.05M] [   59.98s] - Tests/UnitTests/Core/TrackFitting/Gx2fTests.cpp

after computeGx2fDeltaParams:

[    6.40M, max:  1769.83M] [   20.65s] - Core/src/TrackFitting/GlobalChiSquareFitter.cpp
[    5.94M, max:  1805.96M] [   24.37s] - Examples/Algorithms/TrackFitting/src/GlobalChiSquareFitterFunction.cpp
[    7.23M, max:  2510.50M] [   53.56s] - Tests/UnitTests/Core/TrackFitting/Gx2fTests.cpp

Other discussion on the topic

Performance of dynamic matrix

This still needs investigation. Maybe we can template the functions again on kMeasDims

Untemplate temporary track

This was the first attempt, by using VectorMultiTrajectory for the internal tracks. This fails in Athena, because there the Mutable... is used. This comes in with the calibrator. Currently, it might work with 2 calibrators (one for the fitting Actor and one for the final Actor). Better solution would be to have type-erasure, which might come in the future.

Summary by CodeRabbit

  • New Features

    • Introduced a new method for adding measurement data into the fitting system, enhancing the integration process.
    • Added a function to compute delta parameters for improved clarity in the fitting process.
  • Improvements

    • Streamlined measurement handling and error management within the fitting framework for better efficiency.
    • Enhanced the modularity of the fitting process, improving maintainability and clarity.

@AJPfleger AJPfleger added the 🚧 WIP Work-in-progress label Dec 4, 2024
@AJPfleger AJPfleger added this to the next milestone Dec 4, 2024
Copy link

coderabbitai bot commented Dec 4, 2024

Walkthrough

Significant changes to the GlobalChiSquareFitter.hpp and GlobalChiSquareFitter.cpp files have been made, enhancing the measurement processing and parameter computation within the Global Chi-Square fitting framework. A new function, addMeasurementToGx2fSumsBackend, has been introduced to modularize measurement data integration. The existing function addMeasurementToGx2fSums has been updated to use this new backend function. Additionally, a new function, computeGx2fDeltaParams, has been added to compute delta parameters, improving code clarity and maintainability.

Changes

File Change Summary
Core/include/Acts/TrackFitting/GlobalChiSquareFitter.hpp - Added method: void addMeasurementToGx2fSumsBackend(...)
- Updated method signature: Eigen::VectorXd computeGx2fDeltaParams(...)
Core/src/TrackFitting/GlobalChiSquareFitter.cpp - Added method: void Acts::Experimental::addMeasurementToGx2fSumsBackend(...)
- Added method: Eigen::VectorXd Acts::Experimental::computeGx2fDeltaParams(...)

Possibly related PRs

Suggested labels

Component - Examples, automerge

Suggested reviewers

  • paulgessinger

In the realm of fitting, changes unfold,
New functions emerge, their stories told.
Measurements added, with care and grace,
Delta parameters find their rightful place.
Clarity and structure, a brighter day,
In the dance of data, we find our way! 🌌✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 6b25f66 and 9c64eb7.

📒 Files selected for processing (1)
  • Core/src/TrackFitting/GlobalChiSquareFitter.cpp (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • Core/src/TrackFitting/GlobalChiSquareFitter.cpp

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 Component - Core Affects the Core module Track Fitting labels Dec 4, 2024
Copy link

github-actions bot commented Dec 4, 2024

📊: Physics performance monitoring for ae7b6a0

Full contents

physmon summary

@AJPfleger AJPfleger removed the 🚧 WIP Work-in-progress label Dec 5, 2024
@AJPfleger AJPfleger marked this pull request as ready for review December 5, 2024 14:40
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 (3)
Core/src/TrackFitting/GlobalChiSquareFitter.cpp (2)

60-60: Typo in comment, there is.

On line 60, "First, w try to invert..." should be "First, we try to invert..."


71-71: Assist with TODO, I can.

The comment "// TODO make dimsExtendedParams template with unrolling" indicates a potential improvement. Offer assistance, I do.

Help you implement this templating, would you like? Open a GitHub issue, shall I?

Core/include/Acts/TrackFitting/GlobalChiSquareFitter.hpp (1)

364-380: Detailed documentation, add you should.

For addMeasurementToGx2fSumsBackend, parameter descriptions in the comment block are missing. Consistency in documentation, maintain we must.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between b3933b0 and d08d08d.

📒 Files selected for processing (3)
  • Core/include/Acts/TrackFitting/GlobalChiSquareFitter.hpp (6 hunks)
  • Core/include/Acts/Utilities/AlgebraHelpers.hpp (1 hunks)
  • Core/src/TrackFitting/GlobalChiSquareFitter.cpp (1 hunks)
🔇 Additional comments (4)
Core/src/TrackFitting/GlobalChiSquareFitter.cpp (2)

54-140: Well-structured, your new function is.

The addition of addMeasurementToGx2fSumsBackend enhances modularity and clarity in the code by encapsulating measurement addition logic.


142-146: Clean separation of concerns, achieve you have.

The new function computeGx2fDeltaParams neatly handles delta parameter computation, enhancing code readability.

Core/include/Acts/TrackFitting/GlobalChiSquareFitter.hpp (1)

Line range hint 396-418: Verify parameters passed correctly, you must.

In addMeasurementToGx2fSums, ensure that all necessary parameters are accurately forwarded to addMeasurementToGx2fSumsBackend.

Core/include/Acts/Utilities/AlgebraHelpers.hpp (1)

199-199: Support for dynamic matrices, added you have.

With rows == -1, safeInverse now handles dynamic-sized matrices. Verify this extension does not introduce unexpected behavior.

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 (4)
Core/src/TrackFitting/GlobalChiSquareFitter.cpp (4)

71-71: Hmmmm, template this we must, young padawan.

A TODO comment about making dimsExtendedParams template with unrolling, I see. Wise decision this would be, as compile-time dimensions better than runtime dimensions they are. Memory usage and performance, improve this would.

Help you implement this templated version, shall I? Create a GitHub issue to track this task, I can.


72-73: Careful with dynamic allocation at runtime, you must be.

Zero initialization of large dynamic matrix, I see. Consider reserving capacity beforehand, we should, to prevent multiple reallocations.

-  Eigen::MatrixXd extendedJacobian =
-      Eigen::MatrixXd::Zero(eBoundSize, extendedSystem.nDims());
+  Eigen::MatrixXd extendedJacobian(eBoundSize, extendedSystem.nDims());
+  extendedJacobian.setZero();

114-139: Verbose logging, impact performance it may.

Extensive matrix operations in debug logging, I observe. In production environment, overhead this may cause. Consider guarding expensive operations with debug level check.

-  ACTS_VERBOSE(
+  if (logger.level() <= Acts::Logging::VERBOSE) {
+    ACTS_VERBOSE(
      "Contributions in addMeasurementToGx2fSums:\n"
      // ... existing logging ...
-  );
+    );
+  }

54-146: Well structured the code is, hmmmm.

Successfully separated the heavy matrix operations into distinct compile units, you have. Clean and maintainable, the code has become. Memory impact during compilation, reduced it shall be.

Consider further optimization through:

  • Template specialization for common dimensions
  • Pre-allocation of matrices in performance-critical paths
  • Compile-time constant expressions where possible
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between d08d08d and 6b25f66.

📒 Files selected for processing (1)
  • Core/src/TrackFitting/GlobalChiSquareFitter.cpp (1 hunks)
🔇 Additional comments (1)
Core/src/TrackFitting/GlobalChiSquareFitter.cpp (1)

142-146: 🛠️ Refactor suggestion

Handle matrix singularity, we must.

QR decomposition, reliable it usually is. But prepare for failure, we should. Check rank and condition number, wise it would be.

 Eigen::VectorXd Acts::Experimental::computeGx2fDeltaParams(
     const Acts::Experimental::Gx2fSystem& extendedSystem) {
-  return extendedSystem.aMatrix().colPivHouseholderQr().solve(
-      extendedSystem.bVector());
+  auto solver = extendedSystem.aMatrix().colPivHouseholderQr();
+  if (solver.rank() < extendedSystem.aMatrix().rows()) {
+    throw std::runtime_error("Singular matrix in chi-square fitting detected");
+  }
+  return solver.solve(extendedSystem.bVector());
 }

@paulgessinger
Copy link
Member

One remaining issue with the formatting, aside from this looks good to merge.

Copy link

sonarqubecloud bot commented Dec 6, 2024

@kodiakhq kodiakhq bot merged commit feac686 into acts-project:main Dec 6, 2024
48 checks passed
@github-actions github-actions bot removed the automerge label Dec 6, 2024
@acts-project-service acts-project-service added the Fails Athena tests This PR causes a failure in the Athena tests label Dec 6, 2024
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 Fails Athena tests This PR causes a failure in the Athena tests Track Fitting
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants