feat(lammps): load selected dump frames efficiently#1041
Conversation
Add f_idx-based sparse frame loading for LAMMPS dump trajectories while preserving requested order and duplicate indices. Stop scanning after the final requested frame and validate invalid selections explicitly. Coding-Agent: Codex Codex-Version: codex-cli 0.144.6 Model: gpt-5.6-sol Reasoning-Effort: xhigh
Merging this PR will not alter performance
|
📝 WalkthroughWalkthroughLAMMPS dump loading now supports selecting specific frame indices, including ordered duplicates, with input validation and early termination. The plugin forwards ChangesLAMMPS frame selection
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant Caller
participant LAMMPSDumpFormat
participant load_file
participant DumpStream
Caller->>LAMMPSDumpFormat: request frames with f_idx
LAMMPSDumpFormat->>load_file: forward f_idx
load_file->>DumpStream: iterate complete dump frames
DumpStream-->>load_file: yield frames through last requested index
load_file-->>LAMMPSDumpFormat: return ordered selected lines
LAMMPSDumpFormat-->>Caller: construct selected system
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tests/test_lammps_dump_skipload.py (1)
87-93: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winConsider adding a case for the
TypeErrorpath.Coverage here checks empty/negative/out-of-range but not
f_idxcontaining a non-integer element (e.g.f_idx=["a"]), which_normalize_frame_indicesis supposed to reject withTypeError.✅ Suggested addition
def test_invalid_frame_indices(self): with self.assertRaisesRegex(ValueError, "must not be empty"): dump.load_file(self.dump_file, f_idx=[]) with self.assertRaisesRegex(ValueError, "non-negative"): dump.load_file(self.dump_file, f_idx=[-1]) with self.assertRaisesRegex(IndexError, "out of range"): dump.load_file(self.dump_file, f_idx=[5]) + with self.assertRaisesRegex(TypeError, "only integers"): + dump.load_file(self.dump_file, f_idx=["a"])🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/test_lammps_dump_skipload.py` around lines 87 - 93, Add a TypeError assertion to test_invalid_frame_indices for a non-integer frame index such as f_idx=["a"], matching the rejection behavior of _normalize_frame_indices and checking the expected error message.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@tests/test_lammps_dump_skipload.py`:
- Around line 87-93: Add a TypeError assertion to test_invalid_frame_indices for
a non-integer frame index such as f_idx=["a"], matching the rejection behavior
of _normalize_frame_indices and checking the expected error message.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 04b3650b-88e9-4513-a996-777a60b2d15e
📒 Files selected for processing (3)
dpdata/formats/lammps/dump.pydpdata/plugins/lammps.pytests/test_lammps_dump_skipload.py
Summary
f_idxsupport tolammps/dumpso callers can load arbitrary non-negative frame indices directlySystem.sub_systembegin/stepselectionsITEM: TIMESTEPboundaries instead of assuming a fixed block lengthExample:
Performance benchmark
The benchmark compares direct sparse loading against the existing workflow of loading the complete trajectory and then calling
sub_system(indices).System(..., f_idx=indices)System(...).sub_system(indices)Direct sparse loading was 14.38x faster and reduced peak RSS by 64.39% for this workload. Both methods returned the same 10 selected frames. Because the final frame was selected, both methods traversed the full file; the improvement comes from avoiding storage and parsing of unselected frames.
Validation
python -m unittest test_lammps_dump_skipload.py test_lammps_dump_to_system.py test_lammps_dump_unfold.py test_lammps_dump_shift_origin.py test_lammps_dump_idx.py test_lammps_read_from_trajs.py test_lammps_spin.py— 70 tests passedruff check dpdata/ tests/test_lammps_dump_skipload.py— passedruff format --check dpdata/ tests/test_lammps_dump_skipload.py— passeddpdata --helpanddpdata --version— passedparmeddependency is not installed in the environment, and 43 tests were skippedCloses #367.
Coding agent: Codex
Codex version: codex-cli 0.144.6
Model: gpt-5.6-sol
Reasoning effort: xhigh
Summary by CodeRabbit
New Features
Bug Fixes