Skip to content

Commit

Permalink
fixed unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wxj6000 committed Feb 8, 2024
1 parent 588f72f commit 56b39cf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
9 changes: 9 additions & 0 deletions gpu4pyscf/df/tests/test_df_hessian.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class KnownValues(unittest.TestCase):
def test_hessian_rhf(self):
print('-----testing DF RHF Hessian----')
mf = _make_rhf(mol_sph)
mf.conv_tol_cpscf = 1e-7
hobj = mf.Hessian()
hobj.set(auxbasis_response=2)
h = hobj.kernel()
Expand All @@ -123,6 +124,7 @@ def test_hessian_rhf(self):
def test_hessian_lda(self):
print('-----testing DF LDA Hessian----')
mf = _make_rks(mol_sph, 'LDA')
mf.conv_tol_cpscf = 1e-7
hobj = mf.Hessian()
hobj.set(auxbasis_response=2)
h = hobj.kernel()
Expand All @@ -132,6 +134,7 @@ def test_hessian_lda(self):
def test_hessian_gga(self):
print('-----testing DF PBE Hessian----')
mf = _make_rks(mol_sph, 'PBE')
mf.conv_tol_cpscf = 1e-7
hobj = mf.Hessian()
hobj.set(auxbasis_response=2)
h = hobj.kernel()
Expand All @@ -141,6 +144,7 @@ def test_hessian_gga(self):
def test_hessian_hybrid(self):
print('-----testing DF B3LYP Hessian----')
mf = _make_rks(mol_sph, 'b3lyp')
mf.conv_tol_cpscf = 1e-7
hobj = mf.Hessian()
hobj.set(auxbasis_response=2)
h = hobj.kernel()
Expand All @@ -150,6 +154,7 @@ def test_hessian_hybrid(self):
def test_hessian_mgga(self):
print('-----testing DF M06 Hessian----')
mf = _make_rks(mol_sph, 'm06')
mf.conv_tol_cpscf = 1e-7
hobj = mf.Hessian()
hobj.set(auxbasis_response=2)
h = hobj.kernel()
Expand All @@ -159,6 +164,7 @@ def test_hessian_mgga(self):
def test_hessian_rsh(self):
print('-----testing DF wb97 Hessian----')
mf = _make_rks(mol_sph, 'wb97')
mf.conv_tol_cpscf = 1e-7
hobj = mf.Hessian()
hobj.set(auxbasis_response=2)
h = hobj.kernel()
Expand All @@ -171,6 +177,7 @@ def test_hessian_D3(self):

mf = dft.rks.RKS(pmol, xc='B3LYP', disp='d3bj').density_fit(auxbasis=auxbasis0)
mf.conv_tol = 1e-12
mf.conv_tol_cpscf = 1e-7
mf.grids.level = grids_level
mf.verbose = 1
mf.kernel()
Expand All @@ -186,6 +193,7 @@ def test_hessian_D4(self):

mf = dft.rks.RKS(pmol, xc='B3LYP', disp='d4').density_fit(auxbasis=auxbasis0)
mf.conv_tol = 1e-12
mf.conv_tol_cpscf = 1e-7
mf.grids.level = grids_level
mf.verbose = 1
mf.kernel()
Expand All @@ -198,6 +206,7 @@ def test_hessian_D4(self):
def test_hessian_cart(self):
print('-----testing DF Hessian (cartesian)----')
mf = _make_rks(mol_cart, 'b3lyp')
mf.conv_tol_cpscf = 1e-7
hobj = mf.Hessian()
hobj.set(auxbasis_response=2)
h = hobj.kernel()
Expand Down
7 changes: 5 additions & 2 deletions gpu4pyscf/lib/tests/test_to_gpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,10 @@ def test_df_RHF(self):
assert numpy.abs(lib.fp(g) - -0.01641213202225146) < 1e-7

mf = scf.RHF(mol).density_fit().run()
mf.conv_tol_cpscf = 1e-7
hobj = mf.Hessian().to_gpu()
h = hobj.kernel()
assert numpy.abs(lib.fp(h) - 2.198079352288524) < 1e-7
assert numpy.abs(lib.fp(h) - 2.198079352288524) < 1e-4

@pytest.mark.skipif(pyscf_24, reason='requires pyscf 2.5 or higher')
def test_df_b3lyp(self):
Expand All @@ -104,9 +105,10 @@ def test_df_b3lyp(self):
assert numpy.abs(lib.fp(g) - -0.04079190644707999) < 1e-7

mf = rks.RKS(mol, xc='b3lyp').density_fit().run()
mf.conv_tol_cpscf = 1e-7
hobj = mf.Hessian().to_gpu()
h = hobj.kernel()
assert numpy.abs(lib.fp(h) - 2.1527804103141848) < 1e-7
assert numpy.abs(lib.fp(h) - 2.1527804103141848) < 1e-4

@pytest.mark.skipif(pyscf_24, reason='requires pyscf 2.5 or higher')
def test_df_RKS(self):
Expand All @@ -121,6 +123,7 @@ def test_df_RKS(self):
assert numpy.abs(lib.fp(g) - -0.034343799164131) < 1e-5

mf = rks.RKS(mol, xc='wb97x').density_fit().run()
mf.conv_tol_cpscf = 1e-7
hobj = mf.Hessian().to_gpu()
h = hobj.kernel()
assert numpy.abs(lib.fp(h) - 2.187025544697092) < 1e-4
Expand Down

0 comments on commit 56b39cf

Please sign in to comment.