Add Verlet-style neighbor list cache to calculators#8
Merged
Conversation
Build neighbor lists with cutoff + skin and skip expensive rebuilds when atoms have moved less than 0.5 * skin from the reference positions. When within skin, only sr.positions is updated in the cached batch — the model recomputes R_ij from current positions, so forces remain correct. Ewald parameters are derived from the physical cutoff to keep the long-range decomposition unchanged. Skin defaults to 0.25 Å and is configurable via the `skin` kwarg on Calculator, from_model, from_checkpoint, and LOREM_driver. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace the exact cell comparison with a combined Verlet criterion that
accounts for both position displacement and cell deformation:
|ΔR_ij| ≤ 2·d_max + max_shift · Σ|Δcell_A| < skin
max_cell_shift (max |S| in the neighbor list) is extracted from the batch
at build time. When cell changes are within the skin budget, only
sr.positions and sr.cell are updated — the Ewald calculator recomputes
k-vectors from sr.cell on-the-fly (pbc.k_grid stores integer frequency
indices only), so forces, energy, and stress remain correct.
Falls back to exact cell comparison when max_cell_shift is not available
(direct NeighborListCache use without calculator), preserving backward
compatibility.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
PicoCentauri
left a comment
There was a problem hiding this comment.
Isn't this something the engine should do?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
NeighborListCache(src/lorem/neighborlist.py) implementing the Verlet displacement criterion: rebuild only when the combined position + cell deformation exceeds the skin budgetcutoff + skin, caches the batch, and on small geometry changes updates onlysr.positionsandsr.cell— the model recomputesR_ijfrom current positions/cell so forces/energy/stress stay correctsr.cell(pbc.k_gridstores integer frequency indices only), and Ewald parameters (lr_wavelength,smearing) are derived from the physical cutoff to keep the long-range decomposition unchangedskinkwarg (default0.25Å) added toCalculator,from_model,from_checkpoint, andLOREM_driverCombined Verlet criterion (NPT-aware)
max_cell_shift(max |S| in the neighbor list) is extracted from the batch at build time. Falls back to exact cell comparison when shift info is unavailable (backward compatible).Test plan
Unit tests (
test_neighborlist.py— 19 tests)needs_updatereturns True on first call (no reference)>)save_reference+resetlifecycleIntegration tests (
test_calculator.py— 10 tests)from_modelAll 47 tests pass, lint clean.
🤖 Generated with Claude Code