Skip to content

Conversation

JiaxinWang-thu
Copy link
Contributor

@JiaxinWang-thu JiaxinWang-thu commented Mar 21, 2022

  • use Gurobi.write(save_file) to save the model file.
  • cplex and mosek have the similar functionality.

Description

Very simple changes.
Make it possible to write model using gurobi.

Type of change

  • New feature (backwards compatible)
  • New feature (breaking API changes)
  • Bug fix
  • Other (Documentation, CI, ...)

Contribution checklist

  • Add our license to new files.
  • Check that your code adheres to our coding style.
  • Write unittests.
  • Run the unittests and check that they’re passing.
  • Run the benchmarks to make sure your change doesn’t introduce a regression.

- use Gurobi.write(save_file) to save the model file.
- cplex and mosek have the similar functionality.
@CLAassistant
Copy link

CLAassistant commented Mar 21, 2022

CLA assistant check
All committers have signed the CLA.

# Save file (*.mst, *.sol, ect.)
if 'save_file' in solver_opts:
model.write(solver_opts['save_file'])
del solver_opts['save_file']
Copy link
Collaborator

Choose a reason for hiding this comment

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

No need to delete.

@SteveDiamond
Copy link
Collaborator

Thanks for adding this! Could you write a test as well? It's not so much to validate the code (which is very simple), as to commit us to maintaining this functionality.

@JiaxinWang-thu
Copy link
Contributor Author

A test is added

@SteveDiamond
Copy link
Collaborator

Thanks for adding the test! The CI is failing because of code style issues. Please follow these instructions: https://www.cvxpy.org/contributing/index.html#code-style

@rileyjmurray how should this test be integrated into the solver tests?

@phschiele
Copy link
Collaborator

NIT: Perhaps the file out.lp could be moved to a tests/ressources/ folder and renamed to something like gurobi_model.lp.

created a folder called ./cvxpy/tests/resources/
@JiaxinWang-thu
Copy link
Contributor Author

  • the code style has been changed
  • the gurobi_model.lp has been moved to /resources/ folder
  • BUT I got the error "ImportError: cannot import name 'InverseData' from partially initialized module 'cvxpy.reductions' (most likely due to a circular import) (g:\codes\python\cvxpy\cvxpy\reductions_init_.py)". I thought it is for the change of code style . I have no idea about whether it is an error only happens in my PC. Could you help me?

@SteveDiamond
Copy link
Collaborator

No worries, we'll take it from here.

@JiaxinWang-thu
Copy link
Contributor Author

the test fails (might) because there was no ./resources/ folder, and now it fixes the problem.

@@ -0,0 +1,48 @@
"""
Copyright 2022 Jiaxin Wang
Copy link
Collaborator

Choose a reason for hiding this comment

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

@qiuwjx please change this line to "Copyright 2022, the CVXPY authors"



class TestGurobiWrite(BaseTest):
""" Unit tests for the expression/expression module. """
Copy link
Collaborator

Choose a reason for hiding this comment

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

@qiuwjx this docstring isn't correct

@rileyjmurray rileyjmurray merged commit 05157b0 into cvxpy:master Mar 23, 2022
SteveDiamond added a commit that referenced this pull request Apr 24, 2022
…github.com:cvxpy/cvxpy

* 'master' of github.com:QiuWJX/cvxpy:
  changed the copyright and docstring
  create resources folder in codes
  undid changes
  standardized the code style created a folder called ./cvxpy/tests/resources/
  Add unit test for gurobi `model.write()`
  Add 'save_file' kwargs for GUROBI. - use Gurobi.write(save_file) to save the model file. - cplex and mosek have the similar functionality.
  cvxpy/tests: Add test for infeasible boolean problem (#1705)
  Handle new CyLP statuses from coin-or/CyLP#150 (#1707)

* 'master' of github.com:cvxpy/cvxpy:
  SCIP: add version requirement (< 4.0.0) and fix solve_via_data to eliminate certain error messages
  update error message for mixed-integer problems (#1738)
  remove out of date news
  fix TypeError in GLOP and PDLP interfaces (#1736)
  Propagate today's documentation improvements from release/1.2.x (#1733)
  Cylp update (#1727)
  Add 'save_file' kwargs for GUROBI. (#1720)
  pip install cvxpy[GLOP,XPRESS] (#1719)
  Fix #1714
  cvxpy/tests: Add test for infeasible boolean problem (#1705)
  Handle new CyLP statuses from coin-or/CyLP#150 (#1707)
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.

5 participants