0

I am attempting to translate a semidefinite programming problem from CVX to CVXPY as described here. My attempt follows:

import cvxpy as cvx
import numpy as np

c = [0, 1]
n = len(c)

# Create optimization variables.
f = cvx.Variable((n, n), hermitian=True)

# Create constraints.
constraints = [f >> 0]
for k in range(1, n):
    indices = [(i * n) + i - (n - k) for i in range(n - k, n)]
    constraints += [cvx.sum(cvx.vec(f)[indices]) == c[n - k]]

# Form objective.
obj = cvx.Maximize(c[0] - cvx.trace(f))

# Form and solve problem.
prob = cvx.Problem(obj, constraints)
sol = prob.solve()

print(sol)
print(f.value)

The issue here is that when I take the coefficients of the Fourier series and translate them into the array c it fails on complex values. I think this is due to a discrepancy between the maximize function of CVX and CVXPY. I'm not sure what CVX is maximizing, since the trace of the matrix is a complex value. As pointed out below the trace is real since the matrix is Hermitian, but the code still fails. Can someone with CVXPY knowledge clear this up?

Wulfsta
  • 1
  • 2
  • Does this have something to do with hermitian matrices having real valued traces? The diagonal values are real valued. Maybe your values are complex but the imaginary values are close to zero? – Jacques Kvam Feb 10 '19 at 23:48
  • Ahh, very good point. Looking through the documentation there appears to be a `hermitian=True` attribute that can be set on the variable `f`. I am still getting that the maximize value must be real valued. Let me see if I can sort that out and I will update with results. – Wulfsta Feb 11 '19 at 04:03

0 Answers0