Пример #1
0
    def init_amplitudes(self, ham):
        """
        Initialize amplitudes from interaction
        """
        e_ai = cc_denom(ham.f, 2, 'dir', 'full')
        e_abij = cc_denom(ham.f, 4, 'dir', 'full')
        nocc = self.mos.nocc
        nvir = self.mos.nvir

        t1 = ham.f.ov.transpose().conj() * (- e_ai)
        v_vovo = einsum("pia,pjb->aibj", ham.l.pov, ham.l.pov).conj()

        t2_full = v_vovo.transpose([0, 2, 1, 3]) * (- e_abij)
        t2names = ['xlam', 'x1', 'x2', 'x3', 'x4']
        t3names = ['xlam', 'x1', 'x2', 'x3', 'x4', 'x5', 'x6']

        t2x = ncpd_initialize(t2_full.shape, self.rankt.t2)
        t2x = als_dense(t2x, t2_full, max_cycle=100,
                        tensor_format='ncpd')

        t3x = ncpd_initialize(
            (nvir,) * 3 + (nocc,) * 3,
            self.rankt.t3,
            init_function=(lambda x: 0.001 * np.random.rand(*x)))

        return Tensors(t1=t1, t2=Tensors(zip(t2names, t2x)),
                       t3=Tensors(zip(t3names, t3x)))
Пример #2
0
    def init_amplitudes(self, ham):
        """
        Initialize amplitudes from interaction
        """
        e_ai = cc_denom(ham.f, 2, 'dir', 'full')
        e_abij = cc_denom(ham.f, 4, 'dir', 'full')

        t1 = ham.f.ov.transpose().conj() * (-e_ai)
        v_vovo = einsum("pia,pjb->aibj", ham.l.pov, ham.l.pov).conj()

        t2_full = v_vovo.transpose([0, 2, 1, 3]) * (-e_abij)
        xs = ncpd_initialize(t2_full.shape, self.rankt.t2)
        xs = als_dense(xs, t2_full, max_cycle=100, tensor_format='ncpd')
        # xs_sym = cpd_symmetrize(xs, {(1, 0, 3, 2): ('ident',)})

        names = ['xlam', 'x1', 'x2', 'x3', 'x4']

        return Tensors(t1=t1, t2=Tensors(zip(names, xs)))
Пример #3
0
def run_cc_cpd(workdir):
    from pyscf.lib import logger

    print('Running CC-CPD')

    # Restore RHF object
    with open(workdir + 'rhf_results.p', 'rb') as fp:
        rhf_results = pickle.load(fp)

    e_tot, mo_coeff, mo_energy, atom = rhf_results
    mol = gto.Mole()
    mol.atom = atom
    mol.basis = BASIS
    mol.build()

    # nbasis = mol.nao_nr()

    rhf = scf.density_fit(scf.RHF(mol))
    rhf.max_cycle = 1
    rhf.scf()

    nbasis_ri = rhf.with_df.get_naoaux()
    # Get CCSD results to generate initial guess

    with open(workdir + 'ccsd_results.p', 'rb') as fp:
        energy_ref, amps_ref = pickle.load(fp)

    # Run RCCSD_RI_CPD
    from tcc.rccsd_cpd import RCCSD_nCPD_LS_T
    from tcc.cc_solvers import classic_solver, update_diis_solver
    from tcc.tensors import Tensors
    from tcc.cpd import ncpd_initialize, als_dense

    ranks_t = [int(el * nbasis_ri) for el in RANKS_T_FACTOR]

    energies = []
    deltas = []

    for idxr, rank in enumerate(ranks_t):
        tim = time.process_time()
        if not isfile(
                workdir +
                'ccsd_results_rank_{}.p'.format(rank)):
            cc = RCCSD_nCPD_LS_T(rhf,
                                 mo_coeff=mo_coeff,
                                 mo_energy=mo_energy)
            # Initial guess
            t2x = als_dense(
                ncpd_initialize(amps_ref.t2.shape, rank),
                amps_ref.t2, max_cycle=100, tensor_format='ncpd'
            )
            t2names = ['xlam', 'x1', 'x2', 'x3', 'x4']
            amps_guess = Tensors(t1=amps_ref.t1,
                                 t2=Tensors(zip(t2names, t2x)))

            converged, energy, amps = update_diis_solver(
                cc, conv_tol_energy=1e-6, conv_tol_res=1e-6,
                max_cycle=500,
                verbose=logger.INFO,
                amps=amps_guess, ndiis=3)

            if not converged:
                energy = np.nan
            ccsd_results = [energy, amps]
            with open(workdir +
                      'ccsd_results_rank_{}.p'.format(rank), 'wb') as fp:
                pickle.dump(ccsd_results, fp)
        else:
            with open(workdir +
                      'ccsd_results_rank_{}.p'.format(rank), 'rb') as fp:
                ccsd_results = pickle.load(fp)
                energy, _ = ccsd_results

        energies.append(energy)
        deltas.append(energy - energy_ref)
        elapsed = time.process_time() - tim

        print('Step {} out of {} done, rank = {}, time: {}'.format(
            idxr + 1, len(ranks_t), rank, elapsed
        ))

    np.savetxt(
        workdir + 'RCCSD_CPD.txt',
        np.column_stack((ranks_t, energies, deltas)),
        header='Rank Energy Delta',
        fmt=('%i', '%e', '%e')
    )
    print('Summary')
    print('=========================================')
    for idxr, rank in enumerate(ranks_t):
        print('{} {}'.format(rank, deltas[idxr]))
    print('=========================================')