def kernel(cc, eris, t1=None, t2=None, max_cycle=50, tol=1e-8, tolnormt=1e-6, max_memory=2000, verbose=logger.INFO): """Exactly the same as pyscf.cc.ccsd.kernel, which calls a *local* energy() function.""" if isinstance(verbose, logger.Logger): log = verbose else: log = Logger(cc.stdout, verbose) if t1 is None and t2 is None: t1, t2 = cc.init_amps(eris)[1:] elif t1 is None: nocc = cc.nocc nvir = cc.nmo - nocc t1 = numpy.zeros((nocc, nvir), eris.dtype) elif t2 is None: t2 = cc.init_amps(eris)[2] cput1 = cput0 = (time.clock(), time.time()) nkpts, nocc, nvir = t1.shape eold = 0.0 eccsd = 0.0 if cc.diis: adiis = lib.diis.DIIS(cc, cc.diis_file) adiis.space = cc.diis_space else: adiis = lambda t1, t2, *args: (t1, t2) conv = False for istep in range(max_cycle): t1new, t2new = cc.update_amps(t1, t2, eris) #normt = numpy.linalg.norm(t1new-t1) + numpy.linalg.norm(t2new-t2) dt = t1new - t1 normt = einsum('xia,xia->', dt.conj(), dt) dt = t2new - t2 normt += einsum('xyzijab,xyzijab->', dt.conj(), dt) normt = numpy.real(normt.sum())**.5 t1, t2 = t1new, t2new t1new = t2new = dt = None if cc.diis: t1, t2 = cc.diis(t1, t2, istep, normt, eccsd - eold, adiis) eold, eccsd = eccsd, energy(cc, t1, t2, eris) log.info('istep = %d E(CCSD) = %.15g dE = %.9g norm(t1,t2) = %.6g', istep, eccsd, eccsd - eold, normt) cput1 = log.timer('CCSD iter', *cput1) if abs(eccsd - eold) < tol and normt < tolnormt: conv = True break log.timer('CCSD', *cput0) return conv, eccsd, t1, t2
def kernel(cc, eris, t1=None, t2=None, max_cycle=50, tol=1e-8, tolnormt=1e-6, max_memory=2000, verbose=logger.INFO): """Exactly the same as pyscf.cc.ccsd.kernel, which calls a *local* energy() function.""" if isinstance(verbose, logger.Logger): log = verbose else: log = logger.Logger(cc.stdout, verbose) if t1 is None and t2 is None: t1, t2 = cc.init_amps(eris)[1:] elif t1 is None: nocc = cc.nocc() nvir = cc.nmo() - nocc nkpts = cc.nkpts t1 = numpy.zeros((nkpts,nocc,nvir), numpy.complex128) elif t2 is None: t2 = cc.init_amps(eris)[2] cput1 = cput0 = (time.clock(), time.time()) nkpts, nocc, nvir = t1.shape eold = 0 eccsd = 0 if cc.diis: adiis = lib.diis.DIIS(cc, cc.diis_file) adiis.space = cc.diis_space else: adiis = lambda t1,t2,*args: (t1,t2) conv = False for istep in range(max_cycle): t1new, t2new = cc.update_amps(t1, t2, eris, max_memory) normt = numpy.linalg.norm(t1new-t1) + numpy.linalg.norm(t2new-t2) t1, t2 = t1new, t2new t1new = t2new = None if cc.diis: t1, t2 = cc.diis(t1, t2, istep, normt, eccsd-eold, adiis) eold, eccsd = eccsd, energy(cc, t1, t2, eris) log.info('istep = %d E(CCSD) = %.15g dE = %.9g norm(t1,t2) = %.6g', istep, eccsd, eccsd - eold, normt) cput1 = log.timer('CCSD iter', *cput1) if abs(eccsd-eold) < tol and normt < tolnormt: conv = True break log.timer('CCSD', *cput0) return conv, eccsd, t1, t2