def IX_intermediates(mycc, t1, t2, l1, l2, eris=None, d1=None, d2=None): if eris is None: # Note eris are in Chemist's notation eris = ccsd._ERIS(mycc) if d1 is None: d1 = ccsd_rdm.gamma1_intermediates(mycc, t1, t2, l1, l2) if d2 is None: d2 = ccsd_rdm.gamma2_incore(mycc, t1, t2, l1, l2) doo, dov, dvo, dvv = d1 dovov, dvvvv, doooo, doovv, dovvo, dvvov, dovvv, dooov = d2 log = logger.Logger(mycc.stdout, mycc.verbose) nocc, nvir = t1.shape nov = nocc * nvir # Note Ioo, Ivv are not hermitian Ioo = numpy.zeros((nocc, nocc)) Ivv = numpy.zeros((nvir, nvir)) Ivo = numpy.zeros((nvir, nocc)) Xvo = numpy.zeros((nvir, nocc)) eris_oooo = _cp(eris.oooo) eris_ooov = _cp(eris.ooov) d_oooo = _cp(doooo) d_oooo = _cp(d_oooo + d_oooo.transpose(1, 0, 2, 3)) #:Ioo += numpy.einsum('jmlk,imlk->ij', d_oooo, eris_oooo) * 2 Ioo += lib.dot(eris_oooo.reshape(nocc, -1), d_oooo.reshape(nocc, -1).T, 2) d_oooo = _cp(d_oooo.transpose(0, 2, 3, 1)) #:Xvo += numpy.einsum('iljk,ljka->ai', d_oooo, eris_ooov) * 2 Xvo += lib.dot( eris_ooov.reshape(-1, nvir).T, d_oooo.reshape(nocc, -1).T, 2) Xvo += (numpy.einsum('kj,kjia->ai', doo, eris_ooov) * 4 - numpy.einsum('kj,ikja->ai', doo + doo.T, eris_ooov)) eris_oooo = eris_ooov = d_oooo = None d_ooov = _cp(dooov) eris_oooo = _cp(eris.oooo) eris_ooov = _cp(eris.ooov) #:Ivv += numpy.einsum('ijkb,ijka->ab', d_ooov, eris_ooov) #:Ivo += numpy.einsum('jlka,jlki->ai', d_ooov, eris_oooo) Ivv += lib.dot(eris_ooov.reshape(-1, nvir).T, d_ooov.reshape(-1, nvir)) Ivo += lib.dot(d_ooov.reshape(-1, nvir).T, eris_oooo.reshape(-1, nocc)) #:Ioo += numpy.einsum('klja,klia->ij', d_ooov, eris_ooov) #:Xvo += numpy.einsum('kjib,kjba->ai', d_ooov, eris.oovv) eris_oovv = _cp(eris.oovv) tmp = _cp(d_ooov.transpose(0, 1, 3, 2).reshape(-1, nocc)) tmpooov = _cp(eris_ooov.transpose(0, 1, 3, 2)) Ioo += lib.dot(tmpooov.reshape(-1, nocc).T, tmp) Xvo += lib.dot(eris_oovv.reshape(-1, nvir).T, tmp) eris_oooo = tmp = None d_ooov = d_ooov + d_ooov.transpose(1, 0, 2, 3) eris_ovov = _cp(eris.ovov) #:Ioo += numpy.einsum('jlka,ilka->ij', d_ooov, eris_ooov) #:Xvo += numpy.einsum('ijkb,kbja->ai', d_ooov, eris.ovov) Ioo += lib.dot(eris_ooov.reshape(nocc, -1), d_ooov.reshape(nocc, -1).T) Xvo += lib.dot( eris_ovov.reshape(-1, nvir).T, _cp(d_ooov.transpose(0, 2, 3, 1).reshape(nocc, -1)).T) d_ooov = None #:Ioo += numpy.einsum('kjba,kiba->ij', d_oovv, eris.oovv) #:Ivv += numpy.einsum('ijcb,ijca->ab', d_oovv, eris.oovv) #:Ivo += numpy.einsum('kjba,kjib->ai', d_oovv, eris.ooov) d_oovv = _cp(doovv + doovv.transpose(1, 0, 3, 2)) for i in range(nocc): Ioo += lib.dot(eris_oovv[i].reshape(nocc, -1), d_oovv[i].reshape(nocc, -1).T) Ivv += lib.dot(eris_oovv.reshape(-1, nvir).T, d_oovv.reshape(-1, nvir)) Ivo += lib.dot(d_oovv.reshape(-1, nvir).T, tmpooov.reshape(-1, nocc)) d_oovv = _ccsd.precontract(d_oovv.reshape(-1, nvir, nvir)).reshape(nocc, nocc, -1) eris_ooov = tmpooov = None blksize = 4 d_ovov = numpy.empty((nocc, nvir, nocc, nvir)) for p0, p1 in prange(0, nocc, blksize): d_ovov[p0:p1] = _cp(dovov[p0:p1]) d_ovvo = _cp(dovvo[p0:p1]) for i in range(p0, p1): d_ovov[i] += d_ovvo[i - p0].transpose(0, 2, 1) d_ovvo = None #:d_ovov = d_ovov + d_ovov.transpose(2,3,0,1) lib.transpose_sum(d_ovov.reshape(nov, nov), inplace=True) #:Ivo += numpy.einsum('jbka,jbki->ai', d_ovov, eris.ovoo) Ivo += lib.dot( d_ovov.reshape(-1, nvir).T, _cp(eris.ovoo).reshape(-1, nocc)) #:Ioo += numpy.einsum('jakb,iakb->ij', d_ovov, eris.ovov) #:Ivv += numpy.einsum('jcib,jcia->ab', d_ovov, eris.ovov) Ioo += lib.dot(eris_ovov.reshape(nocc, -1), d_ovov.reshape(nocc, -1).T) Ivv += lib.dot(eris_ovov.reshape(-1, nvir).T, d_ovov.reshape(-1, nvir)) nvir_pair = nvir * (nvir + 1) // 2 bufe_ovvv = numpy.empty((blksize, nvir, nvir, nvir)) bufc_ovvv = numpy.empty((blksize, nvir, nvir_pair)) bufc_ovvv.data = bufe_ovvv.data c_vvvo = numpy.empty((nvir_pair, nvir, nocc)) for p0, p1 in prange(0, nocc, blksize): d_ovvv = numpy.empty((p1 - p0, nvir, nvir, nvir)) #:Ivo += numpy.einsum('jadc,jidc->ai', d_ovvv, eris_oovv) for i in range(p1 - p0): lib.dot(dovvv[p0 + i].reshape(nvir, -1), eris_oovv[p0 + i].reshape(nocc, -1).T, 1, Ivo, 1) c_ovvv = bufc_ovvv[:p1 - p0] # tril part of (d_ovvv + d_ovvv.transpose(0,1,3,2)) _ccsd.precontract(dovvv[p0:p1].reshape(-1, nvir, nvir), out=c_ovvv) for i0, i1, in prange(0, nvir_pair, BLKSIZE): for j0, j1 in prange(0, nvir, BLKSIZE // (p1 - p0) + 1): c_vvvo[i0:i1, j0:j1, p0:p1] = c_ovvv[:, j0:j1, i0:i1].transpose(2, 1, 0) eris_ovx = _cp(eris.ovvv[p0:p1]) #:Xvo += numpy.einsum('jibc,jabc->ai', d_oovv, eris_ovvv) #:Ivv += numpy.einsum('ibdc,iadc->ab', d_ovvv, eris_ovvv) for i in range(p1 - p0): lib.dot(eris_ovx[i].reshape(nvir, -1), d_oovv[p0 + i].reshape(nocc, -1).T, 1, Xvo, 1) lib.dot(eris_ovx[i].reshape(nvir, -1), c_ovvv[i].reshape(nvir, -1).T, 1, Ivv, 1) eris_ovvv = bufe_ovvv[:p1 - p0] lib.unpack_tril(eris_ovx.reshape(-1, nvir_pair), out=eris_ovvv.reshape(-1, nvir**2)) eris_ovx = None #:Xvo += numpy.einsum('icjb,acjb->ai', d_ovov, eris_vvov) d_ovvo = _cp(d_ovov[p0:p1].transpose(0, 1, 3, 2)) lib.dot( eris_ovvv.reshape(-1, nvir).T, d_ovvo.reshape(-1, nocc), 1, Xvo, 1) e_ovvo, d_ovvo = d_ovvo, None for i in range(p1 - p0): d_ovvv[i] = _ccsd.sum021(dovvv[p0 + i]) e_ovvo[i] = eris_ovov[p0 + i].transpose(0, 2, 1) #:Ivo += numpy.einsum('jcab,jcib->ai', d_ovvv, eris_ovov) #:Ivv += numpy.einsum('icdb,icda->ab', d_ovvv, eris_ovvv) lib.dot( d_ovvv.reshape(-1, nvir).T, e_ovvo[:p1 - p0].reshape(-1, nocc), 1, Ivo, 1) lib.dot( eris_ovvv.reshape(-1, nvir).T, d_ovvv.reshape(-1, nvir), 1, Ivv, 1) Xvo[:, p0:p1] += (numpy.einsum('cb,iacb->ai', dvv, eris_ovvv) * 4 - numpy.einsum('cb,icba->ai', dvv + dvv.T, eris_ovvv)) d_oovv = d_ovvv = bufc_ovvv = bufe_ovvv = None eris_ovov = eris_ovvv = eris_oovv = e_ovvo = None eris_ovvv = _cp(eris.ovvv) bufe_vvvo = numpy.empty((blksize * nvir, nvir, nocc)) bufe_vvvv = numpy.empty((blksize * nvir, nvir, nvir)) bufd_vvvv = numpy.empty((blksize * nvir, nvir, nvir)) for p0, p1 in prange(0, nvir, blksize): off0 = p0 * (p0 + 1) // 2 off1 = p1 * (p1 + 1) // 2 d_vvvv = _cp(dvvvv[off0:off1]) * 4 for i in range(p0, p1): d_vvvv[i * (i + 1) // 2 + i - off0] *= .5 d_vvvv = lib.unpack_tril(d_vvvv, out=bufd_vvvv[:off1 - off0]) eris_vvvv = lib.unpack_tril(eris.vvvv[off0:off1], out=bufe_vvvv[:off1 - off0]) #:Ivv += numpy.einsum('decb,deca->ab', d_vvvv, eris_vvvv) * 2 #:Xvo += numpy.einsum('icdb,acdb->ai', d_ovvv, eris_vvvv) lib.dot( eris_vvvv.reshape(-1, nvir).T, d_vvvv.reshape(-1, nvir), 2, Ivv, 1) d_vvvo = _cp(c_vvvo[off0:off1]) lib.dot( eris_vvvv.reshape(-1, nvir).T, d_vvvo.reshape(-1, nocc), 1, Xvo, 1) #:Ioo += numpy.einsum('abjc,abci->ij', d_vvov, eris_vvvo) #:Ivo += numpy.einsum('dbca,dbci->ai', d_vvvv, eris_vvvo) * 2 eris_vvvo = bufe_vvvo[:off1 - off0] for i0, i1 in prange(off0, off1, BLKSIZE): for j0, j1, in prange(0, nvir, BLKSIZE // nocc + 1): eris_vvvo[i0 - off0:i1 - off0, j0:j1, :] = eris_ovvv[:, j0:j1, i0:i1].transpose(2, 1, 0) lib.dot( eris_vvvo.reshape(-1, nocc).T, d_vvvo.reshape(-1, nocc), 1, Ioo, 1) lib.dot( d_vvvv.reshape(-1, nvir).T, eris_vvvo.reshape(-1, nocc), 2, Ivo, 1) Ioo *= -1 Ivv *= -1 Ivo *= -1 Xvo += Ivo return Ioo, Ivv, Ivo, Xvo
def IX_intermediates(mycc, t1, t2, l1, l2, eris=None, d1=None, d2=None): if eris is None: # Note eris are in Chemist's notation eris = ccsd._ERIS(mycc) if d1 is None: d1 = ccsd_rdm.gamma1_intermediates(mycc, t1, t2, l1, l2) doo, dov, dvo, dvv = d1 if d2 is None: _d2tmpfile = tempfile.NamedTemporaryFile(dir=lib.param.TMPDIR) fd2intermediate = h5py.File(_d2tmpfile.name, 'w') ccsd_rdm.gamma2_outcore(mycc, t1, t2, l1, l2, fd2intermediate) dovov = fd2intermediate['dovov'] dvvvv = fd2intermediate['dvvvv'] doooo = fd2intermediate['doooo'] doovv = fd2intermediate['doovv'] dovvo = fd2intermediate['dovvo'] dovvv = fd2intermediate['dovvv'] dooov = fd2intermediate['dooov'] else: dovov, dvvvv, doooo, doovv, dovvo, dvvov, dovvv, dooov = d2 log = logger.Logger(mycc.stdout, mycc.verbose) nocc, nvir = t1.shape nov = nocc * nvir nvir_pair = nvir * (nvir + 1) // 2 _tmpfile = tempfile.NamedTemporaryFile(dir=lib.param.TMPDIR) fswap = h5py.File(_tmpfile.name, 'w') fswap.create_group('e_vvov') fswap.create_group('c_vvov') # Note Ioo, Ivv are not hermitian Ioo = numpy.zeros((nocc, nocc)) Ivv = numpy.zeros((nvir, nvir)) Ivo = numpy.zeros((nvir, nocc)) Xvo = numpy.zeros((nvir, nocc)) eris_oooo = _cp(eris.oooo) eris_ooov = _cp(eris.ooov) d_oooo = _cp(doooo) d_oooo = _cp(d_oooo + d_oooo.transpose(1, 0, 2, 3)) #:Ioo += numpy.einsum('jmlk,imlk->ij', d_oooo, eris_oooo) * 2 Ioo += lib.dot(eris_oooo.reshape(nocc, -1), d_oooo.reshape(nocc, -1).T, 2) d_oooo = _cp(d_oooo.transpose(0, 2, 3, 1)) #:Xvo += numpy.einsum('iljk,ljka->ai', d_oooo, eris_ooov) * 2 Xvo += lib.dot( eris_ooov.reshape(-1, nvir).T, d_oooo.reshape(nocc, -1).T, 2) Xvo += (numpy.einsum('kj,kjia->ai', doo, eris_ooov) * 4 - numpy.einsum( 'kj,ikja->ai', doo + doo.T, eris_ooov)) eris_oooo = eris_ooov = d_oooo = None d_ovov = numpy.empty((nocc, nvir, nocc, nvir)) blksize = 8 for p0, p1 in prange(0, nocc, blksize): d_ovov[p0:p1] = _cp(dovov[p0:p1]) d_ovvo = _cp(dovvo[p0:p1]) for i in range(p0, p1): d_ovov[i] += d_ovvo[i - p0].transpose(0, 2, 1) d_ovvo = None d_ovov = lib.transpose_sum(d_ovov.reshape(nov, nov)).reshape( nocc, nvir, nocc, nvir) #:Ivo += numpy.einsum('jbka,jbki->ai', d_ovov, eris.ovoo) Ivo += lib.dot( d_ovov.reshape(-1, nvir).T, _cp(eris.ovoo).reshape(-1, nocc)) eris_ovov = _cp(eris.ovov) #:Ioo += numpy.einsum('jakb,iakb->ij', d_ovov, eris.ovov) #:Ivv += numpy.einsum('jcib,jcia->ab', d_ovov, eris.ovov) Ioo += lib.dot(eris_ovov.reshape(nocc, -1), d_ovov.reshape(nocc, -1).T) Ivv += lib.dot(eris_ovov.reshape(-1, nvir).T, d_ovov.reshape(-1, nvir)) eris_ovov = None fswap['dovvo'] = d_ovov.transpose(0, 1, 3, 2) d_ovov = None max_memory = mycc.max_memory - lib.current_memory()[0] unit = max(nvir**3 * 2.5, nvir**3 * 2 + nocc * nvir**2) blksize = max(ccsd.BLKMIN, int(max_memory * 1e6 / 8 / unit)) iobuflen = int(256e6 / 8 / (blksize * nvir)) log.debug1( 'IX_intermediates pass 1: block size = %d, nocc = %d in %d blocks', blksize, nocc, int((nocc + blksize - 1) / blksize)) for istep, (p0, p1) in enumerate(prange(0, nocc, blksize)): d_ooov = _cp(dooov[p0:p1]) eris_oooo = _cp(eris.oooo[p0:p1]) eris_ooov = _cp(eris.ooov[p0:p1]) #:Ivv += numpy.einsum('ijkb,ijka->ab', d_ooov, eris_ooov) #:Ivo += numpy.einsum('jlka,jlki->ai', d_ooov, eris_oooo) Ivv += lib.dot(eris_ooov.reshape(-1, nvir).T, d_ooov.reshape(-1, nvir)) Ivo += lib.dot(d_ooov.reshape(-1, nvir).T, eris_oooo.reshape(-1, nocc)) #:Ioo += numpy.einsum('klja,klia->ij', d_ooov, eris_ooov) #:Xvo += numpy.einsum('kjib,kjba->ai', d_ooov, eris.oovv) eris_oovv = _cp(eris.oovv[p0:p1]) tmp = _cp(d_ooov.transpose(0, 1, 3, 2).reshape(-1, nocc)) Ioo += lib.dot( _cp(eris_ooov.transpose(0, 1, 3, 2).reshape(-1, nocc)).T, tmp) Xvo += lib.dot(eris_oovv.reshape(-1, nvir).T, tmp) eris_oooo = tmp = None d_ooov = d_ooov + dooov[:, p0:p1].transpose(1, 0, 2, 3) eris_ovov = _cp(eris.ovov[p0:p1]) #:Ioo += numpy.einsum('ljka,lika->ij', d_ooov, eris_ooov) #:Xvo += numpy.einsum('jikb,jakb->ai', d_ooov, eris_ovov) for i in range(p1 - p0): lib.dot(eris_ooov[i].reshape(nocc, -1), d_ooov[i].reshape( nocc, -1).T, 1, Ioo, 1) lib.dot(eris_ovov[i].reshape(nvir, -1), d_ooov[i].reshape( nocc, -1).T, 1, Xvo, 1) d_ooov = None #:Ioo += numpy.einsum('kjba,kiba->ij', d_oovv, eris.oovv) #:Ivv += numpy.einsum('ijcb,ijca->ab', d_oovv, eris.oovv) #:Ivo += numpy.einsum('kjba,kjib->ai', d_oovv, eris.ooov) d_oovv = _cp(doovv[p0:p1]) + doovv[:, p0:p1].transpose(1, 0, 3, 2) for i in range(p1 - p0): Ioo += lib.dot(eris_oovv[i].reshape(nocc, -1), d_oovv[i].reshape( nocc, -1).T) Ivv += lib.dot(eris_oovv.reshape(-1, nvir).T, d_oovv.reshape(-1, nvir)) Ivo += lib.dot( d_oovv.reshape(-1, nvir).T, _cp(eris_ooov.transpose(0, 1, 3, 2).reshape(-1, nocc))) eris_ooov = None d_oovv = _ccsd.precontract(d_oovv.reshape(-1, nvir, nvir)).reshape( p1 - p0, nocc, -1) d_ovvv = numpy.empty((p1 - p0, nvir, nvir, nvir)) ao2mo.outcore._load_from_h5g(dovvv, p0 * nvir, p1 * nvir, d_ovvv.reshape(-1, nvir**2)) #:Ivo += numpy.einsum('jadc,jidc->ai', d_ovvv, eris_oovv) for i in range(p1 - p0): Ivo += lib.dot(d_ovvv[i].reshape(nvir, -1), eris_oovv[i].reshape( nocc, -1).T) eris_oovv = None # tril part of (d_ovvv + d_ovvv.transpose(0,1,3,2)) c_ovvv = _ccsd.precontract(d_ovvv.reshape(-1, nvir, nvir)) ao2mo.outcore._transpose_to_h5g(fswap, 'c_vvov/%d' % istep, c_ovvv, iobuflen) c_ovvv = c_ovvv.reshape(-1, nvir, nvir_pair) eris_ovx = _cp(eris.ovvv[p0:p1]) ao2mo.outcore._transpose_to_h5g(fswap, 'e_vvov/%d' % istep, eris_ovx.reshape(-1, nvir_pair), iobuflen) #:Xvo += numpy.einsum('jibc,jabc->ai', d_oovv, eris_ovvv) #:Ivv += numpy.einsum('ibdc,iadc->ab', d_ovvv, eris_ovvv) for i in range(p1 - p0): lib.dot(eris_ovx[i].reshape(nvir, -1), d_oovv[i].reshape(nocc, -1).T, 1, Xvo, 1) lib.dot(eris_ovx[i].reshape(nvir, -1), c_ovvv[i].reshape(nvir, -1).T, 1, Ivv, 1) c_ovvv = d_oovv = None eris_ovvo = numpy.empty((p1 - p0, nvir, nvir, nocc)) for i in range(p1 - p0): d_ovvv[i] = _ccsd.sum021(d_ovvv[i]) eris_ovvo[i] = eris_ovov[i].transpose(0, 2, 1) #:Ivo += numpy.einsum('abjc,ibjc->ai', d_ovvv, eris_ovov) Ivo += lib.dot(d_ovvv.reshape(-1, nvir).T, eris_ovvo.reshape(-1, nocc)) eris_ovvo = eris_ovov = None eris_ovvv = lib.unpack_tril(eris_ovx.reshape(-1, nvir_pair)) eris_ovx = None eris_ovvv = eris_ovvv.reshape(p1 - p0, nvir, nvir, nvir) #:Ivv += numpy.einsum('icdb,icda->ab', d_ovvv, eris_ovvv) #:Xvo += numpy.einsum('jibc,jabc->ai', d_oovv, eris_ovvv) Ivv += lib.dot(eris_ovvv.reshape(-1, nvir).T, d_ovvv.reshape(-1, nvir)) Xvo[:, p0:p1] += (numpy.einsum('cb,iacb->ai', dvv, eris_ovvv) * 4 - numpy.einsum('cb,icba->ai', dvv + dvv.T, eris_ovvv)) d_ovvo = _cp(fswap['dovvo'][p0:p1]) #:Xvo += numpy.einsum('jbic,jbca->ai', d_ovov, eris_ovvv) lib.dot( eris_ovvv.reshape(-1, nvir).T, d_ovvo.reshape(-1, nocc), 1, Xvo, 1) d_ovvv = d_ovvo = eris_ovvv = None max_memory = mycc.max_memory - lib.current_memory()[0] unit = nocc * nvir**2 + nvir**3 * 2.5 blksize = max(ccsd.BLKMIN, int(max_memory * 1e6 / 8 / unit)) log.debug1( 'IX_intermediates pass 2: block size = %d, nocc = %d in %d blocks', blksize, nocc, int((nocc + blksize - 1) / blksize)) for p0, p1 in prange(0, nvir, blksize): off0 = p0 * (p0 + 1) // 2 off1 = p1 * (p1 + 1) // 2 d_vvvv = _cp(dvvvv[off0:off1]) * 4 for i in range(p0, p1): d_vvvv[i * (i + 1) // 2 + i - off0] *= .5 d_vvvv = lib.unpack_tril(d_vvvv) eris_vvvv = lib.unpack_tril(_cp(eris.vvvv[off0:off1])) #:Ivv += numpy.einsum('decb,deca->ab', d_vvvv, eris_vvvv) * 2 #:Xvo += numpy.einsum('dbic,dbca->ai', d_vvov, eris_vvvv) lib.dot( eris_vvvv.reshape(-1, nvir).T, d_vvvv.reshape(-1, nvir), 2, Ivv, 1) #:d_vvvv = _cp(d_vvvv + d_vvvv.transpose(0,1,3,2)) d_vvov = numpy.empty((off1 - off0, nocc, nvir)) ao2mo.outcore._load_from_h5g(fswap['c_vvov'], off0, off1, d_vvov.reshape(-1, nov)) d_vvvo = _cp(d_vvov.transpose(0, 2, 1)) lib.dot( eris_vvvv.reshape(-1, nvir).T, d_vvvo.reshape(-1, nocc), 1, Xvo, 1) d_vvov = eris_vvvv = None eris_vvov = numpy.empty((off1 - off0, nocc, nvir)) ao2mo.outcore._load_from_h5g(fswap['e_vvov'], off0, off1, eris_vvov.reshape(-1, nov)) eris_vvvo = _cp(eris_vvov.transpose(0, 2, 1)) #:Ioo += numpy.einsum('abjc,abci->ij', d_vvov, eris_vvvo) #:Ivo += numpy.einsum('dbca,dbci->ai', d_vvvv, eris_vvvo) * 2 lib.dot( d_vvvv.reshape(-1, nvir).T, eris_vvvo.reshape(-1, nocc), 2, Ivo, 1) lib.dot( eris_vvvo.reshape(-1, nocc).T, d_vvvo.reshape(-1, nocc), 1, Ioo, 1) eris_vvov = eris_vovv = d_vvvv = None del (fswap['e_vvov']) del (fswap['c_vvov']) del (fswap['dovvo']) fswap.close() _tmpfile = None if d2 is None: for key in fd2intermediate.keys(): del (fd2intermediate[key]) fd2intermediate.close() _d2tmpfile = None Ioo *= -1 Ivv *= -1 Ivo *= -1 Xvo += Ivo return Ioo, Ivv, Ivo, Xvo
def IX_intermediates(mycc, t1, t2, l1, l2, eris=None, d1=None, d2=None): if eris is None: # Note eris are in Chemist's notation eris = ccsd._ERIS(mycc) if d1 is None: d1 = ccsd_rdm.gamma1_intermediates(mycc, t1, t2, l1, l2) doo, dov, dvo, dvv = d1 if d2 is None: _d2tmpfile = tempfile.NamedTemporaryFile(dir=lib.param.TMPDIR) fd2intermediate = h5py.File(_d2tmpfile.name, 'w') ccsd_rdm.gamma2_outcore(mycc, t1, t2, l1, l2, fd2intermediate) dovov = fd2intermediate['dovov'] dvvvv = fd2intermediate['dvvvv'] doooo = fd2intermediate['doooo'] doovv = fd2intermediate['doovv'] dovvo = fd2intermediate['dovvo'] dovvv = fd2intermediate['dovvv'] dooov = fd2intermediate['dooov'] else: dovov, dvvvv, doooo, doovv, dovvo, dvvov, dovvv, dooov = d2 log = logger.Logger(mycc.stdout, mycc.verbose) nocc, nvir = t1.shape nov = nocc * nvir nvir_pair = nvir * (nvir + 1) // 2 _tmpfile = tempfile.NamedTemporaryFile(dir=lib.param.TMPDIR) fswap = h5py.File(_tmpfile.name, 'w') fswap.create_group('e_vvov') fswap.create_group('c_vvov') # Note Ioo, Ivv are not hermitian Ioo = numpy.zeros((nocc, nocc)) Ivv = numpy.zeros((nvir, nvir)) Ivo = numpy.zeros((nvir, nocc)) Xvo = numpy.zeros((nvir, nocc)) eris_oooo = _cp(eris.oooo) eris_ooov = _cp(eris.ooov) d_oooo = _cp(doooo) d_oooo = _cp(d_oooo + d_oooo.transpose(1, 0, 2, 3)) #:Ioo += numpy.einsum('jmlk,imlk->ij', d_oooo, eris_oooo) * 2 Ioo += lib.dot(eris_oooo.reshape(nocc, -1), d_oooo.reshape(nocc, -1).T, 2) d_oooo = _cp(d_oooo.transpose(0, 2, 3, 1)) #:Xvo += numpy.einsum('iljk,ljka->ai', d_oooo, eris_ooov) * 2 Xvo += lib.dot( eris_ooov.reshape(-1, nvir).T, d_oooo.reshape(nocc, -1).T, 2) Xvo += (numpy.einsum('kj,kjia->ai', doo, eris_ooov) * 4 - numpy.einsum('kj,ikja->ai', doo + doo.T, eris_ooov)) eris_oooo = eris_ooov = d_oooo = None d_ovov = numpy.empty((nocc, nvir, nocc, nvir)) blksize = 8 for p0, p1 in prange(0, nocc, blksize): d_ovov[p0:p1] = _cp(dovov[p0:p1]) d_ovvo = _cp(dovvo[p0:p1]) for i in range(p0, p1): d_ovov[i] += d_ovvo[i - p0].transpose(0, 2, 1) d_ovvo = None d_ovov = lib.transpose_sum(d_ovov.reshape(nov, nov)).reshape( nocc, nvir, nocc, nvir) #:Ivo += numpy.einsum('jbka,jbki->ai', d_ovov, eris.ovoo) Ivo += lib.dot( d_ovov.reshape(-1, nvir).T, _cp(eris.ovoo).reshape(-1, nocc)) eris_ovov = _cp(eris.ovov) #:Ioo += numpy.einsum('jakb,iakb->ij', d_ovov, eris.ovov) #:Ivv += numpy.einsum('jcib,jcia->ab', d_ovov, eris.ovov) Ioo += lib.dot(eris_ovov.reshape(nocc, -1), d_ovov.reshape(nocc, -1).T) Ivv += lib.dot(eris_ovov.reshape(-1, nvir).T, d_ovov.reshape(-1, nvir)) eris_ovov = None fswap['dovvo'] = d_ovov.transpose(0, 1, 3, 2) d_ovov = None max_memory = mycc.max_memory - lib.current_memory()[0] unit = max(nvir**3 * 2.5, nvir**3 * 2 + nocc * nvir**2) blksize = max(ccsd.BLKMIN, int(max_memory * 1e6 / 8 / unit)) iobuflen = int(256e6 / 8 / (blksize * nvir)) log.debug1( 'IX_intermediates pass 1: block size = %d, nocc = %d in %d blocks', blksize, nocc, int((nocc + blksize - 1) / blksize)) for istep, (p0, p1) in enumerate(prange(0, nocc, blksize)): d_ooov = _cp(dooov[p0:p1]) eris_oooo = _cp(eris.oooo[p0:p1]) eris_ooov = _cp(eris.ooov[p0:p1]) #:Ivv += numpy.einsum('ijkb,ijka->ab', d_ooov, eris_ooov) #:Ivo += numpy.einsum('jlka,jlki->ai', d_ooov, eris_oooo) Ivv += lib.dot(eris_ooov.reshape(-1, nvir).T, d_ooov.reshape(-1, nvir)) Ivo += lib.dot(d_ooov.reshape(-1, nvir).T, eris_oooo.reshape(-1, nocc)) #:Ioo += numpy.einsum('klja,klia->ij', d_ooov, eris_ooov) #:Xvo += numpy.einsum('kjib,kjba->ai', d_ooov, eris.oovv) eris_oovv = _cp(eris.oovv[p0:p1]) tmp = _cp(d_ooov.transpose(0, 1, 3, 2).reshape(-1, nocc)) Ioo += lib.dot( _cp(eris_ooov.transpose(0, 1, 3, 2).reshape(-1, nocc)).T, tmp) Xvo += lib.dot(eris_oovv.reshape(-1, nvir).T, tmp) eris_oooo = tmp = None d_ooov = d_ooov + dooov[:, p0:p1].transpose(1, 0, 2, 3) eris_ovov = _cp(eris.ovov[p0:p1]) #:Ioo += numpy.einsum('ljka,lika->ij', d_ooov, eris_ooov) #:Xvo += numpy.einsum('jikb,jakb->ai', d_ooov, eris_ovov) for i in range(p1 - p0): lib.dot(eris_ooov[i].reshape(nocc, -1), d_ooov[i].reshape(nocc, -1).T, 1, Ioo, 1) lib.dot(eris_ovov[i].reshape(nvir, -1), d_ooov[i].reshape(nocc, -1).T, 1, Xvo, 1) d_ooov = None #:Ioo += numpy.einsum('kjba,kiba->ij', d_oovv, eris.oovv) #:Ivv += numpy.einsum('ijcb,ijca->ab', d_oovv, eris.oovv) #:Ivo += numpy.einsum('kjba,kjib->ai', d_oovv, eris.ooov) d_oovv = _cp(doovv[p0:p1]) + doovv[:, p0:p1].transpose(1, 0, 3, 2) for i in range(p1 - p0): Ioo += lib.dot(eris_oovv[i].reshape(nocc, -1), d_oovv[i].reshape(nocc, -1).T) Ivv += lib.dot(eris_oovv.reshape(-1, nvir).T, d_oovv.reshape(-1, nvir)) Ivo += lib.dot( d_oovv.reshape(-1, nvir).T, _cp(eris_ooov.transpose(0, 1, 3, 2).reshape(-1, nocc))) eris_ooov = None d_oovv = _ccsd.precontract(d_oovv.reshape(-1, nvir, nvir)).reshape( p1 - p0, nocc, -1) d_ovvv = numpy.empty((p1 - p0, nvir, nvir, nvir)) ao2mo.outcore._load_from_h5g(dovvv, p0 * nvir, p1 * nvir, d_ovvv.reshape(-1, nvir**2)) #:Ivo += numpy.einsum('jadc,jidc->ai', d_ovvv, eris_oovv) for i in range(p1 - p0): Ivo += lib.dot(d_ovvv[i].reshape(nvir, -1), eris_oovv[i].reshape(nocc, -1).T) eris_oovv = None # tril part of (d_ovvv + d_ovvv.transpose(0,1,3,2)) c_ovvv = _ccsd.precontract(d_ovvv.reshape(-1, nvir, nvir)) ao2mo.outcore._transpose_to_h5g(fswap, 'c_vvov/%d' % istep, c_ovvv, iobuflen) c_ovvv = c_ovvv.reshape(-1, nvir, nvir_pair) eris_ovx = _cp(eris.ovvv[p0:p1]) ao2mo.outcore._transpose_to_h5g(fswap, 'e_vvov/%d' % istep, eris_ovx.reshape(-1, nvir_pair), iobuflen) #:Xvo += numpy.einsum('jibc,jabc->ai', d_oovv, eris_ovvv) #:Ivv += numpy.einsum('ibdc,iadc->ab', d_ovvv, eris_ovvv) for i in range(p1 - p0): lib.dot(eris_ovx[i].reshape(nvir, -1), d_oovv[i].reshape(nocc, -1).T, 1, Xvo, 1) lib.dot(eris_ovx[i].reshape(nvir, -1), c_ovvv[i].reshape(nvir, -1).T, 1, Ivv, 1) c_ovvv = d_oovv = None eris_ovvo = numpy.empty((p1 - p0, nvir, nvir, nocc)) for i in range(p1 - p0): d_ovvv[i] = _ccsd.sum021(d_ovvv[i]) eris_ovvo[i] = eris_ovov[i].transpose(0, 2, 1) #:Ivo += numpy.einsum('abjc,ibjc->ai', d_ovvv, eris_ovov) Ivo += lib.dot(d_ovvv.reshape(-1, nvir).T, eris_ovvo.reshape(-1, nocc)) eris_ovvo = eris_ovov = None eris_ovvv = lib.unpack_tril(eris_ovx.reshape(-1, nvir_pair)) eris_ovx = None eris_ovvv = eris_ovvv.reshape(p1 - p0, nvir, nvir, nvir) #:Ivv += numpy.einsum('icdb,icda->ab', d_ovvv, eris_ovvv) #:Xvo += numpy.einsum('jibc,jabc->ai', d_oovv, eris_ovvv) Ivv += lib.dot(eris_ovvv.reshape(-1, nvir).T, d_ovvv.reshape(-1, nvir)) Xvo[:, p0:p1] += (numpy.einsum('cb,iacb->ai', dvv, eris_ovvv) * 4 - numpy.einsum('cb,icba->ai', dvv + dvv.T, eris_ovvv)) d_ovvo = _cp(fswap['dovvo'][p0:p1]) #:Xvo += numpy.einsum('jbic,jbca->ai', d_ovov, eris_ovvv) lib.dot( eris_ovvv.reshape(-1, nvir).T, d_ovvo.reshape(-1, nocc), 1, Xvo, 1) d_ovvv = d_ovvo = eris_ovvv = None max_memory = mycc.max_memory - lib.current_memory()[0] unit = nocc * nvir**2 + nvir**3 * 2.5 blksize = max(ccsd.BLKMIN, int(max_memory * 1e6 / 8 / unit)) log.debug1( 'IX_intermediates pass 2: block size = %d, nocc = %d in %d blocks', blksize, nocc, int((nocc + blksize - 1) / blksize)) for p0, p1 in prange(0, nvir, blksize): off0 = p0 * (p0 + 1) // 2 off1 = p1 * (p1 + 1) // 2 d_vvvv = _cp(dvvvv[off0:off1]) * 4 for i in range(p0, p1): d_vvvv[i * (i + 1) // 2 + i - off0] *= .5 d_vvvv = lib.unpack_tril(d_vvvv) eris_vvvv = lib.unpack_tril(_cp(eris.vvvv[off0:off1])) #:Ivv += numpy.einsum('decb,deca->ab', d_vvvv, eris_vvvv) * 2 #:Xvo += numpy.einsum('dbic,dbca->ai', d_vvov, eris_vvvv) lib.dot( eris_vvvv.reshape(-1, nvir).T, d_vvvv.reshape(-1, nvir), 2, Ivv, 1) #:d_vvvv = _cp(d_vvvv + d_vvvv.transpose(0,1,3,2)) d_vvov = numpy.empty((off1 - off0, nocc, nvir)) ao2mo.outcore._load_from_h5g(fswap['c_vvov'], off0, off1, d_vvov.reshape(-1, nov)) d_vvvo = _cp(d_vvov.transpose(0, 2, 1)) lib.dot( eris_vvvv.reshape(-1, nvir).T, d_vvvo.reshape(-1, nocc), 1, Xvo, 1) d_vvov = eris_vvvv = None eris_vvov = numpy.empty((off1 - off0, nocc, nvir)) ao2mo.outcore._load_from_h5g(fswap['e_vvov'], off0, off1, eris_vvov.reshape(-1, nov)) eris_vvvo = _cp(eris_vvov.transpose(0, 2, 1)) #:Ioo += numpy.einsum('abjc,abci->ij', d_vvov, eris_vvvo) #:Ivo += numpy.einsum('dbca,dbci->ai', d_vvvv, eris_vvvo) * 2 lib.dot( d_vvvv.reshape(-1, nvir).T, eris_vvvo.reshape(-1, nocc), 2, Ivo, 1) lib.dot( eris_vvvo.reshape(-1, nocc).T, d_vvvo.reshape(-1, nocc), 1, Ioo, 1) eris_vvov = eris_vovv = d_vvvv = None del (fswap['e_vvov']) del (fswap['c_vvov']) del (fswap['dovvo']) fswap.close() _tmpfile = None if d2 is None: for key in fd2intermediate.keys(): del (fd2intermediate[key]) fd2intermediate.close() _d2tmpfile = None Ioo *= -1 Ivv *= -1 Ivo *= -1 Xvo += Ivo return Ioo, Ivv, Ivo, Xvo
def IX_intermediates(mycc, t1, t2, l1, l2, eris=None, d1=None, d2=None): if eris is None: # Note eris are in Chemist's notation eris = ccsd._ERIS(mycc) if d1 is None: doo, dvv = ccsd_rdm.gamma1_intermediates(mycc, t1, t2, l1, l2) else: doo, dvv = d1 if d2 is None: d2 = ccsd_rdm.gamma2_incore(mycc, t1, t2, l1, l2) dovov, dvvvv, doooo, doovv, dovvo, dvvov, dovvv, dooov = d2 log = logger.Logger(mycc.stdout, mycc.verbose) nocc, nvir = t1.shape nov = nocc * nvir # Note Ioo, Ivv are not hermitian Ioo = numpy.zeros((nocc,nocc)) Ivv = numpy.zeros((nvir,nvir)) Ivo = numpy.zeros((nvir,nocc)) Xvo = numpy.zeros((nvir,nocc)) eris_oooo = _cp(eris.oooo) eris_ooov = _cp(eris.ooov) d_oooo = _cp(doooo) d_oooo = _cp(d_oooo + d_oooo.transpose(1,0,2,3)) #:Ioo += numpy.einsum('jmlk,imlk->ij', d_oooo, eris_oooo) * 2 Ioo += lib.dot(eris_oooo.reshape(nocc,-1), d_oooo.reshape(nocc,-1).T, 2) d_oooo = _cp(d_oooo.transpose(0,2,3,1)) #:Xvo += numpy.einsum('iljk,ljka->ai', d_oooo, eris_ooov) * 2 Xvo += lib.dot(eris_ooov.reshape(-1,nvir).T, d_oooo.reshape(nocc,-1).T, 2) Xvo +=(numpy.einsum('kj,kjia->ai', doo, eris_ooov) * 4 - numpy.einsum('kj,ikja->ai', doo+doo.T, eris_ooov)) eris_oooo = eris_ooov = d_oooo = None d_ooov = _cp(dooov) eris_oooo = _cp(eris.oooo) eris_ooov = _cp(eris.ooov) #:Ivv += numpy.einsum('ijkb,ijka->ab', d_ooov, eris_ooov) #:Ivo += numpy.einsum('jlka,jlki->ai', d_ooov, eris_oooo) Ivv += lib.dot(eris_ooov.reshape(-1,nvir).T, d_ooov.reshape(-1,nvir)) Ivo += lib.dot(d_ooov.reshape(-1,nvir).T, eris_oooo.reshape(-1,nocc)) #:Ioo += numpy.einsum('klja,klia->ij', d_ooov, eris_ooov) #:Xvo += numpy.einsum('kjib,kjba->ai', d_ooov, eris.oovv) eris_oovv = _cp(eris.oovv) tmp = _cp(d_ooov.transpose(0,1,3,2).reshape(-1,nocc)) tmpooov = _cp(eris_ooov.transpose(0,1,3,2)) Ioo += lib.dot(tmpooov.reshape(-1,nocc).T, tmp) Xvo += lib.dot(eris_oovv.reshape(-1,nvir).T, tmp) eris_oooo = tmp = None d_ooov = d_ooov + d_ooov.transpose(1,0,2,3) eris_ovov = _cp(eris.ovov) #:Ioo += numpy.einsum('jlka,ilka->ij', d_ooov, eris_ooov) #:Xvo += numpy.einsum('ijkb,kbja->ai', d_ooov, eris.ovov) Ioo += lib.dot(eris_ooov.reshape(nocc,-1), d_ooov.reshape(nocc,-1).T) Xvo += lib.dot(eris_ovov.reshape(-1,nvir).T, _cp(d_ooov.transpose(0,2,3,1).reshape(nocc,-1)).T) d_ooov = None #:Ioo += numpy.einsum('kjba,kiba->ij', d_oovv, eris.oovv) #:Ivv += numpy.einsum('ijcb,ijca->ab', d_oovv, eris.oovv) #:Ivo += numpy.einsum('kjba,kjib->ai', d_oovv, eris.ooov) d_oovv = _cp(doovv + doovv.transpose(1,0,3,2)) for i in range(nocc): Ioo += lib.dot(eris_oovv[i].reshape(nocc, -1), d_oovv[i].reshape(nocc,-1).T) Ivv += lib.dot(eris_oovv.reshape(-1,nvir).T, d_oovv.reshape(-1,nvir)) Ivo += lib.dot(d_oovv.reshape(-1,nvir).T, tmpooov.reshape(-1,nocc)) d_oovv = _ccsd.precontract(d_oovv.reshape(-1,nvir,nvir)).reshape(nocc,nocc,-1) eris_ooov = tmpooov = None blksize = 4 d_ovov = numpy.empty((nocc,nvir,nocc,nvir)) for p0, p1 in prange(0, nocc, blksize): d_ovov[p0:p1] = _cp(dovov[p0:p1]) d_ovvo = _cp(dovvo[p0:p1]) for i in range(p0,p1): d_ovov[i] += d_ovvo[i-p0].transpose(0,2,1) d_ovvo = None #:d_ovov = d_ovov + d_ovov.transpose(2,3,0,1) lib.transpose_sum(d_ovov.reshape(nov,nov), inplace=True) #:Ivo += numpy.einsum('jbka,jbki->ai', d_ovov, eris.ovoo) Ivo += lib.dot(d_ovov.reshape(-1,nvir).T, _cp(eris.ovoo).reshape(-1,nocc)) #:Ioo += numpy.einsum('jakb,iakb->ij', d_ovov, eris.ovov) #:Ivv += numpy.einsum('jcib,jcia->ab', d_ovov, eris.ovov) Ioo += lib.dot(eris_ovov.reshape(nocc,-1), d_ovov.reshape(nocc,-1).T) Ivv += lib.dot(eris_ovov.reshape(-1,nvir).T, d_ovov.reshape(-1,nvir)) nvir_pair = nvir * (nvir+1) // 2 bufe_ovvv = numpy.empty((blksize,nvir,nvir,nvir)) bufc_ovvv = numpy.empty((blksize,nvir,nvir_pair)) bufc_ovvv.data = bufe_ovvv.data c_vvvo = numpy.empty((nvir_pair,nvir,nocc)) for p0, p1 in prange(0, nocc, blksize): d_ovvv = numpy.empty((p1-p0,nvir,nvir,nvir)) #:Ivo += numpy.einsum('jadc,jidc->ai', d_ovvv, eris_oovv) for i in range(p1-p0): lib.dot(dovvv[p0+i].reshape(nvir,-1), eris_oovv[p0+i].reshape(nocc,-1).T, 1, Ivo, 1) c_ovvv = bufc_ovvv[:p1-p0] # tril part of (d_ovvv + d_ovvv.transpose(0,1,3,2)) _ccsd.precontract(dovvv[p0:p1].reshape(-1,nvir,nvir), out=c_ovvv) for i0, i1, in prange(0, nvir_pair, BLKSIZE): for j0, j1 in prange(0, nvir, BLKSIZE//(p1-p0)+1): c_vvvo[i0:i1,j0:j1,p0:p1] = c_ovvv[:,j0:j1,i0:i1].transpose(2,1,0) eris_ovx = _cp(eris.ovvv[p0:p1]) #:Xvo += numpy.einsum('jibc,jabc->ai', d_oovv, eris_ovvv) #:Ivv += numpy.einsum('ibdc,iadc->ab', d_ovvv, eris_ovvv) for i in range(p1-p0): lib.dot(eris_ovx[i].reshape(nvir,-1), d_oovv[p0+i].reshape(nocc,-1).T, 1, Xvo, 1) lib.dot(eris_ovx[i].reshape(nvir,-1), c_ovvv[i].reshape(nvir,-1).T, 1, Ivv, 1) eris_ovvv = bufe_ovvv[:p1-p0] _ccsd.unpack_tril(eris_ovx.reshape(-1,nvir_pair), out=eris_ovvv.reshape(-1,nvir**2)) eris_ovx = None #:Xvo += numpy.einsum('icjb,acjb->ai', d_ovov, eris_vvov) d_ovvo = _cp(d_ovov[p0:p1].transpose(0,1,3,2)) lib.dot(eris_ovvv.reshape(-1,nvir).T, d_ovvo.reshape(-1,nocc), 1, Xvo, 1) e_ovvo, d_ovvo = d_ovvo, None for i in range(p1-p0): d_ovvv[i] = _ccsd.sum021(dovvv[p0+i]) e_ovvo[i] = eris_ovov[p0+i].transpose(0,2,1) #:Ivo += numpy.einsum('jcab,jcib->ai', d_ovvv, eris_ovov) #:Ivv += numpy.einsum('icdb,icda->ab', d_ovvv, eris_ovvv) lib.dot(d_ovvv.reshape(-1,nvir).T, e_ovvo[:p1-p0].reshape(-1,nocc), 1, Ivo, 1) lib.dot(eris_ovvv.reshape(-1,nvir).T, d_ovvv.reshape(-1,nvir), 1, Ivv, 1) Xvo[:,p0:p1] +=(numpy.einsum('cb,iacb->ai', dvv, eris_ovvv) * 4 - numpy.einsum('cb,icba->ai', dvv+dvv.T, eris_ovvv)) d_oovv = d_ovvv = bufc_ovvv = bufe_ovvv = None eris_ovov = eris_ovvv = eris_oovv = e_ovvo = None eris_ovvv = _cp(eris.ovvv) bufe_vvvo = numpy.empty((blksize*nvir,nvir,nocc)) bufe_vvvv = numpy.empty((blksize*nvir,nvir,nvir)) bufd_vvvv = numpy.empty((blksize*nvir,nvir,nvir)) for p0, p1 in prange(0, nvir, blksize): off0 = p0*(p0+1)//2 off1 = p1*(p1+1)//2 d_vvvv = _cp(dvvvv[off0:off1]) * 4 for i in range(p0, p1): d_vvvv[i*(i+1)//2+i-off0] *= .5 d_vvvv = _ccsd.unpack_tril(d_vvvv, out=bufd_vvvv[:off1-off0]) eris_vvvv = _ccsd.unpack_tril(eris.vvvv[off0:off1], out=bufe_vvvv[:off1-off0]) #:Ivv += numpy.einsum('decb,deca->ab', d_vvvv, eris_vvvv) * 2 #:Xvo += numpy.einsum('icdb,acdb->ai', d_ovvv, eris_vvvv) lib.dot(eris_vvvv.reshape(-1,nvir).T, d_vvvv.reshape(-1,nvir), 2, Ivv, 1) d_vvvo = _cp(c_vvvo[off0:off1]) lib.dot(eris_vvvv.reshape(-1,nvir).T, d_vvvo.reshape(-1,nocc), 1, Xvo, 1) #:Ioo += numpy.einsum('abjc,abci->ij', d_vvov, eris_vvvo) #:Ivo += numpy.einsum('dbca,dbci->ai', d_vvvv, eris_vvvo) * 2 eris_vvvo = bufe_vvvo[:off1-off0] for i0, i1 in prange(off0, off1, BLKSIZE): for j0, j1, in prange(0, nvir, BLKSIZE//nocc+1): eris_vvvo[i0-off0:i1-off0,j0:j1,:] = eris_ovvv[:,j0:j1,i0:i1].transpose(2,1,0) lib.dot(eris_vvvo.reshape(-1,nocc).T, d_vvvo.reshape(-1,nocc), 1, Ioo, 1) lib.dot(d_vvvv.reshape(-1,nvir).T, eris_vvvo.reshape(-1,nocc), 2, Ivo, 1) Ioo *= -1 Ivv *= -1 Ivo *= -1 Xvo += Ivo return Ioo, Ivv, Ivo, Xvo