Code stuck at model creation, large number of variables
回答済みI am trying to create a model which contains > 6.9M optimization variables. I am adding the variables to the model in matrix form using the addMVar statement. Whenever I run the code, it gets stuck at the addMVar line and does not execute beyond that. The code runs fine when the variable size is reduced. Upon searching for the reason, I understood that it might have been caused due to the lack of required memory. Although, I am not completely sure. Could you please inform me what could be the reason behind this. If memory is the issue, then how do I solve this?Thanks in advance.
-
正式なコメント
This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum, or try Gurobot, our chatbot interface offering instant, expert-level support. -
Hi Aiswariya,
Adding a 1D array of 7M matrix variables to an empty Gurobi model object using the method Model.addMVar() took around 1.8GB of memory on my laptop. Therefore, I doubt the issue is related to memory. Could you please post a minimal reproducible example and we can then have a closer look?
Best regards,
Maliheh
0 -
Hi Aiswariya,
Parallel computing may help. You can give it a try. Parallel computing basic resource for Gurobi platform can be found here. This post seems relevant!
Note: I believe Gurobi uses all cores by default. I don't know exactly how that would serve your purpose. But, often time, when I am aiming to train resource-hungry machine learning models, using ALL CORE does not help (heap memory, & overload issues). So, I manually assign (total number of core - 2) cores; freeing at least 2 cores for other works in the laptop.
0 -
Hello Maliheh Aramon,
I am using var = model.addVar(). On adding around 115K variables, total memory consumption increased by 15MB.
I am confused how in your case, adding 7M variables took only 1.8MB. Can you please help what is the difference in the two methods?
0 -
Hi Amit,
It is 1.8GB. Sorry, I probably made a mistake when I was writing the comment.
The 1.8GB is based on the memory usage of the code snippet below:import gurobipy as gp
The memory usage report is:
from gurobipy import GRB
from memory_profiler import profile
@profile
def define_vars():
m = gp.Model("")
m.addMVar(7000000)
m.update()
return m
if __name__ == "__main__":
m = define_vars()
Line # Mem usage Increment Occurrences Line Contents
=============================================================
6 53.2 MiB 53.2 MiB 1 @profile
7 def define_vars():
8 54.5 MiB 1.3 MiB 1 m = gp.Model("")
9 1204.5 MiB 1150.0 MiB 1 m.addMVar(7000000)
10 1877.4 MiB 672.9 MiB 1 m.update()
11
12 1877.4 MiB 0.0 MiB 1 return mSorry again,
Maliheh
0
投稿コメントは受け付けていません。
コメント
5件のコメント