import simulate_toric as st import random import load_errors n_trials = 100 success_count = 0 size=6 tSteps=5 random.seed(0) ## Load error vector from file evecs3,evecs4 = load_errors.load("example_errorvec.txt") error_vector4 = evecs4[evecs4.keys()[0]] for i in range(n_trials): [x,z],[x2,z2] = st.run3D(size,tSteps,error_vector4) if x==1 and z==1 and x2==1 and z2==1: success_count+=1 print 'lattice size: ',size print 'time steps: ', tSteps print 'random errors applied according the test error vector' print print success_count,' /',n_trials,' were successfully decoded: ',success_count
def run3Dtest(size=8,tSteps=100,errorVec3 = testvec4, errorVec4=testvec4,timespace=[1,1],boundary_weight = 1): errvec_file = "error_vectors/basic_0.txt" errorVec3, errorVec4 = [[] if x=={} else x[0.0] for x in load_errors.load(errvec_file)] t0 = time.time() L=planar_lattice.PlanarLattice(size) PL=planar_lattice.PlanarLattice3D(size) L.applyRandomErrors(0,0) # leave this here for initialisation # t1 = time.time() # print 'initialisation ',t1-t0 for i in range(tSteps): # loop over time L.measureNoisyStabilizers("plaquette",errorVec3, errorVec4) L.measureNoisyStabilizers("star",errorVec3,errorVec4) PL.addMeasurement(L) # add the updated 2D lattice to 3D array L.measurePlaquettes(0) # measure one more layer with L.measureStars(0) # perfect stabilizers and add PL.addMeasurement(L) # this to the parity Lattice PL.findAnyons() # print 'P anyons', sum([len(_) for _ in PL.anyon_positions_P]) # print 'S anyons', sum([len(_) for _ in PL.anyon_positions_S]) # t2 = time.time() # print 'loop over timeslices ', t2 -t1 matchingX=perfect_matching.match_planar_3D(size,"plaquette",PL.anyon_positions_P,timespace,boundary_weight) # t3 = time.time() # print 'perfect matching ', t3 -t2 #matchingZ=perfect_matching.match_toric_3D(size,PL.anyon_positions_S,timespace) flipsX=squashMatching(size,"X",matchingX) #flipsZ=squashMatching(size,matchingZ) # t4 = time.time() # print 'squash matching ',t4-t3 # L.showArray("errors","X") Lbefore = copy.copy(L) #L.apply_flip_array("Z",flipsZ) L.apply_flip_array("X",flipsX) if L.measure_logical[0]==-1: Lbefore.showArray("errors","X") L.showArray("errors","X") #L.showArray("errors","Z") return L.measure_logical()
def run3Dtest(size=8,tSteps=100,errorVec=testvec4,timespace=[1,1]): errvec_file = "error_vectors/basic_0.txt" error_vector3, error_vector4 = [[] if x=={} else x[0.0] for x in load_errors.load(errvec_file)] errorVec = error_vector4 # print error_vector3 # print error_vector4 L=toric_lattice.PlanarLattice(size) PL=toric_lattice.Lattice3D(size) L.applyRandomErrors(0,0) # leave this here for initialisation xcount = 0 zcount = 0 #t0=time.time() for i in range(tSteps): # loop over time L.measureNoisyStabilizers("plaquette",errorVec) L.measureNoisyStabilizers("star",errorVec) #for p0,p1 in L.positions_Q: # x,z = L.array[p0][p1] # if x ==-1: xcount +=1 # if z ==-1: zcount +=1 PL.addMeasurement(L) # add the updated 2D lattice to 3D array # print xcount, zcount # t1 = time.time() # print 'tsteps completed ',t1-t0 L.measurePlaquettes(0) # measure one more layer with L.measureStars(0) # perfect stabilizers and add PL.addMeasurement(L) # this to the parity Lattice PL.findAnyons() # print 'P anyons', sum([len(_) for _ in PL.anyon_positions_P]) # print 'S anyons', sum([len(_) for _ in PL.anyon_positions_S]) #print PL.anyon_positions_P # t2 = time.time() #print 'find anyons ',t2-t1 matchingX=perfect_matching.match_toric_3D(size,PL.anyon_positions_P,timespace) # t3 = time.time() #print 'matching X ',t3-t2 matchingZ=perfect_matching.match_toric_3D(size,PL.anyon_positions_S,timespace) flipsX=squashMatching(size,matchingX) flipsZ=squashMatching(size,matchingZ) # t4 = time.time() # print 'squash matching ',t4-t3 # L.showArray("errors","X") L.apply_flip_array("Z",flipsZ) L.apply_flip_array("X",flipsX) # L.showArray("errors","X") #L.showArray("errors","Z") return L.measure_logical()
def run3Dtest(size=8, tSteps=100, errorVec=testvec4, timespace=[1, 1]): errvec_file = "error_vectors/basic_0.txt" error_vector3, error_vector4 = [[] if x == {} else x[0.0] for x in load_errors.load(errvec_file)] errorVec = error_vector4 # print error_vector3 # print error_vector4 L = toric_lattice.PlanarLattice(size) PL = toric_lattice.Lattice3D(size) L.applyRandomErrors(0, 0) # leave this here for initialisation xcount = 0 zcount = 0 #t0=time.time() for i in range(tSteps): # loop over time L.measureNoisyStabilizers("plaquette", errorVec) L.measureNoisyStabilizers("star", errorVec) #for p0,p1 in L.positions_Q: # x,z = L.array[p0][p1] # if x ==-1: xcount +=1 # if z ==-1: zcount +=1 PL.addMeasurement(L) # add the updated 2D lattice to 3D array # print xcount, zcount # t1 = time.time() # print 'tsteps completed ',t1-t0 L.measurePlaquettes(0) # measure one more layer with L.measureStars(0) # perfect stabilizers and add PL.addMeasurement(L) # this to the parity Lattice PL.findAnyons() # print 'P anyons', sum([len(_) for _ in PL.anyon_positions_P]) # print 'S anyons', sum([len(_) for _ in PL.anyon_positions_S]) #print PL.anyon_positions_P # t2 = time.time() #print 'find anyons ',t2-t1 matchingX = perfect_matching.match_toric_3D(size, PL.anyon_positions_P, timespace) # t3 = time.time() #print 'matching X ',t3-t2 matchingZ = perfect_matching.match_toric_3D(size, PL.anyon_positions_S, timespace) flipsX = squashMatching(size, matchingX) flipsZ = squashMatching(size, matchingZ) # t4 = time.time() # print 'squash matching ',t4-t3 # L.showArray("errors","X") L.apply_flip_array("Z", flipsZ) L.apply_flip_array("X", flipsX) # L.showArray("errors","X") #L.showArray("errors","Z") return L.measure_logical()
def run3Dtest(size=8, tSteps=100, errorVec3=testvec4, errorVec4=testvec4, timespace=[1, 1], boundary_weight=1): errvec_file = "error_vectors/basic_0.txt" errorVec3, errorVec4 = [[] if x == {} else x[0.0] for x in load_errors.load(errvec_file)] t0 = time.time() L = planar_lattice.PlanarLattice(size) PL = planar_lattice.PlanarLattice3D(size) L.applyRandomErrors(0, 0) # leave this here for initialisation # t1 = time.time() # print 'initialisation ',t1-t0 for i in range(tSteps): # loop over time L.measureNoisyStabilizers("plaquette", errorVec3, errorVec4) L.measureNoisyStabilizers("star", errorVec3, errorVec4) PL.addMeasurement(L) # add the updated 2D lattice to 3D array L.measurePlaquettes(0) # measure one more layer with L.measureStars(0) # perfect stabilizers and add PL.addMeasurement(L) # this to the parity Lattice PL.findAnyons() # print 'P anyons', sum([len(_) for _ in PL.anyon_positions_P]) # print 'S anyons', sum([len(_) for _ in PL.anyon_positions_S]) # t2 = time.time() # print 'loop over timeslices ', t2 -t1 matchingX = perfect_matching.match_planar_3D(size, "plaquette", PL.anyon_positions_P, timespace, boundary_weight) # t3 = time.time() # print 'perfect matching ', t3 -t2 #matchingZ=perfect_matching.match_toric_3D(size,PL.anyon_positions_S,timespace) flipsX = squashMatching(size, "X", matchingX) #flipsZ=squashMatching(size,matchingZ) # t4 = time.time() # print 'squash matching ',t4-t3 # L.showArray("errors","X") Lbefore = copy.copy(L) #L.apply_flip_array("Z",flipsZ) L.apply_flip_array("X", flipsX) if L.measure_logical[0] == -1: Lbefore.showArray("errors", "X") L.showArray("errors", "X") #L.showArray("errors","Z") return L.measure_logical()