def setLehmannTermsDynamicFermionic(self, dynamicObservable): for statePair, operatorPair in dynamicObservable.operatorPairs.items(): operator1 = operatorPair[0] operator2 = operatorPair[1] if type(operator1) != ndarray: operator1 = operator1.toarray() operator2 = operator2.toarray() e = self.getEnergyEigenvalues() ve = self.getEnergyEigenstates().toarray() fockstates = range(self.fockspaceSize) n_inds_p = array(scatter_list(fockstates)) nominators_p = [] denominators_p = [] for n in n_inds_p: n_op1 = ve[:,n].dot(operator1) op2_n = operator2.dot(ve[:,n]) expn = exp(-self.beta*e[n]) for m in fockstates: if dynamicObservable.species == 'bosonic': if equals(e[n], e[m]): continue el1 = n_op1.dot(ve[:,m]) if not equals(el1, 0): el2 = ve[:,m].dot(op2_n) if not equals(el2, 0): expm = exp(-self.beta*e[m]) el = el1*el2 nominators_p.append([]) nominators_p[-1].append(expn*el) nominators_p[-1].append(expm*el) denominators_p.append(e[n]-e[m]) dynamicObservable.lehmannNominators.update({statePair: allgather_list(nominators_p)}) dynamicObservable.lehmannDenominators.update({statePair: allgather_list(denominators_p)}) dynamicObservable.partitionFunction = self.getPartitionFunction()
def setZeroFrequencyTerms(self, dynamicObservable): for statePair, operatorPair in dynamicObservable.operatorPairs.items(): operator1 = operatorPair[0] operator2 = operatorPair[1] if type(operator1) != ndarray: operator1 = operator1.toarray() operator2 = operator2.toarray() e = self.getEnergyEigenvalues() ve = self.getEnergyEigenstates().toarray() fockstates = range(self.fockspaceSize) n_inds_p = array(scatter_list(fockstates)) zeroFrequencyTerms_p = [] for n in n_inds_p: n_op1 = ve[:,n].dot(operator1) op2_n = operator2.dot(ve[:,n]) expn = exp(-self.beta*e[n]) for m in fockstates: if equals(e[n], e[m]): el1 = n_op1.dot(ve[:,m]) if not equals(el1, 0): el2 = ve[:,m].dot(op2_n) if not equals(el2, 0): el = el1*el2 zeroFrequencyTerms_p.append(-self.beta*expn*el) dynamicObservable.zeroFrequencyTerms.update({statePair: allgather_list(zeroFrequencyTerms_p)})
def lehmannSumDynamic(elementProducts, energyDifferences, partitionFunction, mesh, zeroFrequencyTerms, imaginaryOffset, nominatorCoefficients): if type(imaginaryOffset) != list: imaginaryOffset = [imaginaryOffset]*2 result = dict() for statePair, nominators, denominators in zip(elementProducts.keys(), elementProducts.values(), energyDifferences.values()): data_p = list() for w in scatter_list(mesh): terms = [coeff * nom/(w + denom + complex(0, offset)) for noms, denom in zip(nominators, denominators) for nom, coeff, offset in zip(noms, nominatorCoefficients, imaginaryOffset)] if len(zeroFrequencyTerms.values()) > 0 and w == 0: terms += zeroFrequencyTerms[statePair] data_p.append(nsum(terms/partitionFunction)) result.update({statePair: array(allgather_list(data_p))}) return result
def setLehmannSumStatic(self, staticObservable): assert type(staticObservable) == StaticObservable, 'StaticObservable expected.' e = self.getEnergyEigenvalues() ve = self.getEnergyEigenstates().toarray() z = self.getPartitionFunction() fockstates = range(self.fockspaceSize) for index, matrix in staticObservable.operators.items(): if type(matrix) != ndarray: m = matrix.toarray() else: m = matrix n_inds_p = array(scatter_list(fockstates)) terms_p = list() for n in n_inds_p: el = ve[:,n].dot(m.dot(ve[:,n])) expn = exp(-self.beta*e[n]) if not equals(el, 0) and not equals(expn, 0): terms_p.append(expn * el) staticObservable.expectationValue.update({index: sumScatteredLists(terms_p)/z})
def solve(self): report('Solving the Hamiltonian...', self.verbose) t0 = time() self.eigenEnergies = list() self.eigenStates = list() self.gatherPermutations() self.matrix = self.transformation.dot(self.matrix).dot(self.transformation.H) hBlocks = BlockMatrix(self.blocksizes, self.all_real) rows, cols = self.matrix.nonzero() for val, i, j in izip(self.matrix.data, rows, cols): hBlocks[i, j] = val hBlocks_scat = scatter_list(hBlocks.datablocks) e_scat = list() v_scat = list() for block in hBlocks_scat: e, v = eigh(block) e_scat += list(e) v_scat += list(v) self.eigenEnergies, self.energyShift = shiftEnergies(diag(self.transformation.H.dot(self.transformation.transpose().dot(diag(allgather_list(e_scat)).transpose()).transpose())).copy()) # scipy hack for A = U^.D.U #self.eigenEnergies = diag(self.transformation.H.dot(self.transformation.transpose().dot(diag(allgather_list(e_scat)).transpose()).transpose())).copy() # scipy hack for A = U^.D.U v = allgather_list(v_scat) self.eigenStates = self.transformation.H.dot(embedV(v, self.blocksizes)).dot(self.transformation) self.matrix = self.transformation.H.dot(self.matrix).dot(self.transformation) report('took '+str(time()-t0)[:4]+' seconds', self.verbose)