Exemplo n.º 1
0
 def test_violation(self):
     I = [[0, -1, 0], [-1, 1, 1], [0, 1, -1]]
     P = Probability([2, 2], [2, 2])
     objective = define_objective_with_I(I, P)
     sdpRelaxation = MoroderHierarchy([flatten(P.parties[0]), flatten(P.parties[1])], verbose=0, normalized=False)
     sdpRelaxation.get_relaxation(1, objective=objective, substitutions=P.substitutions)
     Problem = convert_to_picos(sdpRelaxation, duplicate_moment_matrix=True)
     X = Problem.get_variable("X")
     Y = Problem.get_variable("Y")
     Z = Problem.add_variable("Z", (sdpRelaxation.block_struct[0], sdpRelaxation.block_struct[0]))
     Problem.add_constraint(Y.partial_transpose() >> 0)
     Problem.add_constraint(Z.partial_transpose() >> 0)
     Problem.add_constraint(X - Y + Z == 0)
     Problem.add_constraint(Z[0, 0] == 1)
     solution = Problem.solve(verbose=0)
     self.assertTrue(abs(solution["obj"] - 0.139) < 10e-3)
Exemplo n.º 2
0
"""

from ncpol2sdpa import generate_variables, SdpRelaxation, convert_to_picos

# Number of Hermitian variables
n_vars = 2
# Level of relaxation
level = 2

# Get Hermitian variables
X = generate_variables(n_vars, hermitian=True)

# Define the objective function
obj = X[0] * X[1] + X[1] * X[0]

# Inequality constraints
inequalities = [-X[1]**2 + X[1] + 0.5]

# Equality constraints
equalities = []
equalities.append(X[0]**2 - X[0])

# Obtain SDP relaxation
sdpRelaxation = SdpRelaxation(X)
sdpRelaxation.get_relaxation(level,
                             objective=obj,
                             inequalities=inequalities,
                             equalities=equalities)
P = convert_to_picos(sdpRelaxation)
P.solve()
@author: Peter Wittek
"""

from ncpol2sdpa import generate_variables, SdpRelaxation, convert_to_picos

# Number of Hermitian variables
n_vars = 2
# Level of relaxation
level = 2

# Get Hermitian variables
X = generate_variables(n_vars, hermitian=True)

# Define the objective function
obj = X[0] * X[1] + X[1] * X[0]

# Inequality constraints
inequalities = [-X[1] ** 2 + X[1] + 0.5]

# Equality constraints
equalities = []
equalities.append(X[0] ** 2 - X[0])

# Obtain SDP relaxation
sdpRelaxation = SdpRelaxation(X)
sdpRelaxation.get_relaxation(level, objective=obj,
                             inequalities=inequalities,
                             equalities=equalities)
P = convert_to_picos(sdpRelaxation)
P.solve()