def detToMPS(vmat1): print '\n[detToMPS]' nb, nelec = vmat1.shape civec2 = numpy.zeros(misc.binomial(nb, nelec)) for strAB in itools.combinations(range(nb), nelec): addr = tensorRep.str2addr_o1(nb, nelec, tensorRep.string2bit(strAB)) civec2[addr] = numpy.linalg.det(vmat1[list(strAB), :]) # Fock-space representation citensor = tensorRep.toONtensor(nb, nelec, civec2) # ToMPS format mps = tensorDecomp.toMPS(citensor, [2] * nb, 1.e-14, plot=False) # # It is important to realize that in toONtensor, the ordering of # orbitals is actually [k,...,2,1] while in our case, we need # [1,2,..,k]. So a reverse procedure is need to reverse the MPS. # mps = mpslib.mps_reverse(mps) bdim0 = mpslib.mps_bdim(mps) mpslib.mps_compress(mps) bdim1 = mpslib.mps_bdim(mps) return mps
def bdim(self): tmp = self.torank2() bdim = mpslib.mps_bdim(tmp) return bdim
def testDet(nb=12, nelec=6): import jacobi print '\n[testDet]' # Init numpy.random.seed(2) h = numpy.random.uniform(-1, 1, nb * nb) h = h.reshape(nb, nb) h = 0.5 * (h + h.T) e1, v1, givens = jacobi.jacobi(h, ifswap=False) vmat1 = v1[:, :nelec].copy() mps = detToMPS(vmat1) bdim0 = mpslib.mps_bdim(mps) rdm1 = makeRDM1(mps) diff = numpy.linalg.norm(rdm1 - vmat1.dot(vmat1.T)) print 'RDMdiff=', diff if diff > 1.e-10: exit() #-----------------------------------------------------# # Try to convert MPS(in AO basis) to MPS(in MO basis) # # by applying the unitary transformation gates. # #-----------------------------------------------------# ngivens = len(givens) mps1 = copy.deepcopy(mps) for idx, rot in enumerate(givens): k, l, arg = rot if abs(arg) < 1.e-10: continue print '>>> idx=', idx, '/', ngivens, ' arg=', arg, math.cos( arg), math.sin(arg) umpo = genU1mpo(nb, k, l, -arg) mps1 = copy.deepcopy(umpo.dot(mps1)) print 'mps.bdim = ', mpslib.mps_bdim(mps1) mpslib.mps_compress(mps1) # Print bdim0 = mpslib.mps_bdim(mps) bdim1 = mpslib.mps_bdim(mps1) print 'bdim0', bdim0 print 'bdim1', bdim1 # Comparison dmps = mpslib.detmps(nb, nelec) rr = mpslib.mps_diff(dmps, mps1, iprt=1) print 'diff=', rr nmpo = occmpo(nb) nelec1 = mpslib.mps_dot(dmps, nmpo.dot(dmps)) nelec2 = mpslib.mps_dot(mps1, nmpo.dot(mps1)) print 'Check nelec:' print 'nelec =', nelec print 'nelec1=', nelec1 print 'nelec2=', nelec2 # # bdim0 [2, 4, 8, 16, 32, 64, 128, 256, 128, 64, 32, 16, 8, 4, 2] # bdim1 [2, 3, 3, 3, 3, 3, 4, 4, 4, 3, 2, 2, 2, 1, 1] # [mps_diff] # rr=0.00000e+00 # pp=1.00000 # pq=1.00000 # qp=1.00000 # qq=1.00000 # diff= 0.0 # Check nelec: # nelec = 8 # nelec1= 8.0 # nelec2= 8.00000000001 # return 0