Efficiently Managing RAM Usage When Iterating Over Trajectories #4792
Replies: 2 comments 2 replies
|
|
I also ran into this with netcdf trajectories, after some debugging I could resolve it afaict but Im not fully sure about all the inner workings of MDAnalysis.
It's not a Python-object leak, which is why Dropping each frame's pages once it's been copied into the import mmap
mm = u.trajectory.trjfile._mm
for ts in u.trajectory:
...
mm.madvise(mmap.MADV_DONTNEED)From my test, reading 10 000 frames of a 4.2 GiB For the record Im using Python3.10 on ubuntu with MDAnalysis 2.9.0 / scipy 1.13.1 / numpy 2.2.6. I could try a PR if that is of interest to fix this, although as said im not too familiar with MDAnalysis inner workings. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hi MDAnalysis developers,
First, I want to acknowledge MDAnalysis for its impressive ability to handle large trajectory files while keeping RAM usage under control. I'm seeking advice on optimizing RAM usage in a specific use case.
Use Case
I have a list of trajectories and need to:
Ideally, the best-case scenario would involve loading and processing one frame at a time, ensuring constant and minimal RAM usage throughout.
Issue
To test this, I created an example with a system of 511,244 atoms and 10 trajectories, each containing 200 frames (1 GB each). The script iterates through the trajectories, computes a CV, and extracts a randomly selected frame (for simplicity).
Upon checking the RAM usage, it appears that a new frame is indeed loaded only when needed. However, the frame remains in RAM after it has been analysed, which is not ideal. Are there ways to unload the frame from RAM after it has been processed? Similarly, is there a RAM-efficient method to access a specific frame in the trajectory without having to load all preceding frames?
Test Script
Here’s the example code:
Here is the RAM usage of each command
How I Tested It
I used the memory profiler from Conda (conda install -c conda-forge memory_profiler):
Question
What’s the best way to ensure that MDAnalysis processes only one frame at a time without loading the entire trajectory into RAM?
Thank you for your guidance!
All reactions