From b4429ce344355d1e51a907dd8566230e7c1373be Mon Sep 17 00:00:00 2001 From: Basil Ibrahim Date: Thu, 5 Dec 2024 19:02:04 +0000 Subject: [PATCH 1/6] Remove call to undefined function UFCI_WaveFunction_w_dummy.check_norb --- vayesta/core/types/wf/fci.py | 1 - 1 file changed, 1 deletion(-) diff --git a/vayesta/core/types/wf/fci.py b/vayesta/core/types/wf/fci.py index 4d900e50..d5e9edef 100644 --- a/vayesta/core/types/wf/fci.py +++ b/vayesta/core/types/wf/fci.py @@ -560,7 +560,6 @@ def make_rdm2(self, ao_basis=False, *args, **kwargs): return (dm2[0][np.ix_(sa, sa, sa, sa)], dm2[1][np.ix_(sa, sa, sb, sb)], dm2[2][np.ix_(sb, sb, sb, sb)]) def as_cisd(self, *args, **kwargs): - self.check_norb() with replace_attr(self, mo=self.dummy_mo): wf_cisd = super().as_cisd(*args, **kwargs) va, vb = self._phys_ind_vir() From aa82225b2286915f5eb059020915b4d70244089b Mon Sep 17 00:00:00 2001 From: Basil Ibrahim Date: Thu, 5 Dec 2024 19:27:18 +0000 Subject: [PATCH 2/6] Fix bug due to type of array initalised by empty list --- vayesta/core/types/wf/fci.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vayesta/core/types/wf/fci.py b/vayesta/core/types/wf/fci.py index d5e9edef..a24083eb 100644 --- a/vayesta/core/types/wf/fci.py +++ b/vayesta/core/types/wf/fci.py @@ -536,11 +536,11 @@ def dummy_mo(self): return type(self.mo)(coeff_w_dummy, occ=self.mo.nocc) def _phys_ind_orbs(self): - return [np.array([i for i in range(y) if i not in x]) for x, y in zip(self.dummy_orbs, self.norb)] + return [np.array([i for i in range(y) if i not in x], dtype=np.int64) for x, y in zip(self.dummy_orbs, self.norb)] def _phys_ind_vir(self): return [ - np.array([i for i in range(y) if i + z not in x]) for x, y, z in zip(self.dummy_orbs, self.nvir, self.nocc) + np.array([i for i in range(y) if i + z not in x], dtype=np.int64) for x, y, z in zip(self.dummy_orbs, self.nvir, self.nocc) ] def make_rdm1(self, ao_basis=False, *args, **kwargs): From 3f7ac985b4fd532f35914e50dbdfff17601f3b4a Mon Sep 17 00:00:00 2001 From: Basil Ibrahim Date: Thu, 5 Dec 2024 21:07:00 +0000 Subject: [PATCH 3/6] Resolve issue for due to padding index mismatch and zero sized indices --- vayesta/ewf/ufragment.py | 80 +++++++++++++++++++++++++++------------- 1 file changed, 54 insertions(+), 26 deletions(-) diff --git a/vayesta/ewf/ufragment.py b/vayesta/ewf/ufragment.py index 8b57f61f..3615dab1 100644 --- a/vayesta/ewf/ufragment.py +++ b/vayesta/ewf/ufragment.py @@ -43,35 +43,9 @@ def get_fragment_energy(self, c1, c2, hamil=None, fock=None, axis1="fragment", c e_corr: float Total fragment correlation energy contribution. """ - nocc = (c2[0].shape[1], c2[-1].shape[1]) - nvir = (c2[0].shape[2], c2[-1].shape[2]) - self.log.debugv("nocc= %d, %d nvir= %d, %d", *nocc, *nvir) - oa, ob = np.s_[: nocc[0]], np.s_[: nocc[1]] - va, vb = np.s_[nocc[0] :], np.s_[nocc[1] :] if axis1 == "fragment": pxa, pxb = self.get_overlap("proj|cluster-occ") - # --- Singles energy (zero for HF-reference) - if c1 is not None: - # if hasattr(eris, 'fock'): - # fa = eris.fock[0][oa,va] - # fb = eris.fock[1][ob,vb] - # else: - # fock = self.base.get_fock() - # fa = dot(self.c_active_occ[0].T, fock[0], self.c_active_vir[0]) - # fb = dot(self.c_active_occ[1].T, fock[1], self.c_active_vir[1]) - if fock is None: - fock = self.base.get_fock_for_energy() - fova = dot(self.cluster.c_active_occ[0].T, fock[0], self.cluster.c_active_vir[0]) - fovb = dot(self.cluster.c_active_occ[1].T, fock[1], self.cluster.c_active_vir[1]) - assert len(c1) == 2 - ca, cb = c1 - if axis1 == "fragment": - e_singles = einsum("ia,xi,xa->", fova, pxa, ca) + einsum("ia,xi,xa->", fovb, pxb, cb) - else: - e_singles = np.sum(fova * ca) + np.sum(fovb * cb) - else: - e_singles = 0 # Doubles energy # TODO: loop to reduce memory? if hamil is None: @@ -80,9 +54,22 @@ def get_fragment_energy(self, c1, c2, hamil=None, fock=None, axis1="fragment", c gab = hamil.get_eris_bare(block="ovOV") gbb = hamil.get_eris_bare(block="OVOV") + nocc = gab.shape[0], gab.shape[2] + nvir = gab.shape[1], gab.shape[3] + self.log.debugv("nocc= %d, %d nvir= %d, %d", *nocc, *nvir) + oa, ob = np.s_[:nocc[0]], np.s_[:nocc[1]] + va, vb = np.s_[:nvir[0]], np.s_[:nvir[1]] + if axis1 == "fragment": assert len(c2) == 4 caa, cab, cba, cbb = c2 + + # Remove padding + caa = caa[oa, oa, va, va] + cab = cab[oa, ob, va, vb] + cba = cba[ob, oa, vb, va] + cbb = cbb[ob, ob, vb, vb] + if c2ba_order == "ab": cba = cba.transpose(1, 0, 3, 2) e_doubles = ( @@ -96,6 +83,10 @@ def get_fragment_energy(self, c1, c2, hamil=None, fock=None, axis1="fragment", c else: assert len(c2) == 3 caa, cab, cbb = c2 + # Remove padding + caa = caa[oa, oa, va, va] + cab = cab[oa, ob, va, vb] + cbb = cbb[ob, ob, vb, vb] e_doubles = ( einsum("ijab,iajb", caa, gaa) / 4 - einsum("ijab,ibja", caa, gaa) / 4 @@ -104,6 +95,43 @@ def get_fragment_energy(self, c1, c2, hamil=None, fock=None, axis1="fragment", c + einsum("ijab,iajb", cab, gab) ) + # --- Singles energy (zero for HF-reference) + if c1 is not None: + # if hasattr(eris, 'fock'): + # fa = eris.fock[0][oa,va] + # fb = eris.fock[1][ob,vb] + # else: + # fock = self.base.get_fock() + # fa = dot(self.c_active_occ[0].T, fock[0], self.c_active_vir[0]) + # fb = dot(self.c_active_occ[1].T, fock[1], self.c_active_vir[1]) + if fock is None: + fock = self.base.get_fock_for_energy() + fova = dot(self.cluster.c_active_occ[0].T, fock[0], self.cluster.c_active_vir[0]) + fovb = dot(self.cluster.c_active_occ[1].T, fock[1], self.cluster.c_active_vir[1]) + assert len(c1) == 2 + ca, cb = c1 + + # Remove padding + ca = ca[oa, va] + cb = cb[ob, vb] + + e_singles = 0 + + if fova.shape[0] != 0 and fova.shape[1] != 0: + if axis1 == "fragment": + e_singles += einsum("ia,xi,xa->", fova, pxa, ca) + else: + e_singles += np.sum(fova * ca) + + if fovb.shape[0] != 0 and fovb.shape[1] != 0: + if axis1 == "fragment": + e_singles += einsum("ia,xi,xa->", fovb, pxb, cb) + else: + e_singles += np.sum(fovb * cb) + + else: + e_singles = 0 + e_singles = self.sym_factor * e_singles e_doubles = self.sym_factor * e_doubles e_corr = e_singles + e_doubles From 09244f9ed1fda9160a32cf21d53409042d035b13 Mon Sep 17 00:00:00 2001 From: Basil Ibrahim Date: Thu, 5 Dec 2024 21:08:16 +0000 Subject: [PATCH 4/6] Formatting --- vayesta/ewf/ufragment.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/vayesta/ewf/ufragment.py b/vayesta/ewf/ufragment.py index 3615dab1..5ff01c97 100644 --- a/vayesta/ewf/ufragment.py +++ b/vayesta/ewf/ufragment.py @@ -83,10 +83,12 @@ def get_fragment_energy(self, c1, c2, hamil=None, fock=None, axis1="fragment", c else: assert len(c2) == 3 caa, cab, cbb = c2 + # Remove padding caa = caa[oa, oa, va, va] cab = cab[oa, ob, va, vb] cbb = cbb[ob, ob, vb, vb] + e_doubles = ( einsum("ijab,iajb", caa, gaa) / 4 - einsum("ijab,ibja", caa, gaa) / 4 From 6748cea5fa6160fccafffd6f0673a3ee97ec48ab Mon Sep 17 00:00:00 2001 From: Basil Ibrahim Date: Fri, 6 Dec 2024 14:29:41 +0000 Subject: [PATCH 5/6] Fix bug --- vayesta/ewf/ufragment.py | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/vayesta/ewf/ufragment.py b/vayesta/ewf/ufragment.py index 5ff01c97..26ebc03f 100644 --- a/vayesta/ewf/ufragment.py +++ b/vayesta/ewf/ufragment.py @@ -45,6 +45,8 @@ def get_fragment_energy(self, c1, c2, hamil=None, fock=None, axis1="fragment", c """ if axis1 == "fragment": pxa, pxb = self.get_overlap("proj|cluster-occ") + oaf, obf = np.s_[: pxa.shape[0]], np.s_[: pxb.shape[0]] + # Doubles energy # TODO: loop to reduce memory? @@ -64,12 +66,25 @@ def get_fragment_energy(self, c1, c2, hamil=None, fock=None, axis1="fragment", c assert len(c2) == 4 caa, cab, cba, cbb = c2 - # Remove padding - caa = caa[oa, oa, va, va] - cab = cab[oa, ob, va, vb] - cba = cba[ob, oa, vb, va] - cbb = cbb[ob, ob, vb, vb] + print('caa: ', caa.shape) + print('cab: ', cab.shape) + print('cba: ', cba.shape) + print('cbb: ', cbb.shape) + # Remove padding + caa = caa[oaf, oa, va, va] + cab = cab[oaf, ob, va, vb] + cba = cba[obf, oa, vb, va] + cbb = cbb[obf, ob, vb, vb] + + print("pxa: ", pxa.shape) + print("gaa: ", gaa.shape) + print("caa: ", caa.shape) + print("gab: ", gab.shape) + print("cab: ", cab.shape) + print("gbb: ", gbb.shape) + print("cbb: ", cbb.shape) + print("pxb: ", pxb.shape) if c2ba_order == "ab": cba = cba.transpose(1, 0, 3, 2) e_doubles = ( @@ -114,8 +129,8 @@ def get_fragment_energy(self, c1, c2, hamil=None, fock=None, axis1="fragment", c ca, cb = c1 # Remove padding - ca = ca[oa, va] - cb = cb[ob, vb] + ca = ca[oaf, va] + cb = cb[obf, vb] e_singles = 0 From 26eefad8fe8df4045e4b877407a5f83f6a60e916 Mon Sep 17 00:00:00 2001 From: Basil Ibrahim Date: Fri, 6 Dec 2024 14:30:35 +0000 Subject: [PATCH 6/6] Remove debug prints --- vayesta/ewf/ufragment.py | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/vayesta/ewf/ufragment.py b/vayesta/ewf/ufragment.py index 26ebc03f..a015d9d6 100644 --- a/vayesta/ewf/ufragment.py +++ b/vayesta/ewf/ufragment.py @@ -47,7 +47,6 @@ def get_fragment_energy(self, c1, c2, hamil=None, fock=None, axis1="fragment", c pxa, pxb = self.get_overlap("proj|cluster-occ") oaf, obf = np.s_[: pxa.shape[0]], np.s_[: pxb.shape[0]] - # Doubles energy # TODO: loop to reduce memory? if hamil is None: @@ -66,25 +65,12 @@ def get_fragment_energy(self, c1, c2, hamil=None, fock=None, axis1="fragment", c assert len(c2) == 4 caa, cab, cba, cbb = c2 - print('caa: ', caa.shape) - print('cab: ', cab.shape) - print('cba: ', cba.shape) - print('cbb: ', cbb.shape) - # Remove padding caa = caa[oaf, oa, va, va] cab = cab[oaf, ob, va, vb] cba = cba[obf, oa, vb, va] cbb = cbb[obf, ob, vb, vb] - print("pxa: ", pxa.shape) - print("gaa: ", gaa.shape) - print("caa: ", caa.shape) - print("gab: ", gab.shape) - print("cab: ", cab.shape) - print("gbb: ", gbb.shape) - print("cbb: ", cbb.shape) - print("pxb: ", pxb.shape) if c2ba_order == "ab": cba = cba.transpose(1, 0, 3, 2) e_doubles = ( @@ -95,6 +81,7 @@ def get_fragment_energy(self, c1, c2, hamil=None, fock=None, axis1="fragment", c + einsum("xi,xjab,iajb", pxa, cab, gab) / 2 + einsum("xi,xjab,jbia", pxb, cba, gab) / 2 ) + else: assert len(c2) == 3 caa, cab, cbb = c2