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

Interface for Gurobi through the gurobipy API #45

Merged
merged 41 commits into from
Jun 1, 2021

Conversation

RichardOberdieck
Copy link
Contributor

Summary

Currently, qiskit only works with docplex as the LP/QP/MIP optimization engine. This pull request adds the ability to use Gurobi as well.

Details and comments

Gurobi is a commercial optimization solver (like CPLEX). However, at the moment it is only possible to use cplex if one uses qiskit. As I see that qiskit will grow in the future, I believe that it adds value to enable the use of other optimization engines as well, specifically Gurobi in this case.

I was quite careful to preserve the style of the original codebase, as I mostly copied the docplex methods and replaced the API calls with the corresponding gurobipy calls. All the tests pass, and I added some where I found them to be relevant.

The only question I was unable to answer comes in test_quadratic_program.py in line 830-831 of my PR. Specifically, the LP formats between Gurobi and cplex differ, and therefore that test does not carry over from the corresponding test for docplex. Therefore I decided to comment it out as fixing it would require adding additional logic to the __repr__ method of QuadraticProgram. I believe this is not very clean and therefore commented it out. If you have a better idea, then please do share.

Also, if you have any other comments/questions/remarks, please share.

@CLAassistant
Copy link

CLAassistant commented Mar 12, 2021

CLA assistant check
All committers have signed the CLA.

@stefan-woerner
Copy link
Contributor

Hi @RichardOberdieck, thanks for your contribution! We'll have a look and get back to you soon. Small first comment, max_cut.py has been recently refactored and is now build around the QuadraticProgram, so you can remove that from your PR.

@RichardOberdieck
Copy link
Contributor Author

Hi @RichardOberdieck, thanks for your contribution! We'll have a look and get back to you soon. Small first comment, max_cut.py has been recently refactored and is now build around the QuadraticProgram, so you can remove that from your PR.

Ok, sure. Shall I keep any of it or shall I just delete max_cut.py completely?

@stefan-woerner
Copy link
Contributor

stefan-woerner commented Mar 15, 2021

@RichardOberdieck the whole ising folder under applications has been deleted (i.e. moved and refactored), so you can delete applications/ising/max_cut.py or fetch from master, which should do it automatically (possibly via resolving a merge conflict). Thanks!

Since the interface of new applications does only involve the QuadraticProgram, None of the applications should be affected by your PR.

@RichardOberdieck
Copy link
Contributor Author

When I ran lint on my machine everything worked well. Are these failing checks a consequence of the merge conflicts? If so, shall I have a look at those?

@manoelmarques
Copy link
Contributor

manoelmarques commented Mar 19, 2021

Gurobipy requires an installation from a private Pypi site. Until it goes to the public Pypi it cannot be included in setup.py because it will fail any install that doesn't have guropbipy installed. I added an install of gurobipy to the CI in order to test it.
Also, the 'disp' property doesn't suppress all gurobipy output, first because the Model creation already prints some license stuff and LogToConsole should be set to 0 also: https://support.gurobi.com/hc/en-us/articles/360044784552-How-do-I-suppress-all-console-output-from-Gurobi-

@RichardOberdieck
Copy link
Contributor Author

Gurobipy requires an installation from a private Pypi site. Until it goes to the public Pypi it cannot be included in setup.py because it will fail any install that doesn't have guropbipy installed. I added an install of gurobipy to the CI in order to test it.

That's fair. Gurobi is currently in the process of getting to the public PyPI server, but there are some bureaucratic steps in the way. I'll let you know here when gurobipy is available from the public PyPI server.

Also, the 'disp' property doesn't suppress all gurobipy output, first because the Model creation already prints some license stuff and LogToConsole should be set to 0 also: https://support.gurobi.com/hc/en-us/articles/360044784552-How-do-I-suppress-all-console-output-from-Gurobi-

The key here is actually that it is set during the environment creation, rather than on the model level. Will you fix this in the PR or shall I?

@t-imamichi
Copy link
Collaborator

What is the license of gurobipy?

@RichardOberdieck
Copy link
Contributor Author

What is the license of gurobipy?

When installing through pip, a non-production license limited to 2000 variables and linear constraints is issued. Otherwise, the user has to get a Gurobi license on www.gurobi.com. For academics, this is free. For commercial users, they will need to purchase a license from Gurobi.

requirements.txt Outdated Show resolved Hide resolved
@t-imamichi t-imamichi added the Changelog: New feature Include in the Added section of the changelog label May 26, 2021
@t-imamichi
Copy link
Collaborator

We are discussing generalization of QP.from_XXX and QP.to_XXX in #116 #122. The discussion of the design is not finalized yet. We may separate your implementation as one of translators in the future.

t-imamichi
t-imamichi previously approved these changes May 27, 2021
Copy link
Collaborator

@t-imamichi t-imamichi left a comment

Choose a reason for hiding this comment

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

LGTM

@t-imamichi
Copy link
Collaborator

Could you write a release note following the guide?

@RichardOberdieck
Copy link
Contributor Author

@t-imamichi, @manoelmarques : let me know if I can contribute to the release note.

@t-imamichi
Copy link
Collaborator

Thanks. Could you check out the following guide and write a reno?
https://github.com/Qiskit/qiskit-optimization/blob/main/CONTRIBUTING.md#adding-a-new-release-note

@t-imamichi
Copy link
Collaborator

@RichardOberdieck If you cannot write a reno, we can write one on be half of you and merge this PR.

@RichardOberdieck
Copy link
Contributor Author

@t-imamichi : I'd appreciate that. Due to the refactor of quadratic_program.py etc. I am not quite sure I could say anything except "QISKIT supports gurobipy now".

@t-imamichi
Copy link
Collaborator

Thanks. I will do that.

t-imamichi
t-imamichi previously approved these changes Jun 1, 2021
stefan-woerner
stefan-woerner previously approved these changes Jun 1, 2021
Copy link
Contributor

@stefan-woerner stefan-woerner left a comment

Choose a reason for hiding this comment

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

lgtm

@t-imamichi t-imamichi dismissed stale reviews from stefan-woerner and themself via 0f7264e June 1, 2021 12:26
@t-imamichi t-imamichi merged commit 507074e into qiskit-community:main Jun 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: New feature Include in the Added section of the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants