def test_class(self): """Tests container behavior (frozen vs non-frozen).""" for frozen in (1, [0, 1]): try: model = ktd.TDRHF(self.model_krhf, frozen=frozen) model.nroots = self.td_model_krhf.nroots model.kernel() e = numpy.concatenate(tuple(model.e[i] for i in range(self.k))) ref_e = numpy.concatenate( tuple(self.td_model_krhf.e[i] for i in range(self.k))) testing.assert_allclose(e, ref_e, atol=1e-4) mask_o, mask_v = tdhf_frozen_mask(model.eri, kind="o,v") for k in range(self.k): try: assert_vectors_close( model.xy[k], numpy.array( self.td_model_krhf.xy[k])[..., mask_o, :][..., mask_v], atol=1e-3) except Exception: print( "When comparing vectors @k={:d} the following exception occurred:" .format(k)) raise except Exception: print( "When testing class with frozen={} the following exception occurred:" .format(repr(frozen))) raise
def test_eri(self): """Tests all ERI implementations: with and without symmetries.""" for eri in (PhysERI, PhysERI4, PhysERI8): # Test plain try: e = eri(self.model_rhf) m = e.tdhf_full_form() # Test matrix vs ref testing.assert_allclose(m, retrieve_m_hf(e), atol=1e-14) # Test matrix vs pyscf testing.assert_allclose(self.ref_m, m, atol=1e-14) vals, vecs = eig(m, nroots=self.td_model_rhf.nroots) testing.assert_allclose(vals, self.td_model_rhf.e, atol=1e-5) except Exception: print("When testing {} the following exception occurred:".format(eri)) raise # Test frozen for frozen in (1, [0, -1]): try: e = eri(self.model_rhf, frozen=frozen) m = e.tdhf_full_form() ov_mask = tdhf_frozen_mask(e) ref_m = self.ref_m[numpy.ix_(ov_mask, ov_mask)] testing.assert_allclose(ref_m, m, atol=1e-14) except Exception: print("When testing {} with frozen={} the following exception occurred:".format(eri, repr(frozen))) raise
def test_class_frozen(self): """Tests container behavior.""" for frozen in (1, [0, -1]): try: model = TDProxy(self.model_rks, "dft", frozen=frozen) model.nroots = self.td_model_rks.nroots model.kernel() mask_o, mask_v = tdhf_frozen_mask(model.eri, kind="o,v") testing.assert_allclose(model.e, self.td_model_rks.e, atol=1e-3) assert_vectors_close(model.xy, numpy.array(self.td_model_rks.xy)[..., mask_o, :][..., mask_v], atol=1e-3) except Exception: print("When testing class with frozen={} the following exception occurred:".format(repr(frozen))) raise
def test_eri(self): """Tests all ERI implementations: with and without symmetries.""" e = PhysERI(self.model_rks, "dft") mk, _ = e.tdhf_mk_form() testing.assert_allclose(self.ref_m, mk, atol=1e-13) # Test frozen for frozen in (1, [0, -1]): try: e = PhysERI(self.model_rks, "dft", frozen=frozen) mk, _ = e.tdhf_mk_form() ov_mask = tdhf_frozen_mask(e, kind="1ov") ref_m = self.ref_m[numpy.ix_(ov_mask, ov_mask)] testing.assert_allclose(ref_m, mk, atol=1e-13) except Exception: print("When testing with frozen={} the following exception occurred:".format(repr(frozen))) raise
def test_class(self): """Tests container behavior (frozen vs non-frozen).""" for frozen in (1, [0, 1]): try: model = ktd.TDRHF(self.model_krhf, frozen=frozen) model.nroots = self.td_model_krhf.nroots model.kernel() mask_o, mask_v = tdhf_frozen_mask(model.eri, kind="o,v") testing.assert_allclose(model.e, self.td_model_krhf.e, atol=1e-4) assert_vectors_close( model.xy, numpy.array(self.td_model_krhf.xy)[..., mask_o, :][..., mask_v], atol=1e-3, ) except Exception: print( "When testing class with frozen={} the following exception occurred:" .format(repr(frozen))) raise