コード例 #1
0
    def solve_amps(self, h, a, g):
        """
        Solving for new T amlitudes using RHS and denominator
        It is assumed that the order of fields in the RHS
        is consistent with the order in amplitudes
        """

        # Symmetrize T3 RHS - see RCCSDT code
        g3 = (+g.t3 + g.t3.transpose([1, 2, 0, 4, 5, 3]) + g.t3.transpose(
            [2, 0, 1, 5, 3, 4]) + g.t3.transpose([0, 2, 1, 3, 5, 4]) +
              g.t3.transpose([2, 1, 0, 5, 4, 3]) +
              g.t3.transpose([1, 0, 2, 4, 3, 5])) / 6

        # Solve T3
        t3 = g3 * (-cc_denom(h.f, g.t3.ndim, 'dir', 'full'))

        # Symmetrize
        t3 = (+t3 + t3.transpose([1, 2, 0, 4, 5, 3]) + t3.transpose(
            [2, 0, 1, 5, 3, 4]) + t3.transpose([0, 2, 1, 3, 5, 4]) +
              t3.transpose([2, 1, 0, 5, 4, 3]) +
              t3.transpose([1, 0, 2, 4, 3, 5])) / 6

        # Symmetrize T2 RHS
        g2 = 1 / 2 * (g.t2 + g.t2.transpose([1, 0, 3, 2]))

        # Solve T2
        t2 = g2 * (-cc_denom(h.f, g.t2.ndim, 'dir', 'full'))

        # Symmetrize
        t2 = 1 / 2 * (t2 + t2.transpose([1, 0, 3, 2]))

        # Solve for factors
        t2x = als_dense([a.t2.xlam, a.t2.x1, a.t2.x2, a.t2.x3, a.t2.x4],
                        t2,
                        max_cycle=1,
                        tensor_format='ncpd')
        t3x = als_dense(
            [a.t3.xlam, a.t3.x1, a.t3.x2, a.t3.x3, a.t3.x4, a.t3.x5, a.t3.x6],
            t3,
            max_cycle=1,
            tensor_format='ncpd')
        return Tensors(
            t1=g.t1 * (-cc_denom(h.f, g.t1.ndim, 'dir', 'full')),
            t2=Tensors(xlam=t2x[0], x1=t2x[1], x2=t2x[2], x3=t2x[3],
                       x4=t2x[4]),
            t3=Tensors(xlam=t3x[0],
                       x1=t3x[1],
                       x2=t3x[2],
                       x3=t3x[3],
                       x4=t3x[4],
                       x5=t3x[5],
                       x6=t3x[6]),
        )
コード例 #2
0
ファイル: rccsdt_unit_cpd.py プロジェクト: qbit-/tcc
    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 = ['x1', 'x2', 'x3', 'x4']
        t3names = ['x1', 'x2', 'x3', 'x4', 'x5', 'x6']

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

        t3x = cpd_initialize((nvir,) * 3 + (nocc,) * 3,
                             self.rankt.t3, init_function=np.zeros)

        return Tensors(t1=t1, t2=Tensors(zip(t2names, t2x)),
                       t3=Tensors(zip(t3names, t3x)))
コード例 #3
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 = 2 * ham.f.ov.transpose().conj() * (-e_ai)
        v_vovo = einsum("pia,pjb->aibj", ham.l.pov, ham.l.pov).conj()

        t2_full = 2 * v_vovo.transpose([0, 2, 1, 3]) * (-e_abij)
        xs = cpd_initialize(t2_full.shape, self.rankt.t2)
        xs = als_dense(xs, t2_full, max_cycle=100)

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

        return Tensors(t1=t1, t2=Tensors(zip(names, xs)))
コード例 #4
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)))
コード例 #5
0
    def solve_amps(self, h, a, g):
        """
        Solve for new amplitudes using RHS and denominator
        """

        t1 = g.t1 * (-cc_denom(h.f, 2, 'dir', 'full'))

        # Symmetrize T2 HS
        g2 = 1 / 2 * (g.t2 + g.t2.transpose([1, 0, 3, 2]))

        # Solve T2
        t2_full = g2 * (-cc_denom(h.f, 4, 'dir', 'full'))

        xs = als_dense([a.t2.x1, a.t2.x2, a.t2.x3, a.t2.x4],
                       t2_full,
                       max_cycle=1,
                       tensor_format='cpd')

        return Tensors(t1=t1,
                       t2=Tensors(x1=xs[0], x2=xs[1], x3=xs[2], x4=xs[3]))
コード例 #6
0
    def solve_amps(self, h, a, g):
        """
        Solving for new T amlitudes using RHS and denominator
        It is assumed that the order of fields in the RHS
        is consistent with the order in amplitudes
        """
        t1 = g.t1 / (-2) * cc_denom(h.f, 2, 'dir', 'full')

        # Build unit RHS
        g2 = (2 * g.t2 + g.t2.transpose([0, 1, 3, 2])) / 6

        # Symmetrize RHS
        g2 = 1 / 2 * (g2 + g2.transpose([1, 0, 3, 2]))

        # Solve
        t2_full = g2 * (-cc_denom(h.f, 4, 'dir', 'full'))
        xs = als_dense([a.t2.x1, a.t2.x2, a.t2.x3, a.t2.x4],
                       t2_full,
                       max_cycle=1)

        names = ['x1', 'x2', 'x3', 'x4']
        return Tensors(t1=t1, t2=Tensors(zip(names, xs)))
コード例 #7
0
ファイル: run_system.py プロジェクト: qbit-/tcc-scratch
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('=========================================')