From e0abe469597bd6585e228d1abeac8f740463d6cd Mon Sep 17 00:00:00 2001 From: Matthew R Hermes Date: Mon, 27 Apr 2026 10:36:54 -0500 Subject: [PATCH 01/10] Warning for incorrect mem arg in csfstring Instead of raising an exception when "max_memory" gets incorrectly turned into "remaining memory", do a warning. --- pyscf/csf_fci/csfstring.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pyscf/csf_fci/csfstring.py b/pyscf/csf_fci/csfstring.py index 390d18e0b..a56706fdf 100644 --- a/pyscf/csf_fci/csfstring.py +++ b/pyscf/csf_fci/csfstring.py @@ -1,6 +1,7 @@ import numpy as np import sys, os, time import ctypes +import warnings from pyscf.csf_fci import csdstring from pyscf.fci import cistring from pyscf.fci.spin_op import spin_square0 @@ -935,6 +936,11 @@ def get_spin_evecs (nspin, neleca, nelecb, smult, max_memory=param.MAX_MEMORY): mem_current = lib.current_memory ()[0] mem_rem = max_memory - mem_current mem_reqd = ndet * ncsf * np.dtype (np.float64).itemsize / 1e6 + if max_memory < 0: + warnings.warn ("Negative max_memory ({} MB)".format (max_memory), RuntimeWarning) + elif mem_rem < 0: + warnings.warn ("Negative available memory ({} - {} = {} MB)".format ( + mem_current, max_memory, mem_rem), RuntimeWarning) if mem_reqd > mem_rem: memstr = ('CSF unitary matrix for {} unpaired of {} total electrons w/ s={:.1f} is too big' " ({} MB req'd of {} MB remaining; {} MB total available)").format ( From b06084e5d230d0b89f6d23a6fb524aea93352a6b Mon Sep 17 00:00:00 2001 From: Matthew R Hermes Date: Tue, 28 Apr 2026 14:12:45 -0500 Subject: [PATCH 02/10] Don't actually raise the exception if you warn --- pyscf/csf_fci/csfstring.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyscf/csf_fci/csfstring.py b/pyscf/csf_fci/csfstring.py index a56706fdf..d960e4e36 100644 --- a/pyscf/csf_fci/csfstring.py +++ b/pyscf/csf_fci/csfstring.py @@ -941,7 +941,7 @@ def get_spin_evecs (nspin, neleca, nelecb, smult, max_memory=param.MAX_MEMORY): elif mem_rem < 0: warnings.warn ("Negative available memory ({} - {} = {} MB)".format ( mem_current, max_memory, mem_rem), RuntimeWarning) - if mem_reqd > mem_rem: + elif mem_reqd > mem_rem: memstr = ('CSF unitary matrix for {} unpaired of {} total electrons w/ s={:.1f} is too big' " ({} MB req'd of {} MB remaining; {} MB total available)").format ( nspin, neleca+nelecb, s, mem_reqd, mem_rem, max_memory) From d5e860b0151aeaec41ea62d9c541143a935c1209 Mon Sep 17 00:00:00 2001 From: Matthew R Hermes Date: Thu, 30 Apr 2026 11:42:21 -0500 Subject: [PATCH 03/10] Fix csf fci kernel max_memory kwarg Since this is only ever passed with "remaining memory" rather than actual max memory, just add back the consumed memory that was just subtracted from it to get the "real" number. --- pyscf/csf_fci/csf.py | 3 +++ pyscf/csf_fci/csf_symm.py | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/pyscf/csf_fci/csf.py b/pyscf/csf_fci/csf.py index 2cd347d04..b262c2c8b 100644 --- a/pyscf/csf_fci/csf.py +++ b/pyscf/csf_fci/csf.py @@ -566,6 +566,9 @@ def get_init_guess(self, norb, nelec, nroots, hdiag_csf, **kwargs): return get_init_guess (norb, nelec, nroots, hdiag_csf, self.transformer) def kernel(self, h1e, eri, norb, nelec, ci0=None, **kwargs): + # Assume we are passed "remaining memory" if max_memory is a kwarg + if 'max_memory' in kwargs: + kwargs['max_memory'] += lib.current_memory ()[0] self.norb = norb self.nelec = nelec if 'smult' in kwargs: diff --git a/pyscf/csf_fci/csf_symm.py b/pyscf/csf_fci/csf_symm.py index 415e77aea..731329c5b 100644 --- a/pyscf/csf_fci/csf_symm.py +++ b/pyscf/csf_fci/csf_symm.py @@ -34,6 +34,10 @@ def kernel(self, h1e, eri, norb, nelec, ci0=None, **kwargs): ''' Over the top of the existing kernel, I just need to set the parameters and cache values related to spin. ...and electron configuration point group ''' + + # Assume we are passed "remaining memory" if max_memory is a kwarg + if 'max_memory' in kwargs: + kwargs['max_memory'] += lib.current_memory ()[0] log = logger.new_logger (self, self.verbose) gpname = getattr (self.mol, 'groupname', None) if gpname in ('Dooh', 'Coov'): From d1f99d8846aab32b94677a01bccec56639e9dee4 Mon Sep 17 00:00:00 2001 From: Matthew R Hermes Date: Thu, 30 Apr 2026 12:06:13 -0500 Subject: [PATCH 04/10] fix occri for non-square mo_coeff arrays Since there is an automatic pruning of linear dependencies now in core-module SCF. --- pyscf/occri/__init__.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pyscf/occri/__init__.py b/pyscf/occri/__init__.py index b711f0fd0..3108805b9 100644 --- a/pyscf/occri/__init__.py +++ b/pyscf/occri/__init__.py @@ -229,15 +229,17 @@ def get_jk( dm_shape = dm.shape nk = self.kpts.shape[0] nao = cell.nao + ndm = dm.reshape (-1, nk, nao, nao).shape[0] if with_k: if self.scf_iter == 0: dm = numpy.asarray(dm) if getattr(dm, 'mo_coeff', None) is None: dm = self.make_natural_orbitals(dm.reshape(-1, nk, nao, nao)) else: - mo_coeff = numpy.asarray(dm.mo_coeff).reshape(-1, nk, nao, nao) - mo_occ = numpy.asarray(dm.mo_occ).reshape(-1, nk, nao) - dm = lib.tag_array(dm.reshape(-1, nk, nao, nao), mo_coeff=mo_coeff, mo_occ=mo_occ) + mo_occ = numpy.asarray(dm.mo_occ).reshape(ndm, nk, -1) + nmo = mo_occ.shape[2] + mo_coeff = numpy.asarray(dm.mo_coeff).reshape(ndm, nk, nao, nmo) + dm = lib.tag_array(dm.reshape(ndm, nk, nao, nao), mo_coeff=mo_coeff, mo_occ=mo_occ) if with_j: vj = self.get_j(self, dm, kpts=self.kpts) From 9569df89972ec569608c039dcf0f0040d403ea3c Mon Sep 17 00:00:00 2001 From: Matthew R Hermes Date: Thu, 30 Apr 2026 13:01:30 -0500 Subject: [PATCH 05/10] import lib in csf_symm --- pyscf/csf_fci/csf_symm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyscf/csf_fci/csf_symm.py b/pyscf/csf_fci/csf_symm.py index 731329c5b..c8367eed3 100644 --- a/pyscf/csf_fci/csf_symm.py +++ b/pyscf/csf_fci/csf_symm.py @@ -1,6 +1,6 @@ import numpy as np import scipy -from pyscf import symm, __config__ +from pyscf import symm, __config__, lib from pyscf.lib import logger, davidson1 from pyscf.fci import direct_spin1_symm, cistring, direct_uhf from pyscf.lib.numpy_helper import tag_array From a677d99be8873fafd81d6fd7ce7ff6abdc578844 Mon Sep 17 00:00:00 2001 From: Matthew R Hermes Date: Thu, 30 Apr 2026 13:20:10 -0500 Subject: [PATCH 06/10] FIXME note for trexio bug --- pyscf/tools/trexio.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pyscf/tools/trexio.py b/pyscf/tools/trexio.py index 681884c0d..0a4a65d0a 100644 --- a/pyscf/tools/trexio.py +++ b/pyscf/tools/trexio.py @@ -726,6 +726,7 @@ def _scf_to_trexio(mf, trexio_file): if _trexio_is_uhf_uks_mf(mf): mo_type = "UHF" # Check for split structure (common in KUKS/KDF): ([up...], [dn...]) + # FIXME: this is now an ndarray rather than a tuple in PySCF 2.13.0 is_split_spin = isinstance(mf.mo_coeff, tuple) and len(mf.mo_coeff) == 2 for i_k, _ in enumerate(kpts): From 2f16fe71c12508f810c8eb9f0ba21ad41a2091b0 Mon Sep 17 00:00:00 2001 From: Matthew R Hermes Date: Thu, 30 Apr 2026 15:24:53 -0500 Subject: [PATCH 07/10] get rid of negative memory safety net? --- pyscf/csf_fci/csfstring.py | 3 --- pyscf/csf_fci/test/test_csfstring.py | 1 + 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/pyscf/csf_fci/csfstring.py b/pyscf/csf_fci/csfstring.py index d960e4e36..c151df9ac 100644 --- a/pyscf/csf_fci/csfstring.py +++ b/pyscf/csf_fci/csfstring.py @@ -938,9 +938,6 @@ def get_spin_evecs (nspin, neleca, nelecb, smult, max_memory=param.MAX_MEMORY): mem_reqd = ndet * ncsf * np.dtype (np.float64).itemsize / 1e6 if max_memory < 0: warnings.warn ("Negative max_memory ({} MB)".format (max_memory), RuntimeWarning) - elif mem_rem < 0: - warnings.warn ("Negative available memory ({} - {} = {} MB)".format ( - mem_current, max_memory, mem_rem), RuntimeWarning) elif mem_reqd > mem_rem: memstr = ('CSF unitary matrix for {} unpaired of {} total electrons w/ s={:.1f} is too big' " ({} MB req'd of {} MB remaining; {} MB total available)").format ( diff --git a/pyscf/csf_fci/test/test_csfstring.py b/pyscf/csf_fci/test/test_csfstring.py index 1e465bfca..0424a1150 100644 --- a/pyscf/csf_fci/test/test_csfstring.py +++ b/pyscf/csf_fci/test/test_csfstring.py @@ -2,6 +2,7 @@ import numpy as np from scipy import special from pyscf.csf_fci.csfstring import * +from pyscf import lib def case_spin_evecs (ks, nspin, ms): neleca = int (round (nspin/2 + ms)) From 8c6ed5df06550cb21256c0f73c2de0c2375512e2 Mon Sep 17 00:00:00 2001 From: Matthew R Hermes Date: Thu, 30 Apr 2026 15:28:36 -0500 Subject: [PATCH 08/10] Fix the trexio incompatibility (ndarray vs tuple) --- pyscf/tools/trexio.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pyscf/tools/trexio.py b/pyscf/tools/trexio.py index 0a4a65d0a..22af2f576 100644 --- a/pyscf/tools/trexio.py +++ b/pyscf/tools/trexio.py @@ -726,8 +726,7 @@ def _scf_to_trexio(mf, trexio_file): if _trexio_is_uhf_uks_mf(mf): mo_type = "UHF" # Check for split structure (common in KUKS/KDF): ([up...], [dn...]) - # FIXME: this is now an ndarray rather than a tuple in PySCF 2.13.0 - is_split_spin = isinstance(mf.mo_coeff, tuple) and len(mf.mo_coeff) == 2 + is_split_spin = (mf.mo_coeff.ndim==4) and (mf.mo_coeff.shape[0]==2) for i_k, _ in enumerate(kpts): if is_split_spin: From 13c061e222006ab6cb4d8ce2916070e0ce2ec655 Mon Sep 17 00:00:00 2001 From: Matthew R Hermes Date: Thu, 30 Apr 2026 18:08:17 -0500 Subject: [PATCH 09/10] tighten basis set in some comparison unit tests --- pyscf/occri/test/test_isdfx_energy.py | 2 +- pyscf/occri/test/test_occri.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyscf/occri/test/test_isdfx_energy.py b/pyscf/occri/test/test_isdfx_energy.py index b26aa3fe9..ab9e5e6d3 100644 --- a/pyscf/occri/test/test_isdfx_energy.py +++ b/pyscf/occri/test/test_isdfx_energy.py @@ -45,7 +45,7 @@ def setUp(self): self.cell_h2.basis = "gth-szv" self.cell_h2.pseudo = "gth-pbe" self.cell_h2.a = numpy.eye(3) * 6.0 - self.cell_h2.mesh = [11] * 3 + self.cell_h2.mesh = [21] * 3 self.cell_h2.verbose = 0 self.cell_h2.build() diff --git a/pyscf/occri/test/test_occri.py b/pyscf/occri/test/test_occri.py index 27f271c7d..89c02e923 100644 --- a/pyscf/occri/test/test_occri.py +++ b/pyscf/occri/test/test_occri.py @@ -34,7 +34,7 @@ def setUpModule(): cell.basis = "gth-szv" cell.pseudo = "gth-pbe" cell.a = numpy.eye(3) * 3.5607 - cell.mesh = [17] * 3 + cell.mesh = [21] * 3 cell.build() # Setup proper k-point mesh From 0ebf77b68580616dfc44019cea99d351c63ff2f8 Mon Sep 17 00:00:00 2001 From: Matthew R Hermes Date: Mon, 4 May 2026 14:54:22 -0500 Subject: [PATCH 10/10] Update test_makeklnordm1 complex refs The change from PySCF v2.12.0 is due to an irrelevant phase difference in the orbital basis; when the MO coefficients are replaced with the v2.12.0 values, the test passed. Therefore just update the references for the new phase. --- pyscf/pbc/lno/test/test_makeklnordm1.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/pyscf/pbc/lno/test/test_makeklnordm1.py b/pyscf/pbc/lno/test/test_makeklnordm1.py index 8dee9a71e..6772e4eca 100644 --- a/pyscf/pbc/lno/test/test_makeklnordm1.py +++ b/pyscf/pbc/lno/test/test_makeklnordm1.py @@ -232,29 +232,32 @@ def test_make_lno_complex(self): verbose=cell.verbose,stdout=cell.stdout) eris.build() + occ_ref = -0.06419439687135728+4.973277156424204e-05j + vir_ref = -0.010792752484758372-0.014791758114215927j + arr = make_lo_rdm1_occ_1h_complex(eris, moeocc, moevir, uocc_loc) fp = lib.fp(arr) - self.assertAlmostEqual(fp, -0.06422719794290856+2.5105071595401036e-05j, 7) + self.assertAlmostEqual(fp, occ_ref, 7) arr = make_lo_rdm1_occ_1p_complex(eris, moeocc, moevir, uvir_loc) fp = lib.fp(arr) - self.assertAlmostEqual(fp, -0.06422719794290856+2.5105071595401036e-05j, 7) + self.assertAlmostEqual(fp, occ_ref, 7) arr = make_lo_rdm1_occ_2p_complex(eris, moeocc, moevir, uvir_loc) fp = lib.fp(arr) - self.assertAlmostEqual(fp, -0.06422719794290856+2.5105071595401036e-05j, 7) + self.assertAlmostEqual(fp, occ_ref, 7) arr = make_lo_rdm1_vir_1h_complex(eris, moeocc, moevir, uocc_loc) fp = lib.fp(arr) - self.assertAlmostEqual(fp, -0.002766848360192287-0.034349212190162834j, 7) + self.assertAlmostEqual(fp, vir_ref, 7) arr = make_lo_rdm1_vir_1p_complex(eris, moeocc, moevir, uvir_loc) fp = lib.fp(arr) - self.assertAlmostEqual(fp, -0.002766848360192287-0.034349212190162834j, 7) + self.assertAlmostEqual(fp, vir_ref, 7) arr = make_lo_rdm1_vir_2h_complex(eris, moeocc, moevir, uocc_loc) fp = lib.fp(arr) - self.assertAlmostEqual(fp, -0.002766848360192287-0.034349212190162834j, 7) + self.assertAlmostEqual(fp, vir_ref, 7)