'Test the duals of PSD constraints.'

def test_psd_duals(self):

    if (s.CVXOPT in installed_solvers()):
        C = Symmetric(2, 2)
        obj = Maximize(C[(0, 0)])
        constraints = [(C << [[2, 0], [0, 2]])]
        prob = Problem(obj, constraints)
        result = prob.solve(solver=s.CVXOPT)
        self.assertAlmostEqual(result, 2)
        psd_constr_dual = constraints[0].dual_value
        C = Symmetric(2, 2)
        X = Semidef(2)
        obj = Maximize(C[(0, 0)])
        constraints = [(X == ([[2, 0], [0, 2]] - C))]
        prob = Problem(obj, constraints)
        result = prob.solve(solver=s.CVXOPT)
        self.assertItemsAlmostEqual(constraints[0].dual_value, psd_constr_dual)
    C = Symmetric(2, 2)
    obj = Maximize(C[(0, 0)])
    constraints = [(C << [[2, 0], [0, 2]])]
    prob = Problem(obj, constraints)
    result = prob.solve(solver=s.SCS)
    self.assertAlmostEqual(result, 2, places=4)
    psd_constr_dual = constraints[0].dual_value
    C = Symmetric(2, 2)
    X = Semidef(2)
    obj = Maximize(C[(0, 0)])
    constraints = [(X == ([[2, 0], [0, 2]] - C))]
    prob = Problem(obj, constraints)
    result = prob.solve(solver=s.SCS)
    self.assertItemsAlmostEqual(constraints[0].dual_value, psd_constr_dual)
    C = Symmetric(2, 2)
    obj = Maximize((C[(0, 1)] + C[(1, 0)]))
    constraints = [(C << [[2, 0], [0, 2]]), (C >= 0)]
    prob = Problem(obj, constraints)
    result = prob.solve(solver=s.SCS)
    self.assertAlmostEqual(result, 4, places=3)
    psd_constr_dual = constraints[0].dual_value
    C = Symmetric(2, 2)
    X = Semidef(2)
    obj = Maximize((C[(0, 1)] + C[(1, 0)]))
    constraints = [(X == ([[2, 0], [0, 2]] - C)), (C >= 0)]
    prob = Problem(obj, constraints)
    result = prob.solve(solver=s.SCS)
    self.assertItemsAlmostEqual(constraints[0].dual_value, psd_constr_dual, places=3)
