Skip to content

Commit

Permalink
Add a edge case test that computes int1e with fakemol, that supposes …
Browse files Browse the repository at this point in the history
…to fail
  • Loading branch information
henryw7 authored Dec 12, 2024
1 parent 010ca2d commit 39b1de7
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion gpu4pyscf/df/tests/test_int3c2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import pyscf
from pyscf import df
from pyscf import df, gto
from pyscf.gto.moleintor import getints, make_cintopt
from pyscf.df.grad.rhf import _int3c_wrapper
import numpy as np
import cupy as cp
import unittest
from gpu4pyscf.df import int3c2e
from gpu4pyscf.lib.cupy_helper import load_library
Expand Down Expand Up @@ -147,6 +148,46 @@ def test_int1e_iprinvip(self):
h1ao = mol.intor('int1e_iprinvip', comp=9) # <\nabla|1/r|>
assert np.linalg.norm(int3c[:,:,:,i] - h1ao) < 1e-7

def test_int1e_edge_case(self):
mol = gto.M(
atom =
"""
H 0 0 0
H -1 0.0 0
""",
basis =
"""
H S
0.1612777588 1.0000000
""")
mol.build()

xs = np.arange(-3.01, 3.00, 5.0)
ys = np.arange(-3.02, 3.00, 10.0)
zs = np.arange(-3.03, 3.00, 10.0)
grid_points = pyscf.lib.cartesian_prod([xs, ys, zs])

nao = mol.nao
ngrids = grid_points.shape[0]
dm = np.ones((nao, nao))
charges = np.ones(ngrids)

int3c2e_ip2 = mol._add_suffix('int3c2e_ip2')
cintopt = gto.moleintor.make_cintopt(mol._atm, mol._bas, mol._env, int3c2e_ip2)
fakemol = gto.fakemol_for_charges(grid_points)
q_nj = df.incore.aux_e2(mol, fakemol, intor=int3c2e_ip2, aosym='s1', cintopt=cintopt)
dq_cpu = np.einsum('xijk,ij,k->xk', q_nj, dm, charges)

dm = cp.asarray(dm)
charges = cp.asarray(charges)
intopt = int3c2e.VHFOpt(mol, fakemol, 'int2e')
intopt.build(1e-14, diag_block_with_triu=True, aosym=False)
coeff = intopt.coeff
dm_cart = coeff @ dm @ coeff.T
dq_gpu, _ = int3c2e.get_int3c2e_ip_jk(intopt, 0, 'ip2', charges, None, dm_cart)

cp.testing.assert_allclose(dq_cpu, dq_gpu, atol = 1e-10)

if __name__ == "__main__":
print("Full Tests for int3c")
unittest.main()

0 comments on commit 39b1de7

Please sign in to comment.