Skip to content

Commit

Permalink
bugfix:v0.6.16 (pyscf#84)
Browse files Browse the repository at this point in the history
* cmake workflow for dftd3 and dftd4

* updated cmake

* new workflow for dftd3 and dftd4

* remove package_data

* resolve dependencies in dftd3 and dftd4

* add dftd3 and dftd4 to __init__.py

* updated the script for building wheels

* memory leak in dftd3 and dft4
  • Loading branch information
wxj6000 authored Jan 17, 2024
1 parent 523dbf1 commit 5f22de4
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion gpu4pyscf/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from . import lib, grad, hessian, solvent, scf, dft
__version__ = '0.6.15'
__version__ = '0.6.16'

# monkey patch libxc reference due to a bug in nvcc
from pyscf.dft import libxc
Expand Down
14 changes: 10 additions & 4 deletions gpu4pyscf/lib/dftd3.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,14 @@
"d3op": libdftd3.dftd3_load_optimizedpower_damping #OptimizedPowerDampingParam,
}


libdftd3.dftd3_new_error.restype = ctypes.c_void_p
libdftd3.dftd3_new_structure.restype = ctypes.c_void_p
libdftd3.dftd3_new_error.restype = ctypes.c_void_p
libdftd3.dftd3_new_structure.restype = ctypes.c_void_p
libdftd3.dftd3_load_optimizedpower_damping.restype = ctypes.c_void_p
libdftd3.dftd3_load_mzero_damping.restype = ctypes.c_void_p
libdftd3.dftd3_load_mrational_damping.restype = ctypes.c_void_p
libdftd3.dftd3_load_zero_damping.restype = ctypes.c_void_p
libdftd3.dftd3_load_rational_damping.restype = ctypes.c_void_p
libdftd3.dftd3_new_d3_model.restype = ctypes.c_void_p

class DFTD3Dispersion(lib.StreamObject):
def __init__(self, mol, xc, version='d3bj', atm=False):
Expand Down Expand Up @@ -63,8 +68,9 @@ def __init__(self, mol, xc, version='d3bj', atm=False):

def __del__(self):
err = libdftd3.dftd3_new_error()
param = ctypes.cast(self._param, ctypes.c_void_p)
libdftd3.dftd3_delete_param(ctypes.byref(param))
libdftd3.dftd3_delete_structure(err, self._mol)
libdftd3.dftd3_delete_param(err, self._param)
libdftd3.dftd3_delete_model(err, self._disp)
libdftd3.dftd3_delete_error(err)

Expand Down
9 changes: 6 additions & 3 deletions gpu4pyscf/lib/dftd4.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@

libdftd4 = np.ctypeslib.load_library('libdftd4', os.path.abspath(os.path.join(__file__, '..', 'deps', 'lib')))

libdftd4.dftd4_new_error.restype = ctypes.c_void_p
libdftd4.dftd4_new_structure.restype = ctypes.c_void_p
libdftd4.dftd4_new_error.restype = ctypes.c_void_p
libdftd4.dftd4_new_structure.restype = ctypes.c_void_p
libdftd4.dftd4_new_d4_model.restype = ctypes.c_void_p
libdftd4.dftd4_load_rational_damping.restype = ctypes.c_void_p

class DFTD4Dispersion(lib.StreamObject):
def __init__(self, mol, xc, atm=False):
Expand Down Expand Up @@ -54,8 +56,9 @@ def __init__(self, mol, xc, atm=False):

def __del__(self):
err = libdftd4.dftd4_new_error()
param = ctypes.cast(self._param, ctypes.c_void_p)
libdftd4.dftd4_delete_param(ctypes.byref(param))
libdftd4.dftd4_delete_structure(err, self._mol)
libdftd4.dftd4_delete_param(err, self._param)
libdftd4.dftd4_delete_model(err, self._disp)
libdftd4.dftd4_delete_error(err)

Expand Down
1 change: 1 addition & 0 deletions gpu4pyscf/lib/tests/test_dftd4.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def test_gradient_r2scan_d4(self):
dftd4_model = dftd4.DFTD4Dispersion(mol, "r2SCAN", atm=False)
res = dftd4_model.get_dispersion(grad=True)
assert np.linalg.norm(ref - res['gradient']) < 1e-10

if __name__ == "__main__":
print("Full tests for DFTD4 module")
unittest.main()
6 changes: 3 additions & 3 deletions gpu4pyscf/qmmm/test/test_chelpg.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def run_dft_chelpg(xc, deltaR):
e_dft = mf.kernel()
q = chelpg.eval_chelpg_layer_gpu(mf, deltaR=deltaR)
return e_dft, q


class KnownValues(unittest.TestCase):
'''
Expand All @@ -63,7 +63,7 @@ class KnownValues(unittest.TestCase):
CHELPG TRUE
SCF_CONVERGENCE 10
$end
Ground-State ChElPG Net Atomic Charges
Atom Charge (a.u.)
Expand All @@ -78,7 +78,7 @@ def test_rks_b3lyp(self):
e_tot, q = run_dft_chelpg('B3LYP', 0.1)
assert np.allclose(e_tot, -76.4666495181)
assert np.allclose(q, np.array([-0.712558, 0.356292, 0.356266]))


if __name__ == "__main__":
print("Full Tests for SCF")
Expand Down

0 comments on commit 5f22de4

Please sign in to comment.