MADNESS 0.10.1
mp3.h
Go to the documentation of this file.
1//
2// Created by Florian Bischoff on 2/15/24.
3//
4
5#ifndef MP3_H
6#define MP3_H
7
8
9#include <madness/mra/mra.h>
15#include <algorithm>
16#include <iomanip>
17#include <iostream>
19
20namespace madness {
21class MP3 {
22public:
23
24 // MP3(World& world, const std::shared_ptr<Nemo> nemo, const CCParameters& param) {}
25
27
28 double mp3_energy_contribution(const Pairs<CCPair>& mp2pairs) const;
29
30 /// compute the MP3 energy contribution, macrotask version
31 double mp3_energy_contribution_macrotask_driver(const Pairs<CCPair>& mp2pairs) const;
32
33private:
35 const Info& info;
36
37 /// helper class for calculating the MP3 energy contributions
39
41 public:
42 Partitioner(const std::string shape) {
45 if (shape=="triangular") dimension=1;
46 else if (shape=="square") dimension=2;
47 else {
48 std::string msg = "Unknown partitioning shape: " + shape;
49 MADNESS_EXCEPTION(msg.c_str(), 1);
50 }
51 };
52 };
53
54 public:
55 MacroTaskMP3(const std::string diagram) : diagram(diagram) {
56 name="MP3_"+diagram;
57 std::string shape;
58 if (diagram=="ghij" or diagram=="cd" or diagram=="ef") shape="triangular";
59 else if (diagram=="klmn") shape="square";
60 else {
61 std::string msg = "Unknown MP3 diagram: " + diagram;
62 MADNESS_EXCEPTION(msg.c_str(), 1);
63 }
64 partitioner.reset(new Partitioner(shape));
65 }
66 std::string diagram="unknown";
67
68 typedef std::tuple<
69 const std::vector<int>&, // dummy vector of size npair or nocc for scheduling
70 const std::vector<int>&, // dummy vector of size npair or nocc for scheduling
71 const std::vector<std::vector<CCPairFunction<double,6>>>& , // all pairs ij
72 const Info&,
73 const std::vector<std::string>& > argtupleT;
74
76
77 resultT allocator(World& world, const argtupleT& argtuple) const {
79 }
80
81 resultT operator() (const std::vector<int>& ij_vec, // dummy vector of size npair or nocc
82 const std::vector<int>& j_vec, // dummy vector of size 0 or nocc
83 const std::vector<std::vector<CCPairFunction<double,6>>>& pair_square, // all pairs ij
84 const Info& info,
85 const std::vector<std::string>& argument) const {
86
87 // the partitioner will break the input vector of pairs into single pairs
88 MADNESS_CHECK(ij_vec.size()==1);
90
91 // nact=active occupied orbitals
92 const long nact=info.mo_ket.size()-info.parameters.freeze();
93 MADNESS_CHECK(pair_square.size()==nact*nact);
94
95 // loop over pairs i<j (triangular) or i,j (square)
96 bool is_triangular=(j_vec.size()==0);
97 if (is_triangular) MADNESS_CHECK(partitioner->dimension==1);
98
99 // determine the orbital indices i and j for the pair
100 int i=0, j=0;
101 if (is_triangular) {
102 // the batch index is the ij composite index [0,nact*(nact+1)-1]
103 const long ij=batch.result.begin;
104 // turn composite index ij into i and j, taking care of frozen orbitals
106 auto ij_to_i_and_j = [&tri_map](const int ij) { return tri_map.map[ij]; };
107 auto [ii,jj]=ij_to_i_and_j(ij);
108 i=ii;
109 j=jj;
110 } else {
111 MADNESS_CHECK(partitioner->dimension==2);
112 MADNESS_CHECK(j_vec.size()==ij_vec.size());
113 i=batch.input[0].begin+info.parameters.freeze();
114 j=batch.input[1].begin+info.parameters.freeze();
115 }
116 // print("i,j,parameters.freeze()=",i,j,parameters.freeze());
117
118 // convert vector of vectors back to Pairs
120 auto clusterfunctions=Pairs<std::vector<CCPairFunction<double,6>>>::vector2pairs(pair_square,square_map);
121
122 double result=0.0;
124 if (diagram=="cd")
125 result= MP3::compute_mp3_cd(world,i,j,clusterfunctions,info,argument);
126 else if (diagram=="ef")
127 result= MP3::compute_mp3_ef(world,i,j,clusterfunctions,info,argument);
128 else if (diagram=="ghij")
129 result= MP3::compute_mp3_ghij(world,i,j,clusterfunctions,info,argument);
130 else if (diagram=="klmn")
131 result= MP3::compute_mp3_klmn(world,i,j,clusterfunctions,info,argument);
132 else {
133 std::string msg = "Unknown MP3 diagram: " + diagram;
134 MADNESS_EXCEPTION(msg.c_str(), 1);
135 }
136 auto result1=ScalarResult<double>(world);
137 result1=result;
138 return result1;
139
140 };
141
142
143 };
144
145
146 double compute_mp3_cd(const Pairs<CCPair>& mp2pairs, const Info& info) const;
147 double compute_mp3_ef(const Pairs<CCPair>& mp2pairs, const Info& info) const;
148 double compute_mp3_ef_with_permutational_symmetry(const Pairs<CCPair>& mp2pairs, const Info& info) const;
149 double compute_mp3_ef_low_scaling(const Pairs<CCPair>& mp2pairs, const Pairs<std::vector<CCPairFunction<double,6>>> clusterfunctions, const Info& info) const;
150 double compute_mp3_ef_as_overlap(const Pairs<CCPair>& mp2pairs, const Pairs<std::vector<CCPairFunction<double,6>>> clusterfunctions, const Info& info) const;
151 double compute_mp3_ghij(const Pairs<CCPair>& mp2pairs, const Pairs<std::vector<CCPairFunction<double,6>>> clusterfunctions, const Info& info) const;
152 double compute_mp3_ghij_fast(const Pairs<CCPair>& mp2pairs, const Pairs<std::vector<CCPairFunction<double,6>>> clusterfunctions, const Info& info) const;
153 double compute_mp3_klmn(const Pairs<CCPair>& mp2pairs, const Info& info) const;
154 double compute_mp3_klmn_fast(const Pairs<CCPair>& mp2pairs, const Info& info) const;
155 double mp3_test(const Pairs<CCPair>& mp2pairs, const Pairs<std::vector<CCPairFunction<double,6>>> clusterfunctions, const Info& info) const;
156
157 /// compute the cd term for single pair ij
158 static double compute_mp3_cd(World& world,
159 const long i, const long j,
160 const Pairs<std::vector<CCPairFunction<double,6>>>& pair_square,
161 const Info& info,
162 const std::vector<std::string>& argument);
163
164 /// compute the ef term for single pair ij
165 static double compute_mp3_ef(World& world,
166 const long i, const long j,
167 const Pairs<std::vector<CCPairFunction<double,6>>>& pair_square,
168 const Info& info,
169 const std::vector<std::string>& argument);
170
171 /// compute the ghij term for single pair ij
172 ///
173 /// the term actually scales linearly with the number of occupied orbitals i, so for all i!=j return zero
174 static double compute_mp3_ghij(World& world,
175 const long i, const long j,
176 const Pairs<std::vector<CCPairFunction<double,6>>>& pair_square,
177 const Info& info,
178 const std::vector<std::string>& argument);
179
180 /// compute the klmn term for single pair ij
181 static double compute_mp3_klmn(World& world,
182 const long i, const long j,
183 const Pairs<std::vector<CCPairFunction<double,6>>>& pair_square,
184 const Info& info,
185 const std::vector<std::string>& argument);
186
187};
188}
189
190
191#endif //MP3_H
long size() const
Definition macrotaskpartitioner.h:71
long begin
Definition macrotaskpartitioner.h:59
Batch_1D result
Definition macrotaskpartitioner.h:128
std::vector< Batch_1D > input
Definition macrotaskpartitioner.h:127
a 6D function, either in full or low rank form, possibly including an 2-particle function
Definition ccpairfunction.h:373
World & world() const
Returns the world.
Definition mra.h:688
Partitioner(const std::string shape)
Definition mp3.h:42
helper class for calculating the MP3 energy contributions
Definition mp3.h:38
resultT operator()(const std::vector< int > &ij_vec, const std::vector< int > &j_vec, const std::vector< std::vector< CCPairFunction< double, 6 > > > &pair_square, const Info &info, const std::vector< std::string > &argument) const
Definition mp3.h:81
std::tuple< const std::vector< int > &, const std::vector< int > &, const std::vector< std::vector< CCPairFunction< double, 6 > > > &, const Info &, const std::vector< std::string > & > argtupleT
Definition mp3.h:73
resultT allocator(World &world, const argtupleT &argtuple) const
Definition mp3.h:77
std::string diagram
Definition mp3.h:66
ScalarResult< double > resultT
Definition mp3.h:75
MacroTaskMP3(const std::string diagram)
Definition mp3.h:55
Definition mp3.h:21
double compute_mp3_klmn_fast(const Pairs< CCPair > &mp2pairs, const Info &info) const
Definition mp3.cc:470
double compute_mp3_cd(const Pairs< CCPair > &mp2pairs, const Info &info) const
Definition mp3.cc:8
double compute_mp3_ef_low_scaling(const Pairs< CCPair > &mp2pairs, const Pairs< std::vector< CCPairFunction< double, 6 > > > clusterfunctions, const Info &info) const
Definition mp3.cc:254
double compute_mp3_ghij(const Pairs< CCPair > &mp2pairs, const Pairs< std::vector< CCPairFunction< double, 6 > > > clusterfunctions, const Info &info) const
Definition mp3.cc:319
const Info & info
Definition mp3.h:35
MP3(World &world, const Info &info)
Definition mp3.h:26
double mp3_energy_contribution_macrotask_driver(const Pairs< CCPair > &mp2pairs) const
compute the MP3 energy contribution, macrotask version
Definition mp3.cc:945
double compute_mp3_ef(const Pairs< CCPair > &mp2pairs, const Info &info) const
Definition mp3.cc:45
double compute_mp3_klmn(const Pairs< CCPair > &mp2pairs, const Info &info) const
Definition mp3.cc:541
double compute_mp3_ef_with_permutational_symmetry(const Pairs< CCPair > &mp2pairs, const Info &info) const
compute the EF term of the MP3 energy with permutational symmetry
Definition mp3.cc:168
World & world
Definition mp3.h:34
double compute_mp3_ghij_fast(const Pairs< CCPair > &mp2pairs, const Pairs< std::vector< CCPairFunction< double, 6 > > > clusterfunctions, const Info &info) const
Definition mp3.cc:403
double compute_mp3_ef_as_overlap(const Pairs< CCPair > &mp2pairs, const Pairs< std::vector< CCPairFunction< double, 6 > > > clusterfunctions, const Info &info) const
double mp3_energy_contribution(const Pairs< CCPair > &mp2pairs) const
Definition mp3.cc:903
double mp3_test(const Pairs< CCPair > &mp2pairs, const Pairs< std::vector< CCPairFunction< double, 6 > > > clusterfunctions, const Info &info) const
Definition mp3.cc:618
Definition macrotaskq.h:978
Batch batch
Definition macrotaskq.h:980
std::shared_ptr< MacroTaskPartitioner > partitioner
Definition macrotaskq.h:982
std::string name
Definition macrotaskq.h:981
partition one (two) vectors into 1D (2D) batches.
Definition macrotaskpartitioner.h:182
std::size_t dimension
partition one or two vectors
Definition macrotaskpartitioner.h:191
std::size_t min_batch_size
minimum batch size
Definition macrotaskpartitioner.h:187
std::size_t max_batch_size
maximum batch size (for memory management)
Definition macrotaskpartitioner.h:188
Definition macrotaskq.h:115
A parallel world class.
Definition world.h:132
Declares the macrotaskq and MacroTaskBase classes.
#define MADNESS_CHECK(condition)
Check a condition — even in a release build the condition is always evaluated so it can have side eff...
Definition madness_exception.h:182
#define MADNESS_EXCEPTION(msg, value)
Macro for throwing a MADNESS exception.
Definition madness_exception.h:119
Main include file for MADNESS and defines Function interface.
Namespace for all elements and tools of MADNESS.
Definition DFParameters.h:10
long freeze() const
Definition CCStructures.h:368
POD holding some basic functions and some intermediates for the CC2 calculation.
Definition CCStructures.h:1107
std::vector< Function< double, 3 > > mo_ket
Definition CCStructures.h:1108
CCParameters parameters
Definition CCStructures.h:1111
Function< double, 3 > R_square
Definition CCStructures.h:1115
Definition CCStructures.h:394
static PairVectorMap triangular_map(const int nfreeze, const int nocc)
Definition CCStructures.h:400
std::vector< std::pair< int, int > > map
maps pair index (i,j) to vector index k
Definition CCStructures.h:396
static PairVectorMap quadratic_map(const int nfreeze, const int nocc)
Definition CCStructures.h:410
Definition CCStructures.h:434
double ij(int64_t i, int64_t j)
Definition test_distributed_matrix.cc:8