Skip to content
25 changes: 16 additions & 9 deletions gpu4pyscf/dft/tests/test_libxc.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def _diff(dat, ref):
return np.min((abs(d/(ref+1e-300)), abs(d)), axis=0)

class KnownValues(unittest.TestCase):
def _check_xc(self, xc, spin=0, fxc_tol=1e-10, kxc_tol=1e-10):
def _check_xc(self, xc, spin=0, deriv=2, fxc_tol=1e-10, kxc_tol=1e-10):
ni_cpu = numint_cpu()
ni_gpu = numint_gpu()
xctype = ni_cpu._xc_type(xc)
Expand All @@ -66,8 +66,15 @@ def _check_xc(self, xc, spin=0, fxc_tol=1e-10, kxc_tol=1e-10):
if spin != 0:
rho = (rho, rho)

exc_cpu, vxc_cpu, fxc_cpu, kxc_cpu = ni_cpu.eval_xc_eff(xc, rho, deriv=2, xctype=xctype)
exc_gpu, vxc_gpu, fxc_gpu, kxc_gpu = ni_gpu.eval_xc_eff(xc, cupy.array(rho), deriv=2, xctype=xctype)
exc_cpu, vxc_cpu, fxc_cpu, kxc_cpu = ni_cpu.eval_xc_eff(xc, rho, deriv=deriv, xctype=xctype)
exc_gpu, vxc_gpu, fxc_gpu, kxc_gpu = ni_gpu.eval_xc_eff(xc, cupy.array(rho), deriv=deriv, xctype=xctype)

print(f"{xc} {spin} exc", _diff(exc_gpu[:,0].get(), exc_cpu).max())
print(f"{xc} {spin} vxc", _diff(vxc_gpu.get(), vxc_cpu).max())
if fxc_gpu is not None:
print(f"{xc} {spin} fxc", _diff(fxc_gpu.get(), fxc_cpu).max())
if kxc_gpu is not None:
print(f"{xc} {spin} kxc", _diff(kxc_gpu.get(), kxc_cpu).max())

assert _diff(exc_gpu[:,0].get(), exc_cpu).max() < 1e-10
assert _diff(vxc_gpu.get(), vxc_cpu).max() < 1e-10
Expand All @@ -77,15 +84,15 @@ def _check_xc(self, xc, spin=0, fxc_tol=1e-10, kxc_tol=1e-10):
assert _diff(kxc_gpu.get(), kxc_cpu).max() < kxc_tol

def test_LDA(self):
self._check_xc('LDA_C_VWN')
self._check_xc('LDA_C_VWN', deriv=3)

def test_GGA(self):
self._check_xc('HYB_GGA_XC_B3LYP')
self._check_xc('GGA_X_B88', fxc_tol=1e-10)
self._check_xc('GGA_C_PBE', fxc_tol=1e-4)
self._check_xc('HYB_GGA_XC_B3LYP', deriv=3, kxc_tol=1e-9)
self._check_xc('GGA_X_B88', fxc_tol=1e-10, deriv=3, kxc_tol=1e-8)
self._check_xc('GGA_C_PBE', fxc_tol=1e-4, deriv=3, kxc_tol=3e2)

def test_mGGA(self):
self._check_xc('MGGA_C_M06', fxc_tol=1e-4)
self._check_xc('MGGA_C_M06', fxc_tol=1e-4, deriv=3, kxc_tol=1e-2)

def test_u_LDA(self):
self._check_xc('LDA_C_VWN', spin=1)
Expand All @@ -101,4 +108,4 @@ def test_u_mGGA(self):

if __name__ == "__main__":
print("Full Tests for xc fun")
unittest.main()
unittest.main()
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cutensor-cu12==2.2.0
gpu4pyscf-libxc-cuda12x==0.5.0
gpu4pyscf-libxc-cuda12x==0.7.0
cupy-cuda12x==13.4.1
pyscf==2.8.0
basis-set-exchange==0.11
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,6 @@ def initialize_with_default_plat_name(self):
'pyscf-dispersion',
f'cupy-cuda{CUDA_VERSION}>=13.0,!=13.4.0', # Due to expm in cupyx.scipy.linalg and cutensor 2.0
'geometric',
f'gpu4pyscf-libxc-cuda{CUDA_VERSION}==0.5',
f'gpu4pyscf-libxc-cuda{CUDA_VERSION}==0.7.0',
]
)