Ejemplo n.º 1
0
def build_mats_dfragf2_outcore(qxi,
                               qja,
                               e_occ,
                               e_vir,
                               os_factor=1.0,
                               ss_factor=1.0):
    ''' Python version of AGF2df_vv_vev_islice to support outcore
    '''

    naux = qxi.shape[0]
    nocc = e_occ.size
    nvir = e_vir.size
    nmo = qxi.size // (naux * nocc)
    assert qxi.size == (naux * nmo * nocc)
    assert qja.size == (naux * nocc * nvir)

    vv = np.zeros((nmo, nmo))
    vev = np.zeros((nmo, nmo))

    fpos = os_factor + ss_factor
    fneg = -ss_factor

    eja = lib.direct_sum('j,a->ja', e_occ, -e_vir)
    eja = eja.ravel()

    buf = (np.zeros((nmo, nocc * nvir)), np.zeros((nmo * nocc, nvir)))

    for i in mpi_helper.nrange(nocc):
        qx = qxi.reshape(naux, nmo, nocc)[:, :, i]
        xija = lib.dot(qx.T, qja, c=buf[0])
        xjia = lib.dot(qxi.T, qja[:, i * nvir:(i + 1) * nvir], c=buf[1])
        xjia = xjia.reshape(nmo, nocc * nvir)

        eija = eja + e_occ[i]

        vv = lib.dot(xija, xija.T, alpha=fpos, beta=1, c=vv)
        vv = lib.dot(xija, xjia.T, alpha=fneg, beta=1, c=vv)

        exija = xija * eija[None]

        vev = lib.dot(exija, xija.T, alpha=fpos, beta=1, c=vev)
        vev = lib.dot(exija, xjia.T, alpha=fneg, beta=1, c=vev)

    vv = vv.reshape(nmo, nmo)
    vev = vev.reshape(nmo, nmo)

    mpi_helper.barrier()
    mpi_helper.allreduce_safe_inplace(vv)
    mpi_helper.allreduce_safe_inplace(vev)

    return vv, vev
Ejemplo n.º 2
0
def build_mats_uagf2_outcore(qeri, e_occ, e_vir, os_factor=1.0, ss_factor=1.0):
    ''' Python version of AGF2uee_vv_vev_islice to support outcore
    '''

    assert qeri[0].ndim == qeri[1].ndim == 4
    nmo = qeri[0].shape[0]
    # noa, nob = e_occ[0].size, e_occ[1].size
    # nva, nvb = e_vir[0].size, e_vir[1].size
    noa = e_occ[0].size

    vv = np.zeros((nmo, nmo))
    vev = np.zeros((nmo, nmo))

    fposa = ss_factor
    fnega = -ss_factor
    fposb = os_factor

    eja_a = lib.direct_sum('j,a->ja', e_occ[0], -e_vir[0]).ravel()
    eja_b = lib.direct_sum('j,a->ja', e_occ[1], -e_vir[1]).ravel()

    for i in mpi_helper.nrange(noa):
        xija_aa = qeri[0][:, i].reshape(nmo, -1)
        xija_ab = qeri[1][:, i].reshape(nmo, -1)
        xjia_aa = qeri[0][:, :, i].reshape(nmo, -1)

        eija_aa = eja_a + e_occ[0][i]
        eija_ab = eja_b + e_occ[0][i]

        vv = lib.dot(xija_aa, xija_aa.T, alpha=fposa, beta=1, c=vv)
        vv = lib.dot(xija_aa, xjia_aa.T, alpha=fnega, beta=1, c=vv)
        vv = lib.dot(xija_ab, xija_ab.T, alpha=fposb, beta=1, c=vv)

        exija_aa = xija_aa * eija_aa[None]
        exija_ab = xija_ab * eija_ab[None]

        vev = lib.dot(exija_aa, xija_aa.T, alpha=fposa, beta=1, c=vev)
        vev = lib.dot(exija_aa, xjia_aa.T, alpha=fnega, beta=1, c=vev)
        vev = lib.dot(exija_ab, xija_ab.T, alpha=fposb, beta=1, c=vev)

    vv = vv.reshape(nmo, nmo)
    vev = vev.reshape(nmo, nmo)

    mpi_helper.barrier()
    mpi_helper.allreduce_safe_inplace(vv)
    mpi_helper.allreduce_safe_inplace(vev)

    return vv, vev
Ejemplo n.º 3
0
def build_mats_ragf2_outcore(qeri, e_occ, e_vir, os_factor=1.0, ss_factor=1.0):
    ''' Python version of AGF2ee_vv_vev_islice to support outcore
    '''

    assert qeri.ndim == 4
    nmo = qeri.shape[0]
    nocc = e_occ.size
    nvir = e_vir.size

    vv = np.zeros((nmo, nmo))
    vev = np.zeros((nmo, nmo))

    fpos = os_factor + ss_factor
    fneg = -ss_factor

    eja = lib.direct_sum('j,a->ja', e_occ, -e_vir)
    eja = eja.ravel()

    for i in mpi_helper.nrange(nocc):
        xija = qeri[:, i].reshape(nmo, -1)
        xjia = qeri[:, :, i].reshape(nmo, -1)

        eija = eja + e_occ[i]

        vv = lib.dot(xija, xija.T, alpha=fpos, beta=1, c=vv)
        vv = lib.dot(xija, xjia.T, alpha=fneg, beta=1, c=vv)

        exija = xija * eija[None]

        vev = lib.dot(exija, xija.T, alpha=fpos, beta=1, c=vev)
        vev = lib.dot(exija, xjia.T, alpha=fneg, beta=1, c=vev)

    vv = vv.reshape(nmo, nmo)
    vev = vev.reshape(nmo, nmo)

    mpi_helper.barrier()
    mpi_helper.allreduce_safe_inplace(vv)
    mpi_helper.allreduce_safe_inplace(vev)

    return vv, vev
Ejemplo n.º 4
0
def energy_2body(agf2, gf, se):
    ''' Calculates the two-body energy using analytically integrated
        Galitskii-Migdal formula. The formula is symmetric and only
        one side needs to be calculated.

    Args:
        gf : GreensFunction
            Auxiliaries of the Green's function
        se : SelfEnergy
            Auxiliaries of the self-energy

    Returns
        Two-body energy
    '''

    assert type(gf) is aux.GreensFunction
    assert type(se) is aux.SelfEnergy

    gf_occ = gf.get_occupied()
    se_vir = se.get_virtual()

    e2b = 0.0

    for l in mpi_helper.nrange(gf_occ.naux):
        vxl = gf_occ.coupling[:, l]
        vxk = se_vir.coupling
        dlk = gf_occ.energy[l] - se_vir.energy

        vv = vxk * vxl[:, None]
        e2b += lib.einsum('xk,yk,k->', vv, vv.conj(), 1. / dlk)

    e2b *= 2

    mpi_helper.barrier()
    e2b = mpi_helper.allreduce(e2b)

    return np.ravel(e2b.real)[0]
Ejemplo n.º 5
0
def build_se_part(gf2,
                  eri,
                  gf_occ,
                  gf_vir,
                  nmom,
                  os_factor=1.0,
                  ss_factor=1.0):
    ''' Builds the auxiliaries.
    '''

    cput0 = (time.clock(), time.time())
    log = logger.Logger(gf2.stdout, gf2.verbose)

    assert type(gf_occ) is agf2.GreensFunction
    assert type(gf_vir) is agf2.GreensFunction

    nmo = gf2.nmo
    nocc = gf_occ.naux
    nvir = gf_vir.naux
    tol = gf2.weight_tol

    if not (gf2.frozen is None or gf2.frozen == 0):
        mask = agf2.ragf2.get_frozen_mask(agf2)
        nmo -= np.sum(~mask)

    ei, ci = gf_occ.energy, gf_occ.coupling
    ea, ca = gf_vir.energy, gf_vir.coupling
    qxi, qja = agf2.dfragf2._make_qmo_eris_incore(gf2, eri, (ci, ci, ca))

    t = np.zeros((2 * nmom + 2, nmo, nmo))

    eija = lib.direct_sum('i,j,a->ija', ei, ei, -ea)
    naux = qxi.shape[0]

    buf = [np.empty((nmo, nocc * nvir)), np.empty((nmo * nocc, nvir))]
    for i in mpi_helper.nrange(nocc):
        qx = qxi.reshape(naux, nmo, nocc)[:, :, i]
        xija = lib.dot(qx.T, qja, c=buf[0])
        xjia = lib.dot(qxi.T, qja[:, i * nvir:(i + 1) * nvir], c=buf[1])
        xjia = xjia.reshape(nmo, nocc * nvir)
        xjia = 2.0 * xija - xjia  #TODO: oo/ss factors
        eja = eija[i].ravel()

        for n in range(2 * nmom + 2):
            t[n] = lib.dot(xija, xjia.T, beta=1, c=t[n])
            xjia *= eja[None]

    mpi_helper.barrier()
    mpi_helper.allreduce_safe_inplace(t)

    #t = _agf2.dfragf2_slow_fast_build(qxi, qja, ei, ea, 2*nmom+2, os_factor=os_factor, ss_factor=ss_factor)

    if not np.all(np.isfinite(t)):
        raise ValueError('Overflow from large moments')

    m, b = block_lanczos.block_lanczos(t, nmom + 1)
    e, v = block_lanczos.build_from_tridiag(m, b)

    se = agf2.SelfEnergy(e, v, chempot=gf_occ.chempot)
    se.remove_uncoupled(tol=tol)

    if not (gf2.frozen is None or gf2.frozen == 0):
        coupling = np.zeros((nmo, se.naux))
        coupling[mask] = se.coupling
        se = agf2.SelfEnergy(se.energy, coupling, chempot=se.chempot)

    log.timer('se part', *cput0)

    return se
Ejemplo n.º 6
0
def build_mats_dfuagf2_outcore(qxi,
                               qja,
                               e_occ,
                               e_vir,
                               os_factor=1.0,
                               ss_factor=1.0):
    ''' Python version of AGF2udf_vv_vev_islice to support outcore
    '''

    naux = qxi[0].shape[0]
    noa, nob = e_occ[0].size, e_occ[1].size
    nva, nvb = e_vir[0].size, e_vir[1].size
    nmo = qxi[0].size // (naux * noa)
    assert qxi[0].size == (naux * nmo * noa)
    assert qja[0].size == (naux * noa * nva)
    assert qja[1].size == (naux * nob * nvb)

    qxi_a, qxi_b = qxi
    qja_a, qja_b = qja

    vv = np.zeros((nmo, nmo))
    vev = np.zeros((nmo, nmo))

    fposa = ss_factor
    fnega = -ss_factor
    fposb = os_factor

    eja_a = lib.direct_sum('j,a->ja', e_occ[0], -e_vir[0]).ravel()
    eja_b = lib.direct_sum('j,a->ja', e_occ[1], -e_vir[1]).ravel()

    buf = (np.zeros((nmo, noa * nva)), np.zeros(
        (nmo, nob * nvb)), np.zeros((nmo * noa, nva)))

    for i in mpi_helper.nrange(noa):
        qx_a = qxi_a.reshape(naux, nmo, noa)[:, :, i]
        xija_aa = lib.dot(qx_a.T, qja_a, c=buf[0])
        xija_ab = lib.dot(qx_a.T, qja_b, c=buf[1])
        xjia_aa = lib.dot(qxi_a.T, qja_a[:, i * nva:(i + 1) * nva], c=buf[2])
        xjia_aa = xjia_aa.reshape(nmo, -1)

        eija_aa = eja_a + e_occ[0][i]
        eija_ab = eja_b + e_occ[0][i]

        vv = lib.dot(xija_aa, xija_aa.T, alpha=fposa, beta=1, c=vv)
        vv = lib.dot(xija_aa, xjia_aa.T, alpha=fnega, beta=1, c=vv)
        vv = lib.dot(xija_ab, xija_ab.T, alpha=fposb, beta=1, c=vv)

        exija_aa = xija_aa * eija_aa[None]
        exija_ab = xija_ab * eija_ab[None]

        vev = lib.dot(exija_aa, xija_aa.T, alpha=fposa, beta=1, c=vev)
        vev = lib.dot(exija_aa, xjia_aa.T, alpha=fnega, beta=1, c=vev)
        vev = lib.dot(exija_ab, xija_ab.T, alpha=fposb, beta=1, c=vev)

    vv = vv.reshape(nmo, nmo)
    vev = vev.reshape(nmo, nmo)

    mpi_helper.barrier()
    mpi_helper.allreduce_safe_inplace(vv)
    mpi_helper.allreduce_safe_inplace(vev)

    return vv, vev