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

Enabling the use of gurobipy directly, which should be faster #60

Closed

Conversation

RichardOberdieck
Copy link
Contributor

I've added support for gurobipy in the solvers, and added a test that works fine. Let me know if you need anything else.


# choose default from installed choices
if 'glpk' in installed_solvers:
if 'gurobi' in installed_solvers:
default_solver = 'gurobi'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I lean towards not making gurobi a default solver, because gurobi and gurobipy are proprietary, closed-source software: https://www.gurobi.com/downloads/end-user-license-agreement-academic/, and: https://pypi.org/project/gurobipy/.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with not making gurobi a default solver. This is not a vote against Gurobi, but rather, automatically using a restrictive-license-encumbered dependency is an anti-pattern of open source code. Users should have to explicitly request it.

Perhaps there is a more convenient way for users to do this, e.g., an environment variable.

@@ -1 +1 @@
cvxopt==1.2.4
cvxopt==1.2.4
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line appears to have only whitespace changes. It seems that the line could be omitted from the changeset.

@@ -88,6 +95,8 @@ def lpsolve(c, G, h, solver=None):
result = _solve_lp_using_cvxopt(c, G, h, solver=solver)
elif solver == 'scipy':
result = _solve_lp_using_scipy(c, G, h)
elif solver == 'gurobi':
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing the selection 'gurobi' as a keyword argument as done here is explicit [PEP 8] and seems preferable.

@@ -486,5 +486,14 @@ def is_glpk_present():
return False


def test_gurobipy_return_same_result_as_scipy():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is good to test the added functionality. However, the absence of the solver gurobi on Travis CI implies that this test fails. Skimming the licensing webpage of gurobi gives the impression that installing gurobi on Travis CI is probably far from its licensing procedure. So it seems that this test would need to not be invoked on Travis CI.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Today I learned that Gurobi has a limited license that is included by default when installing gurobipy, so it is possible now to run tests with Gurobi in CI without requesting special permission1, assuming the model is not "too large" 2.

Footnotes

  1. https://support.gurobi.com/hc/en-us/articles/360044290292-How-do-I-install-Gurobi-for-Python#h_01GRC369WKBMV6VFRCGJPRTSW5

  2. https://support.gurobi.com/hc/en-us/articles/360051597492-How-do-I-resolve-a-Model-too-large-for-size-limited-Gurobi-license-error

@slivingston slivingston self-assigned this Jun 24, 2022
@slivingston
Copy link
Member

@RichardOberdieck Thanks for this pull request. I will try to install Gurobi and provide requirements before this can be accepted. My review is arriving much later than I would have wanted, so no worries if you do not have time to handle comments. It seems that GitHub allows me to push to your pull request branch, so I can do remaining work, too.

@RichardOberdieck
Copy link
Contributor Author

Thanks @slivingston : I am a bit swamped at the moment, but it looks better towards August and September. If some things are outstanding until then, please let me know! Thanks for picking this up again!

@slivingston
Copy link
Member

@RichardOberdieck thanks for this code. Because additional work was required to prepare this for merging, I opened a new pull request that applies changes onto your original commit.

@slivingston slivingston closed this Oct 1, 2024
@slivingston
Copy link
Member

@RichardOberdieck Also, I opened a new PR because it did not appear that I can push changes to this PR (despite seeming to be able to previously). Your authorship will be captured when merging the new PR either as the commit author or via Co-authored-by:.

@RichardOberdieck
Copy link
Contributor Author

@slivingston thanks for your work on this, truly diligent! Thanks for any attribution, although after reviewing my code changes I am not sure they warrant a "co-authored". But I leave that decision up to you!

slivingston added a commit that referenced this pull request Oct 4, 2024
For discussion that concluded with this commit,
#98
#60

Gurobi will not automatically become the default solver due to its
restrictive license. However, users can manually select it by

    import polytope as pc
    pc.solvers.default_solver = 'gurobi'

Then, `polytope` can be used without modification.

If Gurobi returns INF_OR_UNBD, the optimization is run again with
DualReductions=0 as recommended at
https://www.gurobi.com/documentation/current/refman/optimization_status_codes.html
and a notification about this is included under the `"message"` key in
the result returned by `polytope.solvers.lpsolve`.

Tests that require Gurobi are skipped and a warning is shown if
gurobipy is not installed.


Co-authored-by: Richard Oberdieck <[email protected]>
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.

3 participants