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

Cannot set time limit with PDLP and GLOP #1858

Closed
sunnyxxchen opened this issue Aug 4, 2022 · 1 comment · Fixed by #1859
Closed

Cannot set time limit with PDLP and GLOP #1858

sunnyxxchen opened this issue Aug 4, 2022 · 1 comment · Fixed by #1859

Comments

@sunnyxxchen
Copy link

sunnyxxchen commented Aug 4, 2022

Describe the bug
An error occurs when passing the time_limit_sec option to PDLP and GLOP.

To Reproduce

import cvxpy as cp

x = cp.Variable(1)
objective = cp.Minimize(x)
prob = cp.Problem(objective)

prob.solve(solver=cp.PDLP)
prob.solve(solver=cp.PDLP, time_limit_sec=5.0)
prob.solve(solver=cp.GLOP, time_limit_sec=5.0)

Output
Using PDLP produces the following stacktrace:

AttributeError                            Traceback (most recent call last)
Input In [9], in <cell line: 7>()
      3 objective = cp.Minimize(x)
      5 prob = cp.Problem(objective)
----> 7 prob.solve(solver=cp.PDLP, time_limit_sec=5.0)

File ~/opt/anaconda3/envs/aumc/lib/python3.10/site-packages/cvxpy/problems/problem.py:481, in Problem.solve(self, *args, **kwargs)
    479 else:
    480     solve_func = Problem._solve
--> 481 return solve_func(self, *args, **kwargs)

File ~/opt/anaconda3/envs/aumc/lib/python3.10/site-packages/cvxpy/problems/problem.py:1016, in Problem._solve(self, solver, warm_start, verbose, gp, qcp, requires_grad, enforce_dpp, ignore_dpp, **kwargs)
   1012     s.LOGGER.info(
   1013             'Invoking solver %s  to obtain a solution.',
   1014             solving_chain.reductions[-1].name())
   1015 start = time.time()
-> 1016 solution = solving_chain.solve_via_data(
   1017     self, data, warm_start, verbose, kwargs)
   1018 end = time.time()
   1019 self._solve_time = end - start

File ~/opt/anaconda3/envs/aumc/lib/python3.10/site-packages/cvxpy/reductions/solvers/solving_chain.py:361, in SolvingChain.solve_via_data(self, problem, data, warm_start, verbose, solver_opts)
    325 def solve_via_data(self, problem, data, warm_start: bool = False, verbose: bool = False,
    326                    solver_opts={}):
    327     """Solves the problem using the data output by the an apply invocation.
    328 
    329     The semantics are:
   (...)
    359         a Solution object.
    360     """
--> 361     return self.solver.solve_via_data(data, warm_start, verbose,
    362                                       solver_opts, problem._solver_cache)

File ~/opt/anaconda3/envs/aumc/lib/python3.10/site-packages/cvxpy/reductions/solvers/conic_solvers/pdlp_conif.py:161, in PDLP.solve_via_data(self, data, warm_start, verbose, solver_opts, solver_cache)
    159     parameters.MergeFrom(proto)
    160 if "time_limit_sec" in solver_opts:
--> 161     request.solver_time_limit_sec = float(solver_opts["time_limit_sec"])
    163 request.solver_specific_parameters = text_format.MessageToString(parameters)
    164 solver = model_builder_helper.ModelSolverHelper()

AttributeError: Protocol message MPModelRequest has no "solver_time_limit_sec" field.

while GLOP produces the following error:

TypeError                                 Traceback (most recent call last)
Input In [8], in <cell line: 7>()
      3 objective = cp.Minimize(x)
      5 prob = cp.Problem(objective)
----> 7 prob.solve(solver=cp.GLOP, time_limit_sec=5.0)

File ~/opt/anaconda3/envs/aumc/lib/python3.10/site-packages/cvxpy/problems/problem.py:481, in Problem.solve(self, *args, **kwargs)
    479 else:
    480     solve_func = Problem._solve
--> 481 return solve_func(self, *args, **kwargs)

File ~/opt/anaconda3/envs/aumc/lib/python3.10/site-packages/cvxpy/problems/problem.py:1016, in Problem._solve(self, solver, warm_start, verbose, gp, qcp, requires_grad, enforce_dpp, ignore_dpp, **kwargs)
   1012     s.LOGGER.info(
   1013             'Invoking solver %s  to obtain a solution.',
   1014             solving_chain.reductions[-1].name())
   1015 start = time.time()
-> 1016 solution = solving_chain.solve_via_data(
   1017     self, data, warm_start, verbose, kwargs)
   1018 end = time.time()
   1019 self._solve_time = end - start

File ~/opt/anaconda3/envs/aumc/lib/python3.10/site-packages/cvxpy/reductions/solvers/solving_chain.py:361, in SolvingChain.solve_via_data(self, problem, data, warm_start, verbose, solver_opts)
    325 def solve_via_data(self, problem, data, warm_start: bool = False, verbose: bool = False,
    326                    solver_opts={}):
    327     """Solves the problem using the data output by the an apply invocation.
    328 
    329     The semantics are:
   (...)
    359         a Solution object.
    360     """
--> 361     return self.solver.solve_via_data(data, warm_start, verbose,
    362                                       solver_opts, problem._solver_cache)

File ~/opt/anaconda3/envs/aumc/lib/python3.10/site-packages/cvxpy/reductions/solvers/conic_solvers/glop_conif.py:155, in GLOP.solve_via_data(self, data, warm_start, verbose, solver_opts, solver_cache)
    153         return {"status": s.SOLVER_ERROR}
    154 if "time_limit_sec" in solver_opts:
--> 155     solver.SetTimeLimit(1000 * float(solver_opts["time_limit_sec"]))
    156 solver.Solve()
    157 solver.FillSolutionResponseProto(response)

File ~/.local/lib/python3.10/site-packages/ortools/linear_solver/pywraplp.py:525, in Solver.SetTimeLimit(self, x)
    524 def SetTimeLimit(self, x: "int64_t") -> "void":
--> 525     return _pywraplp.Solver_SetTimeLimit(self, x)

TypeError: in method 'Solver_SetTimeLimit', argument 2 of type 'int64_t'

Version

  • OS: macOS 12.4
  • CVXPY Version: 1.2.1
@rileyjmurray
Copy link
Collaborator

It looks like GLOP can be fixed by changing the relevant line to solver.SetTimeLimit(int(1000 * float(solver_opts["time_limit_sec"]))). The error with PDLP is pretty opaque; help(parameters) and help(request) produce no useful documentation when the debugger is paused before the relevant line. @mlubin could you offer a suggestion for how to fix?

mlubin added a commit to mlubin/cvxpy that referenced this issue Aug 6, 2022
SteveDiamond pushed a commit that referenced this issue Aug 7, 2022
SteveDiamond added a commit that referenced this issue Nov 4, 2022
* fix osqp warm start (#1882)

* switch SCS timings to seconds (#1880)

Co-authored-by: Steven Diamond <steven@gridmatic.com>

* merge fix

* fix test

* resolve merge

* Fix SOC residual (#1844)

* fix SOC residual

* dimension test

* Suggestion for how to compute SOC residual (#1853)

Co-authored-by: phschiele <44360364+phschiele@users.noreply.github.com>

* Fix bug with diff (#1835)

* fix #1834

* test error

Co-authored-by: Steven Diamond <steven@gridmatic.com>

* fix #1828 (#1829)

* cap ortools at 9.3

* fix mosek

* switch pcp opt vals back

* resolve merge conflict

* Update __init__.py

Resolve #1910

* allow list as shape input

* fix gradient for multidimensional quad form (#1854)

* fix multidimensional quad form

* autoblack messed up line ordering

* Adding edge case handling for string inputs into norm (#1871)

* Adding edge case handling for string inputs into norm

Signed-off-by: KerimovEmil <emilkerimov93@gmail.com>

* Update cvxpy/atoms/norm.py

Co-authored-by: phschiele <44360364+phschiele@users.noreply.github.com>

* Adding norm exception tests to ensure that invalid string inputs are caught

Signed-off-by: KerimovEmil <emilkerimov93@gmail.com>
Co-authored-by: phschiele <44360364+phschiele@users.noreply.github.com>
Co-authored-by: Steven Diamond <steven@gridmatic.com>

* Fix time_limit_sec for GLOP and PDLP (#1859)

Fixes #1858

Signed-off-by: KerimovEmil <emilkerimov93@gmail.com>
Co-authored-by: Fabian Schramm <55981657+fabinsch@users.noreply.github.com>
Co-authored-by: phschiele <44360364+phschiele@users.noreply.github.com>
Co-authored-by: Riley Murray <rileyjmurray@users.noreply.github.com>
Co-authored-by: Robert Huisman <74955560+roberthuisman@users.noreply.github.com>
Co-authored-by: KerimovEmil <emilkerimov93@gmail.com>
Co-authored-by: Miles Lubin <miles.lubin@gmail.com>
SteveDiamond added a commit that referenced this issue Dec 27, 2022
* cap ortools at 9.3

* fix mosek

* switch pcp opt vals back

* resolve merge conflict

* Update __init__.py

Resolve #1910

* allow list as shape input

* fix gradient for multidimensional quad form (#1854)

* fix multidimensional quad form

* autoblack messed up line ordering

* Adding edge case handling for string inputs into norm (#1871)

* Adding edge case handling for string inputs into norm

Signed-off-by: KerimovEmil <emilkerimov93@gmail.com>

* Update cvxpy/atoms/norm.py

Co-authored-by: phschiele <44360364+phschiele@users.noreply.github.com>

* Adding norm exception tests to ensure that invalid string inputs are caught

Signed-off-by: KerimovEmil <emilkerimov93@gmail.com>
Co-authored-by: phschiele <44360364+phschiele@users.noreply.github.com>
Co-authored-by: Steven Diamond <steven@gridmatic.com>

* Fix time_limit_sec for GLOP and PDLP (#1859)

Fixes #1858

* disallow float for diamatrix values (#1931)

* pin setuptools

* Make log_det robust to numerical issues with complex data (#1866)

* log_det takes Hermitian part of its input, therefore can assume that "sign" from numpys slogdet is real.

* Update test_complex.py

* Update test_complex.py

Make certain failing tests verbose, so we can see why logdet tests fail on a small number of platforms.

* guess for fix

* lower precision of test log det

* Update cvxpy/tests/test_complex.py

Remove verbose

Co-authored-by: phschiele <44360364+phschiele@users.noreply.github.com>

* Update cvxpy/tests/test_complex.py

Remove verbose from test

Co-authored-by: phschiele <44360364+phschiele@users.noreply.github.com>

Co-authored-by: Steven Diamond <diamond.po.central@gmail.com>
Co-authored-by: Steven Diamond <steven@gridmatic.com>
Co-authored-by: phschiele <44360364+phschiele@users.noreply.github.com>

* Adapt to API changes in gurobipy (#1962)

Signed-off-by: KerimovEmil <emilkerimov93@gmail.com>
Co-authored-by: Riley Murray <rileyjmurray@users.noreply.github.com>
Co-authored-by: phschiele <44360364+phschiele@users.noreply.github.com>
Co-authored-by: Robert Huisman <74955560+roberthuisman@users.noreply.github.com>
Co-authored-by: KerimovEmil <emilkerimov93@gmail.com>
Co-authored-by: Miles Lubin <miles.lubin@gmail.com>
Co-authored-by: Theodore Aptekarev <aptekarev@gmail.com>
Co-authored-by: Robert Luce <2168992+rluce@users.noreply.github.com>
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 a pull request may close this issue.

2 participants