From 5c4cd25850a7aa7b7842bee1afdb0f4b469d72f2 Mon Sep 17 00:00:00 2001 From: Matthew R Hermes Date: Wed, 18 Sep 2024 10:36:30 -0500 Subject: [PATCH] Some CSF configuration printout (#124) --- my_pyscf/fci/csf.py | 15 ++++++++++++--- my_pyscf/fci/csf_symm.py | 4 +++- my_pyscf/fci/csfstring.py | 10 ++++++++++ 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/my_pyscf/fci/csf.py b/my_pyscf/fci/csf.py index 7cf25d3a..14a1d02e 100644 --- a/my_pyscf/fci/csf.py +++ b/my_pyscf/fci/csf.py @@ -530,6 +530,17 @@ def pspace (self, h1e, eri, norb, nelec, hdiag_det=None, hdiag_csf=None, npsp=20 return pspace (self, h1e, eri, norb, nelec, self.transformer, hdiag_det=hdiag_det, hdiag_csf=hdiag_csf, npsp=npsp, max_memory=max_memory) + def log_transformer_cache (self, tverbose=lib.logger.INFO, **kwargs): + if len (kwargs): + self.__dict__.update (kwargs) + self.check_transformer_cache () + if self.transformer is None: + return + log = lib.logger.new_logger (self, self.verbose) + printer = (lambda *args, **kwargs: None, log.error, log.warn, log.note, log.info, + log.debug, log.debug1, log.debug2, log.debug3, log.debug4)[tverbose] + self.transformer.print_config (printer) + class FCISolver (CSFFCISolver, direct_spin1.FCISolver): r''' get_init_guess uses csfstring.py and csdstring.py to construct a spin-symmetry-adapted initial guess, and the Davidson algorithm is carried out in the CSF basis. However, the ci attribute is put in the determinant basis at the end of it all, and "ci0" is also assumed @@ -541,8 +552,6 @@ def get_init_guess(self, norb, nelec, nroots, hdiag_csf, **kwargs): self.check_transformer_cache () return get_init_guess (norb, nelec, nroots, hdiag_csf, self.transformer) - - def kernel(self, h1e, eri, norb, nelec, ci0=None, **kwargs): self.norb = norb self.nelec = nelec @@ -550,6 +559,7 @@ def kernel(self, h1e, eri, norb, nelec, ci0=None, **kwargs): self.smult = kwargs['smult'] kwargs.pop ('smult') self.check_transformer_cache () + self.log_transformer_cache (lib.logger.DEBUG) e, c = kernel (self, h1e, eri, norb, nelec, smult=self.smult, idx_sym=None, ci0=ci0, transformer=self.transformer, **kwargs) self.eci, self.ci = e, c @@ -562,4 +572,3 @@ def check_transformer_cache (self): self.transformer = CSFTransformer (self.norb, neleca, nelecb, self.smult) else: self.transformer._update_spin_cache (self.norb, neleca, nelecb, self.smult) - diff --git a/my_pyscf/fci/csf_symm.py b/my_pyscf/fci/csf_symm.py index f04f979f..c7c34f8a 100644 --- a/my_pyscf/fci/csf_symm.py +++ b/my_pyscf/fci/csf_symm.py @@ -57,9 +57,11 @@ def kernel(self, h1e, eri, norb, nelec, ci0=None, **kwargs): self.wfnsym = wfnsym kwargs['wfnsym'] = wfnsym self.check_transformer_cache () + self.log_transformer_cache (logger.DEBUG) idx_sym = self.transformer.confsym[self.transformer.econf_csf_mask] == wfnsym - e, c = kernel (self, h1e, eri, norb, nelec, smult=self.smult, idx_sym=idx_sym, ci0=ci0, transformer=self.transformer, **kwargs) + e, c = kernel (self, h1e, eri, norb, nelec, smult=self.smult, idx_sym=idx_sym, ci0=ci0, + transformer=self.transformer, **kwargs) self.eci, self.ci = e, c self.orbsym = orbsym_back diff --git a/my_pyscf/fci/csfstring.py b/my_pyscf/fci/csfstring.py index 758164a3..7f8a34fb 100644 --- a/my_pyscf/fci/csfstring.py +++ b/my_pyscf/fci/csfstring.py @@ -209,6 +209,16 @@ def ncsf (self): if self.wfnsym is None or self._orbsym is None: return self.econf_csf_mask.size return (np.count_nonzero (self.confsym[self.econf_csf_mask] == self.wfnsym)) + def print_config (self, printer=print): + printer ('***** CSFTransformer configuration *****') + printer ('norb = {}'.format (self.norb)) + printer ('neleca, nelecb = {}, {}'.format (self.neleca, self.nelecb)) + printer ('smult = {}'.format (self.smult)) + printer ('orbsym = {}'.format (self.orbsym)) + printer ('wfnsym = {}'.format (self.wfnsym)) + printer ('ndeta, ndetb = {}, {}'.format (self.ndeta, self.ndetb)) + printer ('ncsf = {}'.format (self.ncsf)) + def unpack_sym_ci (ci, idx, vec_on_cols=False): if idx is None: return ci tot_len = idx.size