From e90d8342e29446365f8570682af4a65fe16be27c Mon Sep 17 00:00:00 2001 From: Qiming Sun Date: Tue, 29 Aug 2023 08:02:36 -0700 Subject: [PATCH] Fix the edge case CAS(2,2) for Selected CI (issue #1808) (#1845) * Fix the edge case CAS(2,2) for Selected CI (issue #1808) * Fix test --- pyscf/fci/selected_ci.py | 2 +- pyscf/fci/test/test_selected_ci.py | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/pyscf/fci/selected_ci.py b/pyscf/fci/selected_ci.py index c51b8a811a..14aae7861c 100644 --- a/pyscf/fci/selected_ci.py +++ b/pyscf/fci/selected_ci.py @@ -115,7 +115,7 @@ def select_strs(myci, eri, eri_pq_max, civec_max, strs, norb, nelec): strs = numpy.asarray(strs, dtype=numpy.int64) nstrs = len(strs) nvir = norb - nelec - strs_add = numpy.empty((nstrs*(nelec*nvir)**2//4), dtype=numpy.int64) + strs_add = numpy.empty((nstrs*((nelec+1)*(nvir+1))**2//4), dtype=numpy.int64) libfci.SCIselect_strs.restype = ctypes.c_int nadd = libfci.SCIselect_strs(strs_add.ctypes.data_as(ctypes.c_void_p), strs.ctypes.data_as(ctypes.c_void_p), diff --git a/pyscf/fci/test/test_selected_ci.py b/pyscf/fci/test/test_selected_ci.py index b138f8468d..1300ea63cf 100644 --- a/pyscf/fci/test/test_selected_ci.py +++ b/pyscf/fci/test/test_selected_ci.py @@ -495,6 +495,16 @@ def test_guess_wfnsym(self): ci0[:] = 0 self.assertRaises(RuntimeError, cis.guess_wfnsym, norb, nelec, ci0, wfnsym=1) + # The edge case CAS(2, 2). issue #1808 + def test_cas_2_2(self): + mol = gto.M(atom='H 0 0 0; H 0 0 1.') + mc = mol.RHF().run().CASCI(2, 2) + mc.fcisolver = fci.SCI(mol) + mc.run() + self.assertAlmostEqual(mc.e_tot, -1.1011503302326, 9) + self.assertAlmostEqual(abs(mc.ci[0,0]), .984513596, 5) + self.assertAlmostEqual(abs(mc.ci[1,1]), .175308242, 5) + def gen_des_linkstr(strs, norb, nelec): '''Given intermediates, the link table to generate input strs @@ -691,4 +701,3 @@ def select_strs(myci, eri, eri_pq_max, civec_max, strs, norb, nelec): if __name__ == "__main__": print("Full Tests for selected_ci") unittest.main() -