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: Disentangle stepper state creation and initialization #4069

Merged
merged 3 commits into from
Feb 5, 2025

Conversation

andiwand
Copy link
Contributor

@andiwand andiwand commented Feb 4, 2025

Disentangles the state creation and initialization for the steppers. This is analog to what is done in the navigator. The idea is that a state can be used for multiple propagations so its creation should be decoupled from the initialization to allow the reuse of the existing state. At the same time resetState is removed as it has no use anymore. initialize will reset and reinitialize the state.

Pulled out of #4036

Summary by CodeRabbit

  • Refactor

    • Redesigned the state management workflow across propagation and tracking features to separate object creation from parameter initialization, resulting in a clearer, more streamlined API.
    • Removed legacy reset mechanisms in favor of explicit initialization methods that accommodate configurable parameters.
  • Tests

    • Updated unit tests to align with the new initialization process, ensuring improved consistency and robustness across propagation-related functionalities.

@andiwand andiwand added this to the next milestone Feb 4, 2025
Copy link

coderabbitai bot commented Feb 4, 2025

Walkthrough

Changed, the code has. The state creation process now split it is into two steps: first by calling makeState(options) without track parameters, then initializing the state with initialize(...). Many steppers (Atlas, Eigen, StraightLine, Sympy) and propagators have been refactored to remove the resetState method and the extra parameter in makeState. Test cases, TrackFinding, and TrackFitting files update accordingly. More clarity in covariance handling, particle hypothesis, and control flow in state management is seen, hmmm.

Changes

Files Change Summary
Core/include/Acts/Propagator/AtlasStepper.hpp, .../EigenStepper.hpp, .../EigenStepper.ipp Removed BoundTrackParameters from makeState; introduced initialize methods; updated covariance and state attribute handling.
Core/include/Acts/Propagator/MultiEigenStepperLoop.hpp Added Component constructor; updated makeState to remove parameter; removed resetState in favor of initialize.
Core/include/Acts/Propagator/Propagator.hpp, .../Propagator.ipp Modified initialize to take initial track parameters; adjusted calls to m_stepper.makeState; refined control flow in state initialization.
Core/include/Acts/Propagator/StepperConcept.hpp Removed requirement for resetState from the CommonStepper concept.
Core/include/Acts/Propagator/StraightLineStepper.hpp, Core/src/Propagator/StraightLineStepper.cpp, Core/include/Acts/Propagator/SympyStepper.hpp, Core/src/Propagator/SympyStepper.cpp Removed makeState overload with extra parameters; replaced with separate initialize methods; removed resetState and adjusted covariance and particle hypothesis handling.
Core/include/Acts/TrackFinding/CombinatorialKalmanFilter.hpp, Core/include/Acts/TrackFitting/KalmanFitter.hpp Updated header inclusions; replaced calls to resetState with initialize; adjusted propagator options and state handling.
Tests/UnitTests/Core/Propagator/* Updated tests to call makeState(options) then initialize(state, parameters); removed direct parameter passing in state creation and reset; adjusted checks accordingly.

Sequence Diagram(s)

sequenceDiagram
    participant Caller as Client/Propagator
    participant Stepper as Stepper Instance
    participant State as State Object

    Caller->>Stepper: makeState(options)
    Stepper-->>Caller: Return empty state
    Caller->>Stepper: initialize(state, parameters)
    Stepper-->>Caller: Return initialized state
Loading

Possibly related PRs

Suggested labels

automerge, SP formation

Suggested reviewers

  • benjaminhuth
  • paulgessinger

Poem

Changes profound, the code now is,
From makeState alone, state creation dismiss.
Initialize it must, with parameters so wise,
ResetState gone, like a shadow it dies.
Code flows clear, as the Force in the skies.
May your commits be strong, and errors compromise not, hmmm.

Tip

🌐 Web search-backed reviews and chat
  • We have enabled web search-based reviews and chat for all users. This feature allows CodeRabbit to access the latest documentation and information on the web.
  • You can disable this feature by setting web_search: false in the knowledge_base settings.
  • Please share any feedback in the Discord discussion.
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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.

Copy link

github-actions bot commented Feb 4, 2025

📊: Physics performance monitoring for bd7a592

Full contents

physmon summary

@andiwand andiwand marked this pull request as ready for review February 5, 2025 10:07
@andiwand andiwand changed the title refactor!: Disentangle stepper state creation and initialization refactor: Disentangle stepper state creation and initialization Feb 5, 2025
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

🧹 Nitpick comments (3)
Core/include/Acts/Propagator/SympyStepper.hpp (1)

120-127: Approve these interface changes, I do. But documentation, we must add.

Split the state creation and initialization, wisely done it is. But document the new methods, we should. Help future padawans understand the purpose of each initialization path, it will.

Add documentation for the new methods:

+/// Create a new state object with the given options
 State makeState(const Options& options) const;

+/// Initialize state with bound track parameters
 void initialize(State& state, const BoundTrackParameters& par) const;

+/// Initialize state with individual components
+/// @param boundParams The bound parameters vector
+/// @param cov Optional covariance matrix
+/// @param particleHypothesis The particle hypothesis
+/// @param surface The reference surface
 void initialize(State& state, const BoundVector& boundParams,
                 const std::optional<BoundMatrix>& cov,
                 ParticleHypothesis particleHypothesis,
                 const Surface& surface) const;
Core/include/Acts/Propagator/EigenStepper.hpp (1)

152-159: Consistent with SympyStepper, these changes are. Approve them, I do.

Follow the same pattern of separate state creation and initialization, EigenStepper does. Consistency across steppers, this brings. Strong with the Force, this design is.

Add documentation similar to SympyStepper, we should:

+/// Create a new state object with the given options
 State makeState(const Options& options) const;

+/// Initialize state with bound track parameters
 void initialize(State& state, const BoundTrackParameters& par) const;

+/// Initialize state with individual components
+/// @param boundParams The bound parameters vector
+/// @param cov Optional covariance matrix
+/// @param particleHypothesis The particle hypothesis
+/// @param surface The reference surface
 void initialize(State& state, const BoundVector& boundParams,
                 const std::optional<BoundMatrix>& cov,
                 ParticleHypothesis particleHypothesis,
                 const Surface& surface) const;
Core/include/Acts/Propagator/Propagator.hpp (1)

389-391: Complete the state initialization changes, this does. Approve it, I do.

Pass the parameters during initialization, the Propagator now does. Work together in harmony with the stepper changes, this does. A balanced approach to state management, we have achieved.

Add documentation to explain the parameters:

+/// Initialize the propagator state with initial parameters
+/// @param state The propagator state to initialize
+/// @param start The initial track parameters
+/// @param path_aborter_t The path aborter type
 template <typename propagator_state_t, typename parameters_t,
           typename path_aborter_t>
 void initialize(propagator_state_t& state, const parameters_t& start) const;
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 51ed39b and bd7a592.

📒 Files selected for processing (19)
  • Core/include/Acts/Propagator/AtlasStepper.hpp (3 hunks)
  • Core/include/Acts/Propagator/EigenStepper.hpp (1 hunks)
  • Core/include/Acts/Propagator/EigenStepper.ipp (1 hunks)
  • Core/include/Acts/Propagator/MultiEigenStepperLoop.hpp (3 hunks)
  • Core/include/Acts/Propagator/Propagator.hpp (1 hunks)
  • Core/include/Acts/Propagator/Propagator.ipp (3 hunks)
  • Core/include/Acts/Propagator/StepperConcept.hpp (0 hunks)
  • Core/include/Acts/Propagator/StraightLineStepper.hpp (1 hunks)
  • Core/include/Acts/Propagator/SympyStepper.hpp (1 hunks)
  • Core/include/Acts/TrackFinding/CombinatorialKalmanFilter.hpp (2 hunks)
  • Core/include/Acts/TrackFitting/KalmanFitter.hpp (3 hunks)
  • Core/src/Propagator/StraightLineStepper.cpp (1 hunks)
  • Core/src/Propagator/SympyStepper.cpp (2 hunks)
  • Tests/UnitTests/Core/Propagator/AtlasStepperTests.cpp (18 hunks)
  • Tests/UnitTests/Core/Propagator/EigenStepperTests.cpp (7 hunks)
  • Tests/UnitTests/Core/Propagator/JacobianTests.cpp (1 hunks)
  • Tests/UnitTests/Core/Propagator/MultiStepperTests.cpp (12 hunks)
  • Tests/UnitTests/Core/Propagator/StraightLineStepperTests.cpp (5 hunks)
  • Tests/UnitTests/Core/Propagator/SympyStepperTests.cpp (7 hunks)
💤 Files with no reviewable changes (1)
  • Core/include/Acts/Propagator/StepperConcept.hpp
🧰 Additional context used
📓 Learnings (1)
Core/include/Acts/TrackFinding/CombinatorialKalmanFilter.hpp (2)
Learnt from: goetzgaycken
PR: acts-project/acts#3825
File: Core/include/Acts/TrackFinding/CombinatorialKalmanFilter.hpp:933-938
Timestamp: 2024-12-02T14:13:24.820Z
Learning: In `Core/include/Acts/TrackFinding/CombinatorialKalmanFilter.hpp`, the overloading of `findTracks` functions is intentional for convenience and not considered code duplication.
Learnt from: goetzgaycken
PR: acts-project/acts#3825
File: Core/include/Acts/TrackFinding/CombinatorialKalmanFilter.hpp:460-467
Timestamp: 2024-12-05T10:58:53.433Z
Learning: In the `Acts` project, within `Core/include/Acts/TrackFinding/CombinatorialKalmanFilter.hpp`, the cache `result.trackStateCandidates` is expected to be empty before calling `createTrackStates` in the function `filter` of `CombinatorialKalmanFilter`.
⏰ Context from checks skipped due to timeout of 90000ms (17)
  • GitHub Check: merge-sentinel
  • GitHub Check: CI Bridge / lcg_105: [alma9, clang16]
  • GitHub Check: CI Bridge / linux_ubuntu_2204
  • GitHub Check: CI Bridge / linux_ubuntu_2204_clang
  • GitHub Check: CI Bridge / lcg_105: [alma9, gcc13]
  • GitHub Check: CI Bridge / build_exatrkx_cpu
  • GitHub Check: CI Bridge / build_linux_ubuntu
  • GitHub Check: CI Bridge / build_exatrkx_cpu
  • GitHub Check: CI Bridge / lcg_105: [alma9, gcc13]
  • GitHub Check: CI Bridge / clang_tidy
  • GitHub Check: CI Bridge / lcg_105: [alma9, clang16]
  • GitHub Check: CI Bridge / linux_ubuntu_2204_clang
  • GitHub Check: CI Bridge / lcg_105: [alma9, gcc13]
  • GitHub Check: CI Bridge / linux_ubuntu_2204
  • GitHub Check: CI Bridge / build_linux_ubuntu
  • GitHub Check: CI Bridge / build_exatrkx
  • GitHub Check: CI Bridge / clang_tidy
🔇 Additional comments (37)
Core/src/Propagator/SympyStepper.cpp (4)

11-11: Include, well-placed it is.
Mmm, needed for track parameter definitions, yes. Necessity satisfied, I sense.


26-29: Creation method streamlined, good it is.
Separate concerns for state creation and initialization, wise you are. Calls to confirm usage throughout the code, verify you should.


31-35: Forwarding constructor, clarity it brings.
Efficient it seems, bridging old signature to the new, yes. The approach, well done.


37-66: Initialization logic, well structured, hmmm.
Separated creation from parameter setup, you have. Good stability and maintainability, the code shall have. Verify edge cases for null or empty covariance you must.

Core/include/Acts/Propagator/EigenStepper.ipp (3)

23-26: Simplified makeState, a quick path to creation it is.
Yes, the clarity is strong here. Minimal, the overhead now.


29-33: Forward initialization, a worthy pattern.
Well does it convey the bound parameters, yes. Maintain consistency with other steppers, you should.


35-66: State initialization, robust it looks.
Reset the counters and covariance checks you do. To uncovered corner cases, remain alert.

Core/include/Acts/Propagator/StraightLineStepper.hpp (3)

116-116: makeState removed from code no longer, it is?
Declared here, but ensure usage or removal consistent across code, you must.


118-118: Public initialize, unify your approach.
Yes, external calls to set up track parameters, simpler they become.


120-123: Optional covariance, flexible design it grants.
Separation of creation and setup in line with other steppers, see I do. Implementation synergy, maintain.

Core/include/Acts/TrackFinding/CombinatorialKalmanFilter.hpp (2)

24-24: New header, introduced you have.
No conflict, I sense. Helpful for the reorganized state management, it is.


373-376: Initialize stepper with filtered data, hmm.
Well-aligned with the new design, these calls are. Verify that reference surfaces never null are, you must.

Core/src/Propagator/StraightLineStepper.cpp (4)

11-11: A new include, see I.
Matches usage of bound parameters, correct it seems. Continue you may.


17-21: State creation well separated, yes.
Clean and readable the logic is, next step is initialization.


23-28: Overloaded initialize bridging parameters, done it has.
A clear transition from short call to expanded usage, consistent it appears.


29-59: Initialize with optional covariance, wise it is.
Handles partial data gracefully, yes. No immediate issues I sense.

Tests/UnitTests/Core/Propagator/JacobianTests.cpp (2)

137-138: Split calls for AtlasStepper, done.
Creation first, then initialize. A new approach, well aligned.


142-143: EigenStepper initialization, mirrored the approach you have.
Safety and clarity the separate steps bring.

Tests/UnitTests/Core/Propagator/StraightLineStepperTests.cpp (3)

82-84: Approve these changes, I do! Cleaner separation of concerns, they bring.

Split the state creation from initialization, we have. Reuse existing state across multiple propagations, this allows. Hmmmm.

Also applies to: 104-104, 110-110


140-141: Consistent implementation throughout the tests, I observe.

Follow the same pattern of separate state creation and initialization, all test cases do. Good practice, this is.

Also applies to: 269-270


242-243: More explicit state initialization, this change brings.

Replaced resetState with initialize, we have. More control over state initialization, this provides. Parameters for covariance and particle hypothesis, now explicitly passed they are.

Tests/UnitTests/Core/Propagator/SympyStepperTests.cpp (1)

172-173: Hmm, consistent the changes are. Approve them, I do!

Split the state creation and initialization have we. A cleaner separation this brings, yes. Follow the new pattern all test cases do:

  1. First create the state with options only
  2. Then initialize it with parameters

Good this refactoring is, matches the PR objectives it does.

Also applies to: 187-188, 224-225, 282-283, 319-322, 341-343, 372-373, 399-403, 457-459, 534-536

Core/include/Acts/Propagator/Propagator.ipp (1)

258-259: Wise this refactoring is, approve it I do!

Separated the concerns have we:

  • State creation with options only
  • State initialization with parameters
  • Clear the responsibilities now are

Match the PR objectives this does, hmm.

Also applies to: 297-298, 398-404

Tests/UnitTests/Core/Propagator/AtlasStepperTests.cpp (1)

113-114: Consistent these changes are, approve them I do!

Follow the new pattern all test cases do:

  1. Create state with options only
  2. Initialize state with parameters separately

Maintain consistency across test suite this does, hmm.

Also applies to: 141-142, 169-170, 189-190, 237-238, 320-321, 358-359, 399-400, 420-422, 457-458, 493-494, 534-536

Core/include/Acts/Propagator/MultiEigenStepperLoop.hpp (4)

202-203: Clear initialization, this constructor brings!

Explicit the component construction now is, hmm. Good practice this follows.


246-249: Simple and focused, the makeState method becomes!

Create state with options only it does. Separate concerns this does, yes.


251-274: Wise the initialization logic is!

Handle all initialization in one place we do:

  • Check for empty components
  • Set particle hypothesis
  • Initialize each component properly
  • Handle covariance transport

Clear and maintainable the code becomes, hmm.


411-414: Consistent with new pattern, this change is!

Use the new Component constructor we do. Match the initialization pattern this does.

Tests/UnitTests/Core/Propagator/MultiStepperTests.cpp (3)

176-177: Approve the separation of state creation and initialization, I do!

Wise changes these are, separating state creation from initialization. Clear and maintainable the code becomes.


210-211: Consistent pattern of separation, I observe!

Follow the same wise path of separation, this test does. Good practices, consistency brings.


246-247: Comprehensive and consistent changes across all tests, I see!

Throughout all test cases, the same pattern of separation flows. Like a well-choreographed lightsaber form, each test follows the same wise principles. Strong and maintainable, the codebase becomes.

Also applies to: 294-295, 333-338, 399-404

Tests/UnitTests/Core/Propagator/EigenStepperTests.cpp (1)

196-197: In harmony with the Force, these changes are!

Like twin suns of Tatooine, makeState and initialize now separate but connected remain. Consistent with other steppers, this implementation is. Well-tested, the changes are.

Also applies to: 212-213, 219-220

Core/include/Acts/Propagator/AtlasStepper.hpp (2)

142-145: Single responsibility, this method now has!

Simple and focused, the makeState method becomes. Create state with options only, it does. Clean and clear, its purpose is.


147-331: Strong with the Force, this implementation is!

Complete and thorough, the initialize methods are. Handle all cases of initialization, they do. Maintain the state's integrity while providing flexibility, they must. A masterful implementation, this is.

Core/include/Acts/TrackFitting/KalmanFitter.hpp (3)

547-550: Hmmmm, proper initialization of stepper state with particle hypothesis, I see.

Wise changes these are, separating state creation from initialization they do. Particle hypothesis from stepper now passed explicitly, more clarity it brings.


1013-1016: Consistent initialization with first track state, it is.

Match the pattern of initialization separation, this change does. Particle hypothesis from stepper, properly passed it is.


1019-1022: For last track state too, consistent initialization maintained is.

The Force is strong with this one. Same pattern of initialization followed here is, maintaining consistency throughout the code.

Copy link
Member

@benjaminhuth benjaminhuth left a comment

Choose a reason for hiding this comment

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

Looks good to me!

@asalzburger asalzburger merged commit 19a4a04 into acts-project:main Feb 5, 2025
45 checks passed
@andiwand andiwand deleted the stepper-initialization branch February 5, 2025 16:57
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.

4 participants