Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion gpu4pyscf/df/df.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,15 @@

class DF(lib.StreamObject):

use_gpu_memory = True

_keys = {'intopt', 'nao', 'naux', 'cd_low', 'mol', 'auxmol', 'use_gpu_memory'}

def __init__(self, mol, auxbasis=None):
self.mol = mol
self.stdout = mol.stdout
self.verbose = mol.verbose
self.max_memory = mol.max_memory
self.use_gpu_memory = True
self._auxbasis = auxbasis

self.auxmol = None
Expand Down
2 changes: 1 addition & 1 deletion gpu4pyscf/df/hessian/rhf.py
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ class Hessian(rhf_hess.Hessian):

_keys = {'auxbasis_response',}

auxbasis_response = 1
auxbasis_response = 2
partial_hess_elec = partial_hess_elec
make_h1 = make_h1
get_jk_mo = _get_jk_mo
2 changes: 1 addition & 1 deletion gpu4pyscf/df/hessian/rks.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class Hessian(rks_hess.Hessian):

_keys = {'auxbasis_response',}

auxbasis_response = 1
auxbasis_response = 2
partial_hess_elec = partial_hess_elec
make_h1 = make_h1
get_jk_mo = df_rhf_hess._get_jk_mo
4 changes: 3 additions & 1 deletion gpu4pyscf/df/hessian/tests/test_df_rks_hessian.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def test_df_lda(self):

mf = mf.to_gpu()
hessobj = mf.Hessian()
hessobj.auxbasis_response = 1
hess_gpu = hessobj.kernel()
assert numpy.linalg.norm(hess_cpu - hess_gpu) < 1e-5

Expand All @@ -81,6 +82,7 @@ def test_df_gga(self):

mf = mf.to_gpu()
hessobj = mf.Hessian()
hessobj.auxbasis_response = 1
hessobj.base.cphf_grids = hessobj.base.grids
hess_gpu = hessobj.kernel()
assert numpy.linalg.norm(hess_cpu - hess_gpu) < 1e-5
Expand All @@ -97,11 +99,11 @@ def test_df_mgga(self):

mf = mf.to_gpu()
hessobj = mf.Hessian()
hessobj.auxbasis_response = 1
hessobj.base.cphf_grids = hessobj.base.grids
hess_gpu = hessobj.kernel()
assert numpy.linalg.norm(hess_cpu - hess_gpu) < 1e-5

if __name__ == "__main__":
print("Full Tests for DF RKS Hessian")
unittest.main()

4 changes: 3 additions & 1 deletion gpu4pyscf/df/hessian/tests/test_df_uks_hessian.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def test_df_lda(self):

mf = mf.to_gpu()
hessobj = mf.Hessian()
hessobj.auxbasis_response = 1
hess_gpu = hessobj.kernel()
assert numpy.linalg.norm(hess_cpu - hess_gpu) < 1e-5

Expand All @@ -82,6 +83,7 @@ def test_df_gga(self):

mf = mf.to_gpu()
hessobj = mf.Hessian()
hessobj.auxbasis_response = 1
hessobj.base.cphf_grids = hessobj.base.grids
hess_gpu = hessobj.kernel()
assert numpy.linalg.norm(hess_cpu - hess_gpu) < 1e-5
Expand All @@ -98,11 +100,11 @@ def test_df_mgga(self):

mf = mf.to_gpu()
hessobj = mf.Hessian()
hessobj.auxbasis_response = 1
hessobj.base.cphf_grids = hessobj.base.grids
hess_gpu = hessobj.kernel()
assert numpy.linalg.norm(hess_cpu - hess_gpu) < 1e-5

if __name__ == "__main__":
print("Full Tests for DF UKS Hessian")
unittest.main()

2 changes: 1 addition & 1 deletion gpu4pyscf/df/hessian/uhf.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ class Hessian(uhf_hess.Hessian):

_keys = {'auxbasis_response',}

auxbasis_response = 1
auxbasis_response = 2
partial_hess_elec = partial_hess_elec
make_h1 = make_h1
get_jk_mo = _get_jk_mo
2 changes: 1 addition & 1 deletion gpu4pyscf/df/hessian/uks.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class Hessian(uks_hess.Hessian):

_keys = {'auxbasis_response',}

auxbasis_response = 1
auxbasis_response = 2
partial_hess_elec = partial_hess_elec
make_h1 = make_h1
get_jk_mo = df_uhf_hess._get_jk_mo
2 changes: 1 addition & 1 deletion gpu4pyscf/dft/gks.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class GKS(gks.GKS, GHF):
def __init__(self, mol, xc='LDA,VWN'):
raise NotImplementedError

reset = rks.RKS.reset
reset = rks.KohnShamDFT.reset
energy_elec = rks.RKS.energy_elec
get_veff = NotImplemented
nuc_grad_method = NotImplemented
Expand Down
29 changes: 15 additions & 14 deletions gpu4pyscf/dft/rks.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,21 @@ def dump_flags(self, verbose=None):
log.info('small_rho_cutoff = %g', self.small_rho_cutoff)
return self

reset = rks.KohnShamDFT.reset
def reset(self, mol=None):
hf.SCF.reset(self, mol)
self.grids.reset(mol)
self.nlcgrids.reset(mol)
self._numint.reset()
# The cphf_grids attribute is not available in the PySCF CPU version.
# In PySCF's to_gpu() function, this attribute is not initialized.
if hasattr(self, 'cphf_grids'):
self.cphf_grids.reset(self.mol)
else:
cphf_grids = self.cphf_grids = gen_grid.Grids(self.mol)
cphf_grids.prune = gen_grid.sg1_prune
cphf_grids.atom_grid = (50,194)
return self

do_nlc = rks.KohnShamDFT.do_nlc

hf.KohnShamDFT = KohnShamDFT
Expand All @@ -264,19 +278,6 @@ def dump_flags(self, verbose=None):
hf.RHF.dump_flags(self, verbose)
return KohnShamDFT.dump_flags(self, verbose)

def reset(self, mol=None):
hf.SCF.reset(self, mol)
self.grids.reset(mol)
self.nlcgrids.reset(mol)
self._numint.reset()
# The cphf_grids attribute is not available in the PySCF CPU version.
# In PySCF's to_gpu() function, this attribute is not properly
# initialized. mol of the KS object must be used for initialization.
if mol is None:
mol = self.mol
self.cphf_grids.reset(mol)
return self

def nuc_grad_method(self):
from gpu4pyscf.grad import rks as rks_grad
return rks_grad.Gradients(self)
Expand Down
9 changes: 0 additions & 9 deletions gpu4pyscf/dft/uks.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,8 @@ def __init__(self, mol, xc='LDA,VWN'):
energy_elec = energy_elec
energy_tot = hf.RHF.energy_tot
init_guess_by_vsap = uks_cpu.UKS.init_guess_by_vsap

to_hf = NotImplemented

def reset(self, mol=None):
hf.SCF.reset(self, mol)
self.grids.reset(mol)
self.nlcgrids.reset(mol)
self.cphf_grids.reset(mol)
self._numint.reset()
return self

def nuc_grad_method(self):
from gpu4pyscf.grad import uks as uks_grad
return uks_grad.Gradients(self)
Expand Down
4 changes: 3 additions & 1 deletion gpu4pyscf/lib/tests/test_to_gpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def test_df_RHF(self):
mf = scf.RHF(mol).density_fit().run()
mf.conv_tol_cpscf = 1e-7
hobj = mf.Hessian().to_gpu()
hobj.auxbasis_response = 1
h = hobj.kernel()
assert numpy.abs(lib.fp(h) - 2.198079352288524) < 1e-4

Expand All @@ -106,6 +107,7 @@ def test_df_b3lyp(self):
mf = rks.RKS(mol, xc='b3lyp').density_fit().run()
mf.conv_tol_cpscf = 1e-7
hobj = mf.Hessian().to_gpu()
hobj.auxbasis_response = 1
h = hobj.kernel()
assert numpy.abs(lib.fp(h) - 2.1527804103141848) < 1e-4

Expand All @@ -123,10 +125,10 @@ def test_df_RKS(self):
mf = rks.RKS(mol, xc='wb97x').density_fit().run()
mf.conv_tol_cpscf = 1e-7
hobj = mf.Hessian().to_gpu()
hobj.auxbasis_response = 1
h = hobj.kernel()
assert numpy.abs(lib.fp(h) - 2.1858589608638384) < 1e-4

if __name__ == "__main__":
print("Full tests for to_gpu module")
unittest.main()

8 changes: 4 additions & 4 deletions gpu4pyscf/solvent/tests/test_pcm_hessian.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
from gpu4pyscf.lib.cupy_helper import contract
from gpu4pyscf.lib.multi_gpu import num_devices

pyscf_211 = version.parse(pyscf.__version__) <= version.parse('2.11.0')

def setUpModule():
global mol, epsilon, lebedev_order, eps, xc, tol
mol = gto.Mole()
Expand Down Expand Up @@ -325,7 +323,6 @@ def test_hess_solver_ssvpe(self):

assert abs(ref_grad_vmat - test_grad_vmat).max() < 1e-9

@pytest.mark.skipif(pyscf_211, reason='requires pyscf 2.12 or higher')
def test_to_gpu_to_cpu(self):
mol = gto.Mole()
mol.atom = '''
Expand Down Expand Up @@ -358,7 +355,10 @@ def test_to_gpu_to_cpu(self):
mf.kernel()
hessobj = mf.Hessian()
# The auxbasis_response attribute was not handled in pyscf-2.11
hessobj.auxbasis_response = 2
if version.parse(pyscf.__version__) <= version.parse('2.11.0'):
hessobj.auxbasis_response = 2
else:
hessobj.auxbasis_response = 1
hess_gpu = hessobj.kernel()
hessobj = hessobj.to_cpu()
hess_cpu = hessobj.kernel()
Expand Down
8 changes: 4 additions & 4 deletions gpu4pyscf/solvent/tests/test_smd_hessian.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
from gpu4pyscf.solvent import smd
from packaging import version

pyscf_211 = version.parse(pyscf.__version__) <= version.parse('2.11.0')

def setUpModule():
global mol
mol = gto.Mole()
Expand Down Expand Up @@ -226,7 +224,6 @@ def test_Br(self):
_check_hess(atom, solvent='water')
_check_hess(atom, solvent='toluene')

@pytest.mark.skipif(pyscf_211, reason='requires pyscf 2.12 or higher')
def test_to_gpu_to_cpu(self):
mf = dft.RKS(mol, xc='b3lyp').SMD()
mf.conv_tol = 1e-12
Expand All @@ -246,7 +243,10 @@ def test_to_gpu_to_cpu(self):
mf.conv_tol_cpscf = 1e-7
mf.kernel()
hessobj = mf.Hessian()
hessobj.auxbasis_response = 2
if version.parse(pyscf.__version__) <= version.parse('2.11.0'):
hessobj.auxbasis_response = 2
else:
hessobj.auxbasis_response = 1
hess_gpu = hessobj.kernel()
hessobj = hessobj.to_cpu()
hess_cpu = hessobj.kernel()
Expand Down
Loading