Ejemplo n.º 1
0
    def testRandProjMeasBetweenAlice1andBob(self):
        scenario = SequentialBellScenario([[2, 2], [2, 2]], [2, 2])
        alice1blochVectors = [[1, 0, 0], [0, 1, 0]]
        alice1Observables = list(
            map(lambda bloch: createQubitObservable(bloch),
                alice1blochVectors))
        alice1Krauss = list(
            map(
                lambda qubitObservable: projectorsForQubitObservable(
                    qubitObservable), alice1Observables))

        phases = [
            np.random.uniform(-np.pi / 2, np.pi / 2),
            np.random.uniform(-np.pi / 2, np.pi / 2)
        ]
        alice2blochVectors = [[np.sin(theta), 0,
                               np.cos(theta)] for theta in phases]
        alice2Observables = list(
            map(lambda bloch: createQubitObservable(bloch),
                alice2blochVectors))
        alice2Effects = list(
            map(
                lambda qubitObservable: projectorsForQubitObservable(
                    qubitObservable), alice2Observables))

        phasesBob = [
            np.random.uniform(-np.pi / 2, np.pi / 2),
            np.random.uniform(-np.pi / 2, np.pi / 2)
        ]
        bobVectors = [[np.sin(theta), 0, np.cos(theta)] for theta in phasesBob]
        bobObservables = list(
            map(lambda bloch: createQubitObservable(bloch), bobVectors))
        bobEffects = list(
            map(
                lambda qubitObservable: projectorsForQubitObservable(
                    qubitObservable), bobObservables))

        aux = alice1Krauss
        alice1Krauss = alice2Effects
        alice2Effects = aux

        psi = createMaxEntState(2)
        rho = psi * psi.dag()
        expectedCorrelations = {}
        for x1 in range(2):
            for a1 in range(2):
                postMeasrmntState = qt.tensor(
                    alice1Krauss[x1][a1], qt.qeye(2)) * rho * (qt.tensor(
                        alice1Krauss[x1][a1], qt.qeye(2))).dag()
                for x2, y, a2, b in product(range(2), repeat=4):
                    expectedCorrelations[(x1, x2), y, (a1, a2), b] = (
                        qt.tensor(alice2Effects[x2][a2], bobEffects[y][b]) *
                        postMeasrmntState).tr().real
        expectedBehaviour = Behaviour(scenario, expectedCorrelations)

        poly = BellPolytopeWithOneWayCommunication(
            SequentialBellPolytope(scenario))
        self.assertTrue(poly.contains(expectedBehaviour.getProbabilityList()),
                        'phases:' + str(phases[0]) + ', ' + str(phases[1]))
Ejemplo n.º 2
0
 def testPRCorrBetweenAlice1andBobAndLocalOtherwiseIsInPolytope(self):
     scenario = SequentialBellScenario([[2, 2], [2, 2]], [2, 2])
     expectedCorrelations = {
         ((x1, x2), y, (a1, a2), b):
         1 / 2 * int((a2 == 0) & (x1 * y == (a1 + b) % 2))
         for ((x1, x2), y, (a1, a2), b) in scenario.getTuplesOfEvents()
     }
     expectedBehaviour = Behaviour(scenario, expectedCorrelations)
     poly = BellPolytopeWithOneWayCommunication(
         SequentialBellPolytope(scenario))
     self.assertTrue(poly.contains(expectedBehaviour.getProbabilityList()))
Ejemplo n.º 3
0
 def testExistsStrategyAchievingAlgMaxOfCHSH(self):
     vertices = BellPolytopeWithOneWayCommunication(
         BellPolytope(BellScenario([2, 2], [2, 2]))).getListOfVertices()
     chshFunctional = [
         1, -1, -1, 1, 1, -1, -1, 1, 1, -1, -1, 1, -1, 1, 1, -1
     ]
     self.assertEqual(
         max([
             np.dot(vertice.getProbabilityList(), chshFunctional)
             for vertice in vertices
         ]), 4)
Ejemplo n.º 4
0
    def testCHSHBetweenAlice1AndBobAndIdentityInAlice2IsInPolytope(self):
        scenario = SequentialBellScenario([[2, 2], [2, 2]], [2, 2])
        alice1blochVectors = [[1, 0, 0], [0, 1, 0]]
        alice1Observables = list(
            map(lambda bloch: createQubitObservable(bloch),
                alice1blochVectors))
        alice1Krauss = list(
            map(
                lambda qubitObservable: projectorsForQubitObservable(
                    qubitObservable), alice1Observables))

        alice2Effects = [[qt.qeye(2), 0 * qt.qeye(2)],
                         [qt.qeye(2), 0 * qt.qeye(2)]]

        bobUnBlochVectors = [[-1, -1, 0], [-1, 1, 0]]
        bobObservables = list(
            map(lambda bloch: createQubitObservable(bloch), bobUnBlochVectors))
        bobEffects = list(
            map(
                lambda qubitObservable: projectorsForQubitObservable(
                    qubitObservable), bobObservables))

        psi = createMaxEntState(2)

        rho = psi * psi.dag()
        expectedCorrelations = {}
        for x1 in range(2):
            for a1 in range(2):
                postMeasrmntState = qt.tensor(
                    alice1Krauss[x1][a1], qt.qeye(2)) * rho * (qt.tensor(
                        alice1Krauss[x1][a1], qt.qeye(2))).dag()
                for x2, y, a2, b in product(range(2), repeat=4):
                    expectedCorrelations[(x1, x2), y, (a1, a2), b] = (
                        qt.tensor(alice2Effects[x2][a2], bobEffects[y][b]) *
                        postMeasrmntState).tr().real
        expectedBehaviour = Behaviour(scenario, expectedCorrelations)

        poly = BellPolytopeWithOneWayCommunication(
            SequentialBellPolytope(scenario))
        self.assertTrue(poly.contains(expectedBehaviour.getProbabilityList()))
Ejemplo n.º 5
0
    B1 = [sum(B[y, b] * (-1)**b for b in range(2)) for y in range(2)]

    prob.add_constraint(pic.trace(CHSH(A1, B1) * rho) == alpha)

    prob.set_objective('max', pic.trace(CHSH(A2, B1) * rho))

    prob.solve()
    #
    return [
        pic.trace(pic.kron(A[x1, x2, a1, a2], B[y, b]) * rho).get_value().real
        for x1, x2, y, a1, a2, b in product(range(2), range(2), range(2),
                                            range(2), range(2), range(2))
    ]


if __name__ == '__main__':

    alpha = 2.5
    qdist = findQDistMaximizingCHSH2ForCHSH1ValueOf(alpha)

    outputsAliceSequence = [[2, 2], [2, 2]]
    outputsBob = [2, 2]
    bellScenario = SequentialBellScenario(outputsAliceSequence, outputsBob)

    polytope = BellPolytopeWithOneWayCommunication(
        SequentialBellPolytope(bellScenario))

    if not polytope.contains(qdist):
        print(
            'We found a qdist not reproducible with one bit of comm in the sequential scenario!'
        )
Ejemplo n.º 6
0
    B1 = [sum(B[y, b] * (-1)**b for b in range(2)) for y in range(n)]

    prob.add_constraint(pic.trace(CHAINED(n, A1, B1) * rho) == alpha)

    prob.set_objective('max', pic.trace(CHSH(A2, B1) * rho))

    prob.solve()
    #
    dist = [
        pic.trace(pic.kron(A[x1, x2, a1, a2], B[y, b]) * rho).get_value().real
        for x1, x2, y, a1, a2, b in product(range(n), range(2), range(n),
                                            range(2), range(2), range(2))
    ]

    vertices = BellPolytopeWithOneWayCommunication(
        outputsAlice, outputsBob).getListOfVertices()

    print(In_ConvexHull(vertices, vertices[0]))

#

#     with Model("lo1") as M:
#
#         # Create variable 'x' of length 4
#         x = M.variable("x", len(vertices), Domain.greaterThan(0.0))
#
#
#         # Create constraints
#         for prob in range(len(vertices[0])):
#             M.constraint('p('+str(prob)+')',Expr.dot(x,list(map(lambda ver : ver[prob],vertices))),Domain.equalsTo(dist[prob]))
#
Ejemplo n.º 7
0
                         [-np.sin(mu), 0, np.cos(mu)]]
    bobObservables = list(
        map(lambda bloch: createQubitObservable(bloch), bobUnBlochVectors))
    bobEffects = list(
        map(
            lambda qubitObservable: projectorsForQubitObservable(
                qubitObservable), bobObservables))

    psi = createMaxEntState(2)
    rho = psi * psi.dag()

    expectedCorrelations = {}
    for x1, x2, y in product(range(len(alice1outputs)),
                             range(len(alice2outputs)),
                             range(len(bobOutputs))):
        for a1, a2, b in product(range(alice1outputs[x1]),
                                 range(alice2outputs[x2]),
                                 range(bobOutputs[y])):
            postMeasrmntState = qt.tensor(
                alice1Krauss[x1][a1], qt.qeye(2)) * rho * (qt.tensor(
                    alice1Krauss[x1][a1], qt.qeye(2))).dag()
            expectedCorrelations[(x1, x2), y, (a1, a2), b] = (
                qt.tensor(alice2Effects[x2][a2], bobEffects[y][b]) *
                postMeasrmntState).tr().real

    expectedBehaviour = Behaviour(scenario, expectedCorrelations)

    polytope = BellPolytopeWithOneWayCommunication(
        SequentialBellPolytope(scenario))

    print(polytope.contains(expectedBehaviour.getProbabilityList()))
Ejemplo n.º 8
0
import numpy as np
from bellpolytope import BellPolytope
from bellscenario import BellScenario
from bellpolytopewithonewaycomm import BellPolytopeWithOneWayCommunication
from ppl import Variable, Generator_System, C_Polyhedron, point
from sequentialbellpolytope import SequentialBellPolytope
from sequentialbellscenario import SequentialBellScenario

if __name__ == '__main__':

    outputsAliceSeq = [[2, 2], [2, 2]]
    outputsBob = [2, 2]
    scenario = SequentialBellScenario(outputsAliceSeq, outputsBob)

    variables = [Variable(i) for i in range(len(scenario.getTuplesOfEvents()))]
    gs = Generator_System()

    for v in BellPolytopeWithOneWayCommunication(
            SequentialBellPolytope(scenario)).getGeneratorForVertices():
        prob = v.getProbabilityList()
        gs.insert(point(sum(prob[i] * variables[i] for i in range(len(prob)))))

    poly = C_Polyhedron(gs)
    constraints = poly.constraints()

    for constraint in constraints:
        inequality = str(constraint.inhomogeneous_term().__float__()) + ' '
        for coef in constraint.coefficients():
            inequality = inequality + str(-coef.__float__()) + ' '
        print(inequality)
Ejemplo n.º 9
0
                                                    for x2 in range(2)]
         
    B1=[sum(B[y,b]*(-1)**b for b in range(2)) for y in range(n)]
     
     
    prob.add_constraint(pic.trace(CHAINED(n,A1,B1)*rho)==alpha)
     
    prob.set_objective('max',
                       pic.trace(CHSH(A2,B1)*rho))
     
    prob.solve()
#     
    dist=[pic.trace(pic.kron(A[x1,x2,a1,a2],B[y,b])*rho).get_value().real
          for x1,x2,y,a1,a2,b in product(range(n),range(2),range(n),range(2),range(2),range(2))]
 
    vertices=BellPolytopeWithOneWayCommunication(outputsAlice,outputsBob).getGeneratorForVertices()
    
    with Model("lo1") as M:

        # Create variables
        bellFunctional = M.variable("func",144)
        localBound = M.variable("bound", 1)

        # Create constraints
        vertexNum=0
        for vertex in vertices:
            M.constraint('const'+str(vertexNum),Expr.sub(Expr.dot(bellFunctional,vertex),localBound)
                         ,Domain.lessThan(0))
            vertexNum+=1
            
        M.constraint('norm',Expr.sub(Expr.dot(bellFunctional,dist),localBound),Domain.lessThan(1))
Ejemplo n.º 10
0
    def testMeasurementsOverSeparableStateAreLocal(self):
        alice1outputs = [2, 2]
        alice2outputs = [2, 3]
        bobOutputs = [2, 2]
        scenario = SequentialBellScenario([alice1outputs, alice2outputs],
                                          bobOutputs)

        epsilon = 0
        plus = 1 / np.sqrt(2) * (qt.basis(2, 0) + qt.basis(2, 1))
        minus = 1 / np.sqrt(2) * (qt.basis(2, 0) - qt.basis(2, 1))
        Kplus = np.cos(epsilon) * plus * plus.dag() + np.sin(
            epsilon) * minus * minus.dag()
        Kminus = -np.cos(epsilon) * minus * minus.dag() + np.sin(
            epsilon) * plus * plus.dag()

        alice1Krauss = [
            projectorsForQubitObservable(createQubitObservable([0, 0, 1])),
            [Kplus, Kminus]
        ]

        alice2blochVectors = [[0, 0, 1]]
        alice2Observables = list(
            map(lambda bloch: createQubitObservable(bloch),
                alice2blochVectors))
        alice2Effects = list(
            map(
                lambda qubitObservable: projectorsForQubitObservable(
                    qubitObservable), alice2Observables))
        trineAlice2 = [[0, 0, 1],
                       [np.sin(2 * np.pi / 3), 0,
                        np.cos(2 * np.pi / 3)],
                       [np.sin(4 * np.pi / 3), 0,
                        np.cos(4 * np.pi / 3)]]
        paulies = [qt.sigmax(), qt.sigmay(), qt.sigmaz()]
        alice2Effects.append(
            list(
                map(
                    lambda bloch: effectForQubitPovm(
                        1 / 3, sum([paulies[i] * bloch[i] for i in range(3)])),
                    trineAlice2)))

        mu = np.arctan(np.sin(2 * epsilon))
        bobUnBlochVectors = [[np.sin(mu), 0, np.cos(mu)],
                             [-np.sin(mu), 0, np.cos(mu)]]
        bobObservables = list(
            map(lambda bloch: createQubitObservable(bloch), bobUnBlochVectors))
        bobEffects = list(
            map(
                lambda qubitObservable: projectorsForQubitObservable(
                    qubitObservable), bobObservables))

        psi = qt.tensor(qt.basis(2, 0), qt.basis(2, 0))
        rho = psi * psi.dag()
        expectedCorrelations = {}
        for x1, x2, y in product(range(len(alice1outputs)),
                                 range(len(alice2outputs)),
                                 range(len(bobOutputs))):
            for a1, a2, b in product(range(alice1outputs[x1]),
                                     range(alice2outputs[x2]),
                                     range(bobOutputs[y])):
                postMeasrmntState = qt.tensor(
                    alice1Krauss[x1][a1], qt.qeye(2)) * rho * (qt.tensor(
                        alice1Krauss[x1][a1], qt.qeye(2))).dag()
                expectedCorrelations[(x1, x2), y, (a1, a2), b] = (
                    qt.tensor(alice2Effects[x2][a2], bobEffects[y][b]) *
                    postMeasrmntState).tr().real

        expectedBehaviour = Behaviour(scenario, expectedCorrelations)

        polytope = BellPolytopeWithOneWayCommunication(
            SequentialBellPolytope(scenario))

        self.assertTrue(
            polytope.contains(expectedBehaviour.getProbabilityList()))
Ejemplo n.º 11
0
    ratios = [0, 0.464, 0.569, 0.636, 0.683, 0.718]
    outputsAlice = [2 for _ in range(K + 1)]
    outputsBob = [2 for _ in range(K + 1)]

    ratio = ratios[K]
    beta = 1 / (1 + ratio)
    alpha = beta * ratio
    c = [(-1)**k * beta**(k + 1 / 2) /
         np.sqrt(beta**(2 * k + 1) + alpha**(2 * k + 1)) for k in range(K + 1)]

    states = [
        c[k] * qt.basis(2, 0) + np.sqrt(1 - c[k]**2) * qt.basis(2, 1)
        for k in range(K + 1)
    ]

    psi = (1 / np.sqrt(alpha**2 + beta**2)) * (
        alpha * qt.tensor(qt.basis(2, 0), qt.basis(2, 0)) -
        beta * qt.tensor(qt.basis(2, 1), qt.basis(2, 1)))
    aliceEffects = [[state * state.dag(),
                     qt.qeye(2) - state * state.dag()] for state in states]
    bobEffects = aliceEffects

    dist = computeDistributionFromStateAndEffects(psi, aliceEffects,
                                                  bobEffects)
    print(dist)
    print(sum(dist))
    polytope = BellPolytopeWithOneWayCommunication(
        BellPolytope(BellScenario(outputsAlice, outputsBob)))

    if not polytope.contains(dist):
        print('We found a qdist not reproducible with one bit of comm!')
Ejemplo n.º 12
0
 def testNumberOfVerticesInScenarioWith4BinaryInputsForBobAnd2ForAliceIs1408(
         self):
     vertices = BellPolytopeWithOneWayCommunication(
         BellPolytope(BellScenario([2, 2],
                                   [2, 2, 2, 2]))).getListOfVertices()
     self.assertEqual(len(vertices), 1408)
Ejemplo n.º 13
0
 def testNumberOfVerticesForCHSHIs64(self):
     vertices = BellPolytopeWithOneWayCommunication(
         BellPolytope(BellScenario([2, 2], [2, 2]))).getListOfVertices()
     self.assertEqual(len(vertices), 64)
Ejemplo n.º 14
0
    psi = 2 / np.sqrt(3) * (qt.tensor(qzero, qzero) -
                            1 / 2 * qt.tensor(plus, plus))

    aliceEffects = [[qzero * qzero.dag(), qone * qone.dag()],
                    [plus * plus.dag(), minus * minus.dag()]]
    bobEffects = [[qzero * qzero.dag(), qone * qone.dag()],
                  [plus * plus.dag(), minus * minus.dag()]]

    bobPostMeasurmentStates = [[
        1 / ((qt.tensor(effect, qt.qeye(2)) * psi * psi.dag()).tr()) *
        (qt.tensor(effect, qt.qeye(2)) * psi).ptrace(1)
        for effect in measurement
    ] for measurement in aliceEffects]
    usdState1 = bobPostMeasurmentStates[0][0]
    usdState2 = bobPostMeasurmentStates[1][1]
    overlap = np.sqrt((usdState1 * usdState2).tr())
    usd = [(qt.qeye(2) - usdState1) / (1 + overlap),
           (qt.qeye(2) - usdState2) / (1 + overlap)]

    #bobEffects.append([usd[0],usd[1],qt.qeye(2)-usd[0]-usd[1]])

    dist = computeDistributionFromStateAndEffects(psi, aliceEffects,
                                                  bobEffects)
    dist = [p.real for p in dist]

    scenario = BellScenario(outputsAlice, outputsBob)
    poly = BellPolytopeWithOneWayCommunication(BellPolytope(scenario))

    print(poly.contains(dist))