Ejemplo n.º 1
0
 def test_maximum_violation(self):
     I = [[0, -1, 0], [-1, 1, 1], [0, 1, -1]]
     P = Probability([2, 2], [2, 2])
     relaxation = SdpRelaxation(P.get_all_operators())
     relaxation.get_relaxation(1,
                               objective=define_objective_with_I(I, P),
                               substitutions=P.substitutions,
                               extramonomials=P.get_extra_monomials('AB'))
     relaxation.solve()
     self.assertTrue(abs(relaxation.primal + (np.sqrt(2)-1)/2) < 10e-5)
Ejemplo n.º 2
0
 def test_maximum_violation(self):
     I = [[0, -1, 0], [-1, 1, 1], [0, 1, -1]]
     P = Probability([2, 2], [2, 2])
     relaxation = SdpRelaxation(P.get_all_operators())
     relaxation.get_relaxation(1,
                               objective=define_objective_with_I(I, P),
                               substitutions=P.substitutions,
                               extramonomials=P.get_extra_monomials('AB'))
     relaxation.solve()
     self.assertTrue(abs(relaxation.primal + (np.sqrt(2) - 1) / 2) < 10e-5)
Ejemplo n.º 3
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)
Ejemplo n.º 4
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 = sdpRelaxation.convert_to_picos(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.1236) < 10e-3)
Ejemplo n.º 5
0
# -*- coding: utf-8 -*-
"""
This example calculates the maximum quantum violation of the CHSH inequality in
the probability picture with a mixed-level relaxation of 1+AB.

Created on Mon Dec  1 14:19:08 2014

@author: Peter Wittek
"""
from ncpol2sdpa import Probability, SdpRelaxation, define_objective_with_I

level = 1
I = [[ 0,   -1,    0 ],
     [-1,    1,    1 ],
     [ 0,    1,   -1 ]]
P = Probability([2, 2], [2, 2])
objective = define_objective_with_I(I, P)

sdpRelaxation = SdpRelaxation(P.get_all_operators())
sdpRelaxation.get_relaxation(level, objective=objective,
                             substitutions=P.substitutions,
                             extramonomials=P.get_extra_monomials('AB'))
sdpRelaxation.solve()
print(sdpRelaxation.primal, sdpRelaxation.status)
Ejemplo n.º 6
0
    def _relax(self):
        """
		Creates the sdp relaxation object from ncpol2sdpa.
		"""
        if self.solver == None:
            self.solver = self.DEFAULT_SOLVER_PATH
        self._eq_cons = []  # equality constraints
        self._proj_cons = {}  # projective constraints
        self._A_ops = []  # Alice's operators
        self._B_ops = []  # Bob's operators
        self._obj = 0  # Objective function
        self._obj_const = ''  # Extra objective normalisation constant
        self._sdp = None  # SDP object

        # Creating the operator constraints
        nrm = ''
        # Need as many decompositions as there are generating outcomes
        for k in range(np.prod(self.generation_output_size)):
            self._A_ops += [
                ncp.generate_measurements(self.io_config[0],
                                          'A' + str(k) + '_')
            ]
            self._B_ops += [
                ncp.generate_measurements(self.io_config[1],
                                          'B' + str(k) + '_')
            ]
            self._proj_cons.update(
                ncp.projective_measurement_constraints(self._A_ops[k],
                                                       self._B_ops[k]))

            #Also building a normalisation string for next step
            nrm += '+' + str(k) + '[0,0]'

        # Adding the constraints
        # Normalisation constraint
        self._eq_cons.append(nrm + '-1')

        self._base_constraint_expressions = []
        # Create the game expressions
        for game in self.games:
            tmp_expr = 0
            for k in range(np.prod(self.generation_output_size)):
                tmp_expr += -ncp.define_objective_with_I(
                    game._cgmatrix, self._A_ops[k], self._B_ops[k])

            self._base_constraint_expressions.append(tmp_expr)

        # Specify the scores for these expressions including any shifts
        for i, game in enumerate(self.games):
            #We must account for overshifting in the score coming from the decomposition
            self._eq_cons.append(self._base_constraint_expressions[i] -
                                 game.score - game._cgshift *
                                 (np.prod(self.generation_output_size) - 1))

        self._obj, self._obj_const = guessingProbabilityObjectiveFunction(
            self.io_config, self.generation_inputs, self._A_ops, self._B_ops)

        # Initialising SDP
        ops = [
            ncp.flatten([self._A_ops[0], self._B_ops[0]]),
            ncp.flatten([self._A_ops[1], self._B_ops[1]]),
            ncp.flatten([self._A_ops[2], self._B_ops[2]]),
            ncp.flatten([self._A_ops[3], self._B_ops[3]])
        ]

        self._sdp = ncp.SdpRelaxation(ops,
                                      verbose=self.verbose,
                                      normalized=False)
        self._sdp.get_relaxation(level=self._relaxation_level,
                                 momentequalities=self._eq_cons,
                                 objective=self._obj,
                                 substitutions=self._proj_cons,
                                 extraobjexpr=self._obj_const)