Example #1
0
 def test_guessing_probability(self):
     p = [
         0.5, 0.5, 0.5, 0.5, 0.4267766952966368, 0.4267766952966368,
         0.4267766952966368, 0.07322330470336313
     ]
     P = Probability([2, 2], [2, 2])
     behaviour_constraint = [
         P([0], [0], 'A') - p[0],
         P([0], [1], 'A') - p[1],
         P([0], [0], 'B') - p[2],
         P([0], [1], 'B') - p[3],
         P([0, 0], [0, 0]) - p[4],
         P([0, 0], [0, 1]) - p[5],
         P([0, 0], [1, 0]) - p[6],
         P([0, 0], [1, 1]) - p[7]
     ]
     behaviour_constraint.append("-0[0,0]+1.0")
     sdpRelaxation = SdpRelaxation(P.get_all_operators(),
                                   normalized=False,
                                   verbose=0)
     sdpRelaxation.get_relaxation(1,
                                  objective=-P([0], [0], 'A'),
                                  momentequalities=behaviour_constraint,
                                  substitutions=P.substitutions)
     sdpRelaxation.solve()
     self.assertTrue(abs(sdpRelaxation.primal + 0.5) < 10e-5)
Example #2
0
def __main__():
    # chsh quantum bound : 4
    # mermin quantum bound : 4
    # svetlichny quantum bound 4sqrt(2) ~ 5.65

    P = Probability([2, 2], [2, 2], [2, 2])
    Chsh = chsh(P)
    Mermin = mermin(P)
    Svetlichny = svetlichny(P)

    dx = 0
    div = 1.0
    step = 0.4
    lim = 5.6
    x = []
    y = []
    while dx <= lim:

        print(dx)
        ineq = []
        ineq.append(Svetlichny - dx)
        ineq.append(-1 * Svetlichny + dx)
        sdpRelaxation = SdpRelaxation(P.get_all_operators(), verbose=0)
        sdpRelaxation.get_relaxation(2,
                                     substitutions=P.substitutions,
                                     inequalities=ineq)
        sdpRelaxation.set_objective(-Chsh)
        solve_sdp(sdpRelaxation, solver="cvxopt")
        x.append(dx)
        y.append(abs(sdpRelaxation.primal) / div)
        dx = dx + step

    plt.plot(x, y, 'k')
    plt.show()
def __main__():   
  # chsh quantum bound : 4
  # mermin quantum bound : 4
  # svetlichny quantum bound 4sqrt(2) ~ 5.65 

  P = Probability([2, 2], [2, 2], [2, 2])
  Chsh = chsh(P)
  Mermin = mermin(P)
  Svetlichny = svetlichny(P)
   
  dx = 0
  div = 1.0
  step = 0.4
  lim = 5.6
  x = []
  y = []
  while dx  <= lim :
  
    print (dx)
    ineq = []
    ineq.append(Svetlichny - dx)
    ineq.append(-1*Svetlichny + dx)
    sdpRelaxation = SdpRelaxation(P.get_all_operators(), verbose=0)
    sdpRelaxation.get_relaxation(2, substitutions = P.substitutions,inequalities = ineq)
    sdpRelaxation.set_objective(-Chsh)
    solve_sdp(sdpRelaxation, solver="cvxopt")
    x.append(dx)
    y.append(abs(sdpRelaxation.primal)/div)
    dx = dx + step 

  plt.plot(x,y,'k')   
  plt.show()   
Example #4
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)
Example #5
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)
Example #6
0
 def test_guessing_probability(self):
     p = [0.5, 0.5, 0.5, 0.5, 0.4267766952966368, 0.4267766952966368, 0.4267766952966368, 0.07322330470336313]
     P = Probability([2, 2], [2, 2])
     behaviour_constraint = [
         P([0], [0], "A") - p[0],
         P([0], [1], "A") - p[1],
         P([0], [0], "B") - p[2],
         P([0], [1], "B") - p[3],
         P([0, 0], [0, 0]) - p[4],
         P([0, 0], [0, 1]) - p[5],
         P([0, 0], [1, 0]) - p[6],
         P([0, 0], [1, 1]) - p[7],
     ]
     behaviour_constraint.append("-0[0,0]+1.0")
     sdpRelaxation = SdpRelaxation(P.get_all_operators(), normalized=False, verbose=0)
     sdpRelaxation.get_relaxation(
         1, objective=-P([0], [0], "A"), momentequalities=behaviour_constraint, substitutions=P.substitutions
     )
     sdpRelaxation.solve()
     self.assertTrue(abs(sdpRelaxation.primal + 0.5) < 10e-5)
 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)
Example #8
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)