Exemple #1
0
    def calc_residuals(self, h, a):
        """
        Updates right hand side of the CC equations, commonly referred as G
        """
        t2names = ['xlam', 'x1', 'x2', 'x3', 'x4']
        t2x = [a.t2[key] for key in t2names]

        t3names = ['xlam', 'x1', 'x2', 'x3', 'x4', 'x5', 'x6']
        t3x = [a.t3[key] for key in t3names]

        # symmetrize t2 before feeding into res
        t2x_sym = ncpd_symmetrize(t2x, {(1, 0, 3, 2): ('ident',)})

        # symmetrize t3 before feeding into res
        t3x_sym = ncpd_symmetrize(t3x, {(1, 2, 0, 4, 5, 3): ('ident',),
                                        (2, 0, 1, 5, 3, 4): ('ident',),
                                        (0, 2, 1, 3, 5, 4): ('ident',),
                                        (2, 1, 0, 5, 4, 3): ('ident',),
                                        (1, 0, 2, 4, 3, 5): ('ident',)})

        # return _rccsdt_ncpd_ls_t_calc_residuals(h, a)
        return _rccsdt_mul_ri_calc_residuals(
            h,
            Tensors(t1=a.t1,
                    t2=ncpd_rebuild(t2x_sym),
                    t3=ncpd_rebuild(t3x_sym))
        )
Exemple #2
0
    def calculate_update(self, h, a):
        """
        Calculate new amplitudes
        """

        names_abij = ['xlam', 'x1', 'x2', 'x3', 'x4']
        xs = [a.t2[key] for key in names_abij]

        # symmetrize t2 before feeding into res
        xs_sym = ncpd_symmetrize(xs, {(1, 0, 3, 2): ('ident', )})

        # Calculate residuals
        r = self.calc_residuals(
            h, Tensors(t1=a.t1, t2=Tensors(zip(names_abij, xs_sym))))

        # Calculate T1
        t1 = a.t1 - r.t1 * (cc_denom(h.f, 2, 'dir', 'full'))

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

        # Solve
        r2_d = -r2 * cc_denom(h.f, 4, 'dir', 'full')

        t2 = [f for f in xs]
        for idx in range(len(t2)):
            g = (als_contract_dense(t2, r2_d, idx, tensor_format='ncpd') +
                 als_contract_cpd(t2, xs_sym, idx, tensor_format='ncpd'))
            s = als_pseudo_inverse(t2, t2, idx)
            f = np.dot(g, s)
            t2[idx] = f

        return Tensors(t1=t1, t2=Tensors(zip(names_abij, t2)))
Exemple #3
0
    def calc_residuals(self, h, a):
        """
        Calculates CC residuals for CC equations
        """

        # Symmetrize T2 before feeding into res
        xs_sym = ncpd_symmetrize(
            [a.t2.xlam, a.t2.x1, a.t2.x2, a.t2.x3, a.t2.x4],
            {(1, 0, 3, 2): ('ident', )})

        amps = Tensors(t1=a.t1, t2=ncpd_rebuild(xs_sym))

        # residuals are calculated with full amps for speed
        return _rccsd_ri_calc_residuals(h, amps)
Exemple #4
0
    def calculate_update(self, h, a):
        """
        Calculate new amplitudes
        """

        t3names = ['xlam', 'x1', 'x2', 'x3', 'x4', 'x5', 'x6']
        t3x = [a.t3[key] for key in t3names]

        # Running residuals with symmetrized amplitudes.
        # symmetrizetion is done inside calc_residuals
        r = self.calc_residuals(
            h,
            Tensors(t1=a.t1, t2=a.t2,
                    t3=Tensors(zip(t3names, t3x)))
        )

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

        # Solve T2
        r2_d = - r.t2 * cc_denom(h.f, 4, 'dir', 'full')
        t2 = a.t2 + r2_d

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

        # Build full unit residual
        r3s = (+ r.t3
               - r.t3.transpose([0, 1, 2, 3, 5, 4])
               + r.t3.transpose([0, 1, 2, 4, 5, 3]))
        r3u = ((+ r.t3
                + r.t3.transpose([1, 2, 0, 4, 5, 3])
                + r.t3.transpose([2, 0, 1, 5, 3, 4])
                + r.t3.transpose([0, 2, 1, 3, 5, 4])
                + r.t3.transpose([2, 1, 0, 5, 4, 3])
                + r.t3.transpose([1, 0, 2, 4, 3, 5])
                + 2 * r3s) / 12)

        # Solve
        r3_d = - r3u * cc_denom(h.f, 6, 'dir', 'full')

        # symmetrize inital T3
        t3x_sym = ncpd_symmetrize(t3x, {(1, 2, 0, 4, 5, 3): ('ident',),
                                        (2, 0, 1, 5, 3, 4): ('ident',),
                                        (0, 2, 1, 3, 5, 4): ('ident',),
                                        (2, 1, 0, 5, 4, 3): ('ident',),
                                        (1, 0, 2, 4, 3, 5): ('ident',)})
        # 0 1 2 4 3 5 permutation of t3
        t3x_sym_a = [t3x_sym[0], t3x_sym[1], t3x_sym[2], t3x_sym[3],
                     t3x_sym[5], t3x_sym[4], t3x_sym[6]]

        # Build combinations of T for unitary residual
        t3x_u = ncpd_symmetrize(
            t3x_sym,
            {(0, 1, 2, 4, 3, 5): ('neg',),
             (0, 1, 2, 5, 4, 3): ('neg',),
             (0, 1, 2, 3, 5, 4): ('neg',),
             (0, 1, 2, 5, 3, 4): ('ident',),
             (0, 1, 2, 4, 5, 3): ('ident',), },
            weights=[2 / 3, 1 / 3, 1 / 3, 1 / 3, 1 / 6, 1 / 6])

        t3x_au = ncpd_symmetrize(
            t3x_sym_a,
            {(0, 1, 2, 4, 3, 5): ('neg',),
             (0, 1, 2, 5, 4, 3): ('neg',),
             (0, 1, 2, 3, 5, 4): ('neg',),
             (0, 1, 2, 5, 3, 4): ('ident',),
             (0, 1, 2, 4, 5, 3): ('ident',), },
            weights=[2 / 3, 1 / 3, 1 / 3, 1 / 3, 1 / 6, 1 / 6])

        t3 = [f for f in t3x]
        for idx in range(len(t3)):
            g = (als_contract_dense(t3, r3_d, idx,
                                    tensor_format='ncpd')
                 + als_contract_cpd(t3, t3x_u, idx,
                                    tensor_format='ncpd')
                 - als_contract_cpd(t3, t3x_au, idx,
                                    tensor_format='ncpd')
                 )

            s = als_pseudo_inverse(t3, t3, idx)
            f = np.dot(g, s)
            t3[idx] = f

        return Tensors(t1=t1, t2=t2,
                       t3=Tensors(zip(t3names, t3)))
Exemple #5
0
    def calculate_update(self, h, a):
        """
        Calculate new amplitudes
        """

        t2names = ['xlam', 'x1', 'x2', 'x3', 'x4']
        t2x = [a.t2[key] for key in t2names]

        t3names = ['xlam', 'x1', 'x2', 'x3', 'x4', 'x5', 'x6']
        t3x = [a.t3[key] for key in t3names]

        # Running residuals with symmetrized amplitudes.
        # Symmetrization done inside calc_residuals

        r = self.calc_residuals(
            h,
            Tensors(t1=a.t1,
                    t2=Tensors(zip(t2names, t2x)),
                    t3=Tensors(zip(t3names, t3x))))

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

        # Build symmetric residual
        r2 = 1 / 2 * (r.t2 + r.t2.transpose([1, 0, 3, 2]))

        # Solve
        r2_d = -r2 * cc_denom(h.f, 4, 'dir', 'full')

        # symmetrize initial T2
        t2x_sym = ncpd_symmetrize(t2x, {(1, 0, 3, 2): ('ident', )})

        t2 = [f for f in t2x]
        for idx in range(len(t2)):
            g = (als_contract_dense(t2, r2_d, idx, tensor_format='ncpd') +
                 als_contract_cpd(t2, t2x_sym, idx, tensor_format='ncpd'))
            s = als_pseudo_inverse(t2, t2, idx)
            f = np.dot(g, s)
            t2[idx] = f

        # Build symmetric residual
        r3 = ((+r.t3 + r.t3.transpose([1, 2, 0, 4, 5, 3]) + r.t3.transpose(
            [2, 0, 1, 5, 3, 4]) + r.t3.transpose([0, 2, 1, 3, 5, 4]) +
               r.t3.transpose([2, 1, 0, 5, 4, 3]) +
               r.t3.transpose([1, 0, 2, 4, 3, 5])) / 6)

        # Solve
        r3_d = -r3 * cc_denom(h.f, 6, 'dir', 'full')

        # symmetrize initial t3
        t3x_sym = ncpd_symmetrize(
            t3x, {
                (1, 2, 0, 4, 5, 3): ('ident', ),
                (2, 0, 1, 5, 3, 4): ('ident', ),
                (0, 2, 1, 3, 5, 4): ('ident', ),
                (2, 1, 0, 5, 4, 3): ('ident', ),
                (1, 0, 2, 4, 3, 5): ('ident', )
            })

        # 0 1 2 4 3 5 permutation of t3
        t3x_sym_a = [
            t3x_sym[0], t3x_sym[1], t3x_sym[2], t3x_sym[3], t3x_sym[5],
            t3x_sym[4], t3x_sym[6]
        ]

        t3 = [f for f in t3x]
        for idx in range(len(t3)):
            g = (als_contract_dense(t3, r3_d, idx, tensor_format='ncpd') +
                 als_contract_cpd(t3, t3x_sym, idx, tensor_format='ncpd') -
                 als_contract_cpd(t3, t3x_sym_a, idx, tensor_format='ncpd'))

            s = als_pseudo_inverse(t3, t3, idx)
            f = np.dot(g, s)
            t3[idx] = f

        return Tensors(t1=t1,
                       t2=Tensors(zip(t2names, t2)),
                       t3=Tensors(zip(t3names, t3)))