Skip to content

Commit

Permalink
Fix linter error, update license comments
Browse files Browse the repository at this point in the history
  • Loading branch information
henryw7 committed Nov 22, 2024
1 parent 78cfa1f commit 18654b9
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 22 deletions.
22 changes: 14 additions & 8 deletions gpu4pyscf/gto/moleintor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 The GPU4PySCF Authors. All Rights Reserved.
# Copyright 2024 The GPU4PySCF Authors. All Rights Reserved.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -122,12 +122,11 @@ def build(self, cutoff=1e-14, group_size=None, diag_block_with_triu=False, aosym
nao = cart_ao_loc[-1]
ao_idx = np.array_split(np.arange(nao), cart_ao_loc[1:-1])
self.cart_ao_idx = np.hstack([ao_idx[i] for i in sorted_idx])
ncart = cart_ao_loc[-1]
nsph = sph_ao_loc[-1]
self.cart2sph = block_c2s_diag(self.angular, l_ctr_counts)
cput1 = log.timer_debug1('AO cart2sph coeff', *cput1)

if _mol.cart:
ncart = cart_ao_loc[-1]
inv_idx = np.argsort(self.cart_ao_idx, kind='stable').astype(np.int32)
self.coeff = cp.eye(ncart)[:,inv_idx]
else:
Expand All @@ -150,7 +149,8 @@ def build(self, cutoff=1e-14, group_size=None, diag_block_with_triu=False, aosym
cp_idx, cp_jdx = np.tril_indices(len(uniq_l_ctr))
l_ij = list(zip(uniq_l_ctr[cp_idx, 0], uniq_l_ctr[cp_jdx, 0]))
self.l_ij = np.asarray(l_ij)
def get_n_hermite_density_of_angular_pair(l): return (l + 1) * (l + 2) * (l + 3) // 6
def get_n_hermite_density_of_angular_pair(l):
return (l + 1) * (l + 2) * (l + 3) // 6
n_density_per_pair = np.array([ get_n_hermite_density_of_angular_pair(li + lj) for (li, lj) in l_ij ])
n_density_per_angular_pair = (bas_pairs_locs[1:] - bas_pairs_locs[:-1]) * n_density_per_pair
self.density_offset = np.append(0, np.cumsum(n_density_per_angular_pair)).astype(np.int32)
Expand Down Expand Up @@ -235,7 +235,8 @@ def get_int3c1e(mol, grids, direct_scf_tol, omega):
allowed_double_number = reserved_available_memory // 8
n_grid_split = int(np.ceil(total_double_number / allowed_double_number))
if (n_grid_split > 100):
raise Exception(f"Available GPU memory ({avail_mem / 1e9 : .1f} GB) is too small for the 3 center integral, which requires {total_double_number * 8 / 1e9 : .1f} GB of memory")
raise Exception(f"Available GPU memory ({avail_mem / 1e9 : .1f} GB) is too small for the 3 center integral, "
"which requires {total_double_number * 8 / 1e9 : .1f} GB of memory")
ngrids_per_split = (ngrids + n_grid_split - 1) // n_grid_split

int3c_pinned_memory_pool = cp.cuda.alloc_pinned_memory(ngrids * nao * nao * np.array([1.0]).nbytes)
Expand Down Expand Up @@ -269,7 +270,10 @@ def get_int3c1e(mol, grids, direct_scf_tol, omega):
grid_idx = np.arange(ngrids_of_split)
int3c_grid_slice = int3c_grid_slice[np.ix_(grid_idx, ao_idx, ao_idx)]

cp.cuda.runtime.memcpy(int3c[i_grid_split : i_grid_split + ngrids_of_split, :, :].ctypes.data, int3c_grid_slice.data.ptr, int3c_grid_slice.nbytes, cp.cuda.runtime.memcpyDeviceToHost)
cp.cuda.runtime.memcpy(int3c[i_grid_split : i_grid_split + ngrids_of_split, :, :].ctypes.data,
int3c_grid_slice.data.ptr,
int3c_grid_slice.nbytes,
cp.cuda.runtime.memcpyDeviceToHost)
# int3c[i_grid_split : i_grid_split + ngrids_of_split, :, :] = cp.asnumpy(int3c_grid_slice) # This is certainly the wrong way of DtoH memcpy

return int3c
Expand All @@ -292,8 +296,8 @@ def get_int3c1e_density_contracted(mol, grids, dm, direct_scf_tol, omega):
cart2sph_transformation_matrix = cp.asnumpy(intopt.cart2sph)
# TODO: This part is inefficient (O(N^3)), should be changed to the O(N^2) algorithm
dm = cart2sph_transformation_matrix @ dm @ cart2sph_transformation_matrix.T
ao_loc_sorted_order = intopt.sorted_mol.ao_loc_nr(cart = True) # This ao_loc order is consistent with the density matrix order and intopt.bas_pair2shls order

ao_loc_sorted_order = intopt.sorted_mol.ao_loc_nr(cart = True)
l_ij = intopt.l_ij.T.flatten()
n_total_hermite_density = intopt.density_offset[-1]
dm_pair_ordered = np.zeros(n_total_hermite_density)
Expand Down Expand Up @@ -341,7 +345,9 @@ def get_int3c1e_density_contracted(mol, grids, dm, direct_scf_tol, omega):

def intor(mol, intor, grids, dm=None, charges=None, direct_scf_tol=1e-13, omega=None):
assert intor == 'int1e_grids' and grids is not None
assert dm is None or charges is None, "Are you sure you want to contract the one electron integrals with both charge and density? If so, pass in density, obtain the result with n_charge and contract with the charges yourself."
assert dm is None or charges is None, \
"Are you sure you want to contract the one electron integrals with both charge and density? " + \
"If so, pass in density, obtain the result with n_charge and contract with the charges yourself."

if dm is None and charges is None:
return get_int3c1e(mol, grids, direct_scf_tol, omega)
Expand Down
2 changes: 1 addition & 1 deletion gpu4pyscf/gto/tests/test_int1e_grids.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 The GPU4PySCF Authors. All Rights Reserved.
# Copyright 2024 The GPU4PySCF Authors. All Rights Reserved.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down
5 changes: 1 addition & 4 deletions gpu4pyscf/lib/gint/g1e.cu
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
/*
* gpu4pyscf is a plugin to use Nvidia GPU in PySCF package
*
* Copyright (C) 2022 Qiming Sun
/* Copyright 2024 The GPU4PySCF Authors. All Rights Reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
5 changes: 1 addition & 4 deletions gpu4pyscf/lib/gint/g1e_root_123.cu
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
/*
* gpu4pyscf is a plugin to use Nvidia GPU in PySCF package
*
* Copyright (C) 2022 Qiming Sun
/* Copyright 2024 The GPU4PySCF Authors. All Rights Reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
16 changes: 16 additions & 0 deletions gpu4pyscf/lib/gint/g3c1e.cu
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/* Copyright 2024 The GPU4PySCF Authors. All Rights Reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "gint.h"
#include "config.h" // For SQRTPI

Expand Down
5 changes: 1 addition & 4 deletions gpu4pyscf/lib/gint/j_engine_matrix_reorder.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
/*
* gpu4pyscf is a plugin to use Nvidia GPU in PySCF package
*
* Copyright (C) 2022 Qiming Sun
/* Copyright 2024 The GPU4PySCF Authors. All Rights Reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion gpu4pyscf/lib/gint/nr_fill_ao_int3c1e.cu
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright 2023 The GPU4PySCF Authors. All Rights Reserved.
/* Copyright 2024 The GPU4PySCF Authors. All Rights Reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down

0 comments on commit 18654b9

Please sign in to comment.