Skip to content

CompositeJK Part 3: SplitJK - #2955

Merged
davpoolechem merged 31 commits into
psi4:masterfrom
davpoolechem:dpoole34/compositejk-splitjk-squash
Oct 2, 2023
Merged

CompositeJK Part 3: SplitJK#2955
davpoolechem merged 31 commits into
psi4:masterfrom
davpoolechem:dpoole34/compositejk-splitjk-squash

Conversation

@davpoolechem

@davpoolechem davpoolechem commented May 8, 2023

Copy link
Copy Markdown
Contributor

Description

The final step of the CompositeJK saga.

The previous PR in this chain, #2833, introduced the CompositeJK framework to Psi4, a class by which to enable arbitrary mixing and matching of different algorithms for constructing the J and K matrices separately, with front-end changes to match. The big issue with the current formulation of CompositeJK, is that every single separate J or K build algorithm in Psi4 (currently DF-DirJ, LinK, and COSX) is contained within CompositeJK itself. This runs a high risk of CompositeJK becoming monolithic, especially as more separate J/K build methods are added (e.g., CFMM).

This PR is meant to be the solution to that issue. Rather than storing every separate J or K build algorithm in CompositeJK itself, they are now implemented as derived classes of a new base class, SplitJK. SplitJK features the build_G_component member function, which derived classes of SplitJK then implement to execute their own algorithm for building one of J or K. CompositeJK is reworked to match, featuring a pair of shared_ptrs to SplitJK classes, one representing the J algorithm, and one representing the K algorithm. Actual machinery for computing J or K, as well as other functionalities such as header printing, is then done through calling corresponding functions from the SplitJK pointers.

My thought is for this PR to be added in v1.9.

User API & Changelog headlines

N/A

Dev notes & details

  • Implements the SplitJK class for representing algorithms that build one of J or K.
  • Refactors DF-DirJ, LinK, and COSX as derived classes of SplitJK.
  • Reworks the CompositeJK class to execute in terms of SplitJK derived classes.

Questions

  • Is passing the eri_computers variable to COSX::build_G_component() as an argument acceptable, even though it is unused in that function? My logic, for now, is that the SplitJK implementation allows for a universal interface for calling different SplitJK derived classes, and thus different composite algorithm combinations; but this is a case where specifically fine-tuning the input for different methods may be preferable. What does everyone think?

Checklist

Status

  • Ready for review
  • Ready for merge

@loriab loriab added this to the Psi4 1.9 milestone May 8, 2023
@loriab loriab added the scf Involves general SCF: convergence algorithms, RHF/UHF/ROHF/CUHF... label May 8, 2023
@davpoolechem
davpoolechem force-pushed the dpoole34/compositejk-splitjk-squash branch 3 times, most recently from 2249f36 to 16ebc0e Compare May 15, 2023 13:52
@davpoolechem
davpoolechem force-pushed the dpoole34/compositejk-splitjk-squash branch 2 times, most recently from 133d799 to 44297ec Compare May 25, 2023 14:25
return esp_bound;
}

COSK::COSK(std::shared_ptr<BasisSet> primary, Options& options) : SplitJK(primary, options) {

@davpoolechem davpoolechem May 25, 2023

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Machinery pulled from the previous CompositeJK::common_init() function.

return num_computed_shells_;
}

void COSK::print_header() const {

@davpoolechem davpoolechem May 25, 2023

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Machinery pulled from the previous CompositeJK::print_COSX_header() function.

// build the K matrix using Neeses's Chain-of-Spheres Exchange algorithm
// algorithm is originally proposed in https://doi.org/10.1016/j.chemphys.2008.10.036
// overlap fitting is discussed in https://doi.org/10.1063/1.3646921
void COSK::build_G_component(std::vector<std::shared_ptr<Matrix>>& D, std::vector<std::shared_ptr<Matrix>>& K,

@davpoolechem davpoolechem May 25, 2023

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Machinery pulled from the previous CompositeJK::build_COSK() function.


namespace psi {

DirectDFJ::DirectDFJ(std::shared_ptr<BasisSet> primary, std::shared_ptr<BasisSet> auxiliary, Options& options) : SplitJK(primary, options), auxiliary_(auxiliary) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Machinery pulled from the previous CompositeJK::common_init() function.

return num_computed_shells_;
}

void DirectDFJ::print_header() const {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Machinery pulled from the previous CompositeJK::print_DirectDFJ_header() function.


// build the J matrix using Weigend's integral-direct density fitting algorithm
// algorithm is in Figure 1 of https://doi.org/10.1039/B204199P
void DirectDFJ::build_G_component(std::vector<std::shared_ptr<Matrix>>& D, std::vector<std::shared_ptr<Matrix>>& J,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Machinery pulled from the previous CompositeJK::build_DirectDFJ() function.


namespace psi {

LinK::LinK(std::shared_ptr<BasisSet> primary, Options& options) : SplitJK(primary, options) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Machinery pulled from the previous CompositeJK::common_init() function.

return num_computed_shells_;
}

void LinK::print_header() const {

@davpoolechem davpoolechem May 25, 2023

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Machinery pulled from the previous CompositeJK::print_linK_header() function.


// build the K matrix using Ochsenfelds's Linear Exchange (LinK) algorithm
// To follow this code, compare with figure 1 of DOI: 10.1063/1.476741
void LinK::build_G_component(std::vector<std::shared_ptr<Matrix>>& D, std::vector<std::shared_ptr<Matrix>>& K,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Machinery pulled from the previous CompositeJK::build_linK() function.

// Is the JK currently on the first SCF iteration of this SCF cycle?
bool initial_iteration_ = true;

// => Density Fitting Stuff, for Direct DF-J <= //

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Moved to respective SplitJK derived classes.

/// Post-iteration Incfock processing
void incfock_postiter();

/// Build the coulomb (J) matrix using Direct DF-J

@davpoolechem davpoolechem May 25, 2023

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Moved to respective SplitJK derived classes, as build_G_component().

* type on output file
*/
void print_header() const override;

@davpoolechem davpoolechem May 25, 2023

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Moved to corresponding SplitJK derived classes, as print_header().


namespace psi {

Matrix compute_numeric_overlap(const DFTGrid &grid, const std::shared_ptr<BasisSet> &primary) {

@davpoolechem davpoolechem May 25, 2023

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Code block moved to libfock/COSK.cc.


// => Set up separate K algorithm <= //

// Linear Exchange (LinK)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Code block moved to libfock/LinK.cc.

linK_ints_cutoff_ = cutoff_;
}

// Chain-of-Spheres Exchange (COSX)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Code block moved to libfock/COSK.cc.

}
}

void CompositeJK::print_DirectDFJ_header() const {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Function moved to DirectDFJ::print_header() in libfock/DirectDFJ.cc.

}
}

void CompositeJK::print_linK_header() const {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Function moved to LinK::print_header() in libfock/LinK.cc.

}
}

void CompositeJK::print_COSX_header() const {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Function moved to COSK::print_header() in libfock/COSK.cc.


void CompositeJK::postiterations() {}

// build the J matrix using Weigend's integral-direct density fitting algorithm

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Function moved to DirectDFJ::build_G_component() function in libfock/DirectDFJ.cc.


}

// build the K matrix using Ochsenfelds's Linear Exchange (LinK) algorithm

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Function moved to LinK::build_G_component() function in libfock/LinK.cc.

// build the K matrix using Neeses's Chain-of-Spheres Exchange algorithm
// algorithm is originally proposed in https://doi.org/10.1016/j.chemphys.2008.10.036
// overlap fitting is discussed in https://doi.org/10.1063/1.3646921
void CompositeJK::build_COSK(std::vector<std::shared_ptr<Matrix>>& D, std::vector<std::shared_ptr<Matrix>>& K) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Function moved to COSK::build_G_component() function in libfock/COSK.cc.

@davpoolechem
davpoolechem marked this pull request as ready for review May 25, 2023 18:58
@davpoolechem

Copy link
Copy Markdown
Contributor Author

All right, I shall officially open this up for review.

@davpoolechem
davpoolechem force-pushed the dpoole34/compositejk-splitjk-squash branch from 319c882 to c6b1840 Compare October 2, 2023 13:15

@jturney jturney left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good!

@davpoolechem
davpoolechem enabled auto-merge October 2, 2023 14:06
@davpoolechem
davpoolechem added this pull request to the merge queue Oct 2, 2023
Merged via the queue into psi4:master with commit 141fcf2 Oct 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scf Involves general SCF: convergence algorithms, RHF/UHF/ROHF/CUHF...

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants