Skip to content

Commit

Permalink
Patch 1.4.1 (#2261)
Browse files Browse the repository at this point in the history
* change conic solver preference order (#2259)

* fix time limit test

* Include use_quad_obj in cache (#2262)

---------

Co-authored-by: Paul Goulart <paul.goulart@eng.ox.ac.uk>
Co-authored-by: Maximilian Schaller <max@schaller.id>
  • Loading branch information
3 people authored Oct 12, 2023
1 parent 94ae9b0 commit 9c6dccb
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
13 changes: 9 additions & 4 deletions cvxpy/problems/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ def invalidate(self) -> None:
self.param_prog = None
self.inverse_data = None

def make_key(self, solver, gp, ignore_dpp):
return (solver, gp, ignore_dpp)
def make_key(self, solver, gp, ignore_dpp, use_quad_obj):
return (solver, gp, ignore_dpp, use_quad_obj)

def gp(self):
return self.key is not None and self.key[1]
Expand Down Expand Up @@ -634,8 +634,13 @@ def get_problem_data(
raise DPPError("Cannot set enforce_dpp = True and ignore_dpp = True.")

start = time.time()
# Cache includes ignore_dpp because it alters compilation.
key = self._cache.make_key(solver, gp, ignore_dpp)
# Cache includes ignore_dpp and solver_opts['use_quad_obj']
# because they alter compilation.
if solver_opts is None:
use_quad_obj = None
else:
use_quad_obj = solver_opts.get('use_quad_obj', None)
key = self._cache.make_key(solver, gp, ignore_dpp, use_quad_obj)
if key != self._cache.key:
self._cache.invalidate()
solving_chain = self._construct_chain(
Expand Down
3 changes: 2 additions & 1 deletion cvxpy/reductions/solvers/defines.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
# CONIC_SOLVERS and QP_SOLVERS are sorted in order of decreasing solver
# preference. QP_SOLVERS are those for which we have written interfaces
# and are supported by QpSolver.
CONIC_SOLVERS = [s.MOSEK, s.ECOS, s.CLARABEL, s.SCS, s.SDPA,
CONIC_SOLVERS = [s.MOSEK, s.ECOS, s.SCS, s.CLARABEL, s.SDPA,
s.CPLEX, s.GUROBI, s.COPT, s.GLPK, s.NAG,
s.GLPK_MI, s.CBC, s.CVXOPT, s.XPRESS, s.DIFFCP,
s.SCIP, s.SCIPY, s.GLOP, s.PDLP, s.ECOS_BB]
Expand Down Expand Up @@ -115,3 +115,4 @@ def installed_solvers():
slv for slv in INSTALLED_SOLVERS if slv in CONIC_SOLVERS]
INSTALLED_MI_SOLVERS = [
slv for slv in INSTALLED_SOLVERS if slv in MI_SOLVERS]

2 changes: 1 addition & 1 deletion cvxpy/tests/test_conic_solvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2196,7 +2196,7 @@ def test_scipy_mi_time_limit_reached(self) -> None:
sth = sths.mi_lp_7()

# We only check that the option does not raise an error.
sth.solve(solver='SCIPY', scipy_options={"time_limit": 0.1})
sth.solve(solver='SCIPY', scipy_options={"time_limit": 100.0})


@unittest.skipUnless('COPT' in INSTALLED_SOLVERS, 'COPT is not installed.')
Expand Down
14 changes: 14 additions & 0 deletions cvxpy/tests/test_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,20 @@ def test_get_problem_data(self) -> None:
self.assertIsNone(data["A"])
self.assertEqual(data["G"].shape, (3, 3))

# caching use_quad_obj
p = Problem(cp.Minimize(cp.sum_squares(self.x) + 2))
data, _, _ = p.get_problem_data(s.SCS, solver_opts={"use_quad_obj": False})
dims = data[ConicSolver.DIMS]
self.assertEqual(dims.soc, [4])
self.assertEqual(data["c"].shape, (3,))
self.assertEqual(data["A"].shape, (4, 3))
data, _, _ = p.get_problem_data(s.SCS, solver_opts={"use_quad_obj": True})
dims = data[ConicSolver.DIMS]
self.assertEqual(dims.soc, [])
self.assertEqual(data["P"].shape, (2, 2))
self.assertEqual(data["c"].shape, (2,))
self.assertEqual(data["A"].shape, (0, 2))

if s.CVXOPT in INSTALLED_SOLVERS:
data, _, _ = Problem(cp.Minimize(cp.norm(self.x) + 3)).get_problem_data(
s.CVXOPT)
Expand Down

0 comments on commit 9c6dccb

Please sign in to comment.