Skip to content

Commit

Permalink
self-hosted CI (pyscf#96)
Browse files Browse the repository at this point in the history
* Create unittest.yml

* Update unittest.yml

* Update unittest.yml

* Update unittest.yml

* Update unittest.yml

* skip pytest for pyscf 2.4

* updated unit test

* remove .coverage

* Update unittest.yml
  • Loading branch information
wxj6000 authored Feb 3, 2024
1 parent 71f731c commit eaf83a4
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 42 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/unittest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: self hosted CI

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

permissions:
contents: read

jobs:
build:

runs-on: self-hosted

steps:
- uses: actions/checkout@v3
- name: Install dependencies
run: |
python3 -m pip install --upgrade pip
pip3 install flake8 pytest coverage
- name: Build GPU4PySCF
run: |
export CUDA_HOME=/usr/local/cuda
export PATH=${CUDA_HOME}/bin:${PATH}
export LD_LIBRARY_PATH=${CUDA_HOME}/lib64:$LD_LIBRARY_PATH
sh build.sh
- name: Test with pytest
run: |
echo $GITHUB_WORKSPACE
export PYTHONPATH="${PYTHONPATH}:$GITHUB_WORKSPACE"
coverage run -m pytest
16 changes: 8 additions & 8 deletions gpu4pyscf/dft/tests/test_dft.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
H -0.7570000000 -0.0000000000 -0.4696000000
H 0.7570000000 0.0000000000 -0.4696000000
'''
bas='def2-qzvpp'
bas='def2-tzvpp'
grids_level = 3
nlcgrids_level = 1

Expand Down Expand Up @@ -53,37 +53,37 @@ def run_dft(xc):

class KnownValues(unittest.TestCase):
'''
known values are obtained by Q-Chem
known values are obtained by Q-Chem, # def2-qzvpp
'''
def test_rks_lda(self):
print('------- LDA ----------------')
e_tot = run_dft("LDA, vwn5")
assert np.allclose(e_tot, -75.9117117360)
assert np.allclose(e_tot, -75.9046410402)# -75.9117117360)

def test_rks_pbe(self):
print('------- PBE ----------------')
e_tot = run_dft('PBE')
assert np.allclose(e_tot, -76.3866453049)
assert np.allclose(e_tot, -76.3800182418) #-76.3866453049)

def test_rks_b3lyp(self):
print('-------- B3LYP -------------')
e_tot = run_dft('B3LYP')
assert np.allclose(e_tot, -76.4728129216)
assert np.allclose(e_tot, -76.4666495594) #-76.4728129216)

def test_rks_m06(self):
print('--------- M06 --------------')
e_tot = run_dft("M06")
assert np.allclose(e_tot, -76.4321318125)
assert np.allclose(e_tot, -76.4265870634) #-76.4321318125)

def test_rks_wb97(self):
print('-------- wB97 --------------')
e_tot = run_dft("HYB_GGA_XC_WB97")
assert np.allclose(e_tot, -76.4543067064)
assert np.allclose(e_tot, -76.4486274326) #-76.4543067064)

def test_rks_vv10(self):
print("------- wB97m-v -------------")
e_tot = run_dft('HYB_MGGA_XC_WB97M_V')
assert np.allclose(e_tot, -76.4391208632)
assert np.allclose(e_tot, -76.4334218842) #-76.4391208632)

#TODO: add test cases for D3/D4 and gradient

Expand Down
29 changes: 4 additions & 25 deletions gpu4pyscf/dft/tests/test_dft_ecp.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
I 0 0 0
I 1 0 0
'''
bas='def2-qzvpp'
grids_level = 6
bas='def2-tzvpp'
grids_level = 7

def setUpModule():
global mol
Expand All @@ -43,36 +43,15 @@ def tearDownModule():
def run_dft(xc):
mf = rks.RKS(mol, xc=xc)
mf.grids.level = grids_level
mf.grids.prune = None
e_dft = mf.kernel()
return e_dft

class KnownValues(unittest.TestCase):
def test_rks_lda(self):
print('------- LDA ----------------')
e_tot = run_dft("LDA, vwn5")
assert np.allclose(e_tot, -582.3202757689)

def test_rks_pbe(self):
print('------- PBE ----------------')
e_tot = run_dft('PBE')
assert np.allclose(e_tot, -583.0195322248)

def test_rks_b3lyp(self):
print('-------- B3LYP -------------')
e_tot = run_dft('B3LYP')
assert np.allclose(e_tot, -583.1585397913)

def test_rks_m06(self):
print('--------- M06 --------------')
e_tot = run_dft("M06")
assert np.allclose(e_tot, -583.0979740883)

def test_rks_wb97(self):
print('-------- wB97 --------------')
e_tot = run_dft("HYB_GGA_XC_WB97")
assert np.allclose(e_tot, -583.0817872870)

#TODO: add test cases for D3/D4 and gradient
assert np.allclose(e_tot, -582.7625143308, rtol=1e-8)

if __name__ == "__main__":
print("Full Tests for dft")
Expand Down
16 changes: 8 additions & 8 deletions gpu4pyscf/dft/tests/test_uks.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
H -0.7570000000 -0.0000000000 -0.4696000000
H 0.7570000000 0.0000000000 -0.4696000000
'''
bas='def2-qzvpp'
bas='def2-tzvpp'
grids_level = 3
nlcgrids_level = 1

Expand Down Expand Up @@ -55,37 +55,37 @@ def run_dft(xc):

class KnownValues(unittest.TestCase):
'''
known values are obtained by pyscf
known values are obtained by pyscf, # def2-qzvpp
'''
def test_uks_lda(self):
print('------- LDA ----------------')
e_tot = run_dft("LDA, vwn5")
assert np.allclose(e_tot, -75.42821982483972)
assert np.allclose(e_tot, -75.4231504131) #-75.42821982483972)

def test_uks_pbe(self):
print('------- PBE ----------------')
e_tot = run_dft('PBE')
assert np.allclose(e_tot, -75.91732813416843)
assert np.allclose(e_tot, -75.9128621398)# -75.91732813416843)

def test_uks_b3lyp(self):
print('-------- B3LYP -------------')
e_tot = run_dft('B3LYP')
assert np.allclose(e_tot, -76.00306439862237)
assert np.allclose(e_tot, -75.9987351592) #-76.00306439862237)

def test_uks_m06(self):
print('--------- M06 --------------')
e_tot = run_dft("M06")
assert np.allclose(e_tot, -75.96551006522827)
assert np.allclose(e_tot, -75.9609384616) #-75.96551006522827)

def test_uks_wb97(self):
print('-------- wB97 --------------')
e_tot = run_dft("HYB_GGA_XC_WB97")
assert np.allclose(e_tot, -75.987601337562)
assert np.allclose(e_tot, -75.9833214499) #-75.987601337562)

def test_uks_vv10(self):
print("------- wB97m-v -------------")
e_tot = run_dft('HYB_MGGA_XC_WB97M_V')
assert np.allclose(e_tot, -75.97363094678428)
assert np.allclose(e_tot, -75.9697577968)# -75.97363094678428)

#TODO: add test cases for D3/D4 and gradient

Expand Down
9 changes: 8 additions & 1 deletion gpu4pyscf/lib/tests/test_to_gpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
import numpy
import cupy
import pyscf
import pytest
from pyscf import scf, lib
from pyscf.dft import rks
from packaging import version

atom = '''
O 0.0000000000 -0.0000000000 0.1174000000
Expand All @@ -28,6 +30,7 @@

bas='sto3g'
grids_level = 1
pyscf_24 = version.parse(pyscf.__version__) <= version.parse('2.4.0')

def setUpModule():
global mol
Expand All @@ -41,8 +44,8 @@ def tearDownModule():
mol.stdout.close()
del mol


class KnownValues(unittest.TestCase):
@pytest.mark.skipif(pyscf_24, reason='requires pyscf 2.5 or higher')
def test_rhf(self):
mf = scf.RHF(mol).to_gpu()
e_tot = mf.to_gpu().kernel()
Expand All @@ -57,6 +60,7 @@ def test_rhf(self):
# h = mf.Hessian().to_gpu()
# h.kernel()

@pytest.mark.skipif(pyscf_24, reason='requires pyscf 2.5 or higher')
def test_rks(self):
mf = rks.RKS(mol).to_gpu()
e_tot = mf.to_gpu().kernel()
Expand All @@ -72,6 +76,7 @@ def test_rks(self):
# h = mf.Hessian().to_gpu()
# h.kernel()

@pytest.mark.skipif(pyscf_24, reason='requires pyscf 2.5 or higher')
def test_df_RHF(self):
mf = scf.RHF(mol).density_fit().to_gpu()
e_tot = mf.to_gpu().kernel()
Expand All @@ -87,6 +92,7 @@ def test_df_RHF(self):
h = hobj.kernel()
assert numpy.abs(lib.fp(h) - 2.198079352288524) < 1e-7

@pytest.mark.skipif(pyscf_24, reason='requires pyscf 2.5 or higher')
def test_df_b3lyp(self):
mf = rks.RKS(mol, xc='b3lyp').density_fit().to_gpu()
e_tot = mf.to_gpu().kernel()
Expand All @@ -105,6 +111,7 @@ def test_df_b3lyp(self):
print('DF b3lyp hessian:', lib.fp(h))
assert numpy.abs(lib.fp(h) - 2.1527804103141848) < 1e-7

@pytest.mark.skipif(pyscf_24, reason='requires pyscf 2.5 or higher')
def test_df_RKS(self):
mf = rks.RKS(mol, xc='wb97x').density_fit().to_gpu()
e_tot = mf.to_gpu().kernel()
Expand Down

0 comments on commit eaf83a4

Please sign in to comment.