メインコンテンツへスキップ

Code stuck at model creation, large number of variables

回答済み

コメント

5件のコメント

  • 正式なコメント
    Simranjit Kaur
    • Gurobi Staff
    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.
  • Maliheh Aramon
    • Gurobi Staff

    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
  • Tanmoy Das
    • Gurobi-versary
    • Investigator
    • Collaborator

    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
  • amit garg
    • Gurobi-versary
    • First Comment

    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
  • Maliheh Aramon
    • Gurobi Staff

    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
    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()
    The memory usage report is:

    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 m

    Sorry again,

    Maliheh

    0

投稿コメントは受け付けていません。