CVXOPT with CVXPY fails to solve simple linear prorgam

26 views
Skip to first unread message

Graham Hulsey

unread,
Apr 26, 2024, 2:55:00 PMApr 26
to CVXOPT
Hello,

I have installed cvxopt and cvxpy in a virtual environment on my Linux machine, running Ubuntu 22.04.4 LTS. I installed both packages through pip.

I took the cvxpy LP example problem and set the solver to cp.CVXOPT, and got the correct solution, which tells me that the packages are working. Then, I wrote the following extremely simple LP:

import cvxpy as cp
import numpy as np

n = 2
x = cp.Variable(n)

prob = cp.Problem(cp.Maximize(cp.sum(x)), [cp.sum(x) <= 10])
prob.solve(verbose=True)

print("\nThe optimal value is", prob.value)
print("A solution x is")
print(x.value)
print("A dual solution is")
print(prob.constraints[0].dual_value)

which solves correctly with the ECOS solver. However, when I take the above model and set solver=cp.CVXOPT, the model fails. The output of the solver is here:

===============================================================================
                                     CVXPY                                    
                                     v1.4.3                                    
===============================================================================
(CVXPY) Apr 17 08:55:08 PM: Your problem has 2 variables, 1 constraints, and 0 parameters.
(CVXPY) Apr 17 08:55:08 PM: It is compliant with the following grammars: DCP, DQCP
(CVXPY) Apr 17 08:55:08 PM: (If you need to solve this problem multiple times, but with different data, consider using parameters.)
(CVXPY) Apr 17 08:55:08 PM: CVXPY will first compile your problem; then, it will invoke a numerical solver to obtain a solution.
(CVXPY) Apr 17 08:55:08 PM: Your problem is compiled with the CPP canonicalization backend.
-------------------------------------------------------------------------------
                                  Compilation                                  
-------------------------------------------------------------------------------
(CVXPY) Apr 17 08:55:08 PM: Compiling problem (target solver=CVXOPT).
(CVXPY) Apr 17 08:55:08 PM: Reduction chain: FlipObjective -> Dcp2Cone -> CvxAttr2Constr -> ConeMatrixStuffing -> CVXOPT
(CVXPY) Apr 17 08:55:08 PM: Applying reduction FlipObjective
(CVXPY) Apr 17 08:55:08 PM: Applying reduction Dcp2Cone
(CVXPY) Apr 17 08:55:08 PM: Applying reduction CvxAttr2Constr
(CVXPY) Apr 17 08:55:08 PM: Applying reduction ConeMatrixStuffing
(CVXPY) Apr 17 08:55:08 PM: Applying reduction CVXOPT
(CVXPY) Apr 17 08:55:08 PM: Finished problem compilation (took 2.663e-03 seconds).
-------------------------------------------------------------------------------
                                Numerical solver                              
-------------------------------------------------------------------------------
(CVXPY) Apr 17 08:55:08 PM: Invoking solver CVXOPT  to obtain a solution.
Traceback (most recent call last):
  File "/home/graham/test2.py", line 8, in <module>
    prob.solve(solver=cp.CVXOPT, verbose=True)
  File "/home/graham/venv/lib/python3.10/site-packages/cvxpy/problems/problem.py", line 503, in solve
    return solve_func(self, *args, **kwargs)
  File "/home/graham/venv/lib/python3.10/site-packages/cvxpy/problems/problem.py", line 1086, in _solve
    self.unpack_results(solution, solving_chain, inverse_data)
  File "/home/graham/venv/lib/python3.10/site-packages/cvxpy/problems/problem.py", line 1411, in unpack_results
    raise error.SolverError(
cvxpy.error.SolverError: Solver 'CVXOPT' failed. Try another solver, or solve with verbose=True for more information.

I am unable to determine why CVXOPT cannot solve this problem, but think it may be related to the syntax of the constraints. Any help is much appreciated.


Martin

unread,
Apr 26, 2024, 3:22:47 PMApr 26
to CVXOPT
The dual to the problem that you are solving has redundant constraints, which means that the problem that cvxpy is passing to cvxopt does not satisfy a certain rank requirement (see https://cvxopt.org/userguide/coneprog.html#linear-cone-programs).

You can either reformulate the problem (e.g., replace sum(x) by a scalar variable) or you can try the following:

   prob.solve(solver="CVXOPT", kktsolver="robust")
Reply all
Reply to author
Forward
0 new messages