Closed aryannsaha closed 3 days ago
Here is a test with memory_profiler
:
from memory_profiler import profile
from monty.serialization import loadfn
@profile
def test():
for _ in range(100):
loadfn("mp-1000005.json.gz")
if __name__ == "__main__":
test()
Doing one iteration:
Line # Mem usage Increment Occurrences Line Contents
=============================================================
5 201.2 MiB 201.2 MiB 1 @profile
6 def test():
7 333.6 MiB 0.0 MiB 2 for _ in range(1):
8 333.6 MiB 132.4 MiB 1 loadfn("mp-1000005.json.gz")
Doing 100 iterations:
Line # Mem usage Increment Occurrences Line Contents
=============================================================
5 201.2 MiB 201.2 MiB 1 @profile
6 def test():
7 450.3 MiB -608.8 MiB 101 for _ in range(100):
8 450.3 MiB -359.7 MiB 100 loadfn("mp-1000005.json.gz")
Chgcar inherits Volumetric data and that inherits from MSONable.from_dict. If there is a leak, it is in MSONable.
Yup, I am looking into it. I also am not yet convinced this is a "bug" or just a quirk of Python. I'm going to close this issue and see if I can reproduce the behavior with the MSONable
class.
Python version
Python 3.12.4
Pymatgen version
2024.10.27
Operating system version
Linux
Current behavior
I'm working with Professor Andrew Rosen @Andrew-S-Rosen. We found what appears to be a memory leak associated with
Chgcar.from_dict
. Even when deleting the object from memory we still witness an increase in memory.Expected Behavior
We expected to see no overall net increase in memory.
Minimal example
Relevant files to reproduce this bug
mp-1000005.json.gz
Output
This was for a different CHGCAR file, but the same behavior is observed for many CHGCARs we tried. In production calculations, the memory usage continually increased, although here it tends to fluctuate after a notable initial increase.