From ad53183663f655a90722f4966e26ad54150e3a5d Mon Sep 17 00:00:00 2001 From: Qiming Sun Date: Mon, 26 Aug 2024 21:55:27 -0700 Subject: [PATCH] Update tests --- pyscf/pbc/tdscf/krhf.py | 2 +- pyscf/pbc/tdscf/test/test_krhf.py | 8 +++++--- pyscf/pbc/tdscf/test/test_krks.py | 2 +- pyscf/pbc/tdscf/test/test_kuhf.py | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/pyscf/pbc/tdscf/krhf.py b/pyscf/pbc/tdscf/krhf.py index 1abe6bcbf7..30e9557f8d 100644 --- a/pyscf/pbc/tdscf/krhf.py +++ b/pyscf/pbc/tdscf/krhf.py @@ -279,7 +279,7 @@ def init_guess(self, mf, kshift, nstates=None): nov = e_ia.size nstates = min(nstates, nov) - e_threshold = numpy.sort(e_ia)[nstates-1] + e_threshold = numpy.partition(e_ia, nstates-1)[nstates-1] e_threshold += self.deg_eia_thresh idx = numpy.where(e_ia <= e_threshold)[0] diff --git a/pyscf/pbc/tdscf/test/test_krhf.py b/pyscf/pbc/tdscf/test/test_krhf.py index 8a2a9e5d70..dbaf765e56 100644 --- a/pyscf/pbc/tdscf/test/test_krhf.py +++ b/pyscf/pbc/tdscf/test/test_krhf.py @@ -116,11 +116,13 @@ def test_tda_triplet(self): self.kernel(tdscf.KTDA, ref, np.arange(2), singlet=False) def test_tdhf_singlet(self): - ref = [[10.60761946, 10.76654619]] - td = self.kernel(tdscf.KTDHF, ref, [0], conv_tol=1e-7) + # The first state can be obtained by solving nstates=9 + #ref = [[10.60761946, 10.76654619, 10.76654619]] + ref = [[10.76654619, 10.76654619]] + td = self.kernel(tdscf.KTDHF, ref, [0]) a0, b0 = td.get_ab(kshift=0) eref0 = diagonalize(a0, b0) - self.assertAlmostEqual(abs(td.e[0][:2] - eref0[:2]).max(), 0, 5) + self.assertAlmostEqual(abs(td.e[0][:2] - eref0[1:3]).max(), 0, 5) nk, no, nv = a0.shape[:3] nkov = nk * no * nv diff --git a/pyscf/pbc/tdscf/test/test_krks.py b/pyscf/pbc/tdscf/test/test_krks.py index 2a39e9f99b..552bca30b1 100644 --- a/pyscf/pbc/tdscf/test/test_krks.py +++ b/pyscf/pbc/tdscf/test/test_krks.py @@ -157,7 +157,7 @@ def test_tda_triplet(self): self.kernel('TDA', ref, singlet=False) def test_tdhf_singlet(self): - ref = [[9.2519208050, 9.3208025447]] + ref = [[9.25192096, 9.32080304]] td = self.kernel('TDDFT', ref) a, b = td.get_ab(kshift=0) eref = diagonalize(a, b) diff --git a/pyscf/pbc/tdscf/test/test_kuhf.py b/pyscf/pbc/tdscf/test/test_kuhf.py index 63e09c3342..4f306ee6cc 100644 --- a/pyscf/pbc/tdscf/test/test_kuhf.py +++ b/pyscf/pbc/tdscf/test/test_kuhf.py @@ -68,7 +68,7 @@ def test_tda(self): def test_tdhf(self): # same as lowest roots in Diamond->test_tdhf_singlet/triplet in test_krhf.py ref = [[5.9794378466, 5.9794378466]] - self.kernel(tdscf.KTDHF, ref, [0], conv_tol=1e-7) + self.kernel(tdscf.KTDHF, ref, [0]) class WaterBigBox(unittest.TestCase):