Ejemplo n.º 1
0
def kernel(mycc,
           eris=None,
           t1=None,
           t2=None,
           max_cycle=50,
           tol=1e-8,
           tolnormt=1e-6,
           verbose=None):
    log = logger.new_logger(mycc, verbose)
    cput0 = (logger.process_clock(), logger.perf_counter())
    _sync_(mycc)

    eris = getattr(mycc, '_eris', None)
    if eris is None:
        mycc.ao2mo(mycc.mo_coeff)
        eris = mycc._eris

    cput1 = (logger.process_clock(), logger.perf_counter())

    # Use the existed amplitudes as initial guess
    if t1 is None: t1 = mycc.t1
    if t2 is None: t2 = mycc.t2
    if t1 is None and t2 is None:
        t1, t2 = mycc.get_init_guess(eris)
    elif t2 is None:
        t2 = mycc.get_init_guess(eris)[1]

    eold = 0
    eccsd = mycc.energy(t1, t2, eris)
    log.info('Init E(CCSD) = %.15g', eccsd)

    if isinstance(mycc.diis, diis.DistributedDIIS):
        adiis = mycc.diis
    elif mycc.diis:
        adiis = diis.DistributedDIIS(mycc, mycc.diis_file)
        adiis.space = mycc.diis_space
    else:
        adiis = None

    conv = False
    for istep in range(max_cycle):
        t1new, t2new = mycc.update_amps(t1, t2, eris)
        normt = _diff_norm(mycc, t1new, t2new, t1, t2)
        t1, t2 = t1new, t2new
        t1new = t2new = None

        t1, t2 = mycc.run_diis(t1, t2, istep, normt, eccsd - eold, adiis)
        eold, eccsd = eccsd, mycc.energy(t1, t2, eris)
        log.info('cycle = %d  E(CCSD) = %.15g  dE = %.9g  norm(t1,t2) = %.6g',
                 istep + 1, eccsd, eccsd - eold, normt)
        cput1 = log.timer('CCSD iter', *cput1)
        if abs(eccsd - eold) < tol and normt < tolnormt:
            conv = True
            break

    mycc.e_corr = eccsd
    mycc.t1 = t1
    mycc.t2 = t2
    log.timer('CCSD', *cput0)
    return conv, eccsd, t1, t2
Ejemplo n.º 2
0
def restore_from_diis_(mycc, diis_file, inplace=True):
    _sync_(mycc)
    if all(comm.allgather(os.path.isfile(diis_file + '__rank' + str(rank)))):
        adiis = diis.DistributedDIIS(mycc, mycc.diis_file)
        adiis.restore(diis_file, inplace=inplace)
        ccvec = adiis.extrapolate()
        mycc.t1, mycc.t2 = mycc.vector_to_amplitudes(ccvec)
        if inplace:
            mycc.diis = adiis

    else:  # Single DIIS file from serial running
        if rank == 0:
            from pyscf.cc import ccsd
            nmo = mycc.nmo
            nocc = mycc.nocc
            adiis = lib.diis.restore(diis_file)
            ccvec = adiis.extrapolate()
            t1, t2 = ccsd.vector_to_amplitudes(ccvec, nmo, nocc)
        else:
            t1 = t2 = None
        mycc.distribute_amplitudes_(t1, t2)

    return mycc
Ejemplo n.º 3
0
def kernel(mycc,
           eris=None,
           t1=None,
           t2=None,
           l1=None,
           l2=None,
           max_cycle=50,
           tol=1e-6,
           verbose=None,
           fintermediates=None,
           fupdate=None,
           approx_l=False):
    """
    CCSD lambda kernel.
    """
    log = logger.new_logger(mycc, verbose)
    cput0 = (logger.process_clock(), logger.perf_counter())
    _sync_(mycc)

    eris = getattr(mycc, '_eris', None)
    if eris is None:
        mycc.ao2mo(mycc.mo_coeff)
        eris = mycc._eris

    if t1 is None:
        t1 = mycc.t1
    if t2 is None:
        t2 = mycc.t2
    if l1 is None:
        if mycc.l1 is None:
            l1 = t1
        else:
            l1 = mycc.l1
    if l2 is None:
        if mycc.l2 is None:
            l2 = t2
        else:
            l2 = mycc.l2

    t1 = np.zeros_like(t1)
    l1 = np.zeros_like(l1)

    if approx_l:
        mycc.l1 = l1
        mycc.l2 = l2
        conv = True
        return conv, l1, l2

    if fintermediates is None:
        fintermediates = make_intermediates
    if fupdate is None:
        fupdate = update_lambda

    imds = fintermediates(mycc, t1, t2, eris)

    if isinstance(mycc.diis, diis.DistributedDIIS):
        adiis = mycc.diis
    elif mycc.diis:
        adiis = diis.DistributedDIIS(mycc, mycc.diis_file)
        adiis.space = mycc.diis_space
    else:
        adiis = None
    cput1 = log.timer('CCSD lambda initialization', *cput0)

    conv = False
    for istep in range(max_cycle):
        l1new, l2new = fupdate(mycc, t1, t2, l1, l2, eris, imds)
        normt = _diff_norm(mycc, l1new, l2new, l1, l2)
        l1, l2 = l1new, l2new
        l1new = l2new = None
        l1, l2 = mycc.run_diis(l1, l2, istep, normt, 0, adiis)
        log.info('cycle = %d  norm(lambda1,lambda2) = %.6g', istep + 1, normt)
        cput1 = log.timer('CCSD iter', *cput1)
        if normt < tol:
            conv = True
            break

    mycc.l1 = l1
    mycc.l2 = l2
    log.timer('CCSD lambda', *cput0)
    return conv, l1, l2