def stateEnergy(psi: List[tn.Node], H: HOp): E = 0 for i in range(len(psi)): psiCopy = bops.copyState(psi) single_i = bops.copyState([H.singles[i]])[0] psiCopy[i] = bops.permute(tn.contract(psiCopy[i][1] ^ single_i[0], name=('site' + str(i))), [0, 2, 1]) E += bops.getOverlap(psiCopy, psi) bops.removeState(psiCopy) tn.remove_node(single_i) for i in range(len(psi) - 1): psiCopy = bops.copyState(psi) r2l = bops.copyState([H.r2l[i+1]])[0] l2r = bops.copyState([H.l2r[i]])[0] psiCopy[i][2] ^ psiCopy[i+1][0] psiCopy[i][1] ^ l2r[0] r2l[0] ^ psiCopy[i+1][1] l2r[2] ^ r2l[2] M = tn.contract_between(psiCopy[i], \ tn.contract_between(l2r, tn.contract_between(r2l, psiCopy[i+1]))) if bops.multiContraction(M, M, '0123', '0123*').tensor != 0: [psiCopy, te] = bops.assignNewSiteTensors(psiCopy, i, M, '>>') E += bops.getOverlap(psiCopy, psi) bops.removeState(psiCopy) tn.remove_node(r2l) tn.remove_node(l2r) return E
def getTridiagonal(HL, HR, H, k, psi, psiCompare=None): accuracy = 1e-10 # 1e-12 v = bops.multiContraction(psi[k], psi[k + 1], '2', '0') # Small innaccuracies ruin everything! v.set_tensor(v.get_tensor() / bops.getNodeNorm(v)) psiCopy = bops.copyState(psi) base = [] base.append(v) Hv = applyHToM(HL, HR, H, v, k) alpha = bops.multiContraction(v, Hv, '0123', '0123*').get_tensor() if psiCompare is not None: copyV = bops.copyState([v])[0] psiCopy = bops.assignNewSiteTensors(psiCopy, k, copyV, '>>')[0] E = stateEnergy(psi, H) w = bops.addNodes(Hv, bops.multNode(v, -alpha)) beta = bops.getNodeNorm(w) # Start with T as an array and turn into tridiagonal matrix at the end. Tarr = [[0, 0, 0]] Tarr[0][1] = alpha counter = 0 formBeta = 2 * beta # This is just some value to init formBeta > beta. while (beta > accuracy) and (counter <= 50) and (beta < formBeta): Tarr[counter][2] = beta Tarr.append([0, 0, 0]) Tarr[counter + 1][0] = beta counter += 1 v = bops.multNode(w, 1 / beta) base.append(v) if psiCompare is not None: copyV = bops.copyState([v])[0] psiCopy = bops.assignNewSiteTensors(psiCopy, k, copyV, '>>')[0] Hv = applyHToM(HL, HR, H, v, k) alpha = bops.multiContraction(v, Hv, '0123', '0123*').get_tensor() Tarr[counter][1] = alpha w = bops.addNodes(bops.addNodes(Hv, bops.multNode(v, -alpha)), \ bops.multNode(base[counter-1], -beta)) formBeta = beta beta = bops.getNodeNorm(w) T = np.zeros((len(Tarr), len(Tarr)), dtype=complex) T[0][0] = Tarr[0][1] if len(Tarr) > 1: T[0][1] = Tarr[0][2] for i in range(1, len(Tarr)-1): T[i][i-1] = Tarr[i][0] T[i][i] = Tarr[i][1] T[i][i+1] = Tarr[i][2] T[len(Tarr)-1][len(Tarr)-2] = Tarr[len(Tarr)-1][0] T[len(Tarr) - 1][len(Tarr) - 1] = Tarr[len(Tarr) - 1][1] return [T, base]
def getIdentity(psi, k, dir): psil = bops.copyState([psi[k]])[0] psilCopy = bops.copyState([psi[k]], conj=True)[0] if dir == '>>': result = bops.multiContraction(psil, psilCopy, '01', '01').tensor else: result = bops.multiContraction(psil, psilCopy, '12', '12').tensor for i in range(len(result)): for j in range(len(result[0])): result[i][j] = round(result[i][j], 2) return result
def applySwap(psi, psiP, startInd, endInd): psiDagger = bops.copyState(psi, conj=True) psiPDagger = bops.copyState(psi, conj=True) curr = bops.multiContraction(psi[startInd], psiDagger[startInd], [0], [0]) currP = bops.multiContraction(psiP[startInd], psiPDagger[startInd], [0], [0]) curr = bops.multiContraction(curr, currP, [2, 0], [0, 2]) for i in range(startInd + 1, endInd + 1): curr = bops.multiContraction(curr, psi[i], [0], [0]) curr = bops.multiContraction(curr, psiDagger[i], [0], [0]) curr = bops.multiContraction(curr, psiP[i], [0, 4], [0, 1]) curr = bops.multiContraction(curr, psiPDagger[i], [0, 1], [0, 1]) bops.removeState(psiPDagger) bops.removeState(psiPDagger) return curr
def expectationValues(psi: List[tn.Node], vs: List[List[np.array]]): vs = np.round(vs, 10) n = len(vs) NA = len(vs[0]) result = 1 # result = np.eye(2, dtype=complex) for copy in range(n): psiCopy = bops.copyState(psi) for alpha in range(NA - 1, -1, -1): overlap = np.matmul(vs[copy][alpha], np.conj(vs[np.mod(copy + 1, n)][alpha])) toEstimate = np.outer(vs[copy][alpha], np.conj(vs[np.mod(copy + 1, n)][alpha])) if np.abs(np.round(overlap, 8)) == 2: toMeasure = toEstimate else: hermitianComponent = np.random.randint(2) if hermitianComponent: toMeasure = (toEstimate + np.conj(np.transpose(toEstimate))) else: toMeasure = (toEstimate - np.conj(np.transpose(toEstimate))) psiCopy[alpha] = bops.permute(bops.multiContraction(psiCopy[alpha], tn.Node(toMeasure), \ '1', '1'), [0, 2, 1]) psiCopy = bops.shiftWorkingSite(psiCopy, alpha, '<<') result *= bops.getOverlap(psiCopy, psi) # result = np.matmul(result, toMeasure) bops.removeState(psiCopy) return result
def singleMeasurement(psi: List[tn.Node], vs: List[List[np.array]]): vs = np.round(vs, 10) n = len(vs) NA = len(vs[0]) result = 1 for copy in range(n): psiCopy = bops.copyState(psi) for alpha in range(NA - 1, -1, -1): toEstimate = np.outer(vs[copy][alpha], np.conj(vs[np.mod(copy + 1, n)][alpha])) hermitianComponent = np.random.randint(2) if hermitianComponent: toMeasure = (toEstimate + np.conj(np.transpose(toEstimate))) else: toMeasure = (toEstimate - np.conj(np.transpose(toEstimate))) / 1j measureVals, measureVecs = np.linalg.eigh(toMeasure) projector = np.outer(measureVecs[:, 0], np.conj(measureVecs[:, 0])) measResult = makeMeasurement(psiCopy, alpha, projector) if measResult: if np.abs(measureVals[0]) < 1e-8: return 0 result *= measureVals[0] else: if np.abs(measureVals[1]) < 1e-8: return 0 result *= measureVals[1] if not hermitianComponent: result *= 1j psiCopy = bops.shiftWorkingSite(psiCopy, alpha, '<<') bops.removeState(psiCopy) return result
def XXVar(statesDir: str, outDir: str, NA, theta, phi): maxBondDim = 100 res = np.zeros(2, dtype=complex) U = tn.Node( np.matmul(ru.getUPhi(np.pi * phi / 2, 2), ru.getUTheta(np.pi * theta / 2, 2))) with open(statesDir + 'psiXX_NA_' + str(NA) + '_NB_' + str(NA), 'rb') as f: psi = pickle.load(f) psiCopy = bops.relaxState(psi, 64) res[0] = bops.getOverlap(psi, psiCopy) bops.removeState(psi) for i in range(NA): psiCopy[i] = bops.permute( bops.multiContraction(psiCopy[i], U, '1', '0'), [0, 2, 1]) doublePsi = [None for j in range(len(psiCopy))] for j in range(len(psiCopy)): doublePsi[j] = doubleMPSSite(psiCopy[j]) doubleCopy = bops.copyState(doublePsi) for j in range(NA): doublePsi[j] = bops.permute( bops.multiContraction(doublePsi[j], E, '1', '0', cleanOr1=True), [0, 2, 1]) res[1] = bops.getOverlap(doublePsi, doubleCopy) with open( outDir + 'XXVar_NA_' + str(NA) + '_t_' + str(theta) + '_p_' + str(phi), 'wb') as f: pickle.dump(res, f) print(res)
def getDensityMatrix(psi, A1Start, A1End, A2Start, A2End): psiCopy = bops.copyState(psi) for k in [len(psiCopy) - 1 - i for i in range(len(psiCopy) - A2End - 1)]: psiCopy = bops.shiftWorkingSite(psiCopy, k, '<<') E1 = getEMatrix(psiCopy, A1Start, A1End) bops.copyState([E1]) N1, N1bar = getNMatrices(E1, 1) N1bar.edges[0].name += '*' E2 = getEMatrix(psiCopy, A2Start, A2End) N2, N2bar = getNMatrices(E2, 2) N2bar.edges[0].name += '*' res = bops.multiContraction(bops.multiContraction(N1, N1bar, [0], [1]), bops.multiContraction(N2, N2bar, [1], [2]), [0, 3], [0, 3]) bops.removeState(psiCopy) return res
def getEMatrix(psi, startInd, endInd): psiDagger = bops.copyState(psi, conj=True) E = bops.multiContraction(psi[startInd], psiDagger[startInd], [1], [1]) for i in range(startInd + 1, endInd + 1): E = bops.multiContraction( E, bops.multiContraction(psi[i], psiDagger[i], [1], [1]), [1, 3], [0, 2]) bops.removeState(psiDagger) return E
def applyO(psi, psiP, startInd, endInd): psiDagger = bops.copyState(psi, conj=True) psiPDagger = bops.copyState(psi, conj=True) OTensor = np.zeros((9, 9), dtype=complex) for i in range(3): for j in range(3): OTensor[i * 3 + i, j * 3 + j] = 1 OTensor = np.reshape(OTensor, [3, 3, 3, 3]) O = tn.Node(OTensor, name='O', backend=None) curr = bops.multiContraction(psi[endInd], psiDagger[endInd], [2], [2]) currP = bops.multiContraction(psiP[endInd], psiPDagger[endInd], [2], [2]) curr = bops.multiContraction(curr, O, [1, 3], [1, 3]) curr = bops.multiContraction(curr, currP, [2, 3], [1, 3]) for i in [endInd - j for j in range(1, endInd - startInd + 1)]: O = tn.Node(OTensor, name='O', backend=None) curr = bops.multiContraction(curr, psi[i], [0], [2]) curr = bops.multiContraction(curr, psiDagger[i], [0], [2]) curr = bops.multiContraction(curr, O, [3, 5], [1, 3]) curr = bops.multiContraction(curr, psiP[i], [0, 4], [2, 1]) curr = bops.multiContraction(curr, psiPDagger[i], [0, 3], [2, 1]) bops.removeState(psiPDagger) bops.removeState(psiPDagger) return curr
def trotterSweep(trotterGates, psi, startSite, endSite, maxBondDim=1024): psiCopy = bops.copyState(psi) truncErr = 0 N = len(psi) for k in [endSite - i for i in range(startSite, endSite)]: M = bops.multiContraction(psiCopy[k - 1], psiCopy[k], [2], [0]) M = bops.permute( bops.multiContraction(M, trotterGates[k - 1], [1, 2], [0, 1]), [0, 2, 3, 1]) [l, r, currTruncErr] = bops.svdTruncation(M, M[:2], M[2:], '<<', maxBondDim, leftName='site' + str(k - 1), rightName='site' + str(k), edgeName='v' + str(k)) if currTruncErr > truncErr: truncErr = currTruncErr psiCopy[k] = r psiCopy[k - 1] = l bops.multiContraction(r, r, [1, 2], [1, 2, '*']) for k in range(startSite, endSite): M = bops.multiContraction(psiCopy[k], psiCopy[k + 1], [2], [0]) M = bops.permute( bops.multiContraction(M, trotterGates[k], [1, 2], [0, 1]), [0, 2, 3, 1]) [l, r, currTruncErr] = bops.svdTruncation(M, M[:2], M[2:], '>>', maxBondDim, leftName='site' + str(k), rightName='site' + str(k + 1), edgeName='v' + str(k + 1)) if currTruncErr > truncErr: truncErr = currTruncErr psiCopy[k] = l psiCopy[k + 1] = r # For imaginary time propagation, renormalize state. norm = bops.getOverlap(psiCopy, psiCopy) psiCopy[N - 1].tensor = psiCopy[N - 1].tensor / math.sqrt(abs(norm)) return psiCopy, truncErr
def localVecsEstimate(psi: List[tn.Node], vs: List[List[np.array]], half='left'): vs = np.round(vs, 10) n = len(vs) result = 1 for copy in range(n): if half == 'left': NA = len(vs[0]) curr = bops.multiContraction(psi[NA], psi[NA], '12', '12*') sites = range(NA - 1, -1, -1) elif half == 'right': NA = len(psi) - len(vs[0]) curr = bops.multiContraction(psi[len(psi) - NA - 1], psi[len(psi) - NA - 1], '01', '01*') sites = range(NA, len(psi)) psiCopy = bops.copyState(psi) for alpha in sites: toEstimate = np.outer(vs[copy][alpha - NA], np.conj(vs[np.mod(copy + 1, n)][alpha - NA])) psiCopy[alpha] = bops.permute(bops.multiContraction(psiCopy[alpha], tn.Node(toEstimate), \ '1', '1'), [0, 2, 1]) if half == 'left': curr = bops.multiContraction(bops.multiContraction( psiCopy[alpha], curr, '2', '0', cleanOr2=True), psi[alpha], '12', '12*', cleanOr1=True) elif half == 'right': curr = bops.multiContraction(bops.multiContraction( curr, psiCopy[alpha], '0', '0', cleanOr2=True), psi[alpha], '01', '01*', cleanOr1=True) # psiCopy = bops.shiftWorkingSite(psiCopy, alpha, '<<') result *= np.trace(curr.tensor) tn.remove_node(curr) bops.removeState(psiCopy) return result
def singleHaarEstimation(psi: List[tn.Node], us: List[tn.Node], n: int, NA: int): psiCopy = bops.copyState(psi) projector0 = np.zeros((2, 2)) projector0[0, 0] = 1 projector1 = np.zeros((2, 2)) projector1[1, 1] = 1 measurementResults = np.array(NA) estimation = 1 for i in range(NA): psiCopy[i] = bops.permute( bops.multiContraction(psiCopy[i], us[i], '1', '1', cleanOr1=True), [0, 2, 1]) measurementResults[i] = makeMeasurement(psiCopy, i, projector0) if measurementResults: resultProjector = projector0 else: resultProjector = projector1 localEstimation = np.matmul(np.matmul(np.conj(np.transpose(us[i].tensor)), resultProjector), us[i].tensor) \ - np.eye(2) estimation *= np.trace(localEstimation**4) psiCopy = bops.shiftWorkingSite(psiCopy, i, '<<') return estimation
def randomMeasurement(psi, startInd, endInd): d = psi[0].tensor.shape[1] res = [-1] * (endInd - startInd) psiCopy = bops.copyState(psi) for k in [len(psiCopy) - 1 - i for i in range(len(psiCopy) - startInd - 1)]: psiCopy = bops.shiftWorkingSite(psiCopy, k, '<<') for i in range(startInd, endInd): rho = bops.multiContraction(psiCopy[i], psiCopy[i], '02', '02*') measurement = np.random.uniform(low=0, high=1) covered = 0 for s in range(len(rho.tensor)): if covered < measurement < covered + rho.tensor[s, s]: res[i - startInd] = s break covered += rho.tensor[s, s] projectorTensor = np.zeros((d, d), dtype=complex) projectorTensor[res[i - startInd], res[i - startInd]] = 1 projector = tn.Node(projectorTensor, backend=None) bops.applySingleSiteOp(psiCopy, projector, i) psiCopy = bops.shiftWorkingSite(psiCopy, i, '>>') psiCopy[i + 1].tensor /= np.sqrt(bops.getOverlap(psiCopy, psiCopy)) tn.remove_node(rho) bops.removeState(psiCopy) return res
def applyH(psi: List[tn.Node], H: HOp): psiCopy = bops.copyState(psi) single_0 = bops.copyState([H.singles[0]])[0] psiCopy[0] = bops.permute(tn.contract(psiCopy[0][1] ^ single_0[0], name=('site' + str(0))), [0, 2, 1]) result = psiCopy for i in range(1, len(psi)): psiCopy = bops.copyState(psi) single_i = bops.copyState([H.singles[i]])[0] psiCopy[i] = bops.permute(tn.contract(psiCopy[i][1] ^ single_i[0], name=('site' + str(i))), [0, 2, 1]) result = bops.addStates(result, psiCopy) for i in range(len(psi) - 1): psiCopy = bops.copyState(psi) r2l = bops.copyState([H.r2l[i+1]])[0] l2r = bops.copyState([H.l2r[i]])[0] psiCopy[i][2] ^ psiCopy[i+1][0] psiCopy[i][1] ^ l2r[0] r2l[0] ^ psiCopy[i+1][1] l2r[2] ^ r2l[2] M = tn.contract_between(psiCopy[i], \ tn.contract_between(l2r, tn.contract_between(r2l, psiCopy[i+1]))) [psiCopy, te] = bops.assignNewSiteTensors(psiCopy, i, M, '>>') result = bops.addStates(result, psiCopy) return result
N = 32 A1Start = N // 4 A1End = N // 2 lenA1 = A1End - A1Start A2Start = A1End A2End = 3 * N // 4 lenA2 = A2End - A2Start psi = bops.getStartupState(N, d=d, mode='aklt') M = 10000 # int(sys.argv[1]) A1Estimations = [[None for i in range(lenA1)] for m in range(M)] A2Estimations = [[None for i in range(lenA2)] for m in range(M)] for m in range(M): psiCopy = bops.copyState(psi) us = [None for i in range(lenA1 + lenA2)] for i in range(A1Start, A2End): u = rm.haar_measure(d, 's' + str(i)) us[i - A1Start] = u.tensor bops.applySingleSiteOp(psiCopy, u, i) meas = rm.randomMeasurement(psiCopy, A1Start, A2End) for i in range(lenA1): A1Estimations[m][i] = (d + 1) * rotate(getProjector(meas[i], d), dagger(us[i])) - np.eye(d) for i in range(lenA2): A2Estimations[m][i] = (d + 1) * rotate(getProjector(meas[lenA1 + i], d), dagger(us[lenA1 + i])) - np.eye(d) import pickle attemptNumber = sys.argv[2] output = open('akltDMs/A1Estimations' + attemptNumber + '.pkl', 'wb') pickle.dump(A1Estimations, output)
# print('E0 = ' + str(E0)) # print('E0 = ' + str(dmrg.stateEnergy(psi, HXXZ))) # hpsi = dmrg.applyH(psi, HXXZ) # hpsi[0].tensor /= math.sqrt(abs(bops.getOverlap(hpsi, hpsi))) # print('<psi|hpsi> = ' + str(bops.getOverlap(psi, hpsi))) R2 = bops.getRenyiEntropy(psi, 2, int(len(psi) / 2 - 1)) NU = 200 etas = [1, 2, 3, N, int(N * 1.5), N * 2, int(N * 2.5), N * 3] results = [None] * len(etas) dt = J * 1e-2 for e in range(len(etas)): eta = etas[e] sum = 0 for n in range(NU): psiCopy = bops.copyState(psi) for j in range(eta): onsiteTermsA, neighborTermsA = getHAMatrices(N, C, Omega, delta) HA = dmrg.getDMRGH(N, onsiteTermsA, neighborTermsA) trotterGates = trotter.getTrotterGates(N, 2, onsiteTermsA, neighborTermsA, dt) for i in range(int(T / dt)): [psiCopy, truncErr] = trotter.trotterSweep(trotterGates, psiCopy, 0, int(len(psiCopy) / 2 - 1)) psiCopy2 = bops.copyState(psiCopy) projectS(psiCopy, int(len(psiCopy)/2 - 1)) p = bops.getOverlap(psiCopy, psiCopy2) sum += p * p bops.removeState(psiCopy) bops.removeState(psiCopy2) avg = sum / NU results[e] = avg * (2**int(len(psi)/2) * (2**int(len(psi)/2) + 1)) - 1
def getBMPS(hs, steps): for h in hs: h = np.round(h, 1) if int(h) == h: h = int(h) with open('ising/origTensors/ising_field_' + str(h) + '_A', 'rb') as f: ATensor = pickle.load(f) with open('ising/origTensors/ising_field_' + str(h) + '_B', 'rb') as f: BTensor = pickle.load(f) A = tn.Node(ATensor) A = bops.permute(A, [1, 2, 3, 0, 4]) B = tn.Node(BTensor) B = bops.permute(B, [1, 2, 3, 0, 4]) def toEnvOperator(op): result = bops.unifyLegs( bops.unifyLegs( bops.unifyLegs( bops.unifyLegs( bops.permute(op, [0, 4, 1, 5, 2, 6, 3, 7]), 6, 7), 4, 5), 2, 3), 0, 1) tn.remove_node(op) return result AEnv = toEnvOperator(bops.multiContraction(A, A, '4', '4*')) BEnv = toEnvOperator(bops.multiContraction(B, B, '4', '4*')) envOpAB = bops.permute(bops.multiContraction(AEnv, BEnv, '1', '3'), [0, 3, 2, 4, 1, 5]) envOpBA = bops.permute(bops.multiContraction(BEnv, AEnv, '1', '3'), [0, 3, 2, 4, 1, 5]) curr = bops.permute( bops.multiContraction(envOpBA, envOpAB, '45', '01'), [0, 2, 4, 6, 1, 3, 5, 7]) for i in range(2): [C, D, te] = bops.svdTruncation(curr, [0, 1, 2, 3], [4, 5, 6, 7], '>>', normalize=True) curr = bops.permute(bops.multiContraction(D, C, '23', '12'), [1, 3, 0, 5, 2, 4]) curr = bops.permute( bops.multiContraction(curr, envOpAB, '45', '01'), [0, 2, 4, 6, 1, 3, 5, 7]) b = 1 currAB = curr rowTensor = np.zeros((11, 4, 4, 11), dtype=complex) rowTensor[0, 3, 3, 0] = 1 rowTensor[1, 3, 3, 2] = 1 rowTensor[2, 3, 3, 3] = 1 rowTensor[3, 3, 0, 4] = 1 rowTensor[4, 0, 3, 1] = 1 rowTensor[5, 3, 3, 6] = 1 rowTensor[6, 3, 0, 7] = 1 rowTensor[7, 0, 3, 8] = 1 rowTensor[8, 3, 3, 5] = 1 row = tn.Node(rowTensor) print('60') upRow = bops.unifyLegs( bops.unifyLegs( bops.unifyLegs( bops.unifyLegs( bops.permute( bops.multiContraction(row, tn.Node(currAB.tensor), '12', '04'), [0, 2, 3, 4, 7, 1, 5, 6]), 5, 6), 5, 6), 0, 1), 0, 1) [C, D, te] = bops.svdTruncation(upRow, [0, 1], [2, 3], '>>', normalize=True) upRow = bops.multiContraction(D, C, '2', '0') [cUp, dUp, te] = bops.svdTruncation(upRow, [0, 1], [2, 3], '>>', normalize=True) GammaC, LambdaC, GammaD, LambdaD = peps.getBMPSRowOps( cUp, tn.Node(np.ones(cUp[2].dimension)), dUp, tn.Node(np.ones(dUp[2].dimension)), AEnv, BEnv, steps) cUp = bops.multiContraction(GammaC, LambdaC, '2', '0', isDiag2=True) dUp = bops.multiContraction(GammaD, LambdaD, '2', '0', isDiag2=True) upRow = bops.multiContraction(cUp, dUp, '2', '0') downRow = bops.copyState([upRow])[0] rightRow = peps.bmpsCols(upRow, downRow, AEnv, BEnv, steps, option='right', X=upRow) leftRow = peps.bmpsCols(upRow, downRow, AEnv, BEnv, steps, option='left', X=upRow) circle = bops.multiContraction( bops.multiContraction( bops.multiContraction(upRow, rightRow, '3', '0'), upRow, '5', '0'), leftRow, '70', '03') openA = tn.Node( np.transpose( np.reshape(np.kron(A.tensor, np.conj(A.tensor)), [d**2, d**2, d**2, d**2, d, d]), [4, 0, 1, 2, 3, 5])) openB = tn.Node( np.transpose( np.reshape(np.kron(B.tensor, np.conj(B.tensor)), [d**2, d**2, d**2, d**2, d, d]), [4, 0, 1, 2, 3, 5])) ABNet = bops.permute( bops.multiContraction( bops.multiContraction(openB, openA, '2', '4'), bops.multiContraction(openA, openB, '2', '4'), '28', '16', cleanOr1=True, cleanOr2=True), [1, 5, 6, 13, 14, 9, 10, 2, 0, 4, 8, 12, 3, 7, 11, 15]) dm = bops.multiContraction(circle, ABNet, '01234567', '01234567') ordered = np.round(np.reshape(dm.tensor, [16, 16]), 14) ordered /= np.trace(ordered) print(h, getM(ordered)) with open('ising/bmpsResults_' + str(h), 'wb') as f: pickle.dump( [upRow, downRow, leftRow, rightRow, openA, openB, A, B], f)
# temp = bops.copyState([psi[i]])[0] # temp.tensor = np.conj(temp.tensor) # T = bops.permute(bops.multiContraction(bops.multiContraction(temp, sigma, [1], [0]), psiDagger[i], [2], [1]), [0, 2, 1, 3]) # origSizes = [T.tensor.shape[0], T.tensor.shape[1]] # tMatrix = np.round(np.reshape(T.tensor, [origSizes[0] * origSizes[1], origSizes[0] * origSizes[1]]), 14) # vals, vecs = scipy.sparse.linalg.eigs(tMatrix, k=1) # # vals = np.round(vals, 6) # # uVec = vecs[:, list(vals).index(1)] # uVec = vecs[:, 0] # uMatrix = np.reshape(uVec, origSizes) # uMatrix /= np.sqrt(np.trace(np.matmul(uMatrix, np.conj(np.transpose(uMatrix)))) / len(uMatrix)) # print(np.trace(np.matmul(uMatrix, np.conj(uMatrix))) / len(uMatrix)) # U = tn.Node(uMatrix, backend=None) psiP = bops.copyState(psi, conj=True) for i in A1 + A2: currU = trUnitary(i) psiP[i] = bops.permute(bops.multiContraction(psiP[i], currU, [1], [0]), [0, 2, 1]) psiConj = bops.copyState(psi, conj=True) curr = bops.multiContraction(psiP[A1[0]], psiConj[A1[0]], [0, 1], [0, 1]) for i in range(A1[1], A2[-1]-1): curr = bops.multiContraction(bops.multiContraction(curr, psiP[i], [0], [0]), psiConj[i], [0, 1], [0, 1]) curr = bops.multiContraction(bops.multiContraction(curr, psiP[A2[-1]], [0], [0]), psiConj[A2[-1]], [0, 1, 2], [0, 1, 2]) # pt = getPartiallyTransposed(psi, A1[0], A1[-1], A2[0], A2[-1]) # reg = getStraightDM(psiP, A1[0], A1[-1], A2[0], A2[-1]) b=1 """ This does not give the same result as Poleman-Turner's paper! """ def applySwap(psi, psiP, startInd, endInd): psiDagger = bops.copyState(psi, conj=True)
[0, 2, 3, 4, 7, 1, 5, 6]), 5, 6), 5, 6), 0, 1), 0, 1) [C, D, te] = bops.svdTruncation(upRow, [0, 1], [2, 3], '>>', normalize=True) upRow = bops.multiContraction(D, C, '2', '0') [cUp, dUp, te] = bops.svdTruncation(upRow, [0, 1], [2, 3], '>>', normalize=True) GammaC, LambdaC, GammaD, LambdaD = peps.getBMPSRowOps( cUp, tn.Node(np.ones(cUp[2].dimension)), dUp, tn.Node(np.ones(dUp[2].dimension)), AEnv, BEnv, 50) cUp = bops.multiContraction(GammaC, LambdaC, '2', '0', isDiag2=True) dUp = bops.multiContraction(GammaD, LambdaD, '2', '0', isDiag2=True) upRow = bops.multiContraction(cUp, dUp, '2', '0') downRow = bops.copyState([upRow])[0] rightRow = peps.bmpsCols(upRow, downRow, AEnv, BEnv, steps, option='right', X=upRow) leftRow = peps.bmpsCols(upRow, downRow, AEnv, BEnv, steps, option='left', X=upRow) with open('results/toricBoundaries_g_' + str(g), 'wb') as f:
def getHLR(psi, l, H, dir, HLRold): if dir == '>>': if l == -1: opSum = tn.Node(np.zeros((psi[0].get_dimension(0), psi[0].get_dimension(0)), dtype=complex)) openOp = tn.Node(np.zeros((psi[0].get_dimension(0), psi[0].get_dimension(0)), dtype=complex)) return HExpValMid(opSum, openOp) else: psil = bops.copyState([psi[l]], conj=False)[0] psilConj = bops.copyState([psi[l]], conj=True)[0] singlel = bops.copyState([H.singles[l]], conj=False)[0] psil[0] ^ psilConj[0] psil[1] ^ singlel[0] psilConj[1] ^ singlel[1] opSum1 = tn.contract_between(psil, \ tn.contract_between(singlel, psilConj), name='operator-sum') if np.max(opSum1.tensor) > 100: g=1 if l > 0: psil = bops.copyState([psi[l]], conj=False)[0] psilConj = bops.copyState([psi[l]], conj=True)[0] HLRoldCopy = bops.copyState([HLRold.openOp])[0] r2l_l = bops.copyState([H.r2l[l]], conj=False)[0] psil[0] ^ HLRoldCopy[0] psilConj[0] ^ HLRoldCopy[1] psil[1] ^ r2l_l[0] psilConj[1] ^ r2l_l[1] r2l_l[2] ^ HLRoldCopy[2] opSum2 = tn.contract_between(psil, tn.contract_between(psilConj, tn.contract_between(r2l_l, HLRoldCopy))) opSum1 = bops.addNodes(opSum1, opSum2) if np.max(opSum1.tensor) > 100: g = 1 psil = bops.copyState([psi[l]], conj=False)[0] psilConj = bops.copyState([psi[l]], conj=True)[0] HLRoldCopy = bops.copyState([HLRold.opSum])[0] psil[0] ^ HLRoldCopy[0] psilConj[0] ^ HLRoldCopy[1] psil[1] ^ psilConj[1] opSum3 = tn.contract_between(psil, tn.contract_between(psilConj, HLRoldCopy)) opSum1 = bops.addNodes(opSum1, opSum3) if np.max(opSum1.tensor) > 100: g=1 if l < len(psi) - 1: psil = bops.copyState([psi[l]], conj=False)[0] psilConj = bops.copyState([psi[l]], conj=True)[0] l2r_l = bops.copyState([H.l2r[l]], conj=False)[0] psil[0] ^ psilConj[0] psil[1] ^ l2r_l[0] psilConj[1] ^ l2r_l[1] openOp = tn.contract_between(psil, tn.contract_between(psilConj, l2r_l), name='open-operator') else: openOp = None return HExpValMid(opSum1, openOp) if dir == '<<': if l == len(psi): opSum = tn.Node(np.zeros((psi[l-1].get_dimension(2), psi[l-1].get_dimension(2)), dtype=complex)) openOp = tn.Node(np.zeros((psi[l-1].get_dimension(2), psi[l-1].get_dimension(2)), dtype=complex)) return HExpValMid(opSum, openOp) else: psil = bops.copyState([psi[l]], conj=False)[0] psilConj = bops.copyState([psi[l]], conj=True)[0] single_l = bops.copyState([H.singles[l]], conj=False)[0] psil[2] ^ psilConj[2] psil[1] ^ single_l[0] psilConj[1] ^ single_l[1] opSum1 = tn.contract_between(psil, \ tn.contract_between(single_l, psilConj), name='operator-sum') if l < len(psi) -1: psil = bops.copyState([psi[l]], conj=False)[0] psilConj = bops.copyState([psi[l]], conj=True)[0] HLRoldCopy = bops.copyState([HLRold.openOp])[0] l2r_l = bops.copyState([H.l2r[l]], conj=False)[0] psil[2] ^ HLRoldCopy[0] psilConj[2] ^ HLRoldCopy[1] psil[1] ^ l2r_l[0] psilConj[1] ^ l2r_l[1] l2r_l[2] ^ HLRoldCopy[2] opSum2 = tn.contract_between(psil, tn.contract_between(psilConj, tn.contract_between(l2r_l, HLRoldCopy))) opSum1 = bops.addNodes(opSum1, opSum2) psil = bops.copyState([psi[l]], conj=False)[0] psilConj = bops.copyState([psi[l]], conj=True)[0] HLRoldCopy = bops.copyState([HLRold.opSum])[0] psil[2] ^ HLRoldCopy[0] psilConj[2] ^ HLRoldCopy[1] psil[1] ^ psilConj[1] opSum3 = tn.contract_between(psil, tn.contract_between(psilConj, HLRoldCopy)) opSum1 = bops.addNodes(opSum1, opSum3) if l > 0: psil = bops.copyState([psi[l]], conj=False)[0] psilConj = bops.copyState([psi[l]], conj=True)[0] r2l_l = bops.copyState([H.r2l[l]], conj=False)[0] psil[2] ^ psilConj[2] psil[1] ^ r2l_l[0] psilConj[1] ^ r2l_l[1] openOp = tn.contract_between(psil, tn.contract_between(psilConj, r2l_l), name='open-operator') else: openOp = None return HExpValMid(opSum1, openOp)