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

Gurobi backend interface #551

Open
wants to merge 30 commits into
base: main
Choose a base branch
from
Open

Conversation

brynpickering
Copy link
Member

@brynpickering brynpickering commented Jan 26, 2024

Fixes #349

Summary of changes in this pull request:

  • Duplicated pyomo backend interface as a pure gurobipy interface
  • Added basic tests of the interface methods

How to use:

  1. Install gurobipy into your calliope env: mamba install gurobi::gurobi
  2. Build optimisation problem with gurobi backend:
import calliope

model = calliope.Model(...)
model.build(backend="gurobi")
model.solve()

NOTE: without a license, one can only work with very small models. Our example models are already too big (maybe if run over ~2 timesteps it would work?).

Reviewer checklist:

  • Test(s) added to cover contribution
  • Documentation updated
  • Changelog updated
  • Coverage maintained or improved

Copy link

codecov bot commented Jan 26, 2024

Codecov Report

Attention: Patch coverage is 97.14286% with 11 lines in your changes are missing coverage. Please review.

Project coverage is 96.56%. Comparing base (872978d) to head (39099ed).
Report is 13 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #551      +/-   ##
==========================================
+ Coverage   95.85%   96.56%   +0.70%     
==========================================
  Files          24       25       +1     
  Lines        3619     3900     +281     
  Branches      788      771      -17     
==========================================
+ Hits         3469     3766     +297     
+ Misses         86       76      -10     
+ Partials       64       58       -6     
Files Coverage Δ
src/calliope/backend/backend_model.py 98.99% <100.00%> (+1.08%) ⬆️
src/calliope/backend/latex_backend_model.py 97.79% <ø> (ø)
src/calliope/backend/parsing.py 98.64% <100.00%> (+0.88%) ⬆️
src/calliope/backend/pyomo_backend_model.py 98.60% <100.00%> (+3.18%) ⬆️
src/calliope/model.py 94.53% <100.00%> (+0.88%) ⬆️
src/calliope/backend/expression_parser.py 97.63% <95.23%> (+0.44%) ⬆️
src/calliope/backend/gurobi_backend_model.py 95.95% <95.95%> (ø)

... and 2 files with indirect coverage changes

@brynpickering
Copy link
Member Author

I have added tests, but we don't have gurobipy installed in the CI builds so those tests are being skipped. Hence the massive coverage drop.

@brynpickering
Copy link
Member Author

I have run the urban scale model for a full year using the pyomo (with gurobi solver) and gurobi interfaces and get the attached results.

Headline: Gurobi interface peaks at ~30% less memory than pyomo.
I know you got different results when running locally @sjpfenninger. This could be because I'm using a cloud license for Gurobi which I think means it offloads the actual solving onto a remote machine.

memray_flamegraphs.zip


gurobi run:

import calliope

calliope.set_log_verbosity("info")
m = calliope.examples.urban_scale(time_subset=None)
m.build(backend="gurobi")
m.solve(solver_options={"Threads": 1})

pyomo run:

import calliope

calliope.set_log_verbosity("info")
m = calliope.examples.urban_scale(time_subset=None)
m.build(backend="pyomo")
m.solve(
solver="gurobi", solver_options={"Threads": 1})

Profiling using memray and setting [out] and [runfile] separately for pyomo and gurobi runs:

memray run --trace-python-allocators -o [out].bin [runfile].py    
memray flamegraph [out].bin -o [out].html    

@brynpickering
Copy link
Member Author

Last week's new pyomo release has caused an issue in one of our tests (see #597). I've pinned Pyomo upper bound to avoid this issue for now.

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

Successfully merging this pull request may close these issues.

Gurobi solver interfaces
1 participant