Exemple #1
0
def update_amps(cc, t1, t2, eris):
    # Ref: Hirata et al., J. Chem. Phys. 120, 2581 (2004) Eqs.(35)-(36)
    nocc, nvir = t1.shape
    fock = eris.fock

    fov = fock[:nocc, nocc:].copy()
    foo = fock[:nocc, :nocc].copy()
    fvv = fock[nocc:, nocc:].copy()

    Foo = imd.cc_Foo(t1, t2, eris)
    Fvv = imd.cc_Fvv(t1, t2, eris)
    Fov = imd.cc_Fov(t1, t2, eris)

    # Move energy terms to the other side
    Foo -= np.diag(np.diag(foo))
    Fvv -= np.diag(np.diag(fvv))

    # T1 equation
    t1new = np.asarray(fov).conj().copy()
    t1new += -2 * einsum('kc,ka,ic->ia', fov, t1, t1)
    t1new += einsum('ac,ic->ia', Fvv, t1)
    t1new += -einsum('ki,ka->ia', Foo, t1)
    t1new += 2 * einsum('kc,kica->ia', Fov, t2)
    t1new += -einsum('kc,ikca->ia', Fov, t2)
    t1new += einsum('kc,ic,ka->ia', Fov, t1, t1)
    t1new += 2 * einsum('kcai,kc->ia', eris.ovvo, t1)
    t1new += -einsum('kiac,kc->ia', eris.oovv, t1)
    eris_ovvv = np.asarray(eris.ovvv)
    t1new += 2 * einsum('kdac,ikcd->ia', eris_ovvv, t2)
    t1new += -einsum('kcad,ikcd->ia', eris_ovvv, t2)
    t1new += 2 * einsum('kdac,kd,ic->ia', eris_ovvv, t1, t1)
    t1new += -einsum('kcad,kd,ic->ia', eris_ovvv, t1, t1)
    t1new += -2 * einsum('kilc,klac->ia', eris.ooov, t2)
    t1new += einsum('likc,klac->ia', eris.ooov, t2)
    t1new += -2 * einsum('kilc,lc,ka->ia', eris.ooov, t1, t1)
    t1new += einsum('likc,lc,ka->ia', eris.ooov, t1, t1)

    # T2 equation
    t2new = np.asarray(eris.ovov).conj().transpose(0, 2, 1, 3).copy()
    if cc.cc2:
        Woooo2 = np.asarray(eris.oooo).transpose(0, 2, 1, 3).copy()
        Woooo2 += einsum('kilc,jc->klij', eris.ooov, t1)
        Woooo2 += einsum('ljkc,ic->klij', eris.ooov, t1)
        Woooo2 += einsum('kcld,ic,jd->klij', eris.ovov, t1, t1)
        t2new += einsum('klij,ka,lb->ijab', Woooo2, t1, t1)
        Wvvvv = einsum('kcbd,ka->abcd', eris_ovvv, -t1)
        Wvvvv = Wvvvv + Wvvvv.transpose(1, 0, 3, 2)
        Wvvvv += np.asarray(eris.vvvv).transpose(0, 2, 1, 3)
        t2new += einsum('abcd,ic,jd->ijab', Wvvvv, t1, t1)
        Lvv2 = fvv - einsum('kc,ka->ac', fov, t1)
        Lvv2 -= np.diag(np.diag(fvv))
        tmp = einsum('ac,ijcb->ijab', Lvv2, t2)
        t2new += (tmp + tmp.transpose(1, 0, 3, 2))
        Loo2 = foo + einsum('kc,ic->ki', fov, t1)
        Loo2 -= np.diag(np.diag(foo))
        tmp = einsum('ki,kjab->ijab', Loo2, t2)
        t2new -= (tmp + tmp.transpose(1, 0, 3, 2))
    else:
        Loo = imd.Loo(t1, t2, eris)
        Lvv = imd.Lvv(t1, t2, eris)
        Loo -= np.diag(np.diag(foo))
        Lvv -= np.diag(np.diag(fvv))
        Woooo = imd.cc_Woooo(t1, t2, eris)
        Wvoov = imd.cc_Wvoov(t1, t2, eris)
        Wvovo = imd.cc_Wvovo(t1, t2, eris)
        Wvvvv = imd.cc_Wvvvv(t1, t2, eris)
        tau = t2 + einsum('ia,jb->ijab', t1, t1)
        t2new += einsum('klij,klab->ijab', Woooo, tau)
        t2new += einsum('abcd,ijcd->ijab', Wvvvv, tau)
        tmp = einsum('ac,ijcb->ijab', Lvv, t2)
        t2new += (tmp + tmp.transpose(1, 0, 3, 2))
        tmp = einsum('ki,kjab->ijab', Loo, t2)
        t2new -= (tmp + tmp.transpose(1, 0, 3, 2))
        tmp = 2 * einsum('akic,kjcb->ijab', Wvoov, t2)
        tmp -= einsum('akci,kjcb->ijab', Wvovo, t2)
        t2new += (tmp + tmp.transpose(1, 0, 3, 2))
        tmp = einsum('akic,kjbc->ijab', Wvoov, t2)
        t2new -= (tmp + tmp.transpose(1, 0, 3, 2))
        tmp = einsum('bkci,kjac->ijab', Wvovo, t2)
        t2new -= (tmp + tmp.transpose(1, 0, 3, 2))

    tmp2 = einsum('kibc,ka->abic', eris.oovv, -t1)
    tmp2 += np.asarray(eris.ovvv).conj().transpose(1, 3, 0, 2)
    tmp = einsum('abic,jc->ijab', tmp2, t1)
    t2new += (tmp + tmp.transpose(1, 0, 3, 2))
    tmp2 = einsum('kcai,jc->akij', eris.ovvo, t1)
    tmp2 += np.asarray(eris.ooov).transpose(3, 1, 2, 0).conj()
    tmp = einsum('akij,kb->ijab', tmp2, t1)
    t2new -= (tmp + tmp.transpose(1, 0, 3, 2))

    mo_e = eris.fock.diagonal().real
    eia = mo_e[:nocc, None] - mo_e[None, nocc:]
    eijab = lib.direct_sum('ia,jb->ijab', eia, eia)
    t1new /= eia
    t2new /= eijab

    return t1new, t2new
Exemple #2
0
def update_amps(cc, t1, t2, eris):
    # Ref: Hirata et al., J. Chem. Phys. 120, 2581 (2004) Eqs.(35)-(36)
    assert (isinstance(eris, ccsd._ChemistsERIs))
    nocc, nvir = t1.shape
    fock = eris.fock
    mo_e_o = eris.mo_energy[:nocc]
    mo_e_v = eris.mo_energy[nocc:] + cc.level_shift

    fov = fock[:nocc, nocc:].copy()
    foo = fock[:nocc, :nocc].copy()
    fvv = fock[nocc:, nocc:].copy()

    Foo = imd.cc_Foo(t1, t2, eris)
    Fvv = imd.cc_Fvv(t1, t2, eris)
    Fov = imd.cc_Fov(t1, t2, eris)

    # Move energy terms to the other side
    Foo[np.diag_indices(nocc)] -= mo_e_o
    Fvv[np.diag_indices(nvir)] -= mo_e_v

    # T1 equation
    t1new = -2 * np.einsum('kc,ka,ic->ia', fov, t1, t1)
    t1new += np.einsum('ac,ic->ia', Fvv, t1)
    t1new += -np.einsum('ki,ka->ia', Foo, t1)
    t1new += 2 * np.einsum('kc,kica->ia', Fov, t2)
    t1new += -np.einsum('kc,ikca->ia', Fov, t2)
    t1new += np.einsum('kc,ic,ka->ia', Fov, t1, t1)
    t1new += fov.conj()
    t1new += 2 * np.einsum('kcai,kc->ia', eris.ovvo, t1)
    t1new += -np.einsum('kiac,kc->ia', eris.oovv, t1)
    eris_ovvv = np.asarray(eris.get_ovvv())
    t1new += 2 * lib.einsum('kdac,ikcd->ia', eris_ovvv, t2)
    t1new += -lib.einsum('kcad,ikcd->ia', eris_ovvv, t2)
    t1new += 2 * lib.einsum('kdac,kd,ic->ia', eris_ovvv, t1, t1)
    t1new += -lib.einsum('kcad,kd,ic->ia', eris_ovvv, t1, t1)
    eris_ovoo = np.asarray(eris.ovoo, order='C')
    t1new += -2 * lib.einsum('lcki,klac->ia', eris_ovoo, t2)
    t1new += lib.einsum('kcli,klac->ia', eris_ovoo, t2)
    t1new += -2 * lib.einsum('lcki,lc,ka->ia', eris_ovoo, t1, t1)
    t1new += lib.einsum('kcli,lc,ka->ia', eris_ovoo, t1, t1)

    # T2 equation
    tmp2 = lib.einsum('kibc,ka->abic', eris.oovv, -t1)
    tmp2 += np.asarray(eris_ovvv).conj().transpose(1, 3, 0, 2)
    tmp = lib.einsum('abic,jc->ijab', tmp2, t1)
    t2new = tmp + tmp.transpose(1, 0, 3, 2)
    tmp2 = lib.einsum('kcai,jc->akij', eris.ovvo, t1)
    tmp2 += eris_ovoo.transpose(1, 3, 0, 2).conj()
    tmp = lib.einsum('akij,kb->ijab', tmp2, t1)
    t2new -= tmp + tmp.transpose(1, 0, 3, 2)
    t2new += np.asarray(eris.ovov).conj().transpose(0, 2, 1, 3)
    if cc.cc2:
        Woooo2 = np.asarray(eris.oooo).transpose(0, 2, 1, 3).copy()
        Woooo2 += lib.einsum('lcki,jc->klij', eris_ovoo, t1)
        Woooo2 += lib.einsum('kclj,ic->klij', eris_ovoo, t1)
        Woooo2 += lib.einsum('kcld,ic,jd->klij', eris.ovov, t1, t1)
        t2new += lib.einsum('klij,ka,lb->ijab', Woooo2, t1, t1)
        Wvvvv = lib.einsum('kcbd,ka->abcd', eris_ovvv, -t1)
        Wvvvv = Wvvvv + Wvvvv.transpose(1, 0, 3, 2)
        Wvvvv += np.asarray(eris.vvvv).transpose(0, 2, 1, 3)
        t2new += lib.einsum('abcd,ic,jd->ijab', Wvvvv, t1, t1)
        Lvv2 = fvv - np.einsum('kc,ka->ac', fov, t1)
        Lvv2 -= np.diag(np.diag(fvv))
        tmp = lib.einsum('ac,ijcb->ijab', Lvv2, t2)
        t2new += (tmp + tmp.transpose(1, 0, 3, 2))
        Loo2 = foo + np.einsum('kc,ic->ki', fov, t1)
        Loo2 -= np.diag(np.diag(foo))
        tmp = lib.einsum('ki,kjab->ijab', Loo2, t2)
        t2new -= (tmp + tmp.transpose(1, 0, 3, 2))
    else:
        Loo = imd.Loo(t1, t2, eris)
        Lvv = imd.Lvv(t1, t2, eris)
        Loo[np.diag_indices(nocc)] -= mo_e_o
        Lvv[np.diag_indices(nvir)] -= mo_e_v

        Woooo = imd.cc_Woooo(t1, t2, eris)
        Wvoov = imd.cc_Wvoov(t1, t2, eris)
        Wvovo = imd.cc_Wvovo(t1, t2, eris)
        Wvvvv = imd.cc_Wvvvv(t1, t2, eris)

        tau = t2 + np.einsum('ia,jb->ijab', t1, t1)
        t2new += lib.einsum('klij,klab->ijab', Woooo, tau)
        t2new += lib.einsum('abcd,ijcd->ijab', Wvvvv, tau)
        tmp = lib.einsum('ac,ijcb->ijab', Lvv, t2)
        t2new += (tmp + tmp.transpose(1, 0, 3, 2))
        tmp = lib.einsum('ki,kjab->ijab', Loo, t2)
        t2new -= (tmp + tmp.transpose(1, 0, 3, 2))
        tmp = 2 * lib.einsum('akic,kjcb->ijab', Wvoov, t2)
        tmp -= lib.einsum('akci,kjcb->ijab', Wvovo, t2)
        t2new += (tmp + tmp.transpose(1, 0, 3, 2))
        tmp = lib.einsum('akic,kjbc->ijab', Wvoov, t2)
        t2new -= (tmp + tmp.transpose(1, 0, 3, 2))
        tmp = lib.einsum('bkci,kjac->ijab', Wvovo, t2)
        t2new -= (tmp + tmp.transpose(1, 0, 3, 2))

    eia = mo_e_o[:, None] - mo_e_v
    eijab = lib.direct_sum('ia,jb->ijab', eia, eia)
    t1new /= eia
    t2new /= eijab

    return t1new, t2new
Exemple #3
0
def update_amps(cc, t1, t2, eris, max_memory=2000):
    time0 = time.clock(), time.time()
    log = logger.Logger(cc.stdout, cc.verbose)
    nocc, nvir = t1.shape
    fock = eris.fock

    fov = fock[:nocc, nocc:]
    foo = fock[:nocc, :nocc]
    fvv = fock[nocc:, nocc:]

    mo_e = eris.fock.diagonal()
    eia = mo_e[:nocc, None] - mo_e[None, nocc:]
    eijab = lib.direct_sum('ia,jb->ijab', eia, eia)

    Foo = imd.cc_Foo(t1, t2, eris)
    Fvv = imd.cc_Fvv(t1, t2, eris)
    Fov = imd.cc_Fov(t1, t2, eris)
    Loo = imd.Loo(t1, t2, eris)
    Lvv = imd.Lvv(t1, t2, eris)
    Woooo = imd.cc_Woooo(t1, t2, eris)
    Wvvvv = imd.cc_Wvvvv(t1, t2, eris)
    Wvoov = imd.cc_Wvoov(t1, t2, eris)
    Wvovo = imd.cc_Wvovo(t1, t2, eris)

    # Move energy terms to the other side
    Foo -= foo
    Fvv -= fvv
    Loo -= foo
    Lvv -= fvv

    # T1 equation
    # TODO: Check this conj(). Hirata and Bartlett has
    # f_{vo}(a,i), which should be equal to f_{ov}^*(i,a)
    t1new = fov.conj().copy()
    t1new += -2 * einsum('kc,ka,ic->ia', fov, t1, t1)
    t1new += einsum('ac,ic->ia', Fvv, t1)
    t1new += -einsum('ki,ka->ia', Foo, t1)
    t1new += einsum('kc,kica->ia', Fov, 2 * t2)
    t1new += einsum('kc,ikca->ia', Fov, -t2)
    t1new += einsum('kc,ic,ka->ia', Fov, t1, t1)
    t1new += 2 * einsum('akic,kc->ia', eris.voov, t1)
    t1new += -einsum('kaic,kc->ia', eris.ovov, t1)
    t1new += 2 * einsum('akcd,ikcd->ia', eris.vovv, t2)
    t1new += -einsum('akdc,ikcd->ia', eris.vovv, t2)
    t1new += 2 * einsum('akcd,ic,kd->ia', eris.vovv, t1, t1)
    t1new += -einsum('akdc,ic,kd->ia', eris.vovv, t1, t1)
    t1new += -2 * einsum('klic,klac->ia', eris.ooov, t2)
    t1new += einsum('lkic,klac->ia', eris.ooov, t2)
    t1new += -2 * einsum('klic,ka,lc->ia', eris.ooov, t1, t1)
    t1new += einsum('lkic,ka,lc->ia', eris.ooov, t1, t1)

    # T2 equation
    # For conj(), see Hirata and Bartlett, Eq. (36)
    t2new = np.array(eris.oovv).conj()
    t2new += einsum('klij,klab->ijab', Woooo, t2)
    t2new += einsum('klij,ka,lb->ijab', Woooo, t1, t1)
    for a in range(nvir):
        Wvvvv_a = np.array(Wvvvv[a])
        t2new[:, :, a, :] += einsum('bcd,ijcd->ijb', Wvvvv_a, t2)
        t2new[:, :, a, :] += einsum('bcd,ic,jd->ijb', Wvvvv_a, t1, t1)
    tmp = einsum('ac,ijcb->ijab', Lvv, t2)
    t2new += (tmp + tmp.transpose(1, 0, 3, 2))
    tmp = einsum('ki,kjab->ijab', Loo, t2)
    t2new -= (tmp + tmp.transpose(1, 0, 3, 2))
    tmp2 = np.array(eris.vovv).transpose(3,2,1,0).conj() \
            - einsum('kbic,ka->abic',eris.ovov,t1)
    tmp = einsum('abic,jc->ijab', tmp2, t1)
    t2new += (tmp + tmp.transpose(1, 0, 3, 2))
    tmp2 = np.array(eris.ooov).transpose(3,2,1,0).conj() \
            + einsum('akic,jc->akij',eris.voov,t1)
    tmp = einsum('akij,kb->ijab', tmp2, t1)
    t2new -= (tmp + tmp.transpose(1, 0, 3, 2))
    tmp = 2 * einsum('akic,kjcb->ijab', Wvoov, t2) - einsum(
        'akci,kjcb->ijab', Wvovo, t2)
    t2new += (tmp + tmp.transpose(1, 0, 3, 2))
    tmp = einsum('akic,kjbc->ijab', Wvoov, t2)
    t2new -= (tmp + tmp.transpose(1, 0, 3, 2))
    tmp = einsum('bkci,kjac->ijab', Wvovo, t2)
    t2new -= (tmp + tmp.transpose(1, 0, 3, 2))

    t1new /= eia
    t2new /= eijab

    time0 = log.timer_debug1('update t1 t2', *time0)

    return t1new, t2new
Exemple #4
0
def update_amps(cc, t1, t2, eris):
    # Ref: Hirata et al., J. Chem. Phys. 120, 2581 (2004) Eqs.(35)-(36)
    time0 = time.clock(), time.time()
    log = logger.Logger(cc.stdout, cc.verbose)
    nocc, nvir = t1.shape
    fock = eris.fock

    fov = fock[:nocc,nocc:]
    foo = fock[:nocc,:nocc]
    fvv = fock[nocc:,nocc:]

    mo_e = eris.fock.diagonal()
    eia = mo_e[:nocc,None] - mo_e[None,nocc:]
    eijab = lib.direct_sum('ia,jb->ijab',eia,eia)

    Foo = imd.cc_Foo(t1,t2,eris)
    Fvv = imd.cc_Fvv(t1,t2,eris)
    Fov = imd.cc_Fov(t1,t2,eris)
    Loo = imd.Loo(t1,t2,eris)
    Lvv = imd.Lvv(t1,t2,eris)
    Woooo = imd.cc_Woooo(t1,t2,eris)
    Wvvvv = imd.cc_Wvvvv(t1,t2,eris)
    Wvoov = imd.cc_Wvoov(t1,t2,eris)
    Wvovo = imd.cc_Wvovo(t1,t2,eris)

    # Move energy terms to the other side
    Foo -= np.diag(np.diag(foo))
    Fvv -= np.diag(np.diag(fvv))
    Loo -= np.diag(np.diag(foo))
    Lvv -= np.diag(np.diag(fvv))

    # T1 equation
    t1new = np.array(fov).conj()
    t1new += -2*einsum('kc,ka,ic->ia',fov,t1,t1)
    t1new +=   einsum('ac,ic->ia',Fvv,t1)
    t1new +=  -einsum('ki,ka->ia',Foo,t1)
    t1new += 2*einsum('kc,kica->ia',Fov,t2)
    t1new +=  -einsum('kc,ikca->ia',Fov,t2)
    t1new +=   einsum('kc,ic,ka->ia',Fov,t1,t1)
    t1new += 2*einsum('akic,kc->ia',eris.voov,t1)
    t1new +=  -einsum('kaic,kc->ia',eris.ovov,t1)
    t1new += 2*einsum('akcd,ikcd->ia',eris.vovv,t2)
    t1new +=  -einsum('akdc,ikcd->ia',eris.vovv,t2)
    t1new += 2*einsum('akcd,ic,kd->ia',eris.vovv,t1,t1)
    t1new +=  -einsum('akdc,ic,kd->ia',eris.vovv,t1,t1)
    t1new += -2*einsum('klic,klac->ia',eris.ooov,t2)
    t1new +=  einsum('lkic,klac->ia',eris.ooov,t2)
    t1new += -2*einsum('klic,ka,lc->ia',eris.ooov,t1,t1)
    t1new +=  einsum('lkic,ka,lc->ia',eris.ooov,t1,t1)

    # T2 equation
    t2new = np.array(eris.oovv).conj()
    t2new += einsum('klij,klab->ijab',Woooo,t2)
    t2new += einsum('klij,ka,lb->ijab',Woooo,t1,t1)
    for a in range(nvir):
        Wvvvv_a = np.array(Wvvvv[a])
        t2new[:,:,a,:] += einsum('bcd,ijcd->ijb',Wvvvv_a,t2)
        t2new[:,:,a,:] += einsum('bcd,ic,jd->ijb',Wvvvv_a,t1,t1)
    tmp = einsum('ac,ijcb->ijab',Lvv,t2)
    t2new += (tmp + tmp.transpose(1,0,3,2))
    tmp = einsum('ki,kjab->ijab',Loo,t2)
    t2new -= (tmp + tmp.transpose(1,0,3,2))
    tmp2 = np.array(eris.vovv).transpose(3,2,1,0).conj() \
            - einsum('kbic,ka->abic',eris.ovov,t1)
    tmp = einsum('abic,jc->ijab',tmp2,t1)
    t2new += (tmp + tmp.transpose(1,0,3,2))
    tmp2 = np.array(eris.ooov).transpose(3,2,1,0).conj() \
            + einsum('akic,jc->akij',eris.voov,t1)
    tmp = einsum('akij,kb->ijab',tmp2,t1)
    t2new -= (tmp + tmp.transpose(1,0,3,2))
    tmp = 2*einsum('akic,kjcb->ijab',Wvoov,t2) - einsum('akci,kjcb->ijab',Wvovo,t2)
    t2new += (tmp + tmp.transpose(1,0,3,2))
    tmp = einsum('akic,kjbc->ijab',Wvoov,t2)
    t2new -= (tmp + tmp.transpose(1,0,3,2))
    tmp = einsum('bkci,kjac->ijab',Wvovo,t2)
    t2new -= (tmp + tmp.transpose(1,0,3,2))

    t1new /= eia
    t2new /= eijab

    time0 = log.timer_debug1('update t1 t2', *time0)

    return t1new, t2new
Exemple #5
0
def update_amps(cc, t1, t2, eris):
    # Ref: Hirata et al., J. Chem. Phys. 120, 2581 (2004) Eqs.(35)-(36)
    assert(isinstance(eris, ccsd._ChemistsERIs))
    nocc, nvir = t1.shape
    fock = eris.fock
    mo_e_o = eris.mo_energy[:nocc]
    mo_e_v = eris.mo_energy[nocc:] + cc.level_shift

    fov = fock[:nocc,nocc:].copy()
    foo = fock[:nocc,:nocc].copy()
    fvv = fock[nocc:,nocc:].copy()

    Foo = imd.cc_Foo(t1,t2,eris)
    Fvv = imd.cc_Fvv(t1,t2,eris)
    Fov = imd.cc_Fov(t1,t2,eris)

    # Move energy terms to the other side
    Foo[np.diag_indices(nocc)] -= mo_e_o
    Fvv[np.diag_indices(nvir)] -= mo_e_v

    #occ_act = np.arange(cc.frozen_occ,nocc)
    occ_act = np.arange(nocc)
    vir_act = np.arange(cc.nvir_act)
    #print("occ_act =", occ_act)
    #print("vir_act =", vir_act)
    ia_act = np.ix_(occ_act,vir_act)
    ijab_act = np.ix_(occ_act,occ_act,vir_act,vir_act)
    #print("ia =", ia_act)
    #print("ijab =", ijab_act)

    # T1 equation
    t1new = np.copy(fov.conj())
    t1new[ia_act] -= 2*np.einsum('kc,ka,ic->ia', fov, t1, t1)[ia_act]
    t1new[ia_act] +=   np.einsum('ac,ic->ia', Fvv, t1)[ia_act]
    t1new[ia_act] +=  -np.einsum('ki,ka->ia', Foo, t1)[ia_act]
    t1new[ia_act] += 2*np.einsum('kc,kica->ia', Fov, t2)[ia_act]
    t1new[ia_act] +=  -np.einsum('kc,ikca->ia', Fov, t2)[ia_act]
    t1new[ia_act] +=   np.einsum('kc,ic,ka->ia', Fov, t1, t1)[ia_act]
    t1new[ia_act] += 2*np.einsum('kcai,kc->ia', eris.ovvo, t1)[ia_act]
    t1new[ia_act] +=  -np.einsum('kiac,kc->ia', eris.oovv, t1)[ia_act]
    eris_ovvv = np.asarray(eris.get_ovvv())
    t1new[ia_act] += 2*lib.einsum('kdac,ikcd->ia', eris_ovvv, t2)[ia_act]
    t1new[ia_act] +=  -lib.einsum('kcad,ikcd->ia', eris_ovvv, t2)[ia_act]
    t1new[ia_act] += 2*lib.einsum('kdac,kd,ic->ia', eris_ovvv, t1, t1)[ia_act]
    t1new[ia_act] +=  -lib.einsum('kcad,kd,ic->ia', eris_ovvv, t1, t1)[ia_act]
    eris_ovoo = np.asarray(eris.ovoo, order='C')
    t1new[ia_act] +=-2*lib.einsum('lcki,klac->ia', eris_ovoo, t2)[ia_act]
    t1new[ia_act] +=   lib.einsum('kcli,klac->ia', eris_ovoo, t2)[ia_act]
    t1new[ia_act] +=-2*lib.einsum('lcki,lc,ka->ia', eris_ovoo, t1, t1)[ia_act]
    t1new[ia_act] +=   lib.einsum('kcli,lc,ka->ia', eris_ovoo, t1, t1)[ia_act]

    # T2 equation
    t2new = np.copy(np.asarray(eris.ovov).conj().transpose(0,2,1,3))
    tmp2  = lib.einsum('kibc,ka->abic', eris.oovv, -t1)
    tmp2 += np.asarray(eris_ovvv).conj().transpose(1,3,0,2)
    tmp = lib.einsum('abic,jc->ijab', tmp2, t1)
    t2new[ijab_act] += (tmp + tmp.transpose(1,0,3,2))[ijab_act]
    tmp2  = lib.einsum('kcai,jc->akij', eris.ovvo, t1)
    tmp2 += eris_ovoo.transpose(1,3,0,2).conj()
    tmp = lib.einsum('akij,kb->ijab', tmp2, t1)
    t2new[ijab_act] -= (tmp + tmp.transpose(1,0,3,2))[ijab_act]

    Loo = imd.Loo(t1, t2, eris)
    Lvv = imd.Lvv(t1, t2, eris)
    Loo[np.diag_indices(nocc)] -= mo_e_o
    Lvv[np.diag_indices(nvir)] -= mo_e_v

    Woooo = imd.cc_Woooo(t1, t2, eris)
    Wvoov = imd.cc_Wvoov(t1, t2, eris)
    Wvovo = imd.cc_Wvovo(t1, t2, eris)
    Wvvvv = imd.cc_Wvvvv(t1, t2, eris)

    tau = t2 + np.einsum('ia,jb->ijab', t1, t1)
    t2new[ijab_act] += lib.einsum('klij,klab->ijab', Woooo, tau)[ijab_act]
    t2new[ijab_act] += lib.einsum('abcd,ijcd->ijab', Wvvvv, tau)[ijab_act]
    tmp = lib.einsum('ac,ijcb->ijab', Lvv, t2)
    t2new[ijab_act] += (tmp + tmp.transpose(1,0,3,2))[ijab_act]
    tmp = lib.einsum('ki,kjab->ijab', Loo, t2)
    t2new[ijab_act] -= (tmp + tmp.transpose(1,0,3,2))[ijab_act]
    tmp  = 2*lib.einsum('akic,kjcb->ijab', Wvoov, t2)
    tmp -=   lib.einsum('akci,kjcb->ijab', Wvovo, t2)
    t2new[ijab_act] += (tmp + tmp.transpose(1,0,3,2))[ijab_act]
    tmp = lib.einsum('akic,kjbc->ijab', Wvoov, t2)
    t2new[ijab_act] -= (tmp + tmp.transpose(1,0,3,2))[ijab_act]
    tmp = lib.einsum('bkci,kjac->ijab', Wvovo, t2)
    t2new[ijab_act] -= (tmp + tmp.transpose(1,0,3,2))[ijab_act]

    eia = mo_e_o[:,None] - mo_e_v
    eijab = lib.direct_sum('ia,jb->ijab',eia,eia)
    t1new /= eia
    t2new /= eijab

    return t1new, t2new
Exemple #6
0
def update_amps(
    cc: ccsd.CCSD,
    t1: np.ndarray,
    t2: np.ndarray,
    eris: ccsd._ChemistsERIs,
):
    """Update the CC t1 and t2 amplitudes using a compressed t2 tensor for
    several of the contractions.

    Parameters
    ----------
    cc : ccsd.CCSD
        CC object
    t1 : np.ndarray
        t1 amplitudes (nocc,nvirt)
    t2 : np.ndarray
        t2 amplitudes (nocc,nocc,nvirt,nvirt)
    eris : ccsd._ChemistsERIs
        2e-integrals

    Returns
    -------
    (np.ndarray,np.ndarray)
        The new t1 and t2 amplitudes

    Notes
    -----
    Ref: Hirata et al., J. Chem. Phys. 120, 2581 (2004) Eqs.(35)-(36)
    """
    #
    # Check Args
    #

    assert isinstance(eris, ccsd._ChemistsERIs)

    log = lib.logger.new_logger(cc)
    m_keep = cc.fri_settings["m_keep"]
    # TODO add input checks

    m_keep = cc.fri_settings["m_keep"]
    if m_keep > t2.size or m_keep == 0:
        raise ValueError(
            "Bad m_keep value! The following condition wasn't met 0 < m_keep <= t2.size"
        )

    compressed_contractions = cc.fri_settings["compressed_contractions"]
    contraction_timings = {}

    #
    # Shorthands
    #
    nocc, nvir = t1.shape
    fock = eris.fock
    mo_e_o = eris.mo_energy[:nocc]
    mo_e_v = eris.mo_energy[nocc:] + cc.level_shift

    fov = fock[:nocc, nocc:].copy()
    foo = fock[:nocc, :nocc].copy()
    fvv = fock[nocc:, nocc:].copy()
    t_update_amps = time.perf_counter()

    #
    # Compression
    #
    log.debug(f"M_KEEP = {m_keep} of {t2.size}")
    # log.warn(f"|t2|_1 = {np.linalg.norm(t2.ravel(), ord=1)}")
    # np.save("fricc_t2.npy", t2.ravel())
    # exit(0)
    t2 = np.ascontiguousarray(t2)

    t_compress = time.perf_counter()
    t2_sparse = SparseTensor4d(
        t2,
        t2.shape,
        int(m_keep),
        cc.fri_settings["compression"],
        cc.fri_settings["sampling_method"],
        cc.fri_settings["verbose"],
    )
    if "O^3V^3" in compressed_contractions or "O^4V^2" in compressed_contractions:
        t2_sparse_alt = SparseTensor4d(
            t2,
            t2.shape,
            int(m_keep),
            cc.fri_settings["compression"],
            cc.fri_settings["sampling_method"],
            cc.fri_settings["verbose"],
        )
    t_compress = time.perf_counter() - t_compress

    #
    # Updating the Amplitudes
    #

    Foo = imd.cc_Foo(t1, t2, eris)
    Fvv = imd.cc_Fvv(t1, t2, eris)
    Fov = imd.cc_Fov(t1, t2, eris)

    # Move energy terms to the other side
    Foo[np.diag_indices(nocc)] -= mo_e_o
    Fvv[np.diag_indices(nvir)] -= mo_e_v

    # T1 equation
    t1new = -2 * np.einsum("kc,ka,ic->ia", fov, t1, t1)
    t1new += np.einsum("ac,ic->ia", Fvv, t1)
    t1new += -np.einsum("ki,ka->ia", Foo, t1)
    t1new += 2 * np.einsum("kc,kica->ia", Fov, t2)
    t1new += -np.einsum("kc,ikca->ia", Fov, t2)
    t1new += np.einsum("kc,ic,ka->ia", Fov, t1, t1)
    t1new += fov.conj()
    t1new += 2 * np.einsum("kcai,kc->ia", eris.ovvo, t1)
    t1new += -np.einsum("kiac,kc->ia", eris.oovv, t1)

    # (O^2V^3)
    eris_ovvv = np.asarray(eris.get_ovvv())
    t1new += 2 * lib.einsum("kdac,ikcd->ia", eris_ovvv, t2)
    t1new += -lib.einsum("kcad,ikcd->ia", eris_ovvv, t2)
    t1new += 2 * lib.einsum("kdac,kd,ic->ia", eris_ovvv, t1, t1)
    t1new += -lib.einsum("kcad,kd,ic->ia", eris_ovvv, t1, t1)

    # (O^3V^2)
    eris_ovoo = np.asarray(eris.ovoo, order="C")
    t1new += -2 * lib.einsum("lcki,klac->ia", eris_ovoo, t2)
    t1new += lib.einsum("kcli,klac->ia", eris_ovoo, t2)

    t1new += -2 * lib.einsum("lcki,lc,ka->ia", eris_ovoo, t1, t1)
    t1new += lib.einsum("kcli,lc,ka->ia", eris_ovoo, t1, t1)

    # T2 equation
    tmp2 = lib.einsum("kibc,ka->abic", eris.oovv, -t1)
    tmp2 += np.asarray(eris_ovvv).conj().transpose(1, 3, 0, 2)
    tmp = lib.einsum("abic,jc->ijab", tmp2, t1)
    t2new = tmp + tmp.transpose(1, 0, 3, 2)
    tmp2 = lib.einsum("kcai,jc->akij", eris.ovvo, t1)
    tmp2 += eris_ovoo.transpose(1, 3, 0, 2).conj()
    tmp = lib.einsum("akij,kb->ijab", tmp2, t1)
    t2new -= tmp + tmp.transpose(1, 0, 3, 2)
    t2new += np.asarray(eris.ovov).conj().transpose(0, 2, 1, 3)

    Loo = imd.Loo(t1, t2, eris)
    Lvv = imd.Lvv(t1, t2, eris)
    Loo[np.diag_indices(nocc)] -= mo_e_o
    Lvv[np.diag_indices(nvir)] -= mo_e_v

    if "O^4V^2" in compressed_contractions:
        Woooo = sparse_cc_Woooo(t1, t2_sparse_alt, eris, contraction_timings)
    else:
        Woooo = imd.cc_Woooo(t1, t2, eris)

    if "O^3V^3" in compressed_contractions:
        Wvoov = sparse_cc_Wvoov(t1, t2_sparse_alt, eris, contraction_timings)
        Wvovo = sparse_cc_Wvovo(t1, t2_sparse_alt, eris, contraction_timings)

    else:
        Wvoov = imd.cc_Wvoov(t1, t2, eris)
        Wvovo = imd.cc_Wvovo(t1, t2, eris)

    Wvvvv = cc_Wvvvv(t1, t2, eris)  # t2 isn't used in making this intermediate

    # Splitting up some of the taus
    if "O^4V^2" in compressed_contractions:
        t2new += lib.einsum("klij,ka,lb->ijab", Woooo, t1, t1)

        t_0101 = time.perf_counter()
        contract_DTSpT(Woooo, t2_sparse, t2new, "0101")
        contraction_timings["0101"] = time.perf_counter() - t_0101

    else:
        tau = t2 + np.einsum("ia,jb->ijab", t1, t1)
        t2new += lib.einsum("klij,klab->ijab", Woooo, tau)

    # FRI-Compressed contraction
    t2new += lib.einsum("abcd,ia,jb->ijab", Wvvvv, t1, t1)
    if "O^2V^4" in compressed_contractions:
        # log.warn(f"|t2_new|_2323 = {np.linalg.norm(t2new.ravel(), ord=1)}")

        t_2323 = time.perf_counter()
        contract_DTSpT(Wvvvv, t2_sparse, t2new, "2323")
        contraction_timings["2323"] = time.perf_counter() - t_2323

        # log.warn(f"|t2_new|_2323 = {np.linalg.norm(t2new.ravel(), ord=1)}")
        # t2new = t2new.reshape(nocc, nocc, nvir, nvir)
    else:
        # log.warn(f"|t2_new|_2323 = {np.linalg.norm(t2new.ravel(), ord=1)}")
        t2new += lib.einsum("abcd,ijcd->ijab", Wvvvv, t2)
        # log.warn(f"|t2_new|_2323 = {np.linalg.norm(t2new.ravel(), ord=1)}")

    # TODO sparsify? O^2V^3
    tmp = lib.einsum("ac,ijcb->ijab", Lvv, t2)
    t2new += tmp + tmp.transpose(1, 0, 3, 2)
    tmp = lib.einsum("ki,kjab->ijab", Loo, t2)
    t2new -= tmp + tmp.transpose(1, 0, 3, 2)

    # FRI-Compressed contraction
    if "O^3V^3" in compressed_contractions:
        tmp = np.zeros_like(t2new)
        t_1302 = time.perf_counter()
        contract_DTSpT(Wvoov, t2_sparse, tmp, "1302")
        contraction_timings["1302"] = time.perf_counter() - t_1302

        t_1202 = time.perf_counter()
        contract_DTSpT(Wvovo, t2_sparse, tmp, "1202")
        contraction_timings["1202"] = time.perf_counter() - t_1202

        t2new += tmp + tmp.transpose(1, 0, 3, 2)

        tmp = np.zeros_like(t2new)
        t_1303 = time.perf_counter()
        contract_DTSpT(Wvoov, t2_sparse, tmp, "1303")
        contraction_timings["1303"] = time.perf_counter() - t_1303

        t2new -= tmp + tmp.transpose(1, 0, 3, 2)

        tmp = np.zeros_like(t2new)
        t_1203 = time.perf_counter()
        contract_DTSpT(Wvovo, t2_sparse, tmp, "1203")
        contraction_timings["1203"] = time.perf_counter() - t_1203
        t2new -= tmp + tmp.transpose(1, 0, 3, 2)

    else:
        tmp = 2 * lib.einsum("akic,kjcb->ijab", Wvoov, t2)
        tmp -= lib.einsum("akci,kjcb->ijab", Wvovo, t2)

        t2new += tmp + tmp.transpose(1, 0, 3, 2)

        tmp = lib.einsum("akic,kjbc->ijab", Wvoov, t2)
        t2new -= tmp + tmp.transpose(1, 0, 3, 2)

        tmp = lib.einsum("bkci,kjac->ijab", Wvovo, t2)
        t2new -= tmp + tmp.transpose(1, 0, 3, 2)

    eia = mo_e_o[:, None] - mo_e_v
    eijab = lib.direct_sum("ia,jb->ijab", eia, eia)
    t1new /= eia
    t2new /= eijab

    #
    # Timing
    #
    t_update_amps = time.perf_counter() - t_update_amps

    log.debug(f"\nFRI: Compression Time {t_compress:.3f}")
    fri_time = copy.copy(t_compress)
    for k, v in contraction_timings.items():
        log.debug(f"FRI: Contraction {k} Time: {v:.3f} (s)")
        fri_time += v
    fri_time_frac = (fri_time) / t_update_amps
    log.debug(
        f"FRI: CCSD Total Time {t_update_amps:.3f} FRI-related fraction = {fri_time_frac:.3f}\n"
    )

    return t1new, t2new
Exemple #7
0
def update_amps(cc, t1, t2, eris, max_memory=2000):
    time0 = time.clock(), time.time()
    log = logger.Logger(cc.stdout, cc.verbose)
    nocc, nvir = t1.shape
    fock = eris.fock

    fov = fock[:nocc,nocc:]
    foo = fock[:nocc,:nocc]
    fvv = fock[nocc:,nocc:]

    mo_e = eris.fock.diagonal()
    eia = mo_e[:nocc,None] - mo_e[None,nocc:]
    eijab = lib.direct_sum('ia,jb->ijab',eia,eia)

    Foo = imd.cc_Foo(t1,t2,eris)
    Fvv = imd.cc_Fvv(t1,t2,eris)
    Fov = imd.cc_Fov(t1,t2,eris)
    Loo = imd.Loo(t1,t2,eris)
    Lvv = imd.Lvv(t1,t2,eris)
    Woooo = imd.cc_Woooo(t1,t2,eris)
    Wvvvv = imd.cc_Wvvvv(t1,t2,eris)
    Wvoov = imd.cc_Wvoov(t1,t2,eris)
    Wvovo = imd.cc_Wvovo(t1,t2,eris)

    # Move energy terms to the other side
    Foo -= foo
    Fvv -= fvv
    Loo -= foo
    Lvv -= fvv

    # T1 equation
    # TODO: Check this conj(). Hirata and Bartlett has
    # f_{vo}(a,i), which should be equal to f_{ov}^*(i,a)
    t1new = fov.conj().copy()
    t1new += -2*einsum('kc,ka,ic->ia',fov,t1,t1)
    t1new +=   einsum('ac,ic->ia',Fvv,t1)
    t1new +=  -einsum('ki,ka->ia',Foo,t1)
    t1new +=   einsum('kc,kica->ia',Fov,2*t2)
    t1new +=   einsum('kc,ikca->ia',Fov, -t2)
    t1new +=   einsum('kc,ic,ka->ia',Fov,t1,t1)
    t1new += 2*einsum('akic,kc->ia',eris.voov,t1)
    t1new +=  -einsum('kaic,kc->ia',eris.ovov,t1)
    t1new += 2*einsum('akcd,ikcd->ia',eris.vovv,t2)
    t1new +=  -einsum('akdc,ikcd->ia',eris.vovv,t2)
    t1new += 2*einsum('akcd,ic,kd->ia',eris.vovv,t1,t1)
    t1new +=  -einsum('akdc,ic,kd->ia',eris.vovv,t1,t1)
    t1new += -2*einsum('klic,klac->ia',eris.ooov,t2)
    t1new +=  einsum('lkic,klac->ia',eris.ooov,t2)
    t1new += -2*einsum('klic,ka,lc->ia',eris.ooov,t1,t1)
    t1new +=  einsum('lkic,ka,lc->ia',eris.ooov,t1,t1)

    # T2 equation
    # For conj(), see Hirata and Bartlett, Eq. (36)
    t2new = np.array(eris.oovv).conj()
    t2new += einsum('klij,klab->ijab',Woooo,t2)
    t2new += einsum('klij,ka,lb->ijab',Woooo,t1,t1)
    for a in range(nvir):
        Wvvvv_a = np.array(Wvvvv[a])
        t2new[:,:,a,:] += einsum('bcd,ijcd->ijb',Wvvvv_a,t2)
        t2new[:,:,a,:] += einsum('bcd,ic,jd->ijb',Wvvvv_a,t1,t1)
    tmp = einsum('ac,ijcb->ijab',Lvv,t2)
    t2new += (tmp + tmp.transpose(1,0,3,2))
    tmp = einsum('ki,kjab->ijab',Loo,t2)
    t2new -= (tmp + tmp.transpose(1,0,3,2))
    tmp2 = np.array(eris.vovv).transpose(3,2,1,0).conj() \
            - einsum('kbic,ka->abic',eris.ovov,t1)
    tmp = einsum('abic,jc->ijab',tmp2,t1)
    t2new += (tmp + tmp.transpose(1,0,3,2))
    tmp2 = np.array(eris.ooov).transpose(3,2,1,0).conj() \
            + einsum('akic,jc->akij',eris.voov,t1)
    tmp = einsum('akij,kb->ijab',tmp2,t1)
    t2new -= (tmp + tmp.transpose(1,0,3,2))
    tmp = 2*einsum('akic,kjcb->ijab',Wvoov,t2) - einsum('akci,kjcb->ijab',Wvovo,t2)
    t2new += (tmp + tmp.transpose(1,0,3,2))
    tmp = einsum('akic,kjbc->ijab',Wvoov,t2)
    t2new -= (tmp + tmp.transpose(1,0,3,2))
    tmp = einsum('bkci,kjac->ijab',Wvovo,t2)
    t2new -= (tmp + tmp.transpose(1,0,3,2))

    t1new /= eia
    t2new /= eijab

    time0 = log.timer_debug1('update t1 t2', *time0)

    return t1new, t2new
Exemple #8
0
def update_amps(cc, t1, t2, eris):
    # Ref: Hirata et al., J. Chem. Phys. 120, 2581 (2004) Eqs.(35)-(36)
    nocc, nvir = t1.shape
    fock = eris.fock

    fov = fock[:nocc,nocc:].copy()
    foo = fock[:nocc,:nocc].copy()
    fvv = fock[nocc:,nocc:].copy()

    Foo = imd.cc_Foo(t1,t2,eris)
    Fvv = imd.cc_Fvv(t1,t2,eris)
    Fov = imd.cc_Fov(t1,t2,eris)

    # Move energy terms to the other side
    Foo -= np.diag(np.diag(foo))
    Fvv -= np.diag(np.diag(fvv))

    # T1 equation
    t1new = np.asarray(fov).conj().copy()
    t1new +=-2*einsum('kc,ka,ic->ia', fov, t1, t1)
    t1new +=   einsum('ac,ic->ia', Fvv, t1)
    t1new +=  -einsum('ki,ka->ia', Foo, t1)
    t1new += 2*einsum('kc,kica->ia', Fov, t2)
    t1new +=  -einsum('kc,ikca->ia', Fov, t2)
    t1new +=   einsum('kc,ic,ka->ia', Fov, t1, t1)
    t1new += 2*einsum('kcai,kc->ia', eris.ovvo, t1)
    t1new +=  -einsum('kiac,kc->ia', eris.oovv, t1)
    eris_ovvv = np.asarray(eris.ovvv)
    t1new += 2*einsum('kdac,ikcd->ia', eris_ovvv, t2)
    t1new +=  -einsum('kcad,ikcd->ia', eris_ovvv, t2)
    t1new += 2*einsum('kdac,kd,ic->ia', eris_ovvv, t1, t1)
    t1new +=  -einsum('kcad,kd,ic->ia', eris_ovvv, t1, t1)
    t1new +=-2*einsum('kilc,klac->ia', eris.ooov, t2)
    t1new +=   einsum('likc,klac->ia', eris.ooov, t2)
    t1new +=-2*einsum('kilc,lc,ka->ia', eris.ooov, t1, t1)
    t1new +=   einsum('likc,lc,ka->ia', eris.ooov, t1, t1)

    # T2 equation
    t2new = np.asarray(eris.ovov).conj().transpose(0,2,1,3).copy()
    if cc.cc2:
        Woooo2 = np.asarray(eris.oooo).transpose(0,2,1,3).copy()
        Woooo2 += einsum('kilc,jc->klij', eris.ooov, t1)
        Woooo2 += einsum('ljkc,ic->klij', eris.ooov, t1)
        Woooo2 += einsum('kcld,ic,jd->klij', eris.ovov, t1, t1)
        t2new += einsum('klij,ka,lb->ijab', Woooo2, t1, t1)
        Wvvvv = einsum('kcbd,ka->abcd', eris_ovvv, -t1)
        Wvvvv = Wvvvv + Wvvvv.transpose(1,0,3,2)
        Wvvvv += np.asarray(eris.vvvv).transpose(0,2,1,3)
        t2new += einsum('abcd,ic,jd->ijab', Wvvvv, t1, t1)
        Lvv2 = fvv - einsum('kc,ka->ac', fov, t1)
        Lvv2 -= np.diag(np.diag(fvv))
        tmp = einsum('ac,ijcb->ijab', Lvv2, t2)
        t2new += (tmp + tmp.transpose(1,0,3,2))
        Loo2 = foo + einsum('kc,ic->ki', fov, t1)
        Loo2 -= np.diag(np.diag(foo))
        tmp = einsum('ki,kjab->ijab', Loo2, t2)
        t2new -= (tmp + tmp.transpose(1,0,3,2))
    else:
        Loo = imd.Loo(t1, t2, eris)
        Lvv = imd.Lvv(t1, t2, eris)
        Loo -= np.diag(np.diag(foo))
        Lvv -= np.diag(np.diag(fvv))
        Woooo = imd.cc_Woooo(t1, t2, eris)
        Wvoov = imd.cc_Wvoov(t1, t2, eris)
        Wvovo = imd.cc_Wvovo(t1, t2, eris)
        Wvvvv = imd.cc_Wvvvv(t1, t2, eris)
        tau = t2 + einsum('ia,jb->ijab', t1, t1)
        t2new += einsum('klij,klab->ijab', Woooo, tau)
        t2new += einsum('abcd,ijcd->ijab', Wvvvv, tau)
        tmp = einsum('ac,ijcb->ijab', Lvv, t2)
        t2new += (tmp + tmp.transpose(1,0,3,2))
        tmp = einsum('ki,kjab->ijab', Loo, t2)
        t2new -= (tmp + tmp.transpose(1,0,3,2))
        tmp  = 2*einsum('akic,kjcb->ijab', Wvoov, t2)
        tmp -=   einsum('akci,kjcb->ijab', Wvovo, t2)
        t2new += (tmp + tmp.transpose(1,0,3,2))
        tmp = einsum('akic,kjbc->ijab', Wvoov, t2)
        t2new -= (tmp + tmp.transpose(1,0,3,2))
        tmp = einsum('bkci,kjac->ijab', Wvovo, t2)
        t2new -= (tmp + tmp.transpose(1,0,3,2))

    tmp2  = einsum('kibc,ka->abic', eris.oovv, -t1)
    tmp2 += np.asarray(eris.ovvv).conj().transpose(1,3,0,2)
    tmp = einsum('abic,jc->ijab', tmp2, t1)
    t2new += (tmp + tmp.transpose(1,0,3,2))
    tmp2  = einsum('kcai,jc->akij', eris.ovvo, t1)
    tmp2 += np.asarray(eris.ooov).transpose(3,1,2,0).conj()
    tmp = einsum('akij,kb->ijab', tmp2, t1)
    t2new -= (tmp + tmp.transpose(1,0,3,2))

    mo_e = eris.fock.diagonal().real
    eia = mo_e[:nocc,None] - mo_e[None,nocc:]
    eijab = lib.direct_sum('ia,jb->ijab',eia,eia)
    t1new /= eia
    t2new /= eijab

    return t1new, t2new
Exemple #9
0
def update_amps(cc, t1, t2, eris):
    # Ref: Hirata et al., J. Chem. Phys. 120, 2581 (2004) Eqs.(35)-(36)
    nocc, nvir = t1.shape
    fock = eris.fock

    fov = fock[:nocc, nocc:].copy()
    foo = fock[:nocc, :nocc].copy()
    fvv = fock[nocc:, nocc:].copy()

    Foo = imd.cc_Foo(0 * t1, t2, eris)
    Fvv = imd.cc_Fvv(0 * t1, t2, eris)
    Fov = imd.cc_Fov(t1, t2, eris)

    Foo -= np.diag(np.diag(foo))
    Fvv -= np.diag(np.diag(fvv))

    # T1 equation
    t1new = np.asarray(fov).conj().copy()
    t1new += lib.einsum('ac,ic->ia', Fvv, t1)
    t1new += -lib.einsum('ki,ka->ia', Foo, t1)
    t1new += 2 * lib.einsum('kc,kica->ia', Fov, t2)
    t1new += -lib.einsum('kc,ikca->ia', Fov, t2)
    t1new += 2 * lib.einsum('kcai,kc->ia', eris.ovvo, t1)
    t1new += -lib.einsum('kiac,kc->ia', eris.oovv, t1)
    eris_ovvv = np.asarray(eris.ovvv)
    t1new += 2 * lib.einsum('kdac,ikcd->ia', eris_ovvv, t2)
    t1new += -lib.einsum('kcad,ikcd->ia', eris_ovvv, t2)
    t1new += -2 * lib.einsum('kilc,klac->ia', eris.ooov, t2)
    t1new += lib.einsum('likc,klac->ia', eris.ooov, t2)

    # T2 equation
    t2new = np.asarray(eris.ovov).conj().transpose(0, 2, 1, 3).copy()
    Loo = imd.Loo(0 * t1, t2, eris)
    Lvv = imd.Lvv(0 * t1, t2, eris)
    Loo -= np.diag(np.diag(foo))
    Lvv -= np.diag(np.diag(fvv))
    Woooo = imd.cc_Woooo(0 * t1, t2, eris)
    Wvoov = imd.cc_Wvoov(0 * t1, t2, eris)
    Wvovo = imd.cc_Wvovo(0 * t1, t2, eris)
    Wvvvv = imd.cc_Wvvvv(0 * t1, t2, eris)
    t2new += lib.einsum('klij,klab->ijab', Woooo, t2)
    t2new += lib.einsum('abcd,ijcd->ijab', Wvvvv, t2)
    tmp = lib.einsum('ac,ijcb->ijab', Lvv, t2)
    t2new += (tmp + tmp.transpose(1, 0, 3, 2))
    tmp = lib.einsum('ki,kjab->ijab', Loo, t2)
    t2new -= (tmp + tmp.transpose(1, 0, 3, 2))
    tmp = 2 * lib.einsum('akic,kjcb->ijab', Wvoov, t2)
    tmp -= lib.einsum('akci,kjcb->ijab', Wvovo, t2)
    t2new += (tmp + tmp.transpose(1, 0, 3, 2))
    tmp = lib.einsum('akic,kjbc->ijab', Wvoov, t2)
    t2new -= (tmp + tmp.transpose(1, 0, 3, 2))
    tmp = lib.einsum('bkci,kjac->ijab', Wvovo, t2)
    t2new -= (tmp + tmp.transpose(1, 0, 3, 2))

    tmp2 = np.asarray(eris.ovvv).conj().transpose(1, 3, 0, 2)
    tmp = lib.einsum('abic,jc->ijab', tmp2, t1)
    t2new += (tmp + tmp.transpose(1, 0, 3, 2))
    tmp2 = np.asarray(eris.ooov).transpose(3, 1, 2, 0).conj()
    tmp = lib.einsum('akij,kb->ijab', tmp2, t1)
    t2new -= (tmp + tmp.transpose(1, 0, 3, 2))

    mo_e = eris.fock.diagonal().real
    eia = mo_e[:nocc, None] - mo_e[None, nocc:]
    eijab = lib.direct_sum('ia,jb->ijab', eia, eia)
    t1new /= eia
    t2new /= eijab

    return t1new, t2new
Exemple #10
0
def update_amps(cc, t1, t2, eris):
    # Ref: Hirata et al., J. Chem. Phys. 120, 2581 (2004) Eqs.(35)-(36)
    assert(isinstance(eris, ccsd._ChemistsERIs))
    nocc, nvir = t1.shape
    fock = eris.fock
    mo_e_o = eris.mo_energy[:nocc]
    mo_e_v = eris.mo_energy[nocc:] + cc.level_shift

    fov = fock[:nocc,nocc:].copy()
    foo = fock[:nocc,:nocc].copy()
    fvv = fock[nocc:,nocc:].copy()

    Foo = imd.cc_Foo(t1,t2,eris)
    Fvv = imd.cc_Fvv(t1,t2,eris)
    Fov = imd.cc_Fov(t1,t2,eris)

    # Move energy terms to the other side
    Foo[np.diag_indices(nocc)] -= mo_e_o
    Fvv[np.diag_indices(nvir)] -= mo_e_v

    # T1 equation
    t1new  =-2*np.einsum('kc,ka,ic->ia', fov, t1, t1)
    t1new +=   np.einsum('ac,ic->ia', Fvv, t1)
    t1new +=  -np.einsum('ki,ka->ia', Foo, t1)
    t1new += 2*np.einsum('kc,kica->ia', Fov, t2)
    t1new +=  -np.einsum('kc,ikca->ia', Fov, t2)
    t1new +=   np.einsum('kc,ic,ka->ia', Fov, t1, t1)
    t1new += fov.conj()
    t1new += 2*np.einsum('kcai,kc->ia', eris.ovvo, t1)
    t1new +=  -np.einsum('kiac,kc->ia', eris.oovv, t1)
    eris_ovvv = np.asarray(eris.get_ovvv())
    t1new += 2*lib.einsum('kdac,ikcd->ia', eris_ovvv, t2)
    t1new +=  -lib.einsum('kcad,ikcd->ia', eris_ovvv, t2)
    t1new += 2*lib.einsum('kdac,kd,ic->ia', eris_ovvv, t1, t1)
    t1new +=  -lib.einsum('kcad,kd,ic->ia', eris_ovvv, t1, t1)
    eris_ovoo = np.asarray(eris.ovoo, order='C')
    t1new +=-2*lib.einsum('lcki,klac->ia', eris_ovoo, t2)
    t1new +=   lib.einsum('kcli,klac->ia', eris_ovoo, t2)
    t1new +=-2*lib.einsum('lcki,lc,ka->ia', eris_ovoo, t1, t1)
    t1new +=   lib.einsum('kcli,lc,ka->ia', eris_ovoo, t1, t1)

    # T2 equation
    tmp2  = lib.einsum('kibc,ka->abic', eris.oovv, -t1)
    tmp2 += np.asarray(eris_ovvv).conj().transpose(1,3,0,2)
    tmp = lib.einsum('abic,jc->ijab', tmp2, t1)
    t2new = tmp + tmp.transpose(1,0,3,2)
    tmp2  = lib.einsum('kcai,jc->akij', eris.ovvo, t1)
    tmp2 += eris_ovoo.transpose(1,3,0,2).conj()
    tmp = lib.einsum('akij,kb->ijab', tmp2, t1)
    t2new -= tmp + tmp.transpose(1,0,3,2)
    t2new += np.asarray(eris.ovov).conj().transpose(0,2,1,3)
    if cc.cc2:
        Woooo2 = np.asarray(eris.oooo).transpose(0,2,1,3).copy()
        Woooo2 += lib.einsum('lcki,jc->klij', eris_ovoo, t1)
        Woooo2 += lib.einsum('kclj,ic->klij', eris_ovoo, t1)
        Woooo2 += lib.einsum('kcld,ic,jd->klij', eris.ovov, t1, t1)
        t2new += lib.einsum('klij,ka,lb->ijab', Woooo2, t1, t1)
        Wvvvv = lib.einsum('kcbd,ka->abcd', eris_ovvv, -t1)
        Wvvvv = Wvvvv + Wvvvv.transpose(1,0,3,2)
        Wvvvv += np.asarray(eris.vvvv).transpose(0,2,1,3)
        t2new += lib.einsum('abcd,ic,jd->ijab', Wvvvv, t1, t1)
        Lvv2 = fvv - np.einsum('kc,ka->ac', fov, t1)
        Lvv2 -= np.diag(np.diag(fvv))
        tmp = lib.einsum('ac,ijcb->ijab', Lvv2, t2)
        t2new += (tmp + tmp.transpose(1,0,3,2))
        Loo2 = foo + np.einsum('kc,ic->ki', fov, t1)
        Loo2 -= np.diag(np.diag(foo))
        tmp = lib.einsum('ki,kjab->ijab', Loo2, t2)
        t2new -= (tmp + tmp.transpose(1,0,3,2))
    else:
        Loo = imd.Loo(t1, t2, eris)
        Lvv = imd.Lvv(t1, t2, eris)
        Loo[np.diag_indices(nocc)] -= mo_e_o
        Lvv[np.diag_indices(nvir)] -= mo_e_v

        Woooo = imd.cc_Woooo(t1, t2, eris)
        Wvoov = imd.cc_Wvoov(t1, t2, eris)
        Wvovo = imd.cc_Wvovo(t1, t2, eris)
        Wvvvv = imd.cc_Wvvvv(t1, t2, eris)

        tau = t2 + np.einsum('ia,jb->ijab', t1, t1)
        t2new += lib.einsum('klij,klab->ijab', Woooo, tau)
        t2new += lib.einsum('abcd,ijcd->ijab', Wvvvv, tau)
        tmp = lib.einsum('ac,ijcb->ijab', Lvv, t2)
        t2new += (tmp + tmp.transpose(1,0,3,2))
        tmp = lib.einsum('ki,kjab->ijab', Loo, t2)
        t2new -= (tmp + tmp.transpose(1,0,3,2))
        tmp  = 2*lib.einsum('akic,kjcb->ijab', Wvoov, t2)
        tmp -=   lib.einsum('akci,kjcb->ijab', Wvovo, t2)
        t2new += (tmp + tmp.transpose(1,0,3,2))
        tmp = lib.einsum('akic,kjbc->ijab', Wvoov, t2)
        t2new -= (tmp + tmp.transpose(1,0,3,2))
        tmp = lib.einsum('bkci,kjac->ijab', Wvovo, t2)
        t2new -= (tmp + tmp.transpose(1,0,3,2))

    eia = mo_e_o[:,None] - mo_e_v
    eijab = lib.direct_sum('ia,jb->ijab',eia,eia)
    t1new /= eia
    t2new /= eijab

    return t1new, t2new