You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was looking into memory consumption a little, and it seems that that passing an LP to the solver (Gurobi in this case) using the .mps format has a significant memory overhead. Here using mps:
I'm using pypsa-eur to create and solve these models, and "from the outside", pypsa-eur reports a maximum total memory usage of 2531MB in the first case (mps) and 2215MB in the second case (lp).
It's a little strange to me since I would think that the highspy model that's allocated for the mps export would be deallocated immediately after the file export (when it's not needed anymore), but I guess that's not the case. A naive attempt at adding inserting del h at line 302 in io.py doesn't make any difference whatsoever:
h=m.to_highspy()
h.writeModel(str(fn))
delh
I guess I'm just not very good at understanding how memory works in Python.
For completeness, the direct api interface for Gurobi is the worst of the three; the relevant section of the memory profile looks like this
607 754.9 MiB 0.0 MiB 1 log_fn = maybe_convert_path(log_fn)
608 754.9 MiB 0.0 MiB 1 warmstart_fn = maybe_convert_path(warmstart_fn)
609 754.9 MiB 0.0 MiB 1 basis_fn = maybe_convert_path(basis_fn)
610
611 1701.5 MiB 0.0 MiB 2 with contextlib.ExitStack() as stack:
612 754.9 MiB 0.0 MiB 1 if env is None:
613 755.8 MiB 0.9 MiB 1 env = stack.enter_context(gurobipy.Env())
614
615 755.8 MiB 0.0 MiB 1 if io_api is None or io_api in ["lp", "mps"]:
616 problem_fn = model.to_file(problem_fn)
617 problem_fn = maybe_convert_path(problem_fn)
618 m = gurobipy.read(problem_fn, env=env)
619 755.8 MiB 0.0 MiB 1 elif io_api == "direct":
620 755.8 MiB 0.0 MiB 1 problem_fn = None
621 1422.2 MiB 666.4 MiB 1 m = model.to_gurobipy(env=env)
622 else:
623 raise ValueError(
624 "Keyword argument `io_api` has to be one of `lp`, `mps`, `direct` or None"
625 )
626
627 1422.2 MiB 0.0 MiB 1 if solver_options is not None:
628 1422.2 MiB 0.0 MiB 10 for key, value in solver_options.items():
629 1422.2 MiB 0.0 MiB 9 m.setParam(key, value)
630 1422.2 MiB 0.0 MiB 1 if log_fn is not None:
631 1422.2 MiB 0.0 MiB 1 m.setParam("logfile", log_fn)
632
633 1422.2 MiB 0.0 MiB 1 if warmstart_fn:
634 m.read(warmstart_fn)
635 1701.5 MiB 279.3 MiB 1 m.optimize()
636
637 1701.5 MiB 0.0 MiB 1 if basis_fn:
638 try:
639 m.write(basis_fn)
640 except gurobipy.GurobiError as err:
641 logger.info("No model basis stored. Raised error: %s", err)
642
But pypsa-eur reports a maximum memory usage of 2722MB.
Until anyone has any bright ideas for improvements, I figured this issue could at least serve as a reference; the short take-away is that you should use the .lp io interface for the moment if you care about memory.
The text was updated successfully, but these errors were encountered:
This is somewhat expected, MPS files are larger in size than LP files. Maybe I'm missing something? It looks like the largest differences are from handling a larger file?
Hi,
I was looking into memory consumption a little, and it seems that that passing an LP to the solver (Gurobi in this case) using the .mps format has a significant memory overhead. Here using mps:
Compared with the .lp format:
I'm using pypsa-eur to create and solve these models, and "from the outside", pypsa-eur reports a maximum total memory usage of 2531MB in the first case (mps) and 2215MB in the second case (lp).
It's a little strange to me since I would think that the highspy model that's allocated for the mps export would be deallocated immediately after the file export (when it's not needed anymore), but I guess that's not the case. A naive attempt at adding inserting
del h
at line 302 in io.py doesn't make any difference whatsoever:I guess I'm just not very good at understanding how memory works in Python.
For completeness, the direct api interface for Gurobi is the worst of the three; the relevant section of the memory profile looks like this
But pypsa-eur reports a maximum memory usage of 2722MB.
Memory usage of gurobipy seems to be somewhat of a knows issue, see https://support.gurobi.com/hc/en-us/community/posts/12387779995025/comments/12416251123217
Until anyone has any bright ideas for improvements, I figured this issue could at least serve as a reference; the short take-away is that you should use the .lp io interface for the moment if you care about memory.
The text was updated successfully, but these errors were encountered: