Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak caused by eq.solve at each step? #907

Open
aritra-mukhopadhyay opened this issue Mar 10, 2023 · 5 comments
Open

Memory leak caused by eq.solve at each step? #907

aritra-mukhopadhyay opened this issue Mar 10, 2023 · 5 comments

Comments

@aritra-mukhopadhyay
Copy link

I am running a simple code for diffusion in two dimensions, as shown below. However, the memory consumed increases quickly within the for loop, as much as 30GB RAM within a minute. Increasing the number of time steps leads it to eventually being 'Killed' since it runs out of 64GB memory. Is this because somehow the value of the target variable 'C' is stored for all time steps instead of the current one? I am quite new to FiPy, so any clue as to why this is happening would be very helpful :)

Code:

#Diffusion in 2D with periodic grid

#Import necessary modules
from fipy import *
from tqdm import tqdm

#Define the simulation parameters
Lx = 10.0 # length of the domain in x direction
Ly = 10.0 # length of the domain in y direction
nx = 100 # number of cells in x direction
ny = 100 # number of cells in y direction
dx = Lx / nx # cell size in x direction
dy = Ly / ny # cell size in y direction
D = 1.0 # diffusion coefficient
dt = 0.0001 # time step size
time_steps = 5000 # number of time steps to take

#Create the 2D periodic grid
mesh = PeriodicGrid2D(nx=nx, ny=ny, dx=dx, dy=dy)

#Define the target variable with some initial value
C = CellVariable(name="concentration", mesh=mesh)

#Define a random noise initial conditions
noise = UniformNoiseVariable(mesh=mesh,minimum=0.,maximum=1.)
C.setValue(noise)

#Define the PDE
eq = (TransientTerm() == DiffusionTerm(coeff=D))

#Solve the PDE
for i in tqdm(range(time_steps)):
    eq.solve(var=C, dt=dt)

I am using Ubuntu 22.04 and a conda python 3.10 environment.

@guyer
Copy link
Member

guyer commented Mar 10, 2023

What version of FiPy are you running?

python -c "import fipy; print(fipy.__version__)"

This may be an issue that was reported (and fixed) a couple of months ago: #896

@aritra-mukhopadhyay
Copy link
Author

aritra-mukhopadhyay commented Mar 10, 2023

I am using FiPy version 3.4.3. Interestingly, I found that the problem did not arise while running it in Google Colab. In Colab, I installed FiPy via pip, whereas in my machine I am using a conda installation.

@aritra-mukhopadhyay
Copy link
Author

I am attaching the package list of my conda environment below if it would be helpful.
environment_packages.txt

@guyer
Copy link
Member

guyer commented Mar 10, 2023

Thank you for forwarding your environment. We're delinquent in doing a release since fixing #896. Please try a git checkout of FiPy.

@aritra-mukhopadhyay
Copy link
Author

Thanks a lot! I can confirm that the issue was fixed by using the latest Git version of Fipy (3.4.3+5.g4db188c1), but only together with the line PETSc.garbage_cleanup() inside the for loop (after importing: from petsc4py import PETSc) as suggested by you in #896 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants