Skip to content

Commit

Permalink
Fix time_limit_sec for GLOP and PDLP (#1859)
Browse files Browse the repository at this point in the history
Fixes #1858
  • Loading branch information
mlubin authored and SteveDiamond committed Nov 3, 2022
1 parent bd5b19c commit e872ba3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cvxpy/reductions/solvers/conic_solvers/glop_conif.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def solve_via_data(
if not solver.SetSolverSpecificParametersAsString(proto_str):
return {"status": s.SOLVER_ERROR}
if "time_limit_sec" in solver_opts:
solver.SetTimeLimit(1000 * float(solver_opts["time_limit_sec"]))
solver.SetTimeLimit(int(1000 * solver_opts["time_limit_sec"]))
solver.Solve()
solver.FillSolutionResponseProto(response)

Expand Down
2 changes: 1 addition & 1 deletion cvxpy/reductions/solvers/conic_solvers/pdlp_conif.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def solve_via_data(
return {"status": s.SOLVER_ERROR}
parameters.MergeFrom(proto)
if "time_limit_sec" in solver_opts:
request.solver_time_limit_sec = float(solver_opts["time_limit_sec"])
request.solver_time_limit_seconds = float(solver_opts["time_limit_sec"])

request.solver_specific_parameters = text_format.MessageToString(parameters)
solver = model_builder_helper.ModelSolverHelper()
Expand Down
12 changes: 12 additions & 0 deletions cvxpy/tests/test_conic_solvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,12 @@ def test_glop_bad_parameters(self) -> None:
with self.assertRaises(cp.error.SolverError):
prob.solve(solver='GLOP', parameters_proto="not a proto")

def test_glop_time_limit(self) -> None:
sth = sths.lp_1()
# Checks that the option doesn't error. A better test would be to solve
# a large instance and check that the time limit is hit.
sth.solve(solver='GLOP', time_limit_sec=1.0)


@unittest.skipUnless('PDLP' in INSTALLED_SOLVERS, 'PDLP is not installed.')
class TestPDLP(unittest.TestCase):
Expand Down Expand Up @@ -806,6 +812,12 @@ def test_pdlp_bad_parameters(self) -> None:
with self.assertRaises(cp.error.SolverError):
prob.solve(solver='PDLP', parameters_proto="not a proto")

def test_pdlp_time_limit(self) -> None:
sth = sths.lp_1()
# Checks that the option doesn't error. A better test would be to solve
# a large instance and check that the time limit is hit.
sth.solve(solver='PDLP', time_limit_sec=1.0)


@unittest.skipUnless('CPLEX' in INSTALLED_SOLVERS, 'CPLEX is not installed.')
class TestCPLEX(BaseTest):
Expand Down

0 comments on commit e872ba3

Please sign in to comment.