Psi4
jk.h
Go to the documentation of this file.
1 /*
2  * @BEGIN LICENSE
3  *
4  * Psi4: an open-source quantum chemistry software package
5  *
6  * Copyright (c) 2007-2018 The Psi4 Developers.
7  *
8  * The copyrights for code used from other parties are included in
9  * the corresponding files.
10  *
11  * This file is part of Psi4.
12  *
13  * Psi4 is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU Lesser General Public License as published by
15  * the Free Software Foundation, version 3.
16  *
17  * Psi4 is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU Lesser General Public License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public License along
23  * with Psi4; if not, write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25  *
26  * @END LICENSE
27  */
28 
29 #ifndef JK_H
30 #define JK_H
31 
32 #include <vector>
33 #include "psi4/pragma.h"
34 PRAGMA_WARNING_PUSH
35 PRAGMA_WARNING_IGNORE_DEPRECATED_DECLARATIONS
36 #include <memory>
38 #include "psi4/libmints/typedefs.h"
40 
41 namespace psi {
42 class MinimalInterface;
43 class BasisSet;
44 class Matrix;
45 class ERISieve;
46 class TwoBodyAOInt;
47 class Options;
48 class PSIO;
49 class DFHelper;
50 
51 namespace pk {
52 class PKManager;
53 }
54 
55 // => BASE CLASS <= //
56 
227 class PSI_API JK {
228  protected:
229  // => Utility Variables <= //
230 
232  int print_;
234  int debug_;
236  int bench_;
238  size_t memory_;
242  double cutoff_;
244  std::vector<bool> input_symmetry_cast_map_;
245 
246  // => Tasks <= //
247 
249  bool do_J_;
251  bool do_K_;
253  bool do_wK_;
254 
256  double omega_;
257 
260 
261  // => Architecture-Level State Variables (Spatial Symmetry) <= //
262 
264  std::vector<SharedMatrix> C_left_;
266  std::vector<SharedMatrix> C_right_;
268  std::vector<SharedMatrix> D_;
270  std::vector<SharedMatrix> J_;
272  std::vector<SharedMatrix> K_;
274  std::vector<SharedMatrix> wK_;
275 
276  // => Microarchitecture-Level State Variables (No Spatial Symmetry) <= //
277 
279  std::shared_ptr<BasisSet> primary_;
283  std::vector<SharedMatrix> C_left_ao_;
285  std::vector<SharedMatrix> C_right_ao_;
287  std::vector<SharedMatrix> D_ao_;
289  std::vector<SharedMatrix> J_ao_;
291  std::vector<SharedMatrix> K_ao_;
293  std::vector<SharedMatrix> wK_ao_;
294 
295  // => Per-Iteration Setup/Finalize Routines <= //
296 
298  void compute_D();
300  void USO2AO();
302  void AO2USO();
304  void allocate_JK();
316  void common_init();
317 
318  // => Required Algorithm-Specific Methods <= //
319 
321  virtual void preiterations() = 0;
323  virtual void compute_JK() = 0;
325  virtual void postiterations() = 0;
326 
327  // => Helper Routines <= //
328 
330  size_t memory_overhead() const;
331 
332  public:
333  // => Constructors <= //
334 
348  JK(std::shared_ptr<BasisSet> primary);
349 
351  virtual ~JK();
352 
360  static std::shared_ptr<JK> build_JK(std::shared_ptr<BasisSet> primary, std::shared_ptr<BasisSet> auxiliary,
361  Options& options);
362  static std::shared_ptr<JK> build_JK(std::shared_ptr<BasisSet> primary, std::shared_ptr<BasisSet> auxiliary,
363  Options& options, std::string jk_type);
364  static std::shared_ptr<JK> build_JK(std::shared_ptr<BasisSet> primary, std::shared_ptr<BasisSet> auxiliary,
365  Options& options, bool do_wK, size_t doubles);
366 
368  virtual bool C1() const = 0;
369  virtual std::string name() = 0;
370  virtual size_t memory_estimate() = 0;
371 
372  // => Knobs <= //
373 
381  void set_cutoff(double cutoff) { cutoff_ = cutoff; }
382  double get_cutoff() const { return cutoff_; }
388  void set_memory(size_t memory) { memory_ = memory; }
398  void set_omp_nthread(int omp_nthread) { omp_nthread_ = omp_nthread; }
399  int get_omp_nthread() const { return omp_nthread_; }
400 
402  void set_print(int print) { print_ = print; }
404  void set_debug(int debug) { debug_ = debug; }
406  void set_bench(int bench) { bench_ = bench; }
412  void set_do_J(bool do_J) { do_J_ = do_J; }
418  void set_do_K(bool do_K) { do_K_ = do_K; }
424  void set_do_wK(bool do_wK) { do_wK_ = do_wK; }
429  void set_omega(double omega) { omega_ = omega; }
430 
431  // => Computers <= //
432 
438  void initialize();
446  void compute();
453  void finalize();
454 
461  virtual SharedVector iaia(SharedMatrix Ci, SharedMatrix Ca);
462 
463  // => Accessors <= //
464 
468  std::shared_ptr<BasisSet> basisset() { return primary_; }
469 
474  std::vector<SharedMatrix>& C_left() { return C_left_; }
480  std::vector<SharedMatrix>& C_right() { return C_right_; }
481 
490  const std::vector<SharedMatrix>& J() const { return J_; }
499  const std::vector<SharedMatrix>& K() const { return K_; }
508  const std::vector<SharedMatrix>& wK() const { return wK_; }
517  const std::vector<SharedMatrix>& D() const { return D_; }
518 
523  virtual void print_header() const = 0;
524 };
525 
526 // => APPLIED CLASSES <= //
527 
534 class PSI_API DiskJK : public JK {
535  std::string name() override { return "DiskJK"; }
536  size_t memory_estimate() override;
537 
539  int* so2index_;
542 
545 
547  bool C1() const override { return false; }
549  void preiterations() override;
551  void compute_JK() override;
553  void postiterations() override;
554 
556  void common_init();
557 
558  public:
559  // => Constructors < = //
560 
568  DiskJK(std::shared_ptr<BasisSet> primary, Options& options);
570  ~DiskJK() override;
571 
572  // => Accessors <= //
573 
578  void print_header() const override;
579 };
580 
587 class PSI_API PKJK : public JK {
588 
589  std::string name() override { return "PKJK"; }
590  size_t memory_estimate() override;
591 
593  std::shared_ptr<PSIO> psio_;
594 
597 
599  int pk_file_;
600 
603 
605  std::shared_ptr<pk::PKManager> PKmanager_;
606 
608  bool C1() const override;
610  void preiterations() override;
612  void compute_JK() override;
614  void postiterations() override;
615 
617  void common_init();
618 
620  int nso_;
622  int nirrep_;
625 
626  public:
627  // => Constructors < = //
628 
637  PKJK(std::shared_ptr<BasisSet> primary, Options& options);
639  ~PKJK() override;
640 
641  // => Accessors <= //
642 
647  void print_header() const override;
648 };
649 
661 class PSI_API DirectJK : public JK {
662  protected:
666  std::shared_ptr<ERISieve> sieve_;
667 
668  std::string name() override { return "DirectJK"; }
669  size_t memory_estimate() override;
670 
671  // => Required Algorithm-Specific Methods <= //
672 
674  bool C1() const override { return true; }
676  void preiterations() override;
678  void compute_JK() override;
680  void postiterations() override;
681 
683  void build_JK(std::vector<std::shared_ptr<TwoBodyAOInt> >& ints, std::vector<std::shared_ptr<Matrix> >& D,
684  std::vector<std::shared_ptr<Matrix> >& J, std::vector<std::shared_ptr<Matrix> >& K);
685 
687  void common_init();
688 
689  public:
690  // => Constructors < = //
691 
699  DirectJK(std::shared_ptr<BasisSet> primary);
701  ~DirectJK() override;
702 
703  // => Knobs <= //
704 
709  void set_df_ints_num_threads(int val) { df_ints_num_threads_ = val; }
710 
711  // => Accessors <= //
712 
717  void print_header() const override;
718 };
719 
733 class GTFockJK : public JK {
734  private:
736  std::shared_ptr<MinimalInterface> Impl_;
737  int NMats_ = 0;
738 
739  std::string name() override { return "GTFockJK"; }
740  size_t memory_estimate() override;
741 
742  protected:
744  bool C1() const override { return true; }
746  void preiterations() override {}
748  void compute_JK() override;
750  void postiterations() override {}
752  void print_header() const override {}
753 
754  public:
768  GTFockJK(std::shared_ptr<psi::BasisSet> Primary, size_t NMats, bool AreSymm);
773  GTFockJK(std::shared_ptr<psi::BasisSet> Primary);
774 };
775 
782 class PSI_API DiskDFJK : public JK {
783  protected:
784  // => DF-Specific stuff <= //
785 
786  std::string name() override { return "DiskDFJK"; }
787  size_t memory_estimate() override;
788 
790  std::shared_ptr<BasisSet> auxiliary_;
792  std::shared_ptr<PSIO> psio_;
794  std::string df_ints_io_;
798  double condition_;
800  size_t unit_;
802  bool is_core_;
808  std::shared_ptr<ERISieve> sieve_;
809 
816 
817  // => Temps (built/destroyed in compute_JK) <= //
818  std::shared_ptr<Vector> J_temp_;
819  std::shared_ptr<Vector> D_temp_;
820  std::shared_ptr<Vector> d_temp_;
821 
824  std::vector<SharedMatrix> C_temp_;
825  std::vector<SharedMatrix> Q_temp_;
826 
827  // => Required Algorithm-Specific Methods <= //
828 
830  bool C1() const override { return true; }
832  void preiterations() override;
834  void compute_JK() override;
836  void postiterations() override;
837 
839  void common_init();
840 
841  bool is_core();
842  size_t memory_temp() const;
843  int max_rows() const;
844  int max_nocc() const;
845  void initialize_temps();
846  void free_temps();
847  void initialize_w_temps();
848  void free_w_temps();
849 
850  // => J <= //
851  virtual void initialize_JK_core();
852  virtual void initialize_JK_disk();
853  virtual void manage_JK_core();
854  virtual void manage_JK_disk();
855  virtual void block_J(double** Qmnp, int naux);
856  virtual void block_K(double** Qmnp, int naux);
857 
858  // => wK <= //
859  virtual void initialize_wK_core();
860  virtual void initialize_wK_disk();
861  virtual void manage_wK_core();
862  virtual void manage_wK_disk();
863  virtual void block_wK(double** Qlmnp, double** Qrmnp, int naux);
864  virtual void rebuild_wK_disk();
865 
866  public:
867  // => Constructors < = //
868 
877  DiskDFJK(std::shared_ptr<BasisSet> primary, std::shared_ptr<BasisSet> auxiliary);
878 
880  ~DiskDFJK() override;
881 
888  SharedVector iaia(SharedMatrix Ci, SharedMatrix Ca) override;
889 
890  // => Knobs <= //
891 
899  void set_condition(double condition) { condition_ = condition; }
904  void set_unit(size_t unit) { unit_ = unit; }
909  void set_df_ints_io(const std::string& val) { df_ints_io_ = val; }
914  void set_df_ints_num_threads(int val) { df_ints_num_threads_ = val; }
915 
916  // => Accessors <= //
917 
922  void print_header() const override;
923 };
930 class PSI_API CDJK : public DiskDFJK {
931  protected:
932  std::string name() override { return "CDJK"; }
933  size_t memory_estimate() override;
934 
935 
936  // the number of cholesky vectors
937  long int ncholesky_;
938 
939  // => Required Algorithm-Specific Methods <= //
940 
941  virtual bool is_core() { return true; }
942 
943  // => J <= //
944  void initialize_JK_core() override;
945  void initialize_JK_disk() override;
946  void manage_JK_core() override;
947 
949 
950  // => Accessors <= //
951 
956  void print_header() const override;
957 
958  public:
959  // => Constructors < = //
960 
969  CDJK(std::shared_ptr<BasisSet> primary, double cholesky_tolerance);
970 
972  ~CDJK() override;
973 };
974 
983 class PSI_API MemDFJK : public JK {
984  protected:
985  // => DF-Specific stuff <= //
986 
987  std::string name() override { return "MemDFJK"; }
988  size_t memory_estimate() override;
989 
991  std::shared_ptr<DFHelper> dfh_;
992 
994  std::shared_ptr<BasisSet> auxiliary_;
998  double condition_ = 1.0E-12;
999 
1000  // => Required Algorithm-Specific Methods <= //
1001 
1002  int max_nocc() const;
1004  bool C1() const override { return true; }
1007  void preiterations() override;
1009  void compute_JK() override;
1011  void postiterations() override;
1012 
1014  void common_init();
1015 
1016  public:
1017  // => Constructors < = //
1018 
1023  MemDFJK(std::shared_ptr<BasisSet> primary, std::shared_ptr<BasisSet> auxiliary);
1024 
1026  ~MemDFJK() override;
1027 
1028  // => Knobs <= //
1029 
1037  void set_condition(double condition) { condition_ = condition; }
1038 
1043  void set_df_ints_num_threads(int val) { df_ints_num_threads_ = val; }
1044 
1045  // => Accessors <= //
1046 
1051  void print_header() const override;
1052 
1056  std::shared_ptr<DFHelper> dfh() { return dfh_; }
1057 };
1058 }
1059 #endif
std::shared_ptr< BasisSet > auxiliary_
Auxiliary basis set.
Definition: jk.h:994
int nso_
Total number of SOs.
Definition: jk.h:620
std::shared_ptr< BasisSet > primary_
Primary basis set.
Definition: jk.h:279
std::string name() override
Definition: jk.h:668
int debug_
Debug flag, defaults to 0.
Definition: jk.h:234
void set_print(int print)
Print flag (defaults to 1)
Definition: jk.h:402
void set_df_ints_io(const std::string &val)
Definition: jk.h:909
double cholesky_tolerance_
Definition: jk.h:948
std::string name() override
Definition: jk.h:786
size_t unit_
File number for (Q|mn) tensor.
Definition: jk.h:800
Definition: jk.h:534
int * so2index_
Absolute AO index to relative SO index.
Definition: jk.h:539
Derived class extending the JK object to GTFock.
Definition: jk.h:733
std::vector< SharedMatrix > C_left_
Pseudo-occupied C matrices, left side.
Definition: jk.h:264
int pk_file_
The pk file to use for storing the pk batches.
Definition: jk.h:599
void set_omega(double omega)
Definition: jk.h:429
void set_do_wK(bool do_wK)
Definition: jk.h:424
void print_header() const override
I don&#39;t fell the need to further clutter the output...
Definition: jk.h:752
std::string df_ints_io_
Cache action for three-index integrals.
Definition: jk.h:794
std::vector< SharedMatrix > C_temp_
Definition: jk.h:824
Dimension nsopi_
Number of so per irrep.
Definition: jk.h:624
void set_omp_nthread(int omp_nthread)
Definition: jk.h:398
virtual bool is_core()
Definition: jk.h:941
SharedMatrix Qmn_
Main (Q|mn) Tensor (or chunk for disk-based)
Definition: jk.h:811
double omega_
Omega, defaults to 0.0.
Definition: jk.h:256
std::vector< SharedMatrix > C_right_
Pseudo-occupied C matrices, right side.
Definition: jk.h:266
std::string name() override
Definition: jk.h:589
void postiterations() override
Delete integrals, files, etc.
Definition: jk.h:750
void set_cutoff(double cutoff)
Definition: jk.h:381
int NMats_
Definition: jk.h:737
void set_df_ints_num_threads(int val)
Definition: jk.h:914
bool do_wK_
Do wK matrices? Defaults to false.
Definition: jk.h:253
std::shared_ptr< BasisSet > auxiliary_
Auxiliary basis set.
Definition: jk.h:790
std::shared_ptr< pk::PKManager > PKmanager_
Class handling the PK integrals.
Definition: jk.h:605
std::shared_ptr< MinimalInterface > Impl_
The actual instance that does the implementing.
Definition: jk.h:736
bool C1() const override
Do we need to backtransform to C1 under the hood?
Definition: jk.h:674
int max_nocc_
Maximum number of nocc in C vectors.
Definition: jk.h:806
void set_bench(int bench)
Bench flag (defaults to 0)
Definition: jk.h:406
std::vector< SharedMatrix > C_right_ao_
Pseudo-occupied C matrices, right side.
Definition: jk.h:285
std::vector< bool > input_symmetry_cast_map_
Whether to all desymmetrization, for cases when it&#39;s already been performed elsewhere.
Definition: jk.h:244
Definition: PKmanagers.h:95
std::vector< SharedMatrix > D_
Pseudo-density matrices .
Definition: jk.h:268
bool C1() const override
Do we need to backtransform to C1 under the hood?
Definition: jk.h:1004
int bench_
Bench flag, defaults to 0.
Definition: jk.h:236
double cutoff_
Integral cutoff (defaults to 0.0)
Definition: jk.h:242
bool C1() const override
Do we need to backtransform to C1 under the hood?
Definition: jk.h:744
SharedMatrix E_right_
Definition: jk.h:823
std::vector< SharedMatrix > & C_left()
Definition: jk.h:474
std::vector< SharedMatrix > wK_
wK matrices:
Definition: jk.h:274
std::shared_ptr< PSIO > psio_
PSIO object.
Definition: jk.h:792
void set_df_ints_num_threads(int val)
Definition: jk.h:709
int df_ints_num_threads_
Number of threads for DF integrals TODO: DF_INTS_NUM_THREADS.
Definition: jk.h:664
Definition: pointgrp.h:110
bool is_core_
Core or disk?
Definition: jk.h:802
void set_condition(double condition)
Definition: jk.h:1037
std::string name() override
Definition: jk.h:739
int df_ints_num_threads_
Number of threads for DF integrals.
Definition: jk.h:996
const std::vector< SharedMatrix > & K() const
Definition: jk.h:499
int print_
Print flag, defaults to 1.
Definition: jk.h:232
Options & options_
Options object.
Definition: jk.h:544
std::string name() override
Definition: jk.h:535
void set_debug(int debug)
Debug flag (defaults to 0)
Definition: jk.h:404
std::shared_ptr< ERISieve > sieve_
Sieve, must be static throughout the life of the object.
Definition: jk.h:808
void set_condition(double condition)
Definition: jk.h:899
int nthreads_
The number of threads to be used for integral computation.
Definition: jk.h:602
Options & options_
Options object.
Definition: jk.h:596
Definition: jk.h:587
Definition: jk.h:661
double condition_
Condition cutoff in fitting metric, defaults to 1.0E-12.
Definition: jk.h:798
std::string name() override
Definition: jk.h:932
SharedMatrix AO2USO_
AO2USO transformation matrix.
Definition: jk.h:281
Definition: jk.h:983
const std::vector< SharedMatrix > & J() const
Definition: jk.h:490
std::vector< SharedMatrix > C_left_ao_
Pseudo-occupied C matrices, left side.
Definition: jk.h:283
std::shared_ptr< DFHelper > dfh_
This class wraps a DFHelper object.
Definition: jk.h:991
SharedMatrix Qrmn_
(Q|w|mn) for wK (or chunk for disk-based)
Definition: jk.h:815
PRAGMA_WARNING_PUSH PRAGMA_WARNING_IGNORE_DEPRECATED_DECLARATIONS PRAGMA_WARNING_POP
Definition: integraliter.cc:43
int max_rows_
Maximum number of rows to handle at a time.
Definition: jk.h:804
bool do_J_
Do J matrices? Defaults to true.
Definition: jk.h:249
Definition: dimension.h:40
void set_do_J(bool do_J)
Definition: jk.h:412
bool do_K_
Do K matrices? Defaults to true.
Definition: jk.h:251
void set_memory(size_t memory)
Definition: jk.h:388
std::vector< SharedMatrix > K_
K matrices: .
Definition: jk.h:272
std::shared_ptr< ERISieve > sieve_
ERI Sieve.
Definition: jk.h:666
Definition: liboptions.h:352
bool C1() const override
Do we need to backtransform to C1 under the hood?
Definition: jk.h:830
Definition: jk.h:782
SharedMatrix E_left_
Definition: jk.h:822
void set_df_ints_num_threads(int val)
Definition: jk.h:1043
std::string name() override
Definition: jk.h:987
std::vector< SharedMatrix > wK_ao_
wK matrices: wK_mn = (ml|w|ns) C_li^left C_si^right
Definition: jk.h:293
std::vector< SharedMatrix > J_ao_
J matrices: J_mn = (mn|ls) C_li^left C_si^right.
Definition: jk.h:289
void compute_JK() override
Compute J/K for current C/D.
int omp_nthread_
Number of OpenMP threads (defaults to 1 in no OpenMP, Process::environment.get_n_threads() otherwise)...
Definition: jk.h:240
std::vector< SharedMatrix > & C_right()
Definition: jk.h:480
std::shared_ptr< Matrix > SharedMatrix
Definition: adc.h:49
void set_unit(size_t unit)
Definition: jk.h:904
#define PSI_API
Definition: pragma.h:155
Definition: jk.h:930
SharedMatrix Qlmn_
(Q|P)^-1 (P|mn) for wK (or chunk for disk-based)
Definition: jk.h:813
GTFockJK(std::shared_ptr< psi::BasisSet > Primary, size_t NMats, bool AreSymm)
Your public interface to GTFock.
int get_omp_nthread() const
Definition: jk.h:399
std::shared_ptr< Vector > d_temp_
Definition: jk.h:820
Definition: jk.h:227
Definition: pointgrp.h:109
void preiterations() override
Setup integrals, files, etc.
Definition: jk.h:746
std::vector< SharedMatrix > D_ao_
Pseudo-density matrices.
Definition: jk.h:287
size_t memory_
Memory available, in doubles, defaults to 256 MB (32 M doubles)
Definition: jk.h:238
std::shared_ptr< PSIO > psio_
The PSIO instance to use for I/O.
Definition: jk.h:593
bool C1() const override
Do we need to backtransform to C1 under the hood?
Definition: jk.h:547
std::vector< SharedMatrix > K_ao_
K matrices: K_mn = (ml|ns) C_li^left C_si^right.
Definition: jk.h:291
int nirrep_
Number of irreps.
Definition: jk.h:622
int df_ints_num_threads_
Number of threads for DF integrals.
Definition: jk.h:796
int * so2symblk_
Absolute AO index to irrep.
Definition: jk.h:541
void set_do_K(bool do_K)
Definition: jk.h:418
double get_cutoff() const
Definition: jk.h:382
const std::vector< SharedMatrix > & D() const
Definition: jk.h:517
std::shared_ptr< BasisSet > basisset()
Definition: jk.h:468
std::shared_ptr< Vector > D_temp_
Definition: jk.h:819
bool lr_symmetric_
Left-right symmetric? Determined in each call of compute()
Definition: jk.h:259
std::vector< SharedMatrix > Q_temp_
Definition: jk.h:825
long int ncholesky_
Definition: jk.h:937
std::shared_ptr< Vector > SharedVector
Definition: adc.h:51
std::vector< SharedMatrix > J_
J matrices: .
Definition: jk.h:270
std::shared_ptr< DFHelper > dfh()
Definition: jk.h:1056
size_t memory_estimate() override
std::shared_ptr< Vector > J_temp_
Definition: jk.h:818
const std::vector< SharedMatrix > & wK() const
Definition: jk.h:508