CVXR to CVXPY results in infeasible

Uncategorized
Jun 29, 2022
R

When converting the existing example of FMMC from the cvxr page here to cvxpy, the python version results in “Infeasible” for the same graphs in the page. What am I doing differently?

def fmmc_weights(A):
    n, m = np.shape(A)
    I = np.eye(n)
    J = I - (1/n) * np.ones((n, n))
    s = cp.Variable()
    w = cp.Variable(m)
    L = cp.Variable((n, n), symmetric=True)
    constraints = [w >= 0,
                   cp.diag(L) <= 1,
                   L == A @ cp.diag(w) @ A.T,
                   J - L <= s * I,
                   J - L >= -s * I]
    prob = cp.Problem(cp.Minimize(s), constraints)
    prob.solve(verbose=True)
    print(f'status: {prob.status}')
    if prob.status not in ["infeasible", "unbounded"]:
        # Otherwise, problem.value is inf or -inf, respectively.
        print("Optimal value: %s" % prob.value)
        for variable in prob.variables():
            print("Variable %s: value %s" % (variable.name(), variable.value))    
    return w.value, prob.value

Example:

E = np.array([[1, 0, 0, 0, -1, 0],
                  [0, 0, 0, -1, 1, 1],
                  [-1, 1, 0, 0, 0, -1],
                  [0, 0, -1, 1, 0, 0],
                  [0, -1, 1, 0, 0, 0]])

results in:

===============================================================================
                                     CVXPY                                     
                                     v1.2.1                                    
===============================================================================
(CVXPY) Jun 28 10:04:51 PM: Your problem has 32 variables, 5 constraints, and 0 parameters.
(CVXPY) Jun 28 10:04:51 PM: It is compliant with the following grammars: DCP, DQCP
(CVXPY) Jun 28 10:04:51 PM: (If you need to solve this problem multiple times, but with different data, consider using parameters.)
(CVXPY) Jun 28 10:04:51 PM: CVXPY will first compile your problem; then, it will invoke a numerical solver to obtain a solution.
-------------------------------------------------------------------------------
                                  Compilation                                  
-------------------------------------------------------------------------------
(CVXPY) Jun 28 10:04:51 PM: Compiling problem (target solver=ECOS).
(CVXPY) Jun 28 10:04:51 PM: Reduction chain: Dcp2Cone -> CvxAttr2Constr -> ConeMatrixStuffing -> ECOS
(CVXPY) Jun 28 10:04:51 PM: Applying reduction Dcp2Cone
(CVXPY) Jun 28 10:04:51 PM: Applying reduction CvxAttr2Constr
(CVXPY) Jun 28 10:04:51 PM: Applying reduction ConeMatrixStuffing
(CVXPY) Jun 28 10:04:51 PM: Applying reduction ECOS
(CVXPY) Jun 28 10:04:51 PM: Finished problem compilation (took 7.281e-02 seconds).
-------------------------------------------------------------------------------
                                Numerical solver                               
-------------------------------------------------------------------------------
(CVXPY) Jun 28 10:04:51 PM: Invoking solver ECOS  to obtain a solution.
-------------------------------------------------------------------------------
                                    Summary                                    
-------------------------------------------------------------------------------
(CVXPY) Jun 28 10:04:51 PM: Problem status: infeasible
(CVXPY) Jun 28 10:04:51 PM: Optimal value: inf
(CVXPY) Jun 28 10:04:51 PM: Compilation took 7.281e-02 seconds
(CVXPY) Jun 28 10:04:51 PM: Solver (including time spent in interface) took 3.424e-03 seconds
status: infeasible
E

This forum is not a cvxpy forum. Check out cvxpy.org for the appropriate forum.