def testGenerateAliceStrategiesForOneDichotomicAndOneTernaryInput(self): outputsAliceSequence = [2, 3] chshPoly = BellPolytope(BellScenario(outputsAliceSequence, [2, 2])) strgsAlice = list(chshPoly._strategiesGenerator(outputsAliceSequence)) expectedStrategies = [{ 0: 0, 1: 0 }, { 0: 0, 1: 1 }, { 0: 0, 1: 2 }, { 0: 1, 1: 0 }, { 0: 1, 1: 1 }, { 0: 1, 1: 2 }] self.assertTrue(len(strgsAlice), len(expectedStrategies)) for stg in expectedStrategies: self.assertIn(stg, strgsAlice)
def testAliceConstantlyZeroAndBobConstantlyOneIsVertexOfCHSH(self): chshPoly = BellPolytope(BellScenario([2, 2], [2, 2])) verticesAsLists = [ behaviour.getProbabilityList() for behaviour in chshPoly.getListOfVertices() ] self.assertIn([0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0], verticesAsLists)
def testBuildBehaviourFromListAndConvertToDictionary(self): pr=[1/2,0,0,1/2,1/2,0,0,1/2,1/2,0,0,1/2,0,1/2,1/2,0] behaviour=Behaviour(BellScenario([2,2],[2,2]),pr) probabilities = behaviour.getProbabilityDictionary() for x,y,a,b in product(range(2),repeat=4): if x*y==(a+b)%2: self.assertEqual(probabilities[x,y,a,b],1/2) else: self.assertEqual(probabilities[x,y,a,b],0)
def testBuildBehaviourFromDictionaryAndConvertToList(self): pr = {(x, y, a, b): 1 / 2 * int(x * y == (a + b) % 2) for x, y, a, b in product(range(2), repeat=4)} behaviour = Behaviour(BellScenario([2, 2], [2, 2]), pr) probabilities = behaviour.getProbabilityList() self.assertEqual(probabilities, [ 1 / 2, 0, 0, 1 / 2, 1 / 2, 0, 0, 1 / 2, 1 / 2, 0, 0, 1 / 2, 0, 1 / 2, 1 / 2, 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)
def testNumberOfLocalVerticesOfChshIs16(self): chshPoly = BellPolytope(BellScenario([2, 2], [2, 2])) self.assertEquals(len(chshPoly.getListOfVertices()), 16)
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!')
def testSeqStratForOptimalRandIsSimulable(self): alice1outputs = [2, 2] alice2outputs = [2, 2, 3] bobOutputs = [2, 2] sequentialScenario = SequentialBellScenario( [alice1outputs, alice2outputs], bobOutputs) alice1blochVectors = [[0, 0, 1]] alice1Observables = list( map(lambda bloch: createQubitObservable(bloch), alice1blochVectors)) alice1Krauss = list( map( lambda qubitObservable: projectorsForQubitObservable( qubitObservable), alice1Observables)) epsilon = 7 * np.pi / 32 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.append([Kplus, Kminus]) alice2blochVectors = [[0, 0, 1], [1, 0, 0]] 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(0, 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 = createMaxEntState(2) rho = psi * psi.dag() expectedCorrelations = {} for x1, x2, y in product(range(2), range(3), range(2)): 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(sequentialScenario, expectedCorrelations) scenario = BellScenario([4, 4, 6, 4, 4, 6], [2, 2]) polytope = BellPolytopeWithOneWayCommunication(BellPolytope(scenario)) print(polytope.contains(expectedBehaviour.getProbabilityList()))
def testNumberOfVerticesInScenarioWith4BinaryInputsForBobAnd2ForAliceIs1408( self): vertices = BellPolytopeWithOneWayCommunication( BellPolytope(BellScenario([2, 2], [2, 2, 2, 2]))).getListOfVertices() self.assertEqual(len(vertices), 1408)
def testNumberOfVerticesForCHSHIs64(self): vertices = BellPolytopeWithOneWayCommunication( BellPolytope(BellScenario([2, 2], [2, 2]))).getListOfVertices() self.assertEqual(len(vertices), 64)
products.append( np.trace(rho * np.kron(prob.matsolX(a + N * x), prob.matsolY(b + N * y)))) return np.dot(np.array(functional), products) if __name__ == '__main__': parties = 2 N = 3 K = 4 outputsAlice = [4, 4, 4] outputsBob = [4, 4, 4] dim = 2 BellViolations = [] #Creo que así los vértices están bien scenario = BellScenario(outputsAlice, outputsBob) poly = BellPolytope(scenario) vertices = poly.getListOfVertices() distributions = np.matrix(vertices) NumberOfCoefficients = (N * K)**2 '''with open('results.txt','w') as f: f.write('Random functionals \n')''' rho = np.matrix([[0, 0, 0, 0], [0, 1 / 2, -1 / 2, 0], [0, -1 / 2, 1 / 2, 0], [0, 0, 0, 0]]) #Ineqs = np.loadtxt( 'Ineqs.txt') '''for i in range (0,2): functional=np.random.uniform(-N**2*(N**2-2),1,size=NumberOfCoefficients) values=np.dot(distributions,np.transpose(functional)) c=np.amax(values) if c==0:
''' from mosek.fusion import * from bellpolytope import BellPolytope import numpy as np from bellscenario import BellScenario from behaviour import Behaviour from itertools import product if __name__ == '__main__': n = 2 outputs = 2**n * [3] outputsAlice = outputs outputsBob = outputs scenario = BellScenario(outputsAlice, outputsBob) poly = BellPolytope(scenario) toBin = lambda x: format(x, '0' + str(n) + 'b') disjointness = lambda x, y: np.intersect1d(x, y).size == 0 probabilities = {(x, y, a, b): 1 / 2 * int( (a != 2 and b != 2 and (a + b) % 2 == disjointness(toBin(x), toBin(y)))) for (x, y, a, b) in scenario.getTuplesOfEvents()} dist = Behaviour(scenario, probabilities).getProbabilityList() with Model("lo1") as M: fullSpaceDimension = sum( [sum([a * b for b in outputsBob]) for a in outputsAlice])