Skip to content

Commit

Permalink
Issues #54 and #65: fcisolver max_memory?
Browse files Browse the repository at this point in the history
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?
  • Loading branch information
MatthewRHermes committed Feb 5, 2024
1 parent c46847a commit 21a1a51
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 5 deletions.
7 changes: 7 additions & 0 deletions my_pyscf/fci/csf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion my_pyscf/mcscf/lasci.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions my_pyscf/mcscf/lasci_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions my_pyscf/mcscf/lasscf_async/crunch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions my_pyscf/mcscf/mc1step_csf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 21a1a51

Please sign in to comment.