Exemple #1
0
    def template_nontrivial_contraction(self, case):
        refstate = cache.refstate[case]
        f_oo = empty_like(refstate.fock("o1o1")).set_random()
        f_vv = empty_like(refstate.fock("v1v1")).set_random()
        i1 = empty_like(refstate.fock("v1v1")).set_random()
        i2 = empty_like(refstate.fock("o1o1")).set_random()
        oovv = empty_like(refstate.eri("o1o1v1v1")).set_random()
        ovov = empty_like(refstate.eri("o1v1o1v1")).set_random()
        t2 = empty_like(refstate.eri("o1o1v1v1")).set_random()
        u1 = empty_like(refstate.fock("o1v1")).set_random()
        nf_oo = f_oo.to_ndarray()
        nf_vv = f_vv.to_ndarray()
        ni1 = i1.to_ndarray()
        ni2 = i2.to_ndarray()
        noovv = oovv.to_ndarray()
        novov = ovov.to_ndarray()
        nt2 = t2.to_ndarray()
        nu1 = u1.to_ndarray()

        # (Slightly) modified ADC(2) singles block equation
        res = (+einsum("ib,ab->ia", u1, f_vv + i1) -
               einsum("ij,ja->ia", f_oo - i2, u1) -
               einsum("jaib,jb->ia", ovov, u1) -
               0.5 * einsum("ijab,jkbc,kc->ia", t2, oovv, u1) -
               0.5 * einsum("ijab,jkbc,kc->ia", oovv, t2, u1))
        ref = (+np.einsum("ib,ab->ia", nu1, nf_vv + ni1) -
               np.einsum("ij,ja->ia", nf_oo - ni2, nu1) -
               np.einsum("jaib,jb->ia", novov, nu1) -
               0.5 * np.einsum("ijab,jkbc,kc->ia", nt2, noovv, nu1) -
               0.5 * np.einsum("ijab,jkbc,kc->ia", noovv, nt2, nu1))

        assert res.needs_evaluation
        assert_allclose(res.to_ndarray(), ref, rtol=1e-10, atol=1e-14)
Exemple #2
0
    def test_nontrivial_trace(self):
        import libadcc

        refstate = cache.refstate["cn_sto3g"]
        oovv = empty_like(refstate.eri("o1o1v1v1")).set_random()
        ovov = empty_like(refstate.eri("o1v1o1v1")).set_random()
        noovv = oovv.to_ndarray()
        novov = ovov.to_ndarray()

        res = libadcc.trace("iaai", einsum("ijab,kcja->icbk", oovv, ovov))
        ref = np.einsum("ijab,ibja->", noovv, novov)
        assert_allclose(res, ref, rtol=1e-10, atol=1e-14)
Exemple #3
0
    def test_nontrivial_diagonal(self):
        refstate = cache.refstate["cn_sto3g"]
        mtcs = [
            nosym_like(refstate.eri("o1o1v1v1")).set_random(),
            nosym_like(refstate.eri("o1v1o1v1")).set_random(),
            nosym_like(refstate.eri("o1o1v1v1")).set_random()
        ]
        mnps = [m.to_ndarray() for m in mtcs]

        res = einsum("ijab,ibkc,kjad->cd", mtcs[0], mtcs[1],
                     mtcs[2]).diagonal()
        ref = np.einsum("ijab,ibkc,kjad->cd", mnps[0], mnps[1],
                        mnps[2]).diagonal()

        assert res.needs_evaluation
        assert_allclose(res.to_ndarray(), ref, rtol=1e-10, atol=1e-14)
Exemple #4
0
    def test_nontrivial_direct_sum(self):
        refstate = cache.refstate["cn_sto3g"]
        oeo = nosym_like(refstate.orbital_energies("o1")).set_random()
        oovv = empty_like(refstate.eri("o1o1v1v1")).set_random()
        oev = nosym_like(refstate.orbital_energies("v1")).set_random()

        interm = np.einsum("ijac,ijcb->ab", oovv.to_ndarray(),
                           oovv.to_ndarray())
        ref = (interm[:, :, None, None] -
               oeo.to_ndarray()[None, None, :, None] -
               oev.to_ndarray()[None, None, None, :])
        ref = ref.transpose((2, 0, 3, 1))

        res = direct_sum("ab-i-c->iacb", einsum("ijac,ijcb->ab", oovv, oovv),
                         oeo, oev)
        assert_allclose(res.to_ndarray(), ref, rtol=1e-10, atol=1e-14)
Exemple #5
0
 def base_test(self, contr, *arr):
     arr = [a.set_random() for a in arr]
     ref = np.einsum(contr, *[a.to_ndarray() for a in arr])
     out = einsum(contr, *arr)
     assert_allclose(out.to_ndarray(), ref, rtol=1e-10, atol=1e-14)
Exemple #6
0
 def test_partial_trace(self):
     refstate = cache.refstate["h2o_sto3g"]
     a = empty_like(refstate.ovov)
     b = empty_like(refstate.fvv)
     with pytest.raises(NotImplementedError, match=r"Partial traces.*"):
         einsum("iaib,ba->a", a, b)