diff --git a/gpu4pyscf/df/df.py b/gpu4pyscf/df/df.py index 1423a143..a98ae1f2 100644 --- a/gpu4pyscf/df/df.py +++ b/gpu4pyscf/df/df.py @@ -20,7 +20,7 @@ import numpy as np from cupyx.scipy.linalg import solve_triangular from pyscf import lib -from pyscf.df import df, addons +from pyscf.df import df, addons, incore from gpu4pyscf.lib.cupy_helper import ( cholesky, tag_array, get_avail_mem, cart2sph, take_last2d, transpose_sum) from gpu4pyscf.df import int3c2e, df_jk @@ -30,7 +30,7 @@ MIN_BLK_SIZE = getattr(__config__, 'min_ao_blksize', 128) ALIGNED = getattr(__config__, 'ao_aligned', 32) -LINEAR_DEP_TOL = 1e-7 +LINEAR_DEP_TOL = incore.LINEAR_DEP_THR class DF(lib.StreamObject): from gpu4pyscf.lib.utils import to_gpu, device diff --git a/gpu4pyscf/df/grad/rhf.py b/gpu4pyscf/df/grad/rhf.py index fda72fc4..1a1dfb48 100644 --- a/gpu4pyscf/df/grad/rhf.py +++ b/gpu4pyscf/df/grad/rhf.py @@ -243,9 +243,9 @@ class Gradients(rhf_grad.Gradients): def __init__(self, mf): # Whether to include the response of DF auxiliary basis when computing # nuclear gradients of J/K matrices - self.auxbasis_response = True rhf_grad.Gradients.__init__(self, mf) + auxbasis_response = True get_jk = get_jk grad_elec = rhf_grad.grad_elec check_sanity = NotImplemented diff --git a/gpu4pyscf/df/grad/rks.py b/gpu4pyscf/df/grad/rks.py index 8497470c..b0d7269e 100644 --- a/gpu4pyscf/df/grad/rks.py +++ b/gpu4pyscf/df/grad/rks.py @@ -119,8 +119,14 @@ def get_veff(ks_grad, mol=None, dm=None): class Gradients(rks_grad.Gradients): from gpu4pyscf.lib.utils import to_gpu, device - _keys = df_rks_grad.Gradients._keys - __init__ = df_rks_grad.Gradients.__init__ + _keys = {'with_df', 'auxbasis_response'} + + def __init__(self, mf): + rks_grad.Gradients.__init__(self, mf) + + # Whether to include the response of DF auxiliary basis when computing + # nuclear gradients of J/K matrices + auxbasis_response = True get_jk = df_rhf_grad.Gradients.get_jk grad_elec = df_rhf_grad.Gradients.grad_elec diff --git a/gpu4pyscf/df/grad/uhf.py b/gpu4pyscf/df/grad/uhf.py index afe1ccf0..9d1a3f36 100644 --- a/gpu4pyscf/df/grad/uhf.py +++ b/gpu4pyscf/df/grad/uhf.py @@ -266,12 +266,12 @@ class Gradients(uhf_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 - self.auxbasis_response = True self._keys = self._keys.union(['auxbasis_response']) uhf_grad.Gradients.__init__(self, mf) + # Whether to include the response of DF auxiliary basis when computing + # nuclear gradients of J/K matrices + auxbasis_response = True get_jk = get_jk # TODO: finish these two functions diff --git a/gpu4pyscf/df/grad/uks.py b/gpu4pyscf/df/grad/uks.py index cdd3d918..542adad2 100644 --- a/gpu4pyscf/df/grad/uks.py +++ b/gpu4pyscf/df/grad/uks.py @@ -140,11 +140,11 @@ 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 - self.auxbasis_response = True uks_grad.Gradients.__init__(self, mf) + # Whether to include the response of DF auxiliary basis when computing + # nuclear gradients of J/K matrices + auxbasis_response = True get_jk = get_jk def get_j(self, mol=None, dm=None, hermi=0, mo_coeff=None, mo_occ=None, dm2 = None, omega=None): diff --git a/gpu4pyscf/df/hessian/rhf.py b/gpu4pyscf/df/hessian/rhf.py index d4514e7a..e31d006d 100644 --- a/gpu4pyscf/df/hessian/rhf.py +++ b/gpu4pyscf/df/hessian/rhf.py @@ -580,9 +580,9 @@ class Hessian(rhf_hess.Hessian): from gpu4pyscf.lib.utils import to_gpu, device def __init__(self, mf): - self.auxbasis_response = 1 rhf_hess.Hessian.__init__(self, mf) + auxbasis_response = 1 partial_hess_elec = partial_hess_elec make_h1 = make_h1 kernel = rhf_hess.kernel diff --git a/gpu4pyscf/df/hessian/rks.py b/gpu4pyscf/df/hessian/rks.py index a5474dcf..1f962189 100644 --- a/gpu4pyscf/df/hessian/rks.py +++ b/gpu4pyscf/df/hessian/rks.py @@ -111,9 +111,9 @@ class Hessian(rks_hess.Hessian): from gpu4pyscf.lib.utils import to_gpu, device def __init__(self, mf): - self.auxbasis_response = 1 rks_hess.Hessian.__init__(self, mf) + auxbasis_response = 1 partial_hess_elec = partial_hess_elec make_h1 = make_h1 kernel = rhf_hess.kernel diff --git a/gpu4pyscf/df/hessian/uhf.py b/gpu4pyscf/df/hessian/uhf.py index 913ae21c..f20d2092 100644 --- a/gpu4pyscf/df/hessian/uhf.py +++ b/gpu4pyscf/df/hessian/uhf.py @@ -687,9 +687,9 @@ class Hessian(uhf_hess.Hessian): from gpu4pyscf.lib.utils import to_gpu, device def __init__(self, mf): - self.auxbasis_response = 1 uhf_hess.Hessian.__init__(self, mf) + auxbasis_response = 1 partial_hess_elec = partial_hess_elec make_h1 = make_h1 kernel = rhf_hess.kernel diff --git a/gpu4pyscf/df/hessian/uks.py b/gpu4pyscf/df/hessian/uks.py index db1f187d..9b8d73e1 100644 --- a/gpu4pyscf/df/hessian/uks.py +++ b/gpu4pyscf/df/hessian/uks.py @@ -123,7 +123,6 @@ class Hessian(uks_hess.Hessian): from gpu4pyscf.lib.utils import to_gpu, device def __init__(self, mf): - self.auxbasis_response = 1 uks_hess.Hessian.__init__(self, mf) def solve_mo1(self, mo_energy, mo_coeff, mo_occ, h1ao_or_chkfile, @@ -131,6 +130,7 @@ def solve_mo1(self, mo_energy, mo_coeff, mo_occ, h1ao_or_chkfile, return uhf_hess.solve_mo1(self.base, mo_energy, mo_coeff, mo_occ, h1ao_or_chkfile, fx, atmlst, max_memory, verbose) + auxbasis_response = 1 partial_hess_elec = partial_hess_elec make_h1 = make_h1 hess_elec = uhf_hess.hess_elec diff --git a/gpu4pyscf/grad/rhf.py b/gpu4pyscf/grad/rhf.py index ed5565e5..2805b472 100644 --- a/gpu4pyscf/grad/rhf.py +++ b/gpu4pyscf/grad/rhf.py @@ -547,8 +547,8 @@ def calculate_h1e(h1_gpu, s1_gpu): if log.verbose >= logger.DEBUG: log.timer_debug1('gradients of electronic part', *t0) - # net force should be zero - de -= cupy.sum(de, axis=0)/len(atmlst) + ## net force should be zero + #de -= cupy.sum(de, axis=0)/len(atmlst) return de.get() def get_grad_hcore(mf_grad, mo_coeff=None, mo_occ=None): diff --git a/gpu4pyscf/grad/rks.py b/gpu4pyscf/grad/rks.py index 45ae211a..140c58ae 100644 --- a/gpu4pyscf/grad/rks.py +++ b/gpu4pyscf/grad/rks.py @@ -514,7 +514,6 @@ def __init__ (self, mf): rhf_grad.Gradients.__init__(self, mf) self.grids = None self.nlcgrids = None - self.grid_response = False get_veff = _get_veff # TODO: add grid response into this function diff --git a/gpu4pyscf/lib/tests/test_to_gpu.py b/gpu4pyscf/lib/tests/test_to_gpu.py index f825be51..f55421c2 100644 --- a/gpu4pyscf/lib/tests/test_to_gpu.py +++ b/gpu4pyscf/lib/tests/test_to_gpu.py @@ -69,7 +69,7 @@ def test_rks(self): mf = rks.RKS(mol).run() gobj = mf.nuc_grad_method().to_gpu() g = gobj.kernel() - assert numpy.abs(lib.fp(g) - -0.04339987221752033) < 1e-7 + assert numpy.abs(lib.fp(g) - -0.04340162663176693) < 1e-7 # RKS Hessian it not supported yet # mf = rks.RKS(mol).run() @@ -102,7 +102,7 @@ def test_df_b3lyp(self): mf = rks.RKS(mol, xc='b3lyp').density_fit().run() gobj = mf.nuc_grad_method().to_gpu() g = gobj.kernel() - assert numpy.abs(lib.fp(g) - -0.04079190644707999) < 1e-7 + assert numpy.abs(lib.fp(g) - -0.04079319540057938) < 1e-5 mf = rks.RKS(mol, xc='b3lyp').density_fit().run() mf.conv_tol_cpscf = 1e-7 @@ -119,8 +119,7 @@ def test_df_RKS(self): mf = rks.RKS(mol, xc='wb97x').density_fit().run() gobj = mf.nuc_grad_method().to_gpu() g = gobj.kernel() - g -= g.sum(axis=0)/len(g) - assert numpy.abs(lib.fp(g) - -0.034343799164131) < 1e-5 + assert numpy.abs(lib.fp(g) - -0.03432881437746617) < 1e-5 mf = rks.RKS(mol, xc='wb97x').density_fit().run() mf.conv_tol_cpscf = 1e-7