40 {{
DM_eval,
"DensityMatrices1B::evaluate"},
50 basis_functions(
"DensityMatrices1B::basis"),
51 lattice_(P.getLattice()),
62 basis_functions(master.basis_functions),
63 lattice_(P.getLattice()),
85 return std::make_unique<DensityMatrices1B>(*
this, P, psi);
158 bool center_defined =
false;
159 std::string emstr =
"no";
160 std::string igstr =
"uniform_grid";
161 std::string evstr =
"loop";
162 std::string costr =
"no";
163 std::string cdstr =
"no";
164 std::string arstr =
"no";
165 std::string udstr =
"no";
166 std::string wrstr =
"no";
167 std::string nmstr =
"yes";
168 std::string vnstr =
"yes";
169 std::vector<std::string> sposets;
171 xmlNodePtr element = cur->xmlChildrenNode;
172 while (element != NULL)
174 std::string ename((
const char*)element->name);
175 if (ename ==
"parameter")
180 else if (name ==
"energy_matrix")
182 else if (name ==
"integrator")
184 else if (name ==
"evaluator")
186 else if (name ==
"scale")
188 else if (name ==
"center")
191 center_defined =
true;
193 else if (name ==
"points")
195 else if (name ==
"samples")
197 else if (name ==
"warmup")
199 else if (name ==
"timestep")
201 else if (name ==
"use_drift")
203 else if (name ==
"check_overlap")
205 else if (name ==
"check_derivatives")
207 else if (name ==
"acceptance_ratio")
209 else if (name ==
"rstats")
211 else if (name ==
"normalized")
213 else if (name ==
"volume_normed")
216 element = element->next;
221 APP_ABORT(
"DensityMatrices1B::put scale must be less than one");
223 else if (
scale < 0.0 - 1
e-10)
224 APP_ABORT(
"DensityMatrices1B::put scale must be greater than zero");
234 if (igstr ==
"uniform_grid")
241 for (
int d = 1; d <
DIM; ++d)
244 else if (igstr ==
"uniform")
250 else if (igstr ==
"density")
257 throw std::runtime_error(
258 "DensityMatrices1B::set_state invalid integrator\n valid options are: uniform_grid, uniform, density");
262 else if (evstr ==
"matrix")
265 throw std::runtime_error(
"DensityMatrices1B::set_state invalid evaluator\n valid options are: loop, matrix");
277 if (sposets.size() == 0)
278 throw std::runtime_error(
"DensityMatrices1B::put basis must have at least one sposet");
280 for (
int i = 0; i < sposets.size(); ++i)
283 auto spo_it =
spomap.find(sposets[i]);
284 if (spo_it ==
spomap.end())
285 throw std::runtime_error(
"DensityMatrices1B::put sposet " + sposets[i] +
" does not exist.");
291 throw std::runtime_error(
"DensityMatrices1B::put basis_size must be greater than one");
314 for (
int d = 0; d <
DIM; ++d)
373 E_Ntmp.push_back(
new Vector_t(specs_size));
410 delete_iter(Phi_Psi_NBtmp.begin(), Phi_Psi_NBtmp.end());
423 std::vector<std::string> integrator_list;
424 integrator_list.push_back(
"uniform_grid");
425 integrator_list.push_back(
"uniform");
426 integrator_list.push_back(
"density");
427 integrator_list.push_back(
"no_integrator");
428 std::vector<std::string> evaluator_list;
429 evaluator_list.push_back(
"loop");
430 evaluator_list.push_back(
"matrix");
431 evaluator_list.push_back(
"no_evaluator");
432 std::vector<std::string> sampling_list;
433 sampling_list.push_back(
"volume_based");
434 sampling_list.push_back(
"metropolis");
435 sampling_list.push_back(
"no_sampling");
440 out << pad <<
"DensityMatrices1B" << std::endl;
442 out << pad <<
" integrator = " << integrator_list[(int)
integrator] << std::endl;
443 out << pad <<
" sampling = " << sampling_list[(int)
sampling] << std::endl;
444 out << pad <<
" evaluator = " << evaluator_list[(int)
evaluator] << std::endl;
445 out << pad <<
" periodic = " <<
periodic << std::endl;
449 out << pad <<
" points = " <<
points << std::endl;
450 out << pad <<
" scale = " <<
scale << std::endl;
451 out << pad <<
" center = " <<
center << std::endl;
452 out << pad <<
" rmin = " <<
rcorner << std::endl;
453 out << pad <<
" rmax = " << rmax << std::endl;
454 out << pad <<
" volume = " <<
volume << std::endl;
458 out << pad <<
" warmup = " <<
warmup << std::endl;
459 out << pad <<
" timestep = " <<
timestep << std::endl;
461 out << pad <<
" metric = " <<
metric << std::endl;
462 out << pad <<
" nparticles = " <<
nparticles << std::endl;
463 out << pad <<
" nspecies = " <<
nspecies << std::endl;
465 out << pad <<
" species " <<
s <<
" = " <<
species_size[
s] << std::endl;
466 out << pad <<
" basis_size = " <<
basis_size << std::endl;
467 out << pad <<
" samples = " <<
samples << std::endl;
468 out << pad <<
" energy_mat = " <<
energy_mat << std::endl;
469 out << pad <<
" initialized = " <<
initialized << std::endl;
470 out << pad <<
" normalized = " <<
normalized << std::endl;
471 out << pad <<
" volume_normed = " <<
volume_normed << std::endl;
472 out << pad <<
" rsamples : " <<
rsamples.size() << std::endl;
478 out << pad <<
" matrices/vectors for species " <<
s << std::endl;
481 out << pad <<
" E_N : " <<
E_N[
s]->size() << std::endl;
482 out << pad <<
" Phi_NB : " <<
Phi_NB[
s]->rows() <<
" " <<
Phi_NB[
s]->cols() << std::endl;
483 out << pad <<
" Psi_NM : " <<
Psi_NM[
s]->rows() <<
" " <<
Psi_NM[
s]->cols() << std::endl;
485 out << pad <<
" N_BB : " <<
N_BB[
s]->rows() <<
" " <<
N_BB[
s]->cols() << std::endl;
488 out << pad <<
" E_BB : " <<
E_BB[
s]->rows() <<
" " <<
E_BB[
s]->cols() << std::endl;
491 out << pad <<
" basis_norms" << std::endl;
493 out << pad <<
" " << i <<
" " <<
basis_norms[i] << std::endl;
494 out << pad <<
"end DensityMatrices1B" << std::endl;
524 #if defined(QMC_COMPLEX) 531 std::vector<RealType> ntmp(nentries);
532 collectables.
add(ntmp.begin(), ntmp.end());
536 std::vector<RealType> etmp(nentries);
537 collectables.
add(etmp.begin(), etmp.end());
544 #if defined(QMC_COMPLEX) 545 std::vector<int> ng(3);
549 int nentries = ng[0] * ng[1] * ng[2];
551 std::vector<int> ng(2);
554 int nentries = ng[0] * ng[1];
558 hdf_name /=
"number_matrix";
562 auto&
oh = h5desc.back();
568 hdf_name.replace_subgroup(
"energy_matrix");
572 auto&
oh = h5desc.back();
590 APP_ABORT(
"DensityMatrices1B::warmup_sampling invalid integrator");
610 APP_ABORT(
"DensityMatrices1B::evaluate invalid evaluator");
664 for (
int n = 0;
n < basis_size2; ++
n)
669 #if defined(QMC_COMPLEX) 682 for (
int n = 0;
n < basis_size2; ++
n)
687 #if defined(QMC_COMPLEX) 746 app_log() <<
"DM Check" << std::endl;
751 app_log() <<
" species " <<
s << std::endl;
760 app_log() <<
"end DM Check" << std::endl;
772 APP_ABORT(
"DensityMatrices1B::evaluate_check use of E_trace in this function needs to be replaces with " 773 "get_energies() and E_samp");
779 Matrix_t& Phi_Psi_nb = *Phi_Psi_NBtmp[
s];
806 Psi_nm(
ns,
m) = ratio;
829 Phi_nb(
ns, i) = ephi_i;
863 int ij =
nindex +
s * basis_size2;
872 #if defined(QMC_COMPLEX) 881 int ij =
eindex +
s * basis_size2;
890 #if defined(QMC_COMPLEX) 936 PosType rmin = std::numeric_limits<RealType>::max();
937 PosType rmax = -std::numeric_limits<RealType>::max();
941 for (
int d = 0; d <
DIM; ++d)
945 rmax[d] = std::max(rmax[d], rd);
951 for (
int d = 0; d <
DIM; ++d)
952 rstd[d] =
std::sqrt(rstd[d] - rmean[d] * rmean[d]);
953 app_log() <<
"\nrsamples properties:" << std::endl;
954 app_log() <<
" rmin = " << rmin << std::endl;
955 app_log() <<
" rmax = " << rmax << std::endl;
956 app_log() <<
" rmean = " << rmean << std::endl;
957 app_log() <<
" rstd = " << rstd << std::endl;
967 for (
int d = 0; d <
DIM; ++d)
968 ushift[d] += rng() * du;
972 for (
int d = 0; d <
DIM - 1; ++d)
975 rp[d] = ind * du + ushift[d];
978 rp[
DIM - 1] = nrem * du + ushift[
DIM - 1];
989 for (
int d = 0; d <
DIM; ++d)
990 rp[d] =
scale * rng();
1003 for (
int s = 0;
s < steps; ++
s)
1079 for (
int d = 0; d <
DIM; ++d)
1097 for (
int p = 0; p < etrace->
sample.
size(); ++p)
1103 template<
typename T>
1109 for (
int p = 0; p < etrace->
sample.
size(); ++p)
1110 E_samp[p] += weight * etrace->
sample[p];
1114 template<
typename T>
1119 for (
int p = 0; p < etrace->
sample.
size(); ++p)
1120 E_samp[p] += weight * etrace->
sample[p];
1123 for (
int p = 0; p < etrace->
sample.
size(); ++p)
1124 E_samp[p] += weight *
real(etrace->
sample[p]);
1254 int ngrid = std::max(200,
points);
1255 int ngtot =
pow(ngrid,
DIM);
1261 gdims[0] =
pow(ngrid,
DIM - 1);
1262 for (
int d = 1; d <
DIM; ++d)
1263 gdims[d] = gdims[d - 1] / ngrid;
1268 for (
int p = 0; p < ngtot; ++p)
1271 for (
int d = 0; d <
DIM - 1; ++d)
1273 int ind = nrem / gdims[d];
1274 rp[d] = ind * du + du / 2;
1275 nrem -= ind * gdims[d];
1277 rp[
DIM - 1] = nrem * du + du / 2;
1292 int ngrid = std::max(50,
points);
1293 int ngtot =
pow(ngrid,
DIM);
1299 PosType rmin = std::numeric_limits<RealType>::max();
1300 PosType rmax = -std::numeric_limits<RealType>::max();
1302 gdims[0] =
pow(ngrid,
DIM - 1);
1303 for (
int d = 1; d <
DIM; ++d)
1304 gdims[d] = gdims[d - 1] / ngrid;
1312 for (
int p = 0; p < ngtot; ++p)
1315 for (
int d = 0; d <
DIM - 1; ++d)
1317 int ind = nrem / gdims[d];
1318 rp[d] = ind * du + du / 2;
1319 nrem -= ind * gdims[d];
1321 rp[
DIM - 1] = nrem * du + du / 2;
1327 for (
int d = 0; d <
DIM; ++d)
1329 rmin[d] =
std::min(rmin[d], rp[d]);
1330 rmax[d] = std::max(rmax[d], rp[d]);
1334 app_log() <<
"DensityMatrices1B::test_overlap checking overlap matrix" << std::endl;
1335 app_log() <<
" rmin = " << rmin << std::endl;
1336 app_log() <<
" rmax = " << rmax << std::endl;
1338 app_log() <<
" overlap matrix:" << std::endl;
1346 APP_ABORT(
"DensityMatrices1B::test_overlap");
1352 app_log() <<
"DensityMatrices1B::test_derivatives checking drift" << std::endl;
1361 app_log() <<
" warming up" << std::endl;
1363 app_log() <<
" generating samples" << std::endl;
1366 app_log() <<
" testing derivatives at sample points" << std::endl;
1373 for (
int d = 0; d <
DIM; ++d)
1377 rtmp[d] = r[d] + delta;
1380 rtmp[d] = r[d] - delta;
1383 driftn[d] = (densp - densm) / (2 * delta);
1388 app_log() <<
" " << driftn << std::endl;
1392 APP_ABORT(
"DensityMatrices1B::test_derivatives");
1406 APP_ABORT(
"DensityMatrices1B::same(vector) vectors differ in size");
1408 for (
int i = 0; i < v1.
size(); ++i)
1409 sm &=
match(v1[i], v2[i]);
1416 APP_ABORT(
"DensityMatrices1B::same(matrix) matrices differ in size");
1419 for (
int i = 0; i <
n; ++i)
1420 sm &=
match(m1(i), m2(i));
1426 bool sm =
same(v1, v2);
1427 std::string result =
"differ";
1430 app_log() << name <<
" " << result << std::endl;
1432 for (
int i = 0; i < v1.
size(); ++i)
1433 app_log() <<
" " << i <<
" " <<
real(v1[i]) <<
" " <<
real(v2[i]) <<
" " <<
real(v1[i] / v2[i]) <<
" " 1434 <<
real(v2[i] / v1[i]) << std::endl;
1439 bool sm =
same(m1, m2);
1440 std::string result =
"differ";
1443 app_log() << name <<
" " << result << std::endl;
1445 for (
int i = 0; i < m1.
rows(); ++i)
1446 for (
int j = 0; j < m1.
cols(); ++j)
1447 if (!diff_only || !
match(m1(i, j), m2(i, j)))
1448 app_log() <<
" " << i <<
" " << j <<
" " <<
real(m1(i, j)) <<
" " <<
real(m2(i, j)) <<
" " 1449 <<
real(m1(i, j) / m2(i, j)) << std::endl;
void resize(size_type n, Type_t val=Type_t())
Resize the container.
std::vector< Matrix_t * > Phi_NB
std::vector< Value_t > E_samp
int numAttributes() const
return the number of attributes in our list
void density_drift(const PosType &r, RealType &dens, PosType &drift)
ValueType calcRatio(ParticleSet &P, int iat, ComputeType ct=ComputeType::ALL)
compute psi(R_new) / psi(R_current) ratio It returns a complex value if the wavefunction is complex...
Return_t evaluate(ParticleSet &P) override
Evaluate the local energy contribution of this component.
void evaluateRatiosAlltoOne(ParticleSet &P, std::vector< ValueType > &ratios)
void delete_iter(IT first, IT last)
delete the pointers in [first,last)
helper functions for EinsplineSetBuilder
RealType accum_constant(CombinedTraceSample< TraceReal > *etrace, RealType weight=1.0)
SPOSet::ValueVector ValueVector
void getRequiredTraces(TraceManager &tm) override
TODO: add docs.
QTBase::RealType RealType
void set_state(xmlNodePtr cur)
~DensityMatrices1B() override
std::vector< TimerIDName_t< T > > TimerNameList_t
MakeReturn< UnaryNode< FnFabs, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t abs(const Vector< T1, C1 > &l)
void generate_density_samples(bool save, int steps, RandomBase< FullPrecRealType > &rng)
size_t getTotalNum() const
int my_index_
starting index of this object
std::vector< Vector_t * > E_N
std::vector< Matrix_t * > Psi_NM
Return_t evaluate_check(ParticleSet &P)
float real(const float &c)
real part of a scalar. Cannot be replaced by std::real due to AFQMC specific needs.
int size() const
return the size of the orbital set Ye: this needs to be replaced by getOrbitalSetSize(); ...
Vectorized record engine for scalar properties.
RealType acceptance_ratio
Matrix< Value_t > Matrix_t
void resize(size_type n, size_type m)
Resize the container.
void integrate(ParticleSet &P, int n)
void resize(const std::array< SIZET, D > &dims)
Resize the container.
TraceSample< TraceReal > * w_trace
int size() const
return the number of species
DensityMatrices1B::Value_t Value_t
TraceRequest request_
whether traces are being collected
static const TimerNameList_t< DMTimers > DMTimerNames
void registerCollectables(std::vector< ObservableHelper > &h5desc, hdf_archive &file) const override
bool put(xmlNodePtr cur) override
Read the input parameter.
void assignGaussRand(T *restrict a, unsigned n, RG &rng)
MakeReturn< BinaryNode< FnPow, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t, typename CreateLeaf< Vector< T2, C2 > >::Leaf_t > >::Expression_t pow(const Vector< T1, C1 > &l, const Vector< T2, C2 > &r)
omp_int_t omp_get_thread_num()
std::string name_
name of this object
Specialized paritlce class for atomistic simulations.
Vector< RealType > sample_weights
float imag(const float &c)
imaginary part of a scalar. Cannot be replaced by std::imag due to AFQMC specific needs...
CompositeSPOSet basis_functions
std::vector< int > species_size
size_type size() const
return the current size
void diffusion(RealType sqt, PosType &diff)
std::vector< Matrix_t * > E_BB
TraceSample< TraceComp > * T_trace
bool write_acceptance_ratio
void generate_uniform_grid(RandomBase< FullPrecRealType > &rng)
void accum_sample(std::vector< Value_t > &E_samp, CombinedTraceSample< T > *etrace, RealType weight=1.0)
void product(const Matrix< T > &A, const Matrix< T > &B, Matrix< T > &C)
static function to perform C=AB for real matrices
void setRandomGenerator(RandomBase< FullPrecRealType > *rng) override
Set the Random Generator object TODO: add docs.
void get_energies(std::vector< Vector_t *> &E_n)
void rejectMove(Index_t iat)
reject a proposed move in regular mode
int groupsize(int igroup) const
return the size of a group
void generate_sample_basis(Matrix_t &Phi_mb)
std::vector< std::string > species_name
const SPOMap & getSPOMap() const
spomap_ reference accessor
#define APP_ABORT(msg)
Widely used but deprecated fatal error macros from legacy code.
RandomBase< FullPrecRealType > * uniform_random
MakeReturn< UnaryNode< FnExp, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t exp(const Vector< T1, C1 > &l)
const Lattice_t & lattice_
size_type current() const
void add(std::unique_ptr< SPOSet > component)
add a sposet component to this composite sposet
Walker_t * t_walker_
reference to the current walker
void generate_samples(RealType weight, int steps=0)
std::string getXMLAttributeValue(const xmlNodePtr cur, const std::string_view name)
get the value string for attribute name if name is unfound in cur you get an empty string back this i...
void evaluateValue(const ParticleSet &P, int iat, ValueVector &psi) override
evaluate the values of this single-particle orbital set
void request_array(const std::string &name, bool write=false)
void addObservables(PropertySetType &plist, BufferType &olist) override
named values to the property list Default implementaton uses addValue(plist_)
Buffer_t Collectables
observables in addition to those registered in Properties/PropertyList
SpeciesSet & getSpeciesSet()
retrun the SpeciesSet of this particle set
float conj(const float &c)
Workaround to allow conj on scalar to return real instead of complex.
std::vector< std::string > speciesName
Species name list.
bool have_required_traces_
Declaration of a TrialWaveFunction.
bool putContent(T &a, xmlNodePtr cur)
replaces a's value with the first "element" in the "string" returned by XMLNodeString{cur}.
CombinedTraceSample< TraceReal > * Vc_trace
MakeReturn< UnaryNode< FnLog, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t log(const Vector< T1, C1 > &l)
An abstract class for Local Energy operators.
FullPrecRealType Return_t
type of return value of evaluate
void evaluateVGL(const ParticleSet &P, int iat, ValueVector &psi, GradVector &dpsi, ValueVector &d2psi) override
evaluate the values, gradients and laplacians of this single-particle orbital set ...
MakeReturn< UnaryNode< FnSqrt, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t sqrt(const Vector< T1, C1 > &l)
Vector< Value_t > Vector_t
void report(const std::string &pad="")
std::unique_ptr< OperatorBase > makeClone(ParticleSet &P, TrialWaveFunction &psi) final
Return_t evaluate_loop(ParticleSet &P)
Class to represent a many-body trial wave function.
void set_dimensions(const std::vector< int > &dims, int first)
set the shape of this observable
CombinedTraceSample< TraceReal > * E_trace
void makeMove(Index_t iat, const SingleParticlePos &displ, bool maybe_accept=true)
move the iat-th particle to active_pos_
TraceSample< TraceComp > * get_complex_trace(const std::string &name)
Return_t evaluate_matrix(ParticleSet &P)
FullPrecRealType Weight
Weight of the walker.
std::vector< Matrix_t * > Phi_Psi_NB
GradVector basis_gradients
ValueVector basis_laplacians
CombinedTraceSample< TraceReal > * Vq_trace
Tensor< typename BinaryReturn< T1, T2, OpMultiply >::Type_t, D > dot(const AntiSymTensor< T1, D > &lhs, const AntiSymTensor< T2, D > &rhs)
void compare(const std::string &name, Vector_t &v1, Vector_t &v2, bool write=false, bool diff_only=true)
TimerManager< NewTimer > & getGlobalTimerManager()
Custom container for set of attributes for a set of species.
void generate_particle_basis(ParticleSet &P, std::vector< Matrix_t *> &Phi_nb)
bool match(Value_t e1, Value_t e2, RealType tol=1e-12)
A D-dimensional Array class based on PETE.
CombinedTraceSample< TraceReal > * Vcc_trace
void update_basis_d012(const PosType &r)
CombinedTraceSample< TraceReal > * get_real_combined_trace(const std::string &name)
void generate_sample_ratios(std::vector< Matrix_t *> Psi_nm)
void update_basis(const PosType &r)
CombinedTraceSample< TraceReal > * Vqq_trace
std::vector< ValueType > psi_ratios
DensityMatrices1B(ParticleSet &P, TrialWaveFunction &psi, ParticleSet *Pcl)
void generate_uniform_samples(RandomBase< FullPrecRealType > &rng)
void density_only(const PosType &r, RealType &dens)
ValueVector integrated_values
void product_AtB(const Matrix< T > &A, const Matrix< T > &B, Matrix< T > &C)
TraceSample< TraceReal > * get_real_trace(const std::string &name)
std::vector< Matrix_t * > N_BB
bool same(Vector_t &v1, Vector_t &v2, RealType tol=1e-6)
std::vector< PosType > rsamples
void request_scalar(const std::string &name, bool write=false)
CombinedTraceSample< TraceReal > * Vqc_trace
void diag_product(const Matrix< T1 > &A, const Vector< T2 > &B, Matrix< T3 > &C)
C = A*diag(B)
std::bitset< 8 > update_mode_
set the current update mode
void makeVirtualMoves(const SingleParticlePos &newpos)
Handles virtual moves for all the particles to a single newpos.