def energy(mycc, t1=None, t2=None, eris=None): '''CCD correlation energy''' if t1 is None: t1 = mycc.t1 if t2 is None: t2 = mycc.t2 eris = getattr(mycc, '_eris', None) if eris is None: mycc.ao2mo() eris = mycc._eris nocc, nvir = t1.shape fock = eris.fock loc0, loc1 = _task_location(nvir) #if rank == 0: # e = np.einsum('ia, ia', fock[:nocc, nocc:], t1, optimize=True) #else: # e = 0.0 e = 0.0 max_memory = mycc.max_memory - lib.current_memory()[0] blksize = int( min(nvir, max(BLKMIN, max_memory * .3e6 / 8 / (nocc**2 * nvir + 1)))) for p0, p1 in lib.prange(0, loc1 - loc0, blksize): eris_vvoo = eris.xvoo[p0:p1] e += np.einsum('ijab, abij', t2[:, :, p0:p1], eris_vvoo, optimize=True) #e += 0.50 * np.einsum('ia, jb, abij', t1[:, loc0+p0:loc0+p1], t1, # eris_vvoo, optimize=True) e = comm.allreduce(e) * 0.25 if rank == 0 and abs(e.imag) > 1e-4: logger.warn(mycc, 'Non-zero imaginary part found in CCD energy %s', e) return e.real
def extrapolate(self, nd=None): if nd is None: nd = self.get_num_vec() if nd == 0: raise RuntimeError('No vector found in DIIS object.') h = self._H[:nd + 1, :nd + 1].copy() h[1:, 1:] = mpi.comm.allreduce(self._H[1:nd + 1, 1:nd + 1]) g = numpy.zeros(nd + 1, h.dtype) g[0] = 1 w, v = scipy.linalg.eigh(h) if numpy.any(abs(w) < 1e-14): logger.debug(self, 'Singularity found in DIIS error vector space.') idx = abs(w) > 1e-14 c = numpy.dot(v[:, idx] * (1. / w[idx]), numpy.dot(v[:, idx].T.conj(), g)) else: try: c = numpy.linalg.solve(h, g) except numpy.linalg.linalg.LinAlgError as e: logger.warn(self, ' diis singular, eigh(h) %s', w) raise e logger.debug1(self, 'diis-c %s', c) xnew = None for i, ci in enumerate(c[1:]): xi = self.get_vec(i) if xnew is None: xnew = numpy.zeros(xi.size, c.dtype) for p0, p1 in lib.prange(0, xi.size, lib.diis.BLOCK_SIZE): xnew[p0:p1] += xi[p0:p1] * ci return xnew
def energy(mycc, t1=None, t2=None, eris=None): '''CCSD correlation energy''' if t1 is None: t1 = mycc.t1 if t2 is None: t2 = mycc.t2 eris = getattr(mycc, '_eris', None) if eris is None: mycc.ao2mo() eris = mycc._eris nocc, nvir = t1.shape t2T = t2.transpose(2, 3, 0, 1) fock = eris.fock loc0, loc1 = _task_location(nvir) e = numpy.einsum('ia,ia', fock[:nocc, nocc:], t1) * 2 max_memory = mycc.max_memory - lib.current_memory()[0] blksize = int( min(nvir, max(BLKMIN, max_memory * .3e6 / 8 / (nocc**2 * nvir + 1)))) for p0, p1 in lib.prange(0, loc1 - loc0, blksize): eris_ovov = eris.ovov[:, p0:p1] tau = t2T[p0:p1] + numpy.einsum('ia,jb->abij', t1[:, p0 + loc0:p1 + loc0], t1) e += 2 * numpy.einsum('abij,iajb', tau, eris_ovov) e -= numpy.einsum('abji,iajb', tau, eris_ovov) e = comm.allreduce(e) if rank == 0 and abs(e.imag) > 1e-4: logger.warn(mycc, 'Non-zero imaginary part found in CCSD energy %s', e) return e.real
def extrapolate(self, nd=None): if nd is None: nd = self.get_num_vec() if nd == 0: raise RuntimeError('No vector found in DIIS object.') h = self._H[:nd+1,:nd+1].copy() h[1:,1:] = mpi.comm.allreduce(self._H[1:nd+1,1:nd+1]) g = numpy.zeros(nd+1, h.dtype) g[0] = 1 w, v = scipy.linalg.eigh(h) if numpy.any(abs(w)<1e-14): logger.debug(self, 'Singularity found in DIIS error vector space.') idx = abs(w)>1e-14 c = numpy.dot(v[:,idx]*(1./w[idx]), numpy.dot(v[:,idx].T.conj(), g)) else: try: c = numpy.linalg.solve(h, g) except numpy.linalg.linalg.LinAlgError as e: logger.warn(self, ' diis singular, eigh(h) %s', w) raise e logger.debug1(self, 'diis-c %s', c) xnew = None for i, ci in enumerate(c[1:]): xi = self.get_vec(i) if xnew is None: xnew = numpy.zeros(xi.size, c.dtype) for p0, p1 in lib.prange(0, xi.size, lib.diis.BLOCK_SIZE): xnew[p0:p1] += xi[p0:p1] * ci return xnew
def energy(mycc, t1=None, t2=None, eris=None): '''CCSD correlation energy''' if t1 is None: t1 = mycc.t1 if t2 is None: t2 = mycc.t2 eris = getattr(mycc, '_eris', None) if eris is None: mycc.ao2mo() eris = mycc._eris nocc, nvir = t1.shape t2T = t2.transpose(2,3,0,1) fock = eris.fock loc0, loc1 = _task_location(nvir) e = numpy.einsum('ia,ia', fock[:nocc,nocc:], t1) * 2 max_memory = mycc.max_memory - lib.current_memory()[0] blksize = int(min(nvir, max(BLKMIN, max_memory*.3e6/8/(nocc**2*nvir+1)))) for p0, p1 in lib.prange(0, loc1-loc0, blksize): eris_ovov = eris.ovov[:,p0:p1] tau = t2T[p0:p1] + numpy.einsum('ia,jb->abij', t1[:,p0+loc0:p1+loc0], t1) e += 2 * numpy.einsum('abij,iajb', tau, eris_ovov) e -= numpy.einsum('abji,iajb', tau, eris_ovov) e = comm.allreduce(e) if rank == 0 and abs(e.imag) > 1e-4: logger.warn(mycc, 'Non-zero imaginary part found in CCSD energy %s', e) return e.real