Skip to content

Commit

Permalink
Initial Implementation of UKS in GauXC (#59)
Browse files Browse the repository at this point in the history
* Added skeleton api for UKS and GKS

* Added Skeleton api for eval_exc_vxc_local_work for UKS/GKS

* Removed the dimension parameters from the Z, X, and Y arguments (redundant)

* Revised UKS/GKS API naming scheme to overloaded functions, so that all functions have same name

* Replaced exit(0) with GAUXC_GENERIC_EXCEPTION

* added skeleton for eval_uvvar_lda/gga for UKS and GKS

* Fixed capitalization for _UKS/GKS -> _uks/gks

* Added skeleton for eval_zmat uks/gks

* Filled in the eval_exc_vxc functions for uks and gks

* Filled in exc_vxc_local_work for UKS for HOST

* Filled in eval uvvar_lda/gga for uks

* Filled in the pipml-> calls to eval_uvvar and eval_zmat for uks

* Filled in eval_zmat_lda_vxc_uks for HOST

* Fixed code to get LDA UKS reasonably working

* Cleaned up some stuff for GGA UKS. Will work on it some more later

* Cleaned up some stuff for GGA (BUGGED in eval_zmat_gga_vxc_uks)

* Fixed error in how Z matrix was being formed for GGA UKS

* Tweaked some stuff for GGA UKS. Should be correct but still see error at 10^-4 a.u.

* Fixed the n_pm = 0.5(rho_s +- rho_z) -> 0.5(rho_s +- |rho_z|)

* Undid last change, was uneccesary for UKS

* LDA works, added in TestGrid for debugging purposes

* GGA UKS is working. Will need to stress test

* Removed extraneous debug print statements

* Removed GKS stubs

* Removed remaining gks stubs

* Fixed bug in reference_replicated_xc_host_integrator_exc_vxc.hpp and removed testgrid

* Renamed types to _rks and _uks

* Switched UKS naming convention P->Pscalar VXC->VXCscalar

* Fixed other naming conventions, print statements, and misc stuff

* Removed unnecessary comment

* Fixed another missing naming convention

* Added basic unittest for UKS for neutral Li/sto-3g

* Unified RKS/UKS unittest integrator

* Cleaned Up the test_xc_integrator, removed allocation of some UKS variables during RKS

* Clarified that UKS is not implemented in Device for the 'NOT YET IMPLEMENTED' statements

* Changed comment in reference_local_host_work_driver.cxx to use reference DOI
  • Loading branch information
elambros authored Aug 15, 2023
1 parent 6cbdc8c commit adf4788
Show file tree
Hide file tree
Showing 30 changed files with 912 additions and 113 deletions.
6 changes: 4 additions & 2 deletions include/gauxc/xc_integrator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class XCIntegrator {
using value_type = typename matrix_type::value_type;
using basisset_type = BasisSet< value_type >;

using exc_vxc_type = std::tuple< value_type, matrix_type >;
using exc_vxc_type_rks = std::tuple< value_type, matrix_type >;
using exc_vxc_type_uks = std::tuple< value_type, matrix_type, matrix_type >;
using exc_grad_type = std::vector< value_type >;
using exx_type = matrix_type;

Expand All @@ -52,7 +53,8 @@ class XCIntegrator {
XCIntegrator( XCIntegrator&& ) noexcept;

value_type integrate_den( const MatrixType& );
exc_vxc_type eval_exc_vxc ( const MatrixType& );
exc_vxc_type_rks eval_exc_vxc ( const MatrixType& );
exc_vxc_type_uks eval_exc_vxc ( const MatrixType&, const MatrixType& );
exc_grad_type eval_exc_grad( const MatrixType& );
exx_type eval_exx ( const MatrixType&,
const IntegratorSettingsEXX& = IntegratorSettingsEXX{} );
Expand Down
9 changes: 8 additions & 1 deletion include/gauxc/xc_integrator/impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,19 @@ typename XCIntegrator<MatrixType>::value_type
};

template <typename MatrixType>
typename XCIntegrator<MatrixType>::exc_vxc_type
typename XCIntegrator<MatrixType>::exc_vxc_type_rks
XCIntegrator<MatrixType>::eval_exc_vxc( const MatrixType& P ) {
if( not pimpl_ ) GAUXC_PIMPL_NOT_INITIALIZED();
return pimpl_->eval_exc_vxc(P);
};

template <typename MatrixType>
typename XCIntegrator<MatrixType>::exc_vxc_type_uks
XCIntegrator<MatrixType>::eval_exc_vxc( const MatrixType& Pscalar, const MatrixType& Pz ) {
if( not pimpl_ ) GAUXC_PIMPL_NOT_INITIALIZED();
return pimpl_->eval_exc_vxc(Pscalar, Pz);
};

template <typename MatrixType>
typename XCIntegrator<MatrixType>::exc_grad_type
XCIntegrator<MatrixType>::eval_exc_grad( const MatrixType& P ) {
Expand Down
20 changes: 19 additions & 1 deletion include/gauxc/xc_integrator/replicated/impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ typename ReplicatedXCIntegrator<MatrixType>::value_type
}

template <typename MatrixType>
typename ReplicatedXCIntegrator<MatrixType>::exc_vxc_type
typename ReplicatedXCIntegrator<MatrixType>::exc_vxc_type_rks
ReplicatedXCIntegrator<MatrixType>::eval_exc_vxc_( const MatrixType& P ) {

if( not pimpl_ ) GAUXC_PIMPL_NOT_INITIALIZED();
Expand All @@ -76,6 +76,24 @@ typename ReplicatedXCIntegrator<MatrixType>::exc_vxc_type

}

template <typename MatrixType>
typename ReplicatedXCIntegrator<MatrixType>::exc_vxc_type_uks
ReplicatedXCIntegrator<MatrixType>::eval_exc_vxc_( const MatrixType& Pscalar, const MatrixType& Pz ) {

if( not pimpl_ ) GAUXC_PIMPL_NOT_INITIALIZED();
matrix_type VXCscalar( Pscalar.rows(), Pscalar.cols() );
matrix_type VXCz( Pz.rows(), Pz.cols() );
value_type EXC;

pimpl_->eval_exc_vxc( Pscalar.rows(), Pscalar.cols(), Pscalar.data(), Pscalar.rows(),
Pz.data(), Pz.rows(),
VXCscalar.data(), VXCscalar.rows(),
VXCz.data(), VXCz.rows(), &EXC );

return std::make_tuple( EXC, VXCscalar, VXCz );

}

template <typename MatrixType>
typename ReplicatedXCIntegrator<MatrixType>::exc_grad_type
ReplicatedXCIntegrator<MatrixType>::eval_exc_grad_( const MatrixType& P ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ class ReplicatedXCIntegratorImpl {
virtual void eval_exc_vxc_( int64_t m, int64_t n, const value_type* P,
int64_t ldp, value_type* VXC, int64_t ldvxc,
value_type* EXC ) = 0;
virtual void eval_exc_vxc_( int64_t m, int64_t n, const value_type* Pscalar,
int64_t ldpscalar,
const value_type* Pz,
int64_t ldpz,
value_type* VXCscalar, int64_t ldvxcscalar,
value_type* VXCz, int64_t ldvxcz,
value_type* EXC ) = 0;
virtual void eval_exc_grad_( int64_t m, int64_t n, const value_type* P,
int64_t ldp, value_type* EXC_GRAD ) = 0;
virtual void eval_exx_( int64_t m, int64_t n, const value_type* P,
Expand All @@ -64,6 +71,14 @@ class ReplicatedXCIntegratorImpl {
int64_t ldp, value_type* VXC, int64_t ldvxc,
value_type* EXC );

void eval_exc_vxc( int64_t m, int64_t n, const value_type* Pscalar,
int64_t ldpscalar,
const value_type* Pz,
int64_t ldpz,
value_type* VXCscalar, int64_t ldvxcscalar,
value_type* VXCz, int64_t ldvxcz,
value_type* EXC );

void eval_exc_grad( int64_t m, int64_t n, const value_type* P,
int64_t ldp, value_type* EXC_GRAD );

Expand Down
6 changes: 4 additions & 2 deletions include/gauxc/xc_integrator/replicated_xc_integrator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ class ReplicatedXCIntegrator : public XCIntegratorImpl<MatrixType> {

using matrix_type = typename XCIntegratorImpl<MatrixType>::matrix_type;
using value_type = typename XCIntegratorImpl<MatrixType>::value_type;
using exc_vxc_type = typename XCIntegratorImpl<MatrixType>::exc_vxc_type;
using exc_vxc_type_rks = typename XCIntegratorImpl<MatrixType>::exc_vxc_type_rks;
using exc_vxc_type_uks = typename XCIntegratorImpl<MatrixType>::exc_vxc_type_uks;
using exc_grad_type = typename XCIntegratorImpl<MatrixType>::exc_grad_type;
using exx_type = typename XCIntegratorImpl<MatrixType>::exx_type;

Expand All @@ -38,7 +39,8 @@ class ReplicatedXCIntegrator : public XCIntegratorImpl<MatrixType> {
std::unique_ptr< pimpl_type > pimpl_;

value_type integrate_den_( const MatrixType& ) override;
exc_vxc_type eval_exc_vxc_ ( const MatrixType& ) override;
exc_vxc_type_rks eval_exc_vxc_ ( const MatrixType& ) override;
exc_vxc_type_uks eval_exc_vxc_ ( const MatrixType&, const MatrixType& ) override;
exc_grad_type eval_exc_grad_( const MatrixType& ) override;
exx_type eval_exx_ ( const MatrixType&, const IntegratorSettingsEXX& ) override;
const util::Timer& get_timings_() const override;
Expand Down
12 changes: 9 additions & 3 deletions include/gauxc/xc_integrator/xc_integrator_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@ class XCIntegratorImpl {

using matrix_type = MatrixType;
using value_type = typename matrix_type::value_type;
using exc_vxc_type = typename XCIntegrator<MatrixType>::exc_vxc_type;
using exc_vxc_type_rks = typename XCIntegrator<MatrixType>::exc_vxc_type_rks;
using exc_vxc_type_uks = typename XCIntegrator<MatrixType>::exc_vxc_type_uks;
using exc_grad_type = typename XCIntegrator<MatrixType>::exc_grad_type;
using exx_type = typename XCIntegrator<MatrixType>::exx_type;

protected:

virtual value_type integrate_den_( const MatrixType& P ) = 0;
virtual exc_vxc_type eval_exc_vxc_ ( const MatrixType& P ) = 0;
virtual exc_vxc_type_rks eval_exc_vxc_ ( const MatrixType& P ) = 0;
virtual exc_vxc_type_uks eval_exc_vxc_ ( const MatrixType& Pscalar, const MatrixType& Pz ) = 0;
virtual exc_grad_type eval_exc_grad_( const MatrixType& P ) = 0;
virtual exx_type eval_exx_ ( const MatrixType& P,
const IntegratorSettingsEXX& settings ) = 0;
Expand Down Expand Up @@ -60,10 +62,14 @@ class XCIntegratorImpl {
* @param[in] P The alpha density matrix
* @returns EXC / VXC in a combined structure
*/
exc_vxc_type eval_exc_vxc( const MatrixType& P ) {
exc_vxc_type_rks eval_exc_vxc( const MatrixType& P ) {
return eval_exc_vxc_(P);
}

exc_vxc_type_uks eval_exc_vxc( const MatrixType& Pscalar, const MatrixType& Pz ) {
return eval_exc_vxc_(Pscalar, Pz);
}

/** Integrate EXC gradient for RKS
*
* TODO: add API for UKS/GKS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,17 @@ FWD_TO_PIMPL(eval_collocation) // Collocation
FWD_TO_PIMPL(eval_collocation_gradient) // Collocation Gradient
FWD_TO_PIMPL(eval_collocation_hessian) // Collocation Hessian

FWD_TO_PIMPL(eval_uvvar_lda) // U/VVar LDA (density)
FWD_TO_PIMPL(eval_uvvar_gga) // U/VVar GGA (density + grad, gamma)
FWD_TO_PIMPL(eval_uvvar_lda_rks) // U/VVar LDA (density)
FWD_TO_PIMPL(eval_uvvar_gga_rks) // U/VVar GGA (density + grad, gamma)

FWD_TO_PIMPL(eval_zmat_lda_vxc) // Eval Z Matrix LDA VXC
FWD_TO_PIMPL(eval_zmat_gga_vxc) // Eval Z Matrix GGA VXC
FWD_TO_PIMPL(eval_uvvar_lda_uks) // U/VVar LDA (density)
FWD_TO_PIMPL(eval_uvvar_gga_uks) // U/VVar GGA (density + grad, gamma)

FWD_TO_PIMPL(eval_zmat_lda_vxc_rks) // Eval Z Matrix LDA VXC
FWD_TO_PIMPL(eval_zmat_gga_vxc_rks) // Eval Z Matrix GGA VXC

FWD_TO_PIMPL(eval_zmat_lda_vxc_uks) // Eval Z Matrix LDA VXC
FWD_TO_PIMPL(eval_zmat_gga_vxc_uks) // Eval Z Matrix GGA VXC

FWD_TO_PIMPL(eval_exx_fmat) // Eval EXX F Matrix
//FWD_TO_PIMPL(eval_exx_gmat) // Eval EXX G Matrix
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,20 @@ class LocalDeviceWorkDriver : public LocalWorkDriver {

void eval_xmat( XCDeviceData*, bool do_grad = false );

void eval_uvvar_lda( XCDeviceData* );
void eval_uvvar_gga( XCDeviceData* );
void eval_uvvar_lda_rks( XCDeviceData* );
void eval_uvvar_gga_rks( XCDeviceData* );

void eval_uvvar_lda_uks( XCDeviceData* );
void eval_uvvar_gga_uks( XCDeviceData* );

void eval_kern_exc_vxc_lda( const functional_type&, XCDeviceData* );
void eval_kern_exc_vxc_gga( const functional_type&, XCDeviceData* );

void eval_zmat_lda_vxc( XCDeviceData* );
void eval_zmat_gga_vxc( XCDeviceData* );
void eval_zmat_lda_vxc_rks( XCDeviceData* );
void eval_zmat_gga_vxc_rks( XCDeviceData* );

void eval_zmat_lda_vxc_uks( XCDeviceData* );
void eval_zmat_gga_vxc_uks( XCDeviceData* );

void eval_exx_fmat( XCDeviceData* );
void eval_exx_gmat( XCDeviceData*, const BasisSetMap& );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,16 @@ struct LocalDeviceWorkDriverPIMPL {
virtual void eval_exx_fmat( XCDeviceData* ) = 0;
//virtual void eval_exx_gmat( XCDeviceData* ) = 0;
virtual void eval_exx_gmat( XCDeviceData*, const BasisSetMap& ) = 0;
virtual void eval_uvvar_lda( XCDeviceData* ) = 0;
virtual void eval_uvvar_gga( XCDeviceData* ) = 0;
virtual void eval_uvvar_lda_rks( XCDeviceData* ) = 0;
virtual void eval_uvvar_gga_rks( XCDeviceData* ) = 0;
virtual void eval_uvvar_lda_uks( XCDeviceData* ) = 0;
virtual void eval_uvvar_gga_uks( XCDeviceData* ) = 0;
virtual void eval_kern_exc_vxc_lda( const functional_type&, XCDeviceData* ) = 0;
virtual void eval_kern_exc_vxc_gga( const functional_type&, XCDeviceData* ) = 0;
virtual void eval_zmat_lda_vxc( XCDeviceData* ) = 0;
virtual void eval_zmat_gga_vxc( XCDeviceData* ) = 0;
virtual void eval_zmat_lda_vxc_rks( XCDeviceData* ) = 0;
virtual void eval_zmat_gga_vxc_rks( XCDeviceData* ) = 0;
virtual void eval_zmat_lda_vxc_uks( XCDeviceData* ) = 0;
virtual void eval_zmat_gga_vxc_uks( XCDeviceData* ) = 0;
virtual void inc_exc( XCDeviceData* ) = 0;
virtual void inc_nel( XCDeviceData* ) = 0;
virtual void inc_vxc( XCDeviceData* ) = 0;
Expand Down
25 changes: 20 additions & 5 deletions src/xc_integrator/local_work_driver/device/scheme1_base.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ AoSScheme1Base::~AoSScheme1Base() noexcept {
#endif
}

void AoSScheme1Base::eval_zmat_lda_vxc( XCDeviceData* _data){
void AoSScheme1Base::eval_zmat_lda_vxc_rks( XCDeviceData* _data){

auto* data = dynamic_cast<Data*>(_data);
if( !data ) GAUXC_BAD_LWD_DATA_CAST();
Expand All @@ -255,7 +255,7 @@ void AoSScheme1Base::eval_zmat_lda_vxc( XCDeviceData* _data){

}

void AoSScheme1Base::eval_zmat_gga_vxc( XCDeviceData* _data){
void AoSScheme1Base::eval_zmat_gga_vxc_rks( XCDeviceData* _data){

auto* data = dynamic_cast<Data*>(_data);
if( !data ) GAUXC_BAD_LWD_DATA_CAST();
Expand All @@ -276,7 +276,17 @@ void AoSScheme1Base::eval_zmat_gga_vxc( XCDeviceData* _data){

}

void AoSScheme1Base::eval_zmat_lda_vxc_uks( XCDeviceData* _data){

GAUXC_GENERIC_EXCEPTION("UKS NOT YET IMPLEMENTED FOR DEVICE");

}

void AoSScheme1Base::eval_zmat_gga_vxc_uks( XCDeviceData* _data){

GAUXC_GENERIC_EXCEPTION("UKS NOT YET IMPLEMENTED FOR DEVICE");

}

void AoSScheme1Base::eval_collocation( XCDeviceData* _data ) {

Expand Down Expand Up @@ -405,7 +415,7 @@ void AoSScheme1Base::inc_nel( XCDeviceData* _data ){



void AoSScheme1Base::eval_uvvar_lda( XCDeviceData* _data ){
void AoSScheme1Base::eval_uvvar_lda_rks( XCDeviceData* _data ){

auto* data = dynamic_cast<Data*>(_data);
if( !data ) GAUXC_BAD_LWD_DATA_CAST();
Expand Down Expand Up @@ -435,7 +445,7 @@ void AoSScheme1Base::eval_uvvar_lda( XCDeviceData* _data ){



void AoSScheme1Base::eval_uvvar_gga( XCDeviceData* _data ){
void AoSScheme1Base::eval_uvvar_gga_rks( XCDeviceData* _data ){

auto* data = dynamic_cast<Data*>(_data);
if( !data ) GAUXC_BAD_LWD_DATA_CAST();
Expand Down Expand Up @@ -466,12 +476,17 @@ void AoSScheme1Base::eval_uvvar_gga( XCDeviceData* _data ){

}

void AoSScheme1Base::eval_uvvar_lda_uks( XCDeviceData* _data ){

GAUXC_GENERIC_EXCEPTION("UKS NOT YET IMPLEMENTED FOR DEVICE");

}

void AoSScheme1Base::eval_uvvar_gga_uks( XCDeviceData* _data ){

GAUXC_GENERIC_EXCEPTION("UKS NOT YET IMPLEMENTED FOR DEVICE");


}


void AoSScheme1Base::eval_kern_exc_vxc_lda( const functional_type& func,
Expand Down
14 changes: 10 additions & 4 deletions src/xc_integrator/local_work_driver/device/scheme1_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@ struct AoSScheme1Base : public detail::LocalDeviceWorkDriverPIMPL {
void eval_collocation( XCDeviceData* ) override final;
void eval_collocation_gradient( XCDeviceData* ) override final;
void eval_collocation_hessian( XCDeviceData* ) override final;
void eval_uvvar_lda( XCDeviceData* ) override final;
void eval_uvvar_gga( XCDeviceData* ) override final;
void eval_zmat_lda_vxc( XCDeviceData* ) override final;
void eval_zmat_gga_vxc( XCDeviceData* ) override final;
void eval_uvvar_lda_rks( XCDeviceData* ) override final;
void eval_uvvar_gga_rks( XCDeviceData* ) override final;
void eval_zmat_lda_vxc_rks( XCDeviceData* ) override final;
void eval_zmat_gga_vxc_rks( XCDeviceData* ) override final;

void eval_uvvar_lda_uks( XCDeviceData* ) override final;
void eval_uvvar_gga_uks( XCDeviceData* ) override final;
void eval_zmat_lda_vxc_uks( XCDeviceData* ) override final;
void eval_zmat_gga_vxc_uks( XCDeviceData* ) override final;

void eval_kern_exc_vxc_lda( const functional_type&, XCDeviceData* ) override final;
void eval_kern_exc_vxc_gga( const functional_type&, XCDeviceData* ) override final;
void inc_exc( XCDeviceData* ) override final;
Expand Down
Loading

0 comments on commit adf4788

Please sign in to comment.