cvxpy throws error when Mosek solver encounters time limit
This is #735 but for Mosek: cvxpy crashes when Mosek hits a user-set time limit rather than providing partial solution information or giving an informative error.
To Reproduce
import cvxpy
x = cvxpy.Variable(1)
cvxpy.Problem(
cvxpy.Maximize(x),
[x <= 1]
).solve(
solver=cvxpy.MOSEK,
mosek_params={'MSK_DPAR_OPTIMIZER_MAX_TIME': 0.0}
)
Expected behavior
Maybe return cvxpy.settings.USER_LIMIT, but it seems there's a lengthy discussion of desired behavior over at #735. I'm not sure if partial solution information is available for MIPs, but it should be available if so. If there's never partial solution information, then raising a new cvxpy.exceptions.TimeLimitError exception would be best, especially if that exception object could carry information such as those that would normally be carried by the SolverStats object.
Output
From the session above:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File ".../cvxpy/problems/problem.py", line 396, in solve
return solve_func(self, *args, **kwargs)
File ".../cvxpy/problems/problem.py", line 754, in _solve
self.unpack_results(solution, solving_chain, inverse_data)
File ".../cvxpy/problems/problem.py", line 1070, in unpack_results
self.unpack(solution)
File ".../cvxpy/problems/problem.py", line 1030, in unpack
raise ValueError("Cannot unpack invalid solution: %s" % solution)
ValueError: Cannot unpack invalid solution: Solution(status=UNKNOWN, opt_val=nan, primal_vars={}, dual_vars={}, attr={'solve_time': 0.00013589859008789062})
Version
- OS: macOS 10.15.7
- Python: 3.7.9
- CVXPY Version: 1.1.7
We would address this currently by returning the USER_LIMIT status. That can involve returning a solution.
@phschiele @SteveDiamond I am currently taking a look at the issue here and do I understand it correctly if the solver hits a timelimit (timelimit is set by the user) and no solution was generated (presolve optimal solution, inaccurate solution etc.) a timelimit error is returned to the user ?