Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Least Squares Tensor Hypercontraction (LS-THC) for ERIs (Part 1) #3157

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

andyj10224
Copy link
Contributor

@andyj10224 andyj10224 commented Apr 21, 2024

Description

In this PR, we implement a pilot version of least squares tensor hypercontraction (LS-THC)... factoring 4-index ERIs (O(N^4)) into two-index quantities (i.e. $(mn|rs) = x_{m}^{P}x_{n}^{P}Z^{PQ}x_{r}^{Q}x_{s}^{Q}$). In the LS-THC formulation, $P$ and $Q$ are derived from grid points, and

$x_{m}^{P} = w_{P}^{\frac{1}{4}} \phi_{m}(x_{P}, y_{P}, z_{P})$,
$E^{PQ} = x_{m}^{P}x_{n}^{P}(mn|rs)x_{r}^{Q}x_{s}^{Q}$
$S^{PP'} = (x_{m}^{P}x_{m}^{P'})^{2}$
$Z^{PQ} = (S^{PP'})^{-1} E^{P'Q'} (S^{QQ'})^{-1}$

This is based off of the work of Parrish et al. (2012)

These quantities can be constructed integral-direct and non-iteratively. No four or even three-index quantities are stored, thereby allowing for the future development of efficient, low-memory quantum chemistry algorithms in Psi.

This is a PR in a series of planned PRs that will involve:
1.) LS-THC-JK (integral-direct SCF without recomputing ERIs every iteration and faster K construction)
2.) LS-THC-MP2
3.) Local grid implementation of LS-THC to allow for use in local correlation methods (DLPNO-MP2, DLPNO-CCSD/(T))

User API & Changelog headlines

  • Added Python interface (Pybind) for building LS-THC quantities that allow for rapid prototyping of new methods involving THC
  • Developed infrastructure for the development of alternate ways to perform THC (i.e. PF-THC)

Dev notes & details

  • Implemented LS-THC C/Py-side for future QC methods

Questions

  • Is this the proper way to export this object Py-side?

Checklist

Status

  • Ready for review
  • Ready for merge

@andyj10224 andyj10224 changed the title Least Squares Hypercontraction for ERIs (Part 1) Least Squares Tensor Hypercontraction (LS-THC) for ERIs (Part 1) Apr 21, 2024
@andyj10224
Copy link
Contributor Author

Added some comments and addressed initial reviews. @loriab @jturney feel free to take a look

psi4/src/psi4/libmints/thc_eri.cc Outdated Show resolved Hide resolved
psi4/src/psi4/libmints/thc_eri.cc Outdated Show resolved Hide resolved
psi4/src/psi4/libmints/thc_eri.cc Outdated Show resolved Hide resolved
psi4/src/psi4/libmints/thc_eri.cc Outdated Show resolved Hide resolved
psi4/src/psi4/libmints/thc_eri.cc Outdated Show resolved Hide resolved
@andyj10224
Copy link
Contributor Author

Pinging @loriab once again, requesting review


// Parrish 2012, Equation 30
int nremoved = 0;
SharedMatrix S_Qq_inv = S_Qq->pseudoinverse(options_.get_double("LS_THC_S_EPSILON"), nremoved);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: I've run 10 water molecules 240 AO basis, based on test_thc_eri.py, and it seems

Matrix->pseudoinverse bloats memory, more than I would expected.

   --------------------------------------------
       Least-Squares Tensor Hypercontraction   
                   by Andy Jiang               
              doi: 10.1063/1.4768233           
   --------------------------------------------

  Detailed LS-THC thresholds and cutoffs:
    LS_THC_SPHERICAL_POINTS   =    38 
    LS_THC_RADIAL_POINTS      =     8 
    LS_THC_BASIS_TOLERANCE    = 1.000e-12 
    LS_THC_WEIGHTS_TOLERANCE  = 1.000e-12 
    LS_THC_S_EPSILON          = 1.000e-10 
    Using DF?                     Yes 


    Tensor Hypercontraction Complete! 

    Number of Grid Points (Rank) :   6623 (220 per atom)

    Memory Required to Store Exact Integrals :  3.116 [GiB]
    Memory Required to Store DF Integrals :  0.181 [GiB]
    Memory Required in LS-THC factored form  :  0.339 [GiB]

THC completed: 
Z_PQ.shape=(6623, 6623)
x1.shape=(6623, 240)
Filename: thc_eri.py

mprof (a rough idea of process memory), after 100s mark in mprof memory is due to 3-idx AO and einsums.

thc_01

memray flamegraph (.tar.gz), seems to point into Matrix.pseudoinverse and subsequent svd.

memray_flamegraph.tar.gz
image

I know it's a Part 1, nevertheless I wanted to share what I found.

Very good job anyway on adding THC into the Psi4 stack! Can't wait to try it out more, for prototyping!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PhillCli Thank you for your tests and for going above and beyond! I will definitely look into improving the memory footprint! One possible solution is to use truncated SVD for the pseudoinverse (algorithm available in @jturney 's Einsums). I will look into this further once einsums is fully merged with Psi4.

Copy link
Contributor

@davpoolechem davpoolechem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I can consider myself happy with this! Looking forward to seeing this in action for different methods!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants