def testSingletBetweenAlice1AndBobAndLocalOtherwiseIsNotInPolytope(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)) 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) expectedCorrelations = {((x1, x2), y, (a1, a2), b): int( (a2 == 0)) * ((qt.tensor(alice1Krauss[x1][a1], bobEffects[y][b]) * psi * psi.dag()).tr()) for ((x1, x2), y, (a1, a2), b) in scenario.getTuplesOfEvents()} expectedBehaviour = Behaviour(scenario, expectedCorrelations) poly = SequentialBellPolytope(scenario) self.assertFalse(poly.contains(expectedBehaviour.getProbabilityList()))
def testPRCorrBetweenAlice1andBobAndLocalOtherwiseIsNotInPolytope(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 = SequentialBellPolytope(scenario) self.assertFalse(poly.contains(expectedBehaviour.getProbabilityList()))
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]))
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()))
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!' )
import qutip as qt from itertools import product from bellpolytopewithonewaycomm import BellPolytopeWithOneWayCommunication from sequentialbellpolytope import SequentialBellPolytope from sequentialbellscenario import SequentialBellScenario from qutipauxfunc import createQubitObservable, projectorsForQubitObservable,\ createMaxEntState, effectForQubitPovm from behaviour import Behaviour if __name__ == '__main__': alice1outputs = [2, 2] alice2outputs = [2, 2, 3] bobOutputs = [2, 2] scenario = SequentialBellScenario([alice1outputs, alice2outputs], bobOutputs) epsilon = np.pi / 4 - 0.1 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], [1, 0, 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)
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()))
def testNumberOfVerticesForTwoAlicesAndOneBobDoingCHSHIs256(self): poly = SequentialBellPolytope( SequentialBellScenario([[2, 2], [2, 2]], [2, 2])) vertices = poly.getListOfVertices() self.assertEqual(len(vertices), 256)
def testNumberOfVerticesForTwoAliceAndOneBobDoingChained3Is2304(self): poly = SequentialBellPolytope( SequentialBellScenario([[2, 2], [2, 2, 3]], [2, 2])) vertices = poly.getListOfVertices() self.assertEqual(len(vertices), 2304)