0

I'm trying to maximize the value of a function based on qutip to find the hermitian positive semidefinite matrix of trace equal 1 that maximized this function, but CVXPY always returns the value 0.0 and a diagonal matrix, do I have to do something for the solver to allow complex values on the matrix?

My code below:

import numpy as np
from qutip import *
import matplotlib.pyplot as plt
import cvxpy as cp


def Coherence(density_matrix):
    rho = Qobj(density_matrix)
    diag = rho.diag()
    matrix_diag = np.diag(diag)
    rho_diag = Qobj(matrix_diag)
    coherence = entropy_vn(rho_diag, 2) - entropy_vn(rho, 2)
    return coherence

n = 2**7

density_matrix = cp.Variable((n,n), hermitian=True)
constraints = [cp.trace(density_matrix) == 1]

prob = cp.Problem(cp.Maximize(Coherence(density_matrix.value)),constraints)
prob.solve()

# Print result.
print("The optimal value is", prob.value)
print("A solution density matrix is")
print(density_matrix.value)

always returns this results:

The optimal value is -0.0
A solution density matrix is
[[0.0078125+0.j 0.       +0.j 0.       +0.j ... 0.       +0.j
  0.       +0.j 0.       +0.j]
 [0.       +0.j 0.0078125+0.j 0.       +0.j ... 0.       +0.j
  0.       +0.j 0.       +0.j]
 [0.       +0.j 0.       +0.j 0.0078125+0.j ... 0.       +0.j
  0.       +0.j 0.       +0.j]
 ...
 [0.       +0.j 0.       +0.j 0.       +0.j ... 0.0078125+0.j
  0.       +0.j 0.       +0.j]
 [0.       +0.j 0.       +0.j 0.       +0.j ... 0.       +0.j
  0.0078125+0.j 0.       +0.j]
 [0.       +0.j 0.       +0.j 0.       +0.j ... 0.       +0.j
  0.       +0.j 0.0078125+0.j]]
Rodrigo de Azevedo
  • 1,097
  • 9
  • 17
Nillmer
  • 159
  • 1
  • 7
  • sorry, I'm trying to Maximize the value that the function "Coherence" outputs, I declared this function at the beginning of the code, it receives a square matrix and outputs a numeric value. – Nillmer Apr 08 '20 at 23:12
  • Go to Math SE, type your optimization problem in MathJax, get the image, post the image here. Here's a template: `$$\begin{array}{ll} \text{minimize} & \mathrm c^T \mathrm x\\ \text{subject to} & \mathrm A \mathrm x = \mathrm 0_m\end{array}$$`. Change the objective and the constraints. – Rodrigo de Azevedo Apr 09 '20 at 05:14
  • [image](https://imgur.com/d0DA6tV), the S_VN is the Von Neumann Entropy and C(rho) is the coherence, the function I want to maximize. – Nillmer Apr 09 '20 at 19:07
  • Have you tried, say, n=4 or n=8? It's easier to visualize such matrices and try to guess what is happening. Crawl, walk, run. – Rodrigo de Azevedo Apr 09 '20 at 19:21
  • You write "find the hermitian positive semidefinite matrix". Where is the positive semidefiniteness constraint??? I only see an equality constraint on the trace. – Rodrigo de Azevedo Apr 09 '20 at 19:31
  • It does not allow me to include hermitian=True and PSD=True, I've tried even with n=2 and still have the same error. Is it because, for some reason, the solver can't evaluate Coherence properly? – Nillmer Apr 09 '20 at 19:40
  • I tried and it still returns the optimal value as prob.value = -0.0 and a wrong matrix. But the density_matrix can have non-positive components. – Nillmer Apr 09 '20 at 19:47
  • 1
    `rho >> 0` is a PSD constraint, not a positivity constraint. – Rodrigo de Azevedo Apr 09 '20 at 19:50
  • I put the positive semidefinite constraint because density matrix (or rho, they represent the same thing) are a matrix representation of a quantum state, they are a density operator – Nillmer Apr 09 '20 at 19:50
  • 1
    I don't know what to say. There's a CVXPY mailing list on Google Groups. You can try to post there. – Rodrigo de Azevedo Apr 09 '20 at 19:53
  • ok, I'll try, thank you for your help! – Nillmer Apr 09 '20 at 19:54

0 Answers0