Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sunqm committed Sep 28, 2023
1 parent cfa46cb commit fce6f70
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ jobs:
env
cmake -DWITH_CINT2_INTERFACE=1 -DWITH_RANGE_COULOMB=1 -DWITH_COULOMB_ERF=1 -DWITH_F12=1 -DWITH_4C1E=1 -Bbuild -DKEEP_GOING=1 .
cmake --build build
pip install numpy mpmath pyscf
- name: Test for rys-roots
if: startsWith(matrix.os, 'ubuntu')
run: |
cd ${{ github.workspace }}/testsuite
pip install numpy mpmath pyscf
python test_rys_roots.py
- name: Unittest
if: startsWith(matrix.os, 'ubuntu')
Expand Down
6 changes: 6 additions & 0 deletions testsuite/test_int1e.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def run(intor, comp=1, suffix='_sph', thr=1e-9):
args = (mol._atm.ctypes.data_as(ctypes.c_void_p), ctypes.c_int(mol.natm),
mol._bas.ctypes.data_as(ctypes.c_void_p), ctypes.c_int(mol.nbas),
mol._env.ctypes.data_as(ctypes.c_void_p), cintopt)
failed = False
for i in range(mol.nbas):
for j in range(mol.nbas):
ref = mol.intor_by_shell(intor, [i,j], comp=comp)
Expand All @@ -79,10 +80,15 @@ def run(intor, comp=1, suffix='_sph', thr=1e-9):
mol._env.ctypes.data_as(ctypes.c_void_p))
if numpy.linalg.norm(ref-buf) > thr:
print(intor, '| nopt', i, j, numpy.linalg.norm(ref-buf))#, ref, buf
failed = True
#fn(buf.ctypes.data_as(ctypes.c_void_p),
# (ctypes.c_int*2)(i,j), *args)
#if numpy.linalg.norm(ref-buf) > 1e-7:
# print('|', i, j, numpy.linalg.norm(ref-buf))
if failed:
print('failed')
else:
print('pass')

run('int1e_ovlp')
run('int1e_nuc')
Expand Down
43 changes: 29 additions & 14 deletions testsuite/test_int1e_grids.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,11 @@ def test_int1e_grids_sph1(name, vref, dim, place):
dat = op[:ref.size].reshape(dj, di).T
if abs(dat - ref).max() > 1e-12:
print(i, j, abs(dat - ref).max())
print('sum', v1)
print('sum', v1, 'diff', v1 - vref)
if abs(v1 - vref) < 1e-10:
print('pass')
else:
print('failed')

def test_int1e_grids_sph(name, vref, dim, place):
intor = getattr(_cint, name)
Expand All @@ -199,7 +203,11 @@ def test_int1e_grids_sph(name, vref, dim, place):
env_g.ctypes.data_as(ctypes.c_void_p), opt)
v1 += abs(op[:ngrids*di*dj*dim]).sum()
cnt += ngrids*di*dj*dim
print('sum', v1)
print('sum', v1, 'diff', v1 - vref)
if abs(v1 - vref) < 1e-10:
print('pass')
else:
print('failed')

def test_mol1():
import time
Expand All @@ -215,6 +223,14 @@ def test_mol1():
numpy.random.seed(12)
ngrids = 201
grids = numpy.random.random((ngrids, 3)) * 12 - 5

def check(intor, ref):
j3c = mol.intor(intor, grids=grids)
diff = abs(j3c - ref).max()
print(diff)
return diff > 1e-12

failed = False
for omega in (0, 0.1, -0.1):
for zeta in (0, 10, 1e16):
print('omega, zeta', omega, zeta)
Expand All @@ -227,27 +243,26 @@ def test_mol1():
mol.set_rinv_zeta(zeta)
fmol = pyscf.gto.fakemol_for_charges(grids, expnt)
ref = df.incore.aux_e2(mol, fmol, intor='int3c2e').transpose(2,0,1)
j3c = mol.intor('int1e_grids', grids=grids)
print(abs(j3c - ref).max())
failed = check('int1e_grids', ref) or failed

ref = df.incore.aux_e2(mol, fmol, intor='int3c2e_ip1').transpose(0,3,1,2)
j3c = mol.intor('int1e_grids_ip', grids=grids)
print(abs(j3c - ref).max())
failed = check('int1e_grids_ip', ref) or failed

ref = df.incore.aux_e2(mol, fmol, intor='int3c2e_ip1_cart').transpose(0,3,1,2)
j3c = mol.intor('int1e_grids_ip_cart', grids=grids)
print(abs(j3c - ref).max())
failed = check('int1e_grids_ip_cart', ref) or failed

ref = df.incore.aux_e2(mol, fmol, intor='int3c2e_ip1_spinor').transpose(0,3,1,2)
j3c = mol.intor('int1e_grids_ip_spinor', grids=grids)
print(abs(j3c - ref).max())
failed = check('int1e_grids_ip_spinor', ref) or failed

ref = df.r_incore.aux_e2(mol, fmol, intor='int3c2e_spsp1_spinor').transpose(2,0,1)
j3c = mol.intor('int1e_grids_spvsp_spinor', grids=grids)
print(abs(j3c - ref).max())
failed = check('int1e_grids_spvsp_spinor', ref) or failed
if failed:
print('failed')
else:
print('pass')

test_int1e_grids_sph1('cint1e_grids_sph', 0, 1, 9)
test_int1e_grids_sph('cint1e_grids_ip_sph', 0, 1, 9)
test_int1e_grids_sph1('cint1e_grids_sph', 36.81452996003706, 1, 9)
test_int1e_grids_sph('cint1e_grids_ip_sph', 3279.92861109671, 1, 9)
try:
test_mol1()
except ImportError:
Expand Down
9 changes: 7 additions & 2 deletions testsuite/test_int2c2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def run(intor, comp=1, suffix='_sph', thr=1e-7):
mol._bas.ctypes.data_as(ctypes.c_void_p), ctypes.c_int(mol.nbas),
mol._env.ctypes.data_as(ctypes.c_void_p), cintopt)

failed = False
for i in range(mol.nbas):
for j in range(mol.nbas):
ref = mol.intor_by_shell(intor2, [i,j], comp=comp)
Expand All @@ -82,12 +83,16 @@ def run(intor, comp=1, suffix='_sph', thr=1e-7):
mol._env.ctypes.data_as(ctypes.c_void_p), lib.c_null_ptr())
if numpy.linalg.norm(ref-buf) > thr:
print(intor, '| nopt', i, j, numpy.linalg.norm(ref-buf))#, ref, buf
exit()
failed = True
fn1(buf.ctypes.data_as(ctypes.c_void_p),
(ctypes.c_int*2)(i,j), *args)
if numpy.linalg.norm(ref-buf) > thr:
print(intor, '|', i, j, numpy.linalg.norm(ref-buf))
exit()
failed = True
if failed:
print('failed')
else:
print('pass')

run('int2c2e')
run('int2c2e_ip1', 3)
7 changes: 7 additions & 0 deletions testsuite/test_int3c1e.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def run(intor, comp=1, suffix='_sph', thr=1e-7):
args = (mol._atm.ctypes.data_as(ctypes.c_void_p), ctypes.c_int(mol.natm),
mol._bas.ctypes.data_as(ctypes.c_void_p), ctypes.c_int(mol.nbas),
mol._env.ctypes.data_as(ctypes.c_void_p), cintopt)
failed = False
for i in range(mol.nbas):
for j in range(mol.nbas):
for k in range(mol.nbas):
Expand All @@ -86,10 +87,16 @@ def run(intor, comp=1, suffix='_sph', thr=1e-7):
mol._env.ctypes.data_as(ctypes.c_void_p), lib.c_null_ptr())
if numpy.linalg.norm(ref-buf) > thr:
print(intor, '| nopt', i, j, k, numpy.linalg.norm(ref-buf))#, ref, buf
failed = True
fn1(buf.ctypes.data_as(ctypes.c_void_p),
(ctypes.c_int*3)(i,j,k), *args)
if numpy.linalg.norm(ref-buf) > thr:
print(intor, '|', i, j, k, numpy.linalg.norm(ref-buf))
failed = True
if failed:
print('failed')
else:
print('pass')

run('int3c1e')
#run('int3c1e_p2')
Expand Down

0 comments on commit fce6f70

Please sign in to comment.