我正在尝试最大化一个函数的值,qutip
以找到使该函数最大化的迹线等于 1 的厄尔米特半正定矩阵,但 CVXPY 总是返回值 0.0 和一个对角矩阵,我是否必须为求解器做点什么允许矩阵上的复杂值?
我的代码如下:
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)
总是返回这个结果:
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]]