Skip to content

Fix bug due to rounding errors in periodicity computation#146

Open
efaulhaber wants to merge 5 commits into
mainfrom
ef/fix-periodicity
Open

Fix bug due to rounding errors in periodicity computation#146
efaulhaber wants to merge 5 commits into
mainfrom
ef/fix-periodicity

Conversation

@efaulhaber

@efaulhaber efaulhaber commented Mar 17, 2026

Copy link
Copy Markdown
Member

On main, we first computed the periodic continuous coordinates and then converted to discrete cell coordinates. The first computation introduces rounding errors, sometimes resulting in coordinates outside the periodic box, which will then be converted to discrete cell coordinates outside the box as well. This leads to out-of-bounds errors.
This PR first computes the discrete cell coordinates and then applies a discrete modulo, so there are no rounding errors that can break anything.

@efaulhaber efaulhaber self-assigned this Mar 17, 2026
@efaulhaber efaulhaber added the bug Something isn't working label Mar 17, 2026
@efaulhaber efaulhaber requested a review from Copilot March 17, 2026 11:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a rounding error bug in periodicity computation by changing the approach: instead of first wrapping coordinates into the periodic box with periodic_coords and then computing cell indices (which can suffer from floating-point rounding at boundaries), it now computes cell indices from raw coordinates and then applies modular arithmetic to handle periodicity.

Changes:

  • Unified cell_coords and periodic_cell_index into generic versions that no longer dispatch on cell list type, using mod(. - 2, n_cells) + 2 for periodic wrapping
  • Removed FullGridCellList-specific specializations of cell_coords and periodic_cell_index from full_grid.jl
  • Introduced nonperiodic_cell_coords as a separate step before periodic index wrapping

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/nhs_grid.jl Refactored cell_coords to separate non-periodic coordinate computation from periodic wrapping; unified periodic_cell_index to use 2-based modulo for all cell list types
src/cell_lists/full_grid.jl Removed FullGridCellList-specific cell_coords and periodic_cell_index specializations

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/nhs_grid.jl
@codecov

codecov Bot commented Jun 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.40%. Comparing base (f25b0ab) to head (a55b471).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #146      +/-   ##
==========================================
- Coverage   86.06%   85.40%   -0.66%     
==========================================
  Files          15       15              
  Lines         739      733       -6     
==========================================
- Hits          636      626      -10     
- Misses        103      107       +4     
Flag Coverage Δ
unit 85.40% <100.00%> (-0.66%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@efaulhaber efaulhaber left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Codex Review

The PR appears intended to centralize periodic cell-index wrapping and make FullGridCellList use the same periodic path as other cell lists.

This is an AI-generated code review. Please verify the findings and summary before acting on them.
Review generated by codex-pr-review

Comment thread test/nhs_grid.jl
Comment thread src/nhs_grid.jl
Comment thread src/cell_lists/full_grid.jl
Comment thread test/nhs_grid.jl
@efaulhaber efaulhaber marked this pull request as ready for review June 24, 2026 10:48
@efaulhaber efaulhaber requested review from LasNikas and svchb June 24, 2026 10:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants