【发布时间】:2020-06-08 08:15:52
【问题描述】:
我正在使用 CVXPY 在 Python 中计算 SDP 问题,我想设置一个约束,即不仅我的变量矩阵是半正定 (psd),而且它在某个轴上的部分转置也是 psd。我不知道如何设置这个要求。我的代码如下所示
#Set the variable matrix
P_0 = cp.Variable((d,d), symmetric=True)
现在我想定义类似
def PT(d1, d2, rho):
"""Return rho^{T_1}, the partial trace of the density operator rho on C^{d_1} \ot C^{d_2} along the first system."""
assert rho.shape == (d1 * d2, d1 * d2)
# reshape into a 4-tensor (2 ket indices and 2 bra indices)
rho = rho.reshape(d1, d2, d1, d2)
# transpose the first subsystem
rho = rho.transpose((0,3,2,1))
# reshape back into a density operator
return rho.reshape(d1 * d2, d1 * d2)
然后设置PT(3,3, P_0) >> 0的要求,即它是psd。但这在 cvxpy 中是不允许的。我也可以为我的具体情况定义一个新矩阵,比如
P_0_tp = [[P_0[[0,0]], P_0[[1, 0]], P_0[[2, 0]], P_0[[0, 3]], P_0[[1, 3]], P_0[[2, 3]],
P_0[[0, 6]], P_0[[1, 6]], P_0[[2, 6]]], [P_0[[0, 1]], P_0[[1, 1]], P_0[[2, 1]],
P_0[[0, 4]], P_0[[1, 4]], P_0[[2, 4]], P_0[[0, 7]], P_0[[1, 7]],
P_0[[2, 7]]], [P_0[[0, 2]], P_0[[1, 2]], P_0[[2, 2]], P_0[[0, 5]], P_0[[1, 5]],
P_0[[2, 5]], P_0[[0, 8]], P_0[[1, 8]], P_0[[2, 8]]], [P_0[[3, 0]], P_0[[4, 0]],
P_0[[5, 0]], P_0[[3, 3]], P_0[[4, 3]], P_0[[5, 3]], P_0[[3, 6]], P_0[[4, 6]],
P_0[[5, 6]]], [P_0[[3, 1]], P_0[[4, 1]], P_0[[5, 1]], P_0[[3, 4]], P_0[[4, 4]],
P_0[[5, 4]], P_0[[3, 7]], P_0[[4, 7]], P_0[[5, 7]]], [P_0[[3, 2]], P_0[[4, 2]],
P_0[[5, 2]], P_0[[3, 5]], P_0[[4, 5]], P_0[[5, 5]], P_0[[3, 8]], P_0[[4, 8]],
P_0[[5, 8]]], [P_0[[6, 0]], P_0[[7, 0]], P_0[[8, 0]], P_0[[6, 3]], P_0[[7, 3]],
P_0[[8, 3]], P_0[[6, 6]], P_0[[7, 6]], P_0[[8, 6]]], [P_0[[6, 1]], P_0[[7, 1]],
P_0[[8, 1]], P_0[[6, 4]], P_0[[7, 4]], P_0[[8, 4]], P_0[[6, 7]], P_0[[7, 7]],
P_0[[8, 7]]], [P_0[[6, 2]], P_0[[7, 2]], P_0[[8, 2]], P_0[[6, 5]], P_0[[7, 5]],
P_0[[8, 5]], P_0[[6, 8]], P_0[[7, 8]], P_0[[8, 8]]]]
这是一个 9x9 矩阵,现在在第二个 3 维中部分转置。但是如何将其设置为 cvxpy 中的变量?
提前致谢,
【问题讨论】:
标签: python matrix solver sdp cvxpy