Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sunqm committed Sep 11, 2023
1 parent 1fd6dff commit 49ea773
Show file tree
Hide file tree
Showing 14 changed files with 45 additions and 31 deletions.
13 changes: 4 additions & 9 deletions pyscf/__config__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,10 @@
conf_file = None

if conf_file is not None:
if sys.version_info < (3,0):
import imp
imp.load_source('pyscf.__config__', conf_file)
del (imp)
else:
from importlib import machinery
machinery.SourceFileLoader('pyscf.__config__', conf_file).load_module()
del (machinery)
del (os, sys)
with open(conf_file, 'r') as f:
exec(f.read())
del f
del (os, sys, tempfile)

#
# All parameters initialized after loading pyscf_conf.py will be kept in the
Expand Down
2 changes: 2 additions & 0 deletions pyscf/df/grad/casscf.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ def __call__(self, mol_or_geom, **kwargs):
class Gradients(casci_grad.Gradients):
'''Non-relativistic restricted Hartree-Fock gradients'''

_keys = {'with_df', 'auxbasis_response'}

def __init__(self, mc):
self.with_df = mc.with_df
self.auxbasis_response = True
Expand Down
3 changes: 3 additions & 0 deletions pyscf/df/grad/rhf.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,9 @@ def __call__(self, set_id, p0, p1):

class Gradients(rhf_grad.Gradients):
'''Restricted density-fitting Hartree-Fock gradients'''

_keys = {'with_df', 'auxbasis_response'}

def __init__(self, mf):
# Whether to include the response of DF auxiliary basis when computing
# nuclear gradients of J/K matrices
Expand Down
3 changes: 3 additions & 0 deletions pyscf/df/grad/rks.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ def get_veff(ks_grad, mol=None, dm=None):


class Gradients(rks_grad.Gradients):

_keys = {'with_df', 'auxbasis_response'}

def __init__(self, mf):
# Whether to include the response of DF auxiliary basis when computing
# nuclear gradients of J/K matrices
Expand Down
2 changes: 2 additions & 0 deletions pyscf/df/grad/sacasscf.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,8 @@ def __call__(self, mol_or_geom, **kwargs):

class Gradients (sacasscf_grad.Gradients):

_keys = {'with_df', 'auxbasis_response'}

def __init__(self, mc, state=None):
self.auxbasis_response = True
sacasscf_grad.Gradients.__init__(self, mc, state=state)
Expand Down
3 changes: 3 additions & 0 deletions pyscf/df/grad/uhf.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@

class Gradients(uhf_grad.Gradients):
'''Unrestricted density-fitting Hartree-Fock gradients'''

_keys = {'with_df', 'auxbasis_response'}

def __init__(self, mf):
# Whether to include the response of DF auxiliary basis when computing
# nuclear gradients of J/K matrices
Expand Down
3 changes: 3 additions & 0 deletions pyscf/df/grad/uks.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ def get_veff(ks_grad, mol=None, dm=None):


class Gradients(uks_grad.Gradients):

_keys = {'with_df', 'auxbasis_response'}

def __init__(self, mf):
# Whether to include the response of DF auxiliary basis when computing
# nuclear gradients of J/K matrices
Expand Down
3 changes: 3 additions & 0 deletions pyscf/grad/casci.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,9 @@ def __call__(self, mol_or_geom, state=None, **kwargs):

class Gradients(rhf_grad.GradientsBase):
'''Non-relativistic restricted Hartree-Fock gradients'''

_keys = {'state'}

def __init__(self, mc):
if isinstance(mc, StateAverageMCSCFSolver):
self.state = None # not a specific state
Expand Down
4 changes: 4 additions & 0 deletions pyscf/grad/lagrange.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ def get_LdotJnuc (self, Lvec, **kwargs):

####################### Child classes SHOULD overwrite the methods below ######################

_keys = {
'Lvec', 'nlag', 'level_shift', 'conv_atol', 'conv_rtol', 'max_cycle',
}

def __init__(self, method, nlag):
self._conv = False
self.Lvec = None
Expand Down
2 changes: 1 addition & 1 deletion pyscf/grad/rhf.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ class GradientsBase(lib.StreamObject):
Basic nuclear gradient functions for non-relativistic methods
'''

_keys = set(('mol', 'base', 'unit', 'atmlst', 'de'))
_keys = {'mol', 'base', 'unit', 'atmlst', 'de'}

def __init__(self, method):
self.verbose = method.verbose
Expand Down
18 changes: 14 additions & 4 deletions pyscf/grad/sacasscf.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,13 @@ def converged(self, x):

class Gradients (lagrange.Gradients):

_keys = {
'ngorb', 'nroots', 'spin_states', 'na_states', 'nb_states', 'nroots',
'nci', 'state', 'eris', 'weights', 'e_states', 'max_cycle', 'ncas',
'e_cas', 'nelecas', 'mo_occ', 'mo_energy', 'mo_coeff', 'callback',
'chkfile', 'nlag', 'frozen', 'level_shift', 'extrasym', 'fcisolver',
}

def __init__(self, mc, state=None):
self.__dict__.update (mc.__dict__)
nmo = mc.mo_coeff.shape[-1]
Expand Down Expand Up @@ -499,14 +506,12 @@ def make_fcasscf (self, state=None, casscf_attr={}, fcisolver_attr={}):
else:
solver_class = self.base.fcisolver._base_class
solver_obj = self.base.fcisolver
fcasscf.fcisolver = solver_class (self.base.mol)
fcasscf.fcisolver.__dict__.update (solver_obj.__dict__)
fcasscf.fcisolver = solver_obj.view(solver_class)
fcasscf.fcisolver.nroots = 1
# Spin penalty method is inapplicable to response calc'ns
# It must be deactivated for Lagrange multipliers to converge
if isinstance (fcasscf.fcisolver, SpinPenaltyFCISolver):
fcasscf.fcisolver = fcasscf.fcisolver.copy()
fcasscf.fcisolver.ss_penalty = 0
fcasscf.fcisolver = fcasscf.fcisolver.undo_fix_spin()
fcasscf.__dict__.update (casscf_attr)
fcasscf.nelecas = nelecas
fcasscf.fcisolver.__dict__.update (fcisolver_attr)
Expand Down Expand Up @@ -777,6 +782,11 @@ class SACASLagPrec (lagrange.LagPrec):
Make the operand's matrix element with <K|Rci(I) before taking the dot product!
'''

_keys = {
'level_shift', 'nroots', 'nlag', 'ngorb', 'spin_states', 'na_states',
'nb_states', 'grad_method', 'Rorb', 'ci', 'Rci', 'Rci_sa',
}

# TODO: fix me (subclass me? wrap me?) for state_average_mix
def __init__(self, Adiag=None, level_shift=None, ci=None, grad_method=None):
self.level_shift = level_shift
Expand Down
4 changes: 2 additions & 2 deletions pyscf/grad/tdrhf.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,10 @@ class Gradients(rhf_grad.GradientsBase):
cphf_max_cycle = getattr(__config__, 'grad_tdrhf_Gradients_cphf_max_cycle', 20)
cphf_conv_tol = getattr(__config__, 'grad_tdrhf_Gradients_cphf_conv_tol', 1e-8)

_keys = set((
_keys = {
'cphf_max_cycle', 'cphf_conv_tol',
'mol', 'base', 'chkfile', 'state', 'atmlst', 'de',
))
}

def __init__(self, td):
self.verbose = td.verbose
Expand Down
15 changes: 0 additions & 15 deletions pyscf/pbc/cc/test/test_kuccsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,21 +156,6 @@ def test_update_amps(self):
self.assertAlmostEqual(lib.fp(Ht2[1]), (2256.0435017189384-193.16481690849486j ), 4)
self.assertAlmostEqual(lib.fp(Ht2[2]), (-250.59447681063182-397.57189085666982j), 4)

kmf.mo_occ[:] = 0
kmf.mo_occ[:,:,:2] = 1
mycc = kccsd_uhf.KUCCSD(kmf)
eris = mycc.ao2mo()
np.random.seed(1)
nocc = mycc.nocc
nvir = nmo - nocc[0], nmo - nocc[1]
t1, t2 = rand_t1_t2(cell, kmf.kpts, nocc, nvir)
Ht1, Ht2 = mycc.update_amps(t1, t2, eris)
self.assertAlmostEqual(lib.fp(Ht1[0]), (5.4622516572705662+1.990046725028729j ), 4)
self.assertAlmostEqual(lib.fp(Ht1[1]), (4.8801120611799043-5.9940463787453488j), 4)
self.assertAlmostEqual(lib.fp(Ht2[0]), (-192.38864512375193+305.1419101854398j), 4)
self.assertAlmostEqual(lib.fp(Ht2[1]), (23085.056910282714-11527.808856109988j), 4)
self.assertAlmostEqual(lib.fp(Ht2[2]), (115.57932548288559-40.888597453928604j), 4)

kgcc = kccsd.GCCSD(scf.addons.convert_to_ghf(kmf))
kccsd_eris = kccsd._make_eris_incore(kgcc, kgcc._scf.mo_coeff)
r1 = kgcc.spatial2spin(t1)
Expand Down
1 change: 1 addition & 0 deletions pyscf/solvent/test/test_ddcosmo_tdscf_grad.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from pyscf import gto
from pyscf import scf
from pyscf import dft
from pyscf import solvent

def setUpModule():
global mol0, mol1, mol2
Expand Down

0 comments on commit 49ea773

Please sign in to comment.