Memory usage accumulation in CBC solver with python-mip wrapper #353
Replies: 3 comments 1 reply
-
It looks like a "feature" of python-mip or the interface to cbc. I added a print statement to the Cbc_C_Interface when the model is created and when it is deleted - as you can see it is odd. |
Beta Was this translation helpful? Give feedback.
-
I looked at instructions for python-mip and cbc - and downloaded master code to /home/john/clean6 and then used coinbrew with --enable-relocatable. I built in directory /home/john/clean6/python and then added Not sure the LD_LIBRARY_PATH was needed. It is the last export that tells python-mip where to look. |
Beta Was this translation helpful? Give feedback.
-
I had this same issue. In my application, I was looping through, iteratively building an overall solution to a problem I had broken down into smaller chunks.
I tried quite a few avenues to free up the memory that accumulates. In my case, it was several GBs and the OS was eventually killing things. Garbage collection (gc, del), inspecting memory on the python side (tracemalloc), trying to modify the python-mip library (special attention to I couldn't figure it out. Posting my workaround here, in case it's helpful for others. I encapsulated the call in a separate process that could be fully terminated on completion. Pseudocode: import multiprocessing
output_chunks = []
for i in range(num_iterations):
with multiprocessing.Pool(1) as pool:
output_chunks += pool.apply(my_optimization_function, args=(a, b, c, ))
pool.close()
pool.terminate() When I monitor this, the memory usage spikes when the optimization function is called (of course); but, on each iteration, I can see that the memory is returned back to the OS. Hope it helps others in a similar situation! |
Beta Was this translation helpful? Give feedback.
-
The code below solves an IP relating to an$n\times n$ chessboard using CBC solver with
python-mip
wrapper (version 1.15.0), with CBCVersion: Trunk / Build Date: Oct 24 2021
. It solves the problem repeatedly with a time limit of 60 seconds. Within the given time limit, the program only produces a feasible solution. The IP itself does not matter, it only illustrates my question in the end.During the execution on my laptop (Ubuntu 22.04LTS), I notice that the memory usage slowly increases after each iteration. Below are the statistics
Intuitively, the program's memory usage should be reset to 0 after each iteration (since the
model
variable is re-created). I've trieddel model
at the end of the iteration, but it does not resolve the problem.I wonder what is the cause of the accumulation. Right now, I suspect that the search tree stored in CBC solver still exists even after it reaches the time limit.
My questions:
python-mip
wrapper?python-mip
?Side note. This question has been asked on stackoverflow, but it has received no answer until now. It is posted on CBC's discussions as well.
Beta Was this translation helpful? Give feedback.
All reactions