From 21a1a51ffbf3f92b47fe91774016ac022292cb11 Mon Sep 17 00:00:00 2001 From: Matthew R Hermes Date: Mon, 5 Feb 2024 11:12:03 -0600 Subject: [PATCH] Issues #54 and #65: fcisolver max_memory? PySCF apparently wants "remaining memory" on entry to fcisolver kernel. CSFSolver currently wants "maximum memory" (the config input by user) instead. Fix calling lines in LASSCF functions to the CSFSolver behavior for now. Maybe the CSFSolver behavior needs to change? Maybe the PySCF behavior needs to change? --- my_pyscf/fci/csf.py | 7 +++++++ my_pyscf/mcscf/lasci.py | 1 - my_pyscf/mcscf/lasci_sync.py | 3 +++ my_pyscf/mcscf/lasscf_async/crunch.py | 5 +++-- my_pyscf/mcscf/mc1step_csf.py | 5 +++-- 5 files changed, 16 insertions(+), 5 deletions(-) diff --git a/my_pyscf/fci/csf.py b/my_pyscf/fci/csf.py index a6dba6d3..138fb87e 100644 --- a/my_pyscf/fci/csf.py +++ b/my_pyscf/fci/csf.py @@ -92,6 +92,10 @@ def make_hdiag_csf (h1e, eri, norb, nelec, transformer, hdiag_det=None, max_memo csd_offset = npair_csd_offset[ipair] det_addr = transformer.csd_mask[csd_offset:][:nconf*ndet] # mem safety + # Issue #54: PySCF wants "max_memory" on entrance to FCI to be "remaining memory". However, + # the first few lines of this function consume some memory, so that's difficult to + # implement consistently. "max_memory" here is currently the config parameter for the whole + # calculation. mem_remaining = max_memory - lib.current_memory ()[0] safety_factor = 1.2 nfloats = nconf*ndet*ndet + det_addr.size @@ -284,6 +288,9 @@ def pspace (fci, h1e, eri, norb, nelec, transformer, hdiag_det=None, hdiag_csf=N safety_factor = 1.2 nfloats_h0 = (npsp_det+npsp)**2 mem_h0 = safety_factor * nfloats_h0 * np.dtype (float).itemsize / 1e6 + # Issue #54: PySCF wants "max_memory" on entrance to FCI to be "remaining memory". However, + # the earlier lines of this function consume some memory, so that's difficult to implement + # consistently. "max_memory" here is currently the config parameter for the whole calculation. mem_remaining = max_memory - lib.current_memory ()[0] memstr = ("pspace_size of {} CSFs -> {} determinants requires {} MB, cf {} MB " "remaining memory").format (npsp, npsp_det, mem_h0, mem_remaining) diff --git a/my_pyscf/mcscf/lasci.py b/my_pyscf/mcscf/lasci.py index 072a0325..5c4f0bda 100644 --- a/my_pyscf/mcscf/lasci.py +++ b/my_pyscf/mcscf/lasci.py @@ -181,7 +181,6 @@ def get_grad_ci (las, mo_coeff=None, ci=None, h1eff_sub=None, h2eff_sub=None, ve for isub, (fcibox, h1e, ci0, ncas, nelecas) in enumerate (zip ( las.fciboxes, h1eff_sub, ci, las.ncas_sub, las.nelecas_sub)): eri_cas = las.get_h2eff_slice (h2eff_sub, isub, compact=8) - max_memory = max(400, las.max_memory-lib.current_memory()[0]) linkstrl = fcibox.states_gen_linkstr (ncas, nelecas, True) linkstr = fcibox.states_gen_linkstr (ncas, nelecas, False) h2eff = fcibox.states_absorb_h1e(h1e, eri_cas, ncas, nelecas, .5) diff --git a/my_pyscf/mcscf/lasci_sync.py b/my_pyscf/mcscf/lasci_sync.py index 8934e30f..c64f5f46 100644 --- a/my_pyscf/mcscf/lasci_sync.py +++ b/my_pyscf/mcscf/lasci_sync.py @@ -263,6 +263,8 @@ def ci_cycle (las, mo, ci0, veff, h2eff_sub, casdm1frs, log): las.nelecas_sub, h1eff_sub, ci0)): eri_cas = las.get_h2eff_slice (h2eff_sub, isub, compact=8) + #max_memory = max(400, las.max_memory-lib.current_memory()[0]) + # Issue #54: compute max_memory here, or in fcisolver? orbsym = getattr (mo, 'orbsym', None) if orbsym is not None: i = ncas_cum[isub] @@ -288,6 +290,7 @@ def ci_cycle (las, mo, ci0, veff, h2eff_sub, casdm1frs, log): e_sub, fcivec = fcibox.kernel(h1e, eri_cas, ncas, nelecas, ci0=fcivec, verbose=log, + #max_memory = max_memory issue #54 ecore=e0, orbsym=orbsym) e_cas.append (e_sub) ci1.append (fcivec) diff --git a/my_pyscf/mcscf/lasscf_async/crunch.py b/my_pyscf/mcscf/lasscf_async/crunch.py index 52978cbf..00fcb546 100644 --- a/my_pyscf/mcscf/lasscf_async/crunch.py +++ b/my_pyscf/mcscf/lasscf_async/crunch.py @@ -292,10 +292,11 @@ def casci_kernel(casci, mo_coeff=None, ci0=None, verbose=logger.NOTE, envs=None) (mo_coeff.shape[1], casci.ncore, ncas)) # FCI - max_memory = max(400, casci.max_memory-lib.current_memory()[0]) + #max_memory = max(400, casci.max_memory-lib.current_memory()[0]) + # Issue #54: count memory here, or in FCISolver? e_tot, fcivec = casci.fcisolver.kernel(h1eff, eri_cas, ncas, nelecas, ci0=ci0, verbose=log, - max_memory=max_memory, + #max_memory=max_memory, ecore=energy_core) t1 = log.timer('FCI solver', *t1) diff --git a/my_pyscf/mcscf/mc1step_csf.py b/my_pyscf/mcscf/mc1step_csf.py index c11dc311..5a5b81e8 100644 --- a/my_pyscf/mcscf/mc1step_csf.py +++ b/my_pyscf/mcscf/mc1step_csf.py @@ -58,9 +58,10 @@ def contract_2e(c): if mc.ci_response_space > 7: logger.debug(mc, 'CI step by full response') # full response - max_memory = max(400, mc.max_memory-lib.current_memory()[0]) + #max_memory = max(400, mc.max_memory-lib.current_memory()[0]) + # Issue #54: count memory here, or in fcisolver? e, ci1 = mc.fcisolver.kernel(h1, h2, ncas, nelecas, ecore=ecore, - ci0=ci0, tol=tol, max_memory=max_memory) + ci0=ci0, tol=tol)#, max_memory=max_memory) else: # MRH 03/24/2019: this is where I intervene to enforce CSFs fci = mc.fcisolver