Skip to content

Optimize RAD neighbor search and blocking loop in CodeEntropy pipeline#312

Merged
harryswift01 merged 8 commits intomainfrom
307-general-optimizing-rad-neighbor-search-performance
Apr 9, 2026
Merged

Optimize RAD neighbor search and blocking loop in CodeEntropy pipeline#312
harryswift01 merged 8 commits intomainfrom
307-general-optimizing-rad-neighbor-search-performance

Conversation

@harryswift01
Copy link
Copy Markdown
Member

Summary

This PR introduces initial performance optimisations to the RAD neighbour search used in the entropy calculation pipeline. The changes reduce computational overhead in the RAD blocking loop by eliminating redundant operations, improving periodic boundary handling, and precomputing key quantities, while preserving identical numerical results and deterministic behaviour.

Changes

Precompute and reuse core quantities:

  • Precompute center of mass (COM) coordinates per frame to avoid repeated evaluation
  • Reuse precomputed distance arrays throughout sorting and RAD evaluation
  • Introduce inverse squared distance values to reduce repeated arithmetic operations

Optimise RAD blocking loop:

  • Remove redundant square root computations by using squared distances where possible
  • Reuse existing distance values (r_ij, r_ik) instead of recomputing them
  • Reduce repeated vector operations between triplets of molecules
  • Add early skip condition to avoid unnecessary blocking evaluations

Improve periodic boundary handling:

  • Replace np.where-based periodic boundary corrections with scalar operations inside Numba
  • Introduce a helper function to apply minimum image convention consistently
  • Reduce NumPy overhead within the performance-critical inner loop

Improve memory and execution efficiency:

  • Replace Python list accumulation with a preallocated NumPy array in the Numba loop
  • Move invariant calculations outside inner loops to avoid recomputation
  • Reduce temporary allocations and improve cache locality within the blocking routine

Impact

  • Improves runtime performance of RAD neighbour search, particularly for large systems
  • Reduces overhead in the Numba-compiled blocking loop
  • Maintains identical numerical outputs and deterministic ordering
  • Establishes a more efficient baseline for further RAD-related optimisations

@harryswift01 harryswift01 added this to the 2.1.2 milestone Apr 8, 2026
@harryswift01 harryswift01 requested a review from skfegan April 8, 2026 11:42
@harryswift01 harryswift01 self-assigned this Apr 8, 2026
@harryswift01 harryswift01 added the feature request New feature or request label Apr 8, 2026
@harryswift01 harryswift01 linked an issue Apr 8, 2026 that may be closed by this pull request
@harryswift01 harryswift01 merged commit 6e0bc3e into main Apr 9, 2026
44 of 45 checks passed
@harryswift01 harryswift01 deleted the 307-general-optimizing-rad-neighbor-search-performance branch April 9, 2026 09:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature request New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[General]: Optimizing RAD neighbor search performance

2 participants