【问题标题】:Setting a constraint on the partial transpose of a variable matrix in CVXPY在 CVXPY 中对变量矩阵的部分转置设置约束
【发布时间】: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


    【解决方案1】:

    我今天遇到了和你一样的问题:我想创建一个由我之前定义的变量组合组成的新矩阵。我在this answer 中找到了我的问题的答案。第二种方法的问题是数组P_0_tp,它不是使用 cvxpy 操作生成的。您可以使用例如cvxpy.vstackcvxpy.hstack 或其他可用函数来构造它,如您可以找到here(似乎也有一个reshape 函数......)。

    在我提出的问题here 中,您可以看到我最终是如何实现它的。为了完整起见,我在这里复制它:

    import cvxpy as cp
    
    X = cp.Variable((3,3), PSD=True)
    
    row_1 = cp.hstack((0, 1, X[0,0]))
    row_2 = cp.hstack((1, 0, X[1,2]))
    row_3 = cp.hstack((X[0,0], X[1,2], 0))
    
    W = cp.vstack((row_1, row_2, row_3))
    constraint = [W >> 0]
    

    如您所见,我并没有将 W 定义为变量,但现在它是一个 cvxpy 对象:

    In [1] W
    Out[1]: Expression(AFFINE, UNKNOWN, (3, 3))
    

    【讨论】:

    • 很好,这似乎是我想做的。 reshape 函数确实存在,但它不允许维度高于 2 的对象(即张量)。所以你不能将它用于部分跟踪。
    • 如果你觉得可行,你能接受我的回答吗? :)
    猜你喜欢
    • 2019-04-10
    • 2019-08-21
    • 2021-09-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多