def test_product_trace_both_nonsymmetric(self): ref = cache.refstate["cn_sto3g"] dipx_mo = ref.operators.electric_dipole[0] mp2diff_mo = adcc.LazyMp(ref).mp2_diffdm mp2diff_nosym = OneParticleOperator(ref.mospaces, is_symmetric=False) dipx_nosym = OneParticleOperator(ref.mospaces, is_symmetric=False) mp2diff_nosym.oo = mp2diff_mo.oo mp2diff_nosym.ov = mp2diff_mo.ov mp2diff_nosym.vv = mp2diff_mo.vv mp2diff_nosym.vo = zeros_like(mp2diff_mo.ov.transpose()) mp2diff_ao = mp2diff_nosym.to_ao_basis(ref) dipx_nosym.oo = dipx_mo.oo dipx_nosym.ov = dipx_mo.ov dipx_nosym.vv = dipx_mo.vv dipx_nosym.vo = zeros_like(dipx_mo.ov.transpose()) dipx_ao = dipx_nosym.to_ao_basis(ref) mp2a = mp2diff_ao[0].to_ndarray() mp2b = mp2diff_ao[1].to_ndarray() dipxa = dipx_ao[0].to_ndarray() dipxb = dipx_ao[1].to_ndarray() dipx_ref = np.sum(mp2a * dipxa) + np.sum(mp2b * dipxb) oo = np.sum(mp2diff_nosym.oo.to_ndarray() * dipx_nosym.oo.to_ndarray()) ov = np.sum(mp2diff_nosym.ov.to_ndarray() * dipx_nosym.ov.to_ndarray()) vo = np.sum(mp2diff_nosym.vo.to_ndarray() * dipx_nosym.vo.to_ndarray()) vv = np.sum(mp2diff_nosym.vv.to_ndarray() * dipx_nosym.vv.to_ndarray()) dipx_np = oo + ov + vo + vv assert dipx_np == approx(product_trace(mp2diff_nosym, dipx_nosym)) assert product_trace(mp2diff_nosym, dipx_nosym) == approx(dipx_ref) assert product_trace(dipx_nosym, mp2diff_nosym) == approx(dipx_ref)
def test_block_functions(self): ref = cache.refstate["h2o_sto3g"] a = OneParticleOperator(ref.mospaces, is_symmetric=True) # no AO transformation with only zero blocks possible with raises(ValueError): a.to_ao_basis(ref) a.oo.set_random() a.ov.set_random() a.vv.set_random() assert a.size == a.shape[0] * a.shape[1] assert not a.is_zero_block("v1o1") a.set_zero_block("o1o1") assert a.is_zero_block("o1o1") # access to zero blocks forbidden via block function with raises(KeyError): a.block("o1o1") # invalid block names with raises(KeyError): a["xyz"] with raises(KeyError): a["xyz"] = a.oo with raises(KeyError): a.set_zero_block("xyz") # invalid tensor shape with raises(ValueError): a.oo = a.ov # shortcuts np.testing.assert_allclose(a.oo.to_ndarray(), a["o1o1"].to_ndarray())