PR-6 - feat: add C shell loop binding for 2-electron ERI#254
Conversation
| out, self.natm, self.atm, self.nbas, | ||
| self.bas, self.env, self._offs, self.nbfn | ||
| ) | ||
| return out.transpose(0, 2, 1, 3) |
There was a problem hiding this comment.
I think you should fill the two-electron integral array in C such that it doesn't need transposing.
There was a problem hiding this comment.
Done!
I've updated the C code to fill the ERI array directly in physicist notation by swapping the j and k indices, so there's no need for the transpose on the Python side anymore.
| * Loops over shells I, J; calls libcint_func per shell pair; fills the | ||
| * symmetric output matrix using PyArray_GETPTR (NumPy C-API). | ||
| */ | ||
| #define DEFINE_SHELLLOOP_INT1e(func_name, libcint_func) \ |
There was a problem hiding this comment.
Again let's rename this to something more descriptive, like DEFINE_INT1E_ARRAY_FN. Same for the 2-electron integrals.
d4230be to
8bd6884
Compare
There was a problem hiding this comment.
Pull request overview
Adds a new C-level shell-loop wrapper for computing full 4-index 2-electron ERI tensors via libcint, and exposes it as a new CBasis.electron_repulsion() Python method to reduce Python-level looping overhead.
Changes:
- Renamed/standardized C macro names for 1-electron array wrappers and 1-electron shell-loop wrappers.
- Added
eri_shellloopC binding that loops over (I,J,K,L) shells and fills the ERI tensor using 8-fold symmetry. - Added
CBasis.electron_repulsion()that allocates the ERI tensor and calls the new C binding.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
gbasis/integrals/src/libcint_wrap.c |
Adds the new ERI shell-loop C binding and registers it with the Python module; also renames the 1e wrapper macros for consistency. |
gbasis/integrals/libcint.py |
Adds CBasis.electron_repulsion() which calls into the new eri_shellloop binding. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| int shls[4]; | ||
| double buf[100000] = {0}; | ||
|
|
||
| int ipos = 0; |
| out = np.zeros((self.nbfn, self.nbfn, self.nbfn, self.nbfn), dtype=c_double) | ||
| libcint_bindings.eri_shellloop( | ||
| out, self.natm, self.atm, self.nbas, | ||
| self.bas, self.env, self._offs, self.nbfn | ||
| ) | ||
| return out |
| def electron_repulsion(self): | ||
| r""" | ||
| Compute the electron repulsion integrals. | ||
|
|
||
| The two-electron repulsion integral between basis functions |
Summary
LibcintandGBasis#229 (PR-6) [Week-4]DEFINE_SHELLLOOP_INT1epattern from PR-5 to 2-electron integralsChanges
libcint_wrap.c
eri_shellloop— dedicated C function that loops over all 4 shells (I, J, K, L) internally and fills the complete 4-dimensional ERI tensor in one callPyMethodDeflibcint.py
electron_repulsion()method inCBasisclass that callseri_shellloopdirectlytranspose(0, 2, 1, 3)to convert from chemist to physicist notation, matching the existingelectron_repulsion_integral()outputPerformance Results
Tested on H, He, Li with cc-pVDZ basis set (nbfn=24):
Correctness Results
Tested on H, He, Li with cc-pVDZ basis set (nbfn=24),
atol=1e-4:How To Test
Build locally:
pip install -e . --no-build-isolationCorrectness test:
Output:
Speed Test
Output: