QMCPACK
DensityMatrices1B.cpp
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////////////////
2 // This file is distributed under the University of Illinois/NCSA Open Source License.
3 // See LICENSE file in top directory for details.
4 //
5 // Copyright (c) 2016 Jeongnim Kim and QMCPACK developers.
6 //
7 // File developed by: Jaron T. Krogel, krogeljt@ornl.gov, Oak Ridge National Laboratory
8 // Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
9 //
10 // File created by: Jaron T. Krogel, krogeljt@ornl.gov, Oak Ridge National Laboratory
11 //////////////////////////////////////////////////////////////////////////////////////
12 
13 
14 #include "DensityMatrices1B.h"
15 #include "OhmmsData/AttributeSet.h"
19 #include "Utilities/string_utils.h"
20 #include "CPU/math.hpp"
21 
22 namespace qmcplusplus
23 {
27 
29 {
37 };
38 
40  {{DM_eval, "DensityMatrices1B::evaluate"},
41  {DM_gen_samples, "DensityMatrices1B::generate_samples"},
42  {DM_gen_sample_basis, "DensityMatrices1B::generate_sample_basis"},
43  {DM_gen_sample_ratios, "DensityMatrices1B::generate_sample_ratios"},
44  {DM_gen_particle_basis, "DensityMatrices1B::generate_particle_basis"},
45  {DM_matrix_products, "DensityMatrices1B::evaluate_matrix_products"},
46  {DM_accumulate, "DensityMatrices1B::evaluate_matrix_accum"}};
47 
50  basis_functions("DensityMatrices1B::basis"),
51  lattice_(P.getLattice()),
52  Psi(psi),
53  Pq(P),
54  Pc(Pcl)
55 {
56  reset();
57 }
58 
60  : OperatorBase(master),
62  basis_functions(master.basis_functions),
63  lattice_(P.getLattice()),
64  Psi(psi),
65  Pq(P),
66  Pc(master.Pc)
67 {
68  reset();
69  set_state(master);
70  initialize();
71  for (int i = 0; i < basis_size; ++i)
72  basis_norms[i] = master.basis_norms[i];
73 }
74 
75 
77 {
78  if (initialized)
79  finalize();
80 }
81 
82 
83 std::unique_ptr<OperatorBase> DensityMatrices1B::makeClone(ParticleSet& P, TrialWaveFunction& psi)
84 {
85  return std::make_unique<DensityMatrices1B>(*this, P, psi);
86 }
87 
88 
90 {
91  // uninitialized data
92  w_trace = NULL;
93  T_trace = NULL;
94  Vq_trace = NULL;
95  Vc_trace = NULL;
96  Vqq_trace = NULL;
97  Vqc_trace = NULL;
98  Vcc_trace = NULL;
99  basis_size = -1;
100  nindex = -1;
101  eindex = -1;
102  uniform_random = NULL;
103  // basic HamiltonianBase info
104  update_mode_.set(COLLECTABLE, 1);
105  // default values
106  energy_mat = false;
108  evaluator = loop;
110  scale = 1.0;
111  center = 0.0;
112  points = 10;
113  samples = 10;
114  warmup = 30;
115  timestep = .5;
116  use_drift = false;
117  warmed_up = false;
118  metric = 1.0;
119  write_acceptance_ratio = false;
120  write_rstats = false;
121  normalized = true;
122  volume_normed = true;
123  check_overlap = false;
124  check_derivatives = false;
125  // trace data is required
126  request_.request_scalar("weight");
127  request_.request_array("Kinetic_complex");
128  request_.request_array("Vq");
129  request_.request_array("Vc");
130  request_.request_array("Vqq");
131  request_.request_array("Vqc");
132  request_.request_array("Vcc");
133  // has not been initialized
134  initialized = false;
135 }
136 
137 
138 bool DensityMatrices1B::put(xmlNodePtr cur)
139 {
140  // read in parameters from the input xml
141  set_state(cur);
142 
143  // resize local data and perform warmup sampling, if necessary
144  initialize();
145 
146  // write a report to the log
147  report();
148 
149  if (check_overlap)
150  test_overlap();
151 
152  return true;
153 }
154 
155 
156 void DensityMatrices1B::set_state(xmlNodePtr cur)
157 {
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;
170 
171  xmlNodePtr element = cur->xmlChildrenNode;
172  while (element != NULL)
173  {
174  std::string ename((const char*)element->name);
175  if (ename == "parameter")
176  {
177  const std::string name(getXMLAttributeValue(element, "name"));
178  if (name == "basis")
179  putContent(sposets, element);
180  else if (name == "energy_matrix")
181  putContent(emstr, element);
182  else if (name == "integrator")
183  putContent(igstr, element);
184  else if (name == "evaluator")
185  putContent(evstr, element);
186  else if (name == "scale")
187  putContent(scale, element);
188  else if (name == "center")
189  {
190  putContent(center, element);
191  center_defined = true;
192  }
193  else if (name == "points")
194  putContent(points, element);
195  else if (name == "samples")
196  putContent(samples, element);
197  else if (name == "warmup")
198  putContent(warmup, element);
199  else if (name == "timestep")
200  putContent(timestep, element);
201  else if (name == "use_drift")
202  putContent(udstr, element);
203  else if (name == "check_overlap")
204  putContent(costr, element);
205  else if (name == "check_derivatives")
206  putContent(cdstr, element);
207  else if (name == "acceptance_ratio")
208  putContent(arstr, element);
209  else if (name == "rstats")
210  putContent(wrstr, element);
211  else if (name == "normalized")
212  putContent(nmstr, element);
213  else if (name == "volume_normed")
214  putContent(vnstr, element);
215  }
216  element = element->next;
217  }
218 
219  if (scale > 1.0 + 1e-10)
220  {
221  APP_ABORT("DensityMatrices1B::put scale must be less than one");
222  }
223  else if (scale < 0.0 - 1e-10)
224  APP_ABORT("DensityMatrices1B::put scale must be greater than zero");
225 
226  // get volume and cell information
227  if (!center_defined)
228  center = lattice_.Center;
229  volume = lattice_.Volume * std::exp(DIM * std::log(scale));
230  periodic = lattice_.SuperCellEnum != SUPERCELL_OPEN;
231  rcorner = center - scale * lattice_.Center;
232 
233  energy_mat = emstr == "yes";
234  if (igstr == "uniform_grid")
235  {
238  samples = pow(points, DIM);
239  metric = volume / samples;
240  ind_dims[0] = pow(points, DIM - 1);
241  for (int d = 1; d < DIM; ++d)
242  ind_dims[d] = ind_dims[d - 1] / points;
243  }
244  else if (igstr == "uniform")
245  {
248  metric = volume / samples;
249  }
250  else if (igstr == "density")
251  {
254  metric = 1.0 / samples;
255  }
256  else
257  throw std::runtime_error(
258  "DensityMatrices1B::set_state invalid integrator\n valid options are: uniform_grid, uniform, density");
259 
260  if (evstr == "loop")
261  evaluator = loop;
262  else if (evstr == "matrix")
263  evaluator = matrix;
264  else
265  throw std::runtime_error("DensityMatrices1B::set_state invalid evaluator\n valid options are: loop, matrix");
266 
267  normalized = nmstr == "yes";
268  volume_normed = vnstr == "yes";
269  use_drift = udstr == "yes";
270  check_overlap = costr == "yes";
271  check_derivatives = cdstr == "yes";
272  write_rstats = wrstr == "yes";
273  write_acceptance_ratio = arstr == "yes";
274 
275 
276  // get the sposets that form the basis
277  if (sposets.size() == 0)
278  throw std::runtime_error("DensityMatrices1B::put basis must have at least one sposet");
279 
280  for (int i = 0; i < sposets.size(); ++i)
281  {
282  auto& spomap = Psi.getSPOMap();
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.");
286  basis_functions.add(spo_it->second->makeClone());
287  }
289 
290  if (basis_size < 1)
291  throw std::runtime_error("DensityMatrices1B::put basis_size must be greater than one");
292 }
293 
294 
296 {
297  basis_size = master.basis_size;
298  energy_mat = master.energy_mat;
299  integrator = master.integrator;
300  evaluator = master.evaluator;
301  sampling = master.sampling;
302  scale = master.scale;
303  points = master.points;
304  samples = master.samples;
305  warmup = master.warmup;
306  timestep = master.timestep;
307  use_drift = master.use_drift;
308  volume = master.volume;
309  periodic = master.periodic;
310  metric = master.metric;
311  rcorner = master.rcorner;
312  normalized = master.normalized;
313  volume_normed = master.volume_normed;
314  for (int d = 0; d < DIM; ++d)
315  ind_dims[d] = master.ind_dims[d];
316 }
317 
318 
320 {
321  // get particle information
322  SpeciesSet& species = Pq.getSpeciesSet();
324  nspecies = species.size();
325  int natt = species.numAttributes();
326  for (int s = 0; s < nspecies; ++s)
327  species_size.push_back(Pq.groupsize(s));
328  for (int s = 0; s < nspecies; ++s)
329  species_name.push_back(species.speciesName[s]);
330 
331  // allocate space
332  basis_values.resize(basis_size);
334  basis_norms.resize(basis_size);
335  RealType bn_standard = 1.0;
336  if (volume_normed)
337  bn_standard = 1.0 / std::sqrt(volume);
338  for (int i = 0; i < basis_size; ++i)
339  basis_norms[i] = bn_standard;
340 
341  rsamples.resize(samples);
343  psi_ratios.resize(nparticles);
344 
345  if (evaluator == matrix)
346  {
348  for (int s = 0; s < nspecies; ++s)
349  {
350  int specs_size = species_size[s];
351  Phi_NB.push_back(new Matrix_t(specs_size, basis_size));
352  Psi_NM.push_back(new Matrix_t(specs_size, samples));
353  Phi_Psi_NB.push_back(new Matrix_t(specs_size, basis_size));
354  N_BB.push_back(new Matrix_t(basis_size, basis_size));
355  if (energy_mat)
356  {
357  E_N.push_back(new Vector_t(specs_size));
358  E_BB.push_back(new Matrix_t(basis_size, basis_size));
359  }
360  }
361 
362 #ifdef DMCHECK
363  Phi_MBtmp.resize(samples, basis_size);
364  for (int s = 0; s < nspecies; ++s)
365  {
366  int specs_size = species_size[s];
367  Phi_NBtmp.push_back(new Matrix_t(specs_size, basis_size));
368  Psi_NMtmp.push_back(new Matrix_t(specs_size, samples));
369  Phi_Psi_NBtmp.push_back(new Matrix_t(specs_size, basis_size));
370  N_BBtmp.push_back(new Matrix_t(basis_size, basis_size));
371  if (energy_mat)
372  {
373  E_Ntmp.push_back(new Vector_t(specs_size));
374  E_BBtmp.push_back(new Matrix_t(basis_size, basis_size));
375  }
376  }
377 #endif
378  }
379 
380  if (sampling == metropolis)
381  {
382  basis_gradients.resize(basis_size);
384  }
385 
386  if (!normalized)
387  {
388  normalize();
389  }
390 
391  initialized = true;
392 }
393 
394 
396 {
397  delete_iter(Phi_NB.begin(), Phi_NB.end());
398  delete_iter(Psi_NM.begin(), Psi_NM.end());
399  delete_iter(Phi_Psi_NB.begin(), Phi_Psi_NB.end());
400  delete_iter(N_BB.begin(), N_BB.end());
401  if (energy_mat)
402  {
403  delete_iter(E_N.begin(), E_N.end());
404  delete_iter(E_BB.begin(), E_BB.end());
405  }
406 
407 #ifdef DMCHECK
408  delete_iter(Phi_NBtmp.begin(), Phi_NBtmp.end());
409  delete_iter(Psi_NMtmp.begin(), Psi_NMtmp.end());
410  delete_iter(Phi_Psi_NBtmp.begin(), Phi_Psi_NBtmp.end());
411  delete_iter(N_BBtmp.begin(), N_BBtmp.end());
412  if (energy_mat)
413  {
414  delete_iter(E_Ntmp.begin(), E_Ntmp.end());
415  delete_iter(E_BBtmp.begin(), E_BBtmp.end());
416  }
417 #endif
418 }
419 
420 
421 void DensityMatrices1B::report(const std::string& pad)
422 {
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");
436 
437  std::ostream& out = app_log();
438  //std::ostream& out = std::cout;
439 
440  out << pad << "DensityMatrices1B" << std::endl;
441 
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;
446  if (sampling == volume_based)
447  {
448  PosType rmax = rcorner + 2 * scale * lattice_.Center;
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;
455  }
456  else if (sampling == metropolis)
457  {
458  out << pad << " warmup = " << warmup << std::endl;
459  out << pad << " timestep = " << timestep << std::endl;
460  }
461  out << pad << " metric = " << metric << std::endl;
462  out << pad << " nparticles = " << nparticles << std::endl;
463  out << pad << " nspecies = " << nspecies << std::endl;
464  for (int s = 0; s < nspecies; ++s)
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;
473  if (evaluator == matrix)
474  {
475  out << pad << " Phi_MB : " << Phi_MB.rows() << " " << Phi_MB.cols() << std::endl;
476  for (int s = 0; s < nspecies; ++s)
477  {
478  out << pad << " matrices/vectors for species " << s << std::endl;
479  if (energy_mat)
480  if (energy_mat)
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;
484  out << pad << " Phi_Psi_NB : " << Phi_Psi_NB[s]->rows() << " " << Phi_Psi_NB[s]->cols() << std::endl;
485  out << pad << " N_BB : " << N_BB[s]->rows() << " " << N_BB[s]->cols() << std::endl;
486  if (energy_mat)
487  if (energy_mat)
488  out << pad << " E_BB : " << E_BB[s]->rows() << " " << E_BB[s]->cols() << std::endl;
489  }
490  }
491  out << pad << " basis_norms" << std::endl;
492  for (int i = 0; i < basis_size; ++i)
493  out << pad << " " << i << " " << basis_norms[i] << std::endl;
494  out << pad << "end DensityMatrices1B" << std::endl;
495 }
496 
497 
499 {
500  w_trace = tm.get_real_trace("weight");
501  if (energy_mat)
502  {
503  T_trace = tm.get_complex_trace(Pq, "Kinetic_complex");
504  Vq_trace = tm.get_real_combined_trace(Pq, "Vq");
505  Vqq_trace = tm.get_real_combined_trace(Pq, "Vqq");
506  Vqc_trace = tm.get_real_combined_trace(Pq, "Vqc");
507  if (Pc)
508  {
509  Vc_trace = tm.get_real_combined_trace(*Pc, "Vc");
510  Vcc_trace = tm.get_real_combined_trace(*Pc, "Vcc");
511  }
512 
513  E_samp.resize(nparticles);
514  }
515  have_required_traces_ = true;
516 }
517 
518 
520 
521 
523 {
524 #if defined(QMC_COMPLEX)
525  int nentries = 2 * basis_size * basis_size * nspecies;
526 #else
527  int nentries = basis_size * basis_size * nspecies;
528 #endif
529  my_index_ = collectables.current();
530  nindex = my_index_;
531  std::vector<RealType> ntmp(nentries);
532  collectables.add(ntmp.begin(), ntmp.end());
533  if (energy_mat)
534  {
535  eindex = nindex + nentries;
536  std::vector<RealType> etmp(nentries);
537  collectables.add(etmp.begin(), etmp.end());
538  }
539 }
540 
541 
542 void DensityMatrices1B::registerCollectables(std::vector<ObservableHelper>& h5desc, hdf_archive& file) const
543 {
544 #if defined(QMC_COMPLEX)
545  std::vector<int> ng(3);
546  ng[0] = basis_size;
547  ng[1] = basis_size;
548  ng[2] = 2;
549  int nentries = ng[0] * ng[1] * ng[2];
550 #else
551  std::vector<int> ng(2);
552  ng[0] = basis_size;
553  ng[1] = basis_size;
554  int nentries = ng[0] * ng[1];
555 #endif
556 
557  hdf_path hdf_name{name_};
558  hdf_name /= "number_matrix";
559  for (int s = 0; s < nspecies; ++s)
560  {
561  h5desc.emplace_back(hdf_name / species_name[s]);
562  auto& oh = h5desc.back();
563  oh.set_dimensions(ng, nindex + s * nentries);
564  }
565 
566  if (energy_mat)
567  {
568  hdf_name.replace_subgroup("energy_matrix");
569  for (int s = 0; s < nspecies; ++s)
570  {
571  h5desc.emplace_back(hdf_name / species_name[s]);
572  auto& oh = h5desc.back();
573  oh.set_dimensions(ng, eindex + s * nentries);
574  }
575  }
576 }
577 
578 
580 {
581  if (sampling == metropolis)
582  {
583  if (!warmed_up)
584  {
586  rpcur += center;
587  if (integrator == density)
589  else
590  APP_ABORT("DensityMatrices1B::warmup_sampling invalid integrator");
591  }
592  generate_samples(1.0, warmup);
593  warmed_up = true;
594  }
595 }
596 
597 
599 {
602  {
603  if (check_derivatives)
605  if (evaluator == loop)
606  evaluate_loop(P);
607  else if (evaluator == matrix)
608  evaluate_matrix(P);
609  else
610  APP_ABORT("DensityMatrices1B::evaluate invalid evaluator");
611  }
612  return 0.0;
613 }
614 
615 
617 {
618  //perform warmup sampling the first time
619  if (!warmed_up)
620  warmup_sampling();
621  // get weight and single particle energy trace data
622  RealType weight;
623  if (energy_mat)
624  weight = w_trace->sample[0] * metric;
625  else
626  weight = t_walker_->Weight * metric;
627 
628  if (energy_mat)
629  get_energies(E_N); // energies : particles x 1
630  // compute sample positions (monte carlo or deterministic)
631  generate_samples(weight);
632  // compute basis and wavefunction ratio values in matrix form
633  generate_sample_basis(Phi_MB); // basis : samples x basis_size
634  generate_sample_ratios(Psi_NM); // conj(Psi ratio) : particles x samples
635  generate_particle_basis(P, Phi_NB); // conj(basis) : particles x basis_size
636  // perform integration via matrix products
637  {
638  ScopedTimer local_timer(timers[DM_matrix_products]);
639  for (int s = 0; s < nspecies; ++s)
640  {
641  Matrix_t& Psi_nm = *Psi_NM[s];
642  Matrix_t& Phi_Psi_nb = *Phi_Psi_NB[s];
643  Matrix_t& Phi_nb = *Phi_NB[s];
644  diag_product(Psi_nm, sample_weights, Psi_nm);
645  product(Psi_nm, Phi_MB, Phi_Psi_nb); // ratio*basis : particles x basis_size
646  product_AtB(Phi_nb, Phi_Psi_nb, *N_BB[s]); // conj(basis)^T*ratio*basis : basis_size^2
647  if (energy_mat)
648  {
649  Vector_t& E = *E_N[s];
650  diag_product(E, Phi_nb, Phi_nb); // diag(energies)*qmcplusplus::conj(basis)
651  product_AtB(Phi_nb, Phi_Psi_nb, *E_BB[s]); // (energies*conj(basis))^T*ratio*basis
652  }
653  }
654  }
655  // accumulate data into collectables
656  {
657  ScopedTimer local_timer(timers[DM_accumulate]);
658  const int basis_size2 = basis_size * basis_size;
659  int ij = nindex;
660  for (int s = 0; s < nspecies; ++s)
661  {
662  //int ij=nindex; // for testing
663  const Matrix_t& NDM = *N_BB[s];
664  for (int n = 0; n < basis_size2; ++n)
665  {
666  Value_t val = NDM(n);
667  P.Collectables[ij] += real(val);
668  ij++;
669 #if defined(QMC_COMPLEX)
670  P.Collectables[ij] += imag(val);
671  ij++;
672 #endif
673  }
674  }
675  if (energy_mat)
676  {
677  int ij = eindex;
678  for (int s = 0; s < nspecies; ++s)
679  {
680  //int ij=eindex; // for testing
681  const Matrix_t& EDM = *E_BB[s];
682  for (int n = 0; n < basis_size2; ++n)
683  {
684  Value_t val = EDM(n);
685  P.Collectables[ij] += real(val);
686  ij++;
687 #if defined(QMC_COMPLEX)
688  P.Collectables[ij] += imag(val);
689  ij++;
690 #endif
691  }
692  }
693  }
694  }
695 
696 
697  // jtk come back to this
698  // why are matrices so similar across species?
699  // O atom, einspline, points=20, blocks=1, steps=1
700  //
701  //app_log()<<" ntraces = ";
702  //for(int s=0;s<nspecies;++s)
703  //{
704  // const Matrix_t& NDM = *N_BB[s];
705  // Value_t ntrace = 0.0;
706  // for(int i=0;i<basis_size;++i)
707  // ntrace+=NDM(i,i);
708  // app_log()<<ntrace<<" ";
709  //}
710  //app_log()<< std::endl;
711  //
712  //app_log()<<"nmatrices"<< std::endl;
713  //for(int s=0;s<nspecies;++s)
714  //{
715  // app_log()<<" species "<<s<< std::endl;
716  // const Matrix_t& NDM = *N_BB[s];
717  // for(int i=0;i<basis_size;++i)
718  // {
719  // for(int j=0;j<basis_size;++j)
720  // app_log()<<" "<<real(NDM(i,j));
721  // app_log()<< std::endl;
722  // }
723  //}
724  //
725  //app_log()<<"positions"<< std::endl;
726  //int p=0;
727  //for(int s=0;s<nspecies;++s)
728  //{
729  // app_log()<<" species "<<s<< std::endl;
730  // for(int ps=0;ps<species_size[s];++ps,++p)
731  // app_log()<<" "<<p<<" "<<P.R[p]-P.getLattice().Center<< std::endl;
732  //}
733  //
734  ////app_log()<<"basis_values"<< std::endl;
735  ////int p=0;
736  ////for(int s=0;s<nspecies;++s)
737  ////{
738  //// app_log()<<" species "<<s<< std::endl;
739  //// for(int ps=0;ps<species_size[s];++ps,++p)
740  //// app_log()<<" "<<p<<" "<<P.R[p]<< std::endl;
741  ////}
742 
743 
744 #ifdef DMCHECK
745  report();
746  app_log() << "DM Check" << std::endl;
747  evaluate_check(P);
748  compare(" Phi_MB", Phi_MB, Phi_MBtmp);
749  for (int s = 0; s < nspecies; ++s)
750  {
751  app_log() << " species " << s << std::endl;
752  compare(" E_N ", *E_N[s], *E_Ntmp[s]);
753  compare(" Phi_NB ", *Phi_NB[s], *Phi_NBtmp[s]);
754  compare(" Psi_NM ", *Psi_NM[s], *Psi_NMtmp[s]);
755  compare(" Phi_Psi_NB", *Phi_Psi_NB[s], *Phi_Psi_NBtmp[s], true);
756  compare(" N_BB ", *N_BB[s], *N_BBtmp[s], true);
757  if (energy_mat)
758  compare(" E_BB ", *E_BB[s], *E_BBtmp[s], true);
759  }
760  app_log() << "end DM Check" << std::endl;
761  APP_ABORT("DM Check");
762 #endif
763 
764 
765  return 0.0;
766 }
767 
768 
770 {
771 #ifdef DMCHECK
772  APP_ABORT("DensityMatrices1B::evaluate_check use of E_trace in this function needs to be replaces with "
773  "get_energies() and E_samp");
774  int n = 0;
775  for (int s = 0; s < nspecies; ++s)
776  {
777  Matrix_t& Phi_mb = Phi_MBtmp;
778  Matrix_t& Psi_nm = *Psi_NMtmp[s];
779  Matrix_t& Phi_Psi_nb = *Phi_Psi_NBtmp[s];
780  Matrix_t& Phi_nb = *Phi_NBtmp[s];
781  Vector_t& E_n = *E_Ntmp[s];
782  Matrix_t& N_bb = *N_BBtmp[s];
783  Matrix_t& E_bb = *E_BBtmp[s];
784 
785  for (int ij = 0; ij < basis_size * basis_size; ++ij)
786  N_bb(ij) = 0.0;
787  for (int ij = 0; ij < basis_size * basis_size; ++ij)
788  E_bb(ij) = 0.0;
789 
790  for (int ns = 0; ns < species_size[s]; ++ns, ++n)
791  {
792  std::fill(integrated_values.begin(), integrated_values.end(), 0.0);
793  for (int m = 0; m < samples; ++m)
794  {
795  PosType& rsamp = rsamples[m];
796  update_basis(rsamp);
797  PosType dr = rsamp - P.R[n];
798  P.makeMove(n, dr);
800  P.rejectMove(n);
801  for (int i = 0; i < basis_size; ++i)
802  {
803  integrated_values[i] += ratio * basis_values[i];
804  Phi_mb(m, i) = basis_values[i];
805  }
806  Psi_nm(ns, m) = ratio;
807  }
808  update_basis(P.R[n]);
809  for (int i = 0; i < basis_size; ++i)
810  Phi_Psi_nb(ns, i) = integrated_values[i];
811  for (int i = 0; i < basis_size; ++i)
812  Phi_nb(ns, i) = qmcplusplus::conj(basis_values[i]);
813  for (int i = 0; i < basis_size; ++i)
814  {
816  for (int j = 0; j < basis_size; ++j)
817  {
818  Value_t val = phi_i * integrated_values[j];
819  N_bb(i, j) += val;
820  }
821  }
822  if (energy_mat)
823  {
824  RealType e_n = E_trace->sample[n]; //replace this with traces access later
825  E_n[ns] = e_n;
826  for (int i = 0; i < basis_size; ++i)
827  {
828  Value_t ephi_i = e_n * qmcplusplus::conj(basis_values[i]);
829  Phi_nb(ns, i) = ephi_i;
830  for (int j = 0; j < basis_size; ++j)
831  {
832  Value_t val = ephi_i * integrated_values[j];
833  E_bb(i, j) += val;
834  }
835  }
836  }
837  }
838  }
839 #endif
840  return 0.0;
841 }
842 
843 
845 {
846  const int basis_size2 = basis_size * basis_size;
847  if (!warmed_up)
848  warmup_sampling();
849  RealType weight;
850  if (energy_mat)
851  weight = w_trace->sample[0] * metric;
852  else
853  weight = t_walker_->Weight * metric;
854  int nparticles = P.getTotalNum();
855  generate_samples(weight);
856  int n = 0;
857  for (int s = 0; s < nspecies; ++s)
858  {
859  for (int ns = 0; ns < species_size[s]; ++ns, ++n)
860  {
861  integrate(P, n);
862  update_basis(P.R[n]);
863  int ij = nindex + s * basis_size2;
864  for (int i = 0; i < basis_size; ++i)
865  {
867  for (int j = 0; j < basis_size; ++j)
868  {
869  Value_t val = phi_i * integrated_values[j];
870  P.Collectables[ij] += real(val);
871  ij++;
872 #if defined(QMC_COMPLEX)
873  P.Collectables[ij] += imag(val);
874  ij++;
875 #endif
876  }
877  }
878  if (energy_mat)
879  {
880  RealType e_n = E_trace->sample[n]; //replace this with traces access later
881  int ij = eindex + s * basis_size2;
882  for (int i = 0; i < basis_size; ++i)
883  {
884  Value_t ephi_i = e_n * qmcplusplus::conj(basis_values[i]);
885  for (int j = 0; j < basis_size; ++j)
886  {
887  Value_t val = ephi_i * integrated_values[j];
888  P.Collectables[ij] += real(val);
889  ij++;
890 #if defined(QMC_COMPLEX)
891  P.Collectables[ij] += imag(val);
892  ij++;
893 #endif
894  }
895  }
896  }
897  }
898  }
899  return 0.0;
900 }
901 
902 
903 inline void DensityMatrices1B::generate_samples(RealType weight, int steps)
904 {
906  auto& rng = *uniform_random;
907  bool save = false;
908  if (steps == 0)
909  {
910  save = true;
911  steps = samples;
912  }
913  if (integrator == uniform_grid)
915  else if (integrator == uniform)
917  else if (integrator == density)
918  generate_density_samples(save, steps, rng);
919 
920  if (save)
921  {
922  if (sampling == metropolis)
923  {
924  sample_weights *= weight;
925  }
926  else
927  {
928  std::fill(sample_weights.begin(), sample_weights.end(), weight);
929  }
930  }
931 
932 
933  // temporary check
934  if (write_rstats && omp_get_thread_num() == 0)
935  {
936  PosType rmin = std::numeric_limits<RealType>::max();
937  PosType rmax = -std::numeric_limits<RealType>::max();
938  PosType rmean = 0.0;
939  PosType rstd = 0.0;
940  for (int s = 0; s < rsamples.size(); ++s)
941  for (int d = 0; d < DIM; ++d)
942  {
943  RealType rd = rsamples[s][d];
944  rmin[d] = std::min(rmin[d], rd);
945  rmax[d] = std::max(rmax[d], rd);
946  rmean[d] += rd;
947  rstd[d] += rd * rd;
948  }
949  rmean /= rsamples.size();
950  rstd /= rsamples.size();
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;
958  }
959 }
960 
961 
963 {
964  PosType rp;
965  PosType ushift = 0.0;
966  RealType du = scale / points;
967  for (int d = 0; d < DIM; ++d)
968  ushift[d] += rng() * du;
969  for (int s = 0; s < samples; ++s)
970  {
971  int nrem = s;
972  for (int d = 0; d < DIM - 1; ++d)
973  {
974  int ind = nrem / ind_dims[d];
975  rp[d] = ind * du + ushift[d];
976  nrem -= ind * ind_dims[d];
977  }
978  rp[DIM - 1] = nrem * du + ushift[DIM - 1];
979  rsamples[s] = lattice_.toCart(rp) + rcorner;
980  }
981 }
982 
983 
985 {
986  PosType rp;
987  for (int s = 0; s < samples; ++s)
988  {
989  for (int d = 0; d < DIM; ++d)
990  rp[d] = scale * rng();
991  rsamples[s] = lattice_.toCart(rp) + rcorner;
992  }
993 }
994 
995 
997 {
998  RealType sqt = std::sqrt(timestep);
999  RealType ot = 1.0 / timestep;
1000  PosType r = rpcur; //current position
1001  PosType d = dpcur; //current drift
1002  RealType rho = rhocur; //current density
1003  for (int s = 0; s < steps; ++s)
1004  {
1005  nmoves++;
1006  PosType n, rp, dp, ds; //diffusion, trial pos/drift, drift sum
1007  RealType rhop, ratio, Pacc; //trial density, dens ratio, acc prob
1008  diffusion(sqt, n); //get diffusion
1009  if (use_drift)
1010  {
1011  rp = r + n + d; //update trial position
1012  density_drift(rp, rhop, dp); //get trial drift and density
1013  ratio = rhop / rho; //density ratio
1014  ds = dp + d; //drift sum
1015  Pacc = ratio * std::exp(-ot * (dot(n, ds) + .5 * dot(ds, ds))); //acceptance probability
1016  }
1017  else
1018  {
1019  rp = r + n; //update trial position
1020  density_only(rp, rhop); //get trial density
1021  ratio = rhop / rho; //density ratio
1022  Pacc = ratio; //acceptance probability
1023  }
1024  if (rng() < Pacc)
1025  { //accept move
1026  r = rp;
1027  d = dp;
1028  rho = rhop;
1029  naccepted++;
1030  }
1031  if (save)
1032  {
1033  rsamples[s] = r;
1034  sample_weights[s] = 1.0 / rho;
1035  }
1036  }
1038 
1040  app_log() << "dm1b acceptance_ratio = " << acceptance_ratio << std::endl;
1041 
1042  rpcur = r;
1043  dpcur = d;
1044  rhocur = rho;
1045 }
1046 
1047 
1049 {
1050  assignGaussRand(&diff[0], DIM, *uniform_random);
1051  diff *= sqt;
1052 }
1053 
1054 
1056 {
1057  update_basis(r);
1058  dens = 0.0;
1059  for (int i = 0; i < basis_size; ++i)
1060  {
1061  Value_t b = basis_values[i];
1062  dens += std::abs(qmcplusplus::conj(b) * b);
1063  }
1064  dens /= basis_size;
1065 }
1066 
1067 
1068 inline void DensityMatrices1B::density_drift(const PosType& r, RealType& dens, PosType& drift)
1069 {
1070  update_basis_d012(r);
1071  dens = 0.0;
1072  drift = 0.0;
1073  for (int i = 0; i < basis_size; ++i)
1074  {
1075  const Grad_t& bg = basis_gradients[i];
1076  Value_t b = basis_values[i];
1077  Value_t bc = qmcplusplus::conj(b);
1078  dens += std::abs(bc * b);
1079  for (int d = 0; d < DIM; ++d)
1080  drift[d] += std::real(bc * bg[d]);
1081  }
1082  drift *= timestep / dens;
1083  dens /= basis_size;
1084 }
1085 
1086 
1089 
1090 
1092 {
1093  RealType E = 0.0;
1094  if (etrace)
1095  {
1096  etrace->combine();
1097  for (int p = 0; p < etrace->sample.size(); ++p)
1098  E += etrace->sample[p];
1099  }
1100  return weight * E;
1101 }
1102 
1103 template<typename T>
1104 inline void accum_sample(std::vector<Value_t>& E_samp, CombinedTraceSample<T>* etrace, RealType weight = 1.0)
1105 {
1106  if (etrace)
1107  {
1108  etrace->combine();
1109  for (int p = 0; p < etrace->sample.size(); ++p)
1110  E_samp[p] += weight * etrace->sample[p];
1111  }
1112 }
1113 
1114 template<typename T>
1115 inline void accum_sample(std::vector<Value_t>& E_samp, TraceSample<T>* etrace, RealType weight = 1.0)
1116 {
1117 #ifdef QMC_COMPLEX
1118  if (etrace)
1119  for (int p = 0; p < etrace->sample.size(); ++p)
1120  E_samp[p] += weight * etrace->sample[p];
1121 #else
1122  if (etrace)
1123  for (int p = 0; p < etrace->sample.size(); ++p)
1124  E_samp[p] += weight * real(etrace->sample[p]);
1125 #endif
1126 }
1127 
1128 
1129 void DensityMatrices1B::get_energies(std::vector<Vector_t*>& E_n)
1130 {
1131  Value_t Vc = 0;
1132  Vc += accum_constant(Vc_trace);
1133  Vc += accum_constant(Vcc_trace);
1134  Vc /= nparticles;
1135  std::fill(E_samp.begin(), E_samp.end(), Vc);
1139  accum_sample(E_samp, Vqc_trace, 2.0);
1140 
1141  int p = 0;
1142  for (int s = 0; s < nspecies; ++s)
1143  {
1144  Vector_t& E = *E_n[s];
1145  for (int ps = 0; ps < E.size(); ++ps, ++p)
1146  E[ps] = E_samp[p];
1147  }
1148 
1149  //E_trace->combine();
1150  //RealType E = 0.0;
1151  //for(int p=0;p<nparticles;++p)
1152  // E += E_samp[p];
1153  //app_log()<<" E = "<<E<<" "<<E_trace->sample[0]<< std::endl;
1154  //APP_ABORT("dm1b::get_energies check sp traces");
1155 }
1156 
1157 
1159 {
1161  int mb = 0;
1162  for (int m = 0; m < samples; ++m)
1163  {
1165  for (int b = 0; b < basis_size; ++b, ++mb)
1166  Phi_mb(mb) = basis_values[b];
1167  }
1168 }
1169 
1170 
1171 void DensityMatrices1B::generate_sample_ratios(std::vector<Matrix_t*> Psi_nm)
1172 {
1174  for (int m = 0; m < samples; ++m)
1175  {
1176  // get N ratios for the current sample point
1179 
1180  // collect ratios into per-species matrices
1181  int p = 0;
1182  for (int s = 0; s < nspecies; ++s)
1183  {
1184  Matrix_t& P_nm = *Psi_nm[s];
1185  for (int n = 0; n < species_size[s]; ++n, ++p)
1186  {
1187  P_nm(n, m) = qmcplusplus::conj(psi_ratios[p]);
1188  }
1189  }
1190  }
1191 }
1192 
1193 
1194 void DensityMatrices1B::generate_particle_basis(ParticleSet& P, std::vector<Matrix_t*>& Phi_nb)
1195 {
1197  int p = 0;
1198  for (int s = 0; s < nspecies; ++s)
1199  {
1200  int nb = 0;
1201  Matrix_t& P_nb = *Phi_nb[s];
1202  for (int n = 0; n < species_size[s]; ++n, ++p)
1203  {
1204  update_basis(P.R[p]);
1205  for (int b = 0; b < basis_size; ++b, ++nb)
1206  P_nb(nb) = qmcplusplus::conj(basis_values[b]);
1207  }
1208  }
1209 }
1210 
1211 
1213 {
1214  std::fill(integrated_values.begin(), integrated_values.end(), 0.0);
1215  for (int s = 0; s < samples; ++s)
1216  {
1217  PosType& rsamp = rsamples[s];
1218  update_basis(rsamp);
1219  P.makeMove(n, rsamp - P.R[n]);
1221  P.rejectMove(n);
1222  for (int i = 0; i < basis_size; ++i)
1223  integrated_values[i] += ratio * basis_values[i];
1224  }
1225 }
1226 
1227 
1229 {
1230  Pq.makeMove(0, r - Pq.R[0]);
1232  Pq.rejectMove(0);
1233  for (int i = 0; i < basis_size; ++i)
1234  basis_values[i] *= basis_norms[i];
1235 }
1236 
1237 
1239 {
1240  Pq.makeMove(0, r - Pq.R[0]);
1242  Pq.rejectMove(0);
1243  for (int i = 0; i < basis_size; ++i)
1244  basis_values[i] *= basis_norms[i];
1245  for (int i = 0; i < basis_size; ++i)
1246  basis_gradients[i] *= basis_norms[i];
1247  for (int i = 0; i < basis_size; ++i)
1248  basis_laplacians[i] *= basis_norms[i];
1249 }
1250 
1251 
1253 {
1254  int ngrid = std::max(200, points);
1255  int ngtot = pow(ngrid, DIM);
1256  RealType du = scale / ngrid;
1257  RealType dV = volume / ngtot;
1258  PosType rp;
1259  ValueVector bnorms;
1260  int gdims[DIM];
1261  gdims[0] = pow(ngrid, DIM - 1);
1262  for (int d = 1; d < DIM; ++d)
1263  gdims[d] = gdims[d - 1] / ngrid;
1264  bnorms.resize(basis_size);
1265  for (int i = 0; i < basis_size; ++i)
1266  bnorms[i] = 0.0;
1267  std::fill(basis_norms.begin(), basis_norms.end(), 1.0);
1268  for (int p = 0; p < ngtot; ++p)
1269  {
1270  int nrem = p;
1271  for (int d = 0; d < DIM - 1; ++d)
1272  {
1273  int ind = nrem / gdims[d];
1274  rp[d] = ind * du + du / 2;
1275  nrem -= ind * gdims[d];
1276  }
1277  rp[DIM - 1] = nrem * du + du / 2;
1278  rp = lattice_.toCart(rp) + rcorner;
1279  update_basis(rp);
1280  for (int i = 0; i < basis_size; ++i)
1281  bnorms[i] += qmcplusplus::conj(basis_values[i]) * basis_values[i] * dV;
1282  }
1283  for (int i = 0; i < basis_size; ++i)
1284  basis_norms[i] = 1.0 / std::sqrt(real(bnorms[i]));
1285  normalized = true;
1286 }
1287 
1288 
1290 {
1291  //int ngrid = std::max(200,points);
1292  int ngrid = std::max(50, points);
1293  int ngtot = pow(ngrid, DIM);
1294 
1295  PosType rp;
1296  RealType du = scale / ngrid;
1297  RealType dV = volume / ngtot;
1298 
1299  PosType rmin = std::numeric_limits<RealType>::max();
1300  PosType rmax = -std::numeric_limits<RealType>::max();
1301  int gdims[DIM];
1302  gdims[0] = pow(ngrid, DIM - 1);
1303  for (int d = 1; d < DIM; ++d)
1304  gdims[d] = gdims[d - 1] / ngrid;
1305 
1306  Array<Value_t, 2> omat;
1307  omat.resize(basis_size, basis_size);
1308  for (int i = 0; i < basis_size; ++i)
1309  for (int j = 0; j < basis_size; ++j)
1310  omat(i, j) = 0.0;
1311 
1312  for (int p = 0; p < ngtot; ++p)
1313  {
1314  int nrem = p;
1315  for (int d = 0; d < DIM - 1; ++d)
1316  {
1317  int ind = nrem / gdims[d];
1318  rp[d] = ind * du + du / 2;
1319  nrem -= ind * gdims[d];
1320  }
1321  rp[DIM - 1] = nrem * du + du / 2;
1322  rp = lattice_.toCart(rp) + rcorner;
1323  update_basis(rp);
1324  for (int i = 0; i < basis_size; ++i)
1325  for (int j = 0; j < basis_size; ++j)
1326  omat(i, j) += qmcplusplus::conj(basis_values[i]) * basis_values[j] * dV;
1327  for (int d = 0; d < DIM; ++d)
1328  {
1329  rmin[d] = std::min(rmin[d], rp[d]);
1330  rmax[d] = std::max(rmax[d], rp[d]);
1331  }
1332  }
1333 
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;
1337  app_log() << " overlap scale " << std::abs(omat(0, 0)) << std::endl;
1338  app_log() << " overlap matrix:" << std::endl;
1339  for (int i = 0; i < basis_size; ++i)
1340  {
1341  app_log() << std::endl;
1342  for (int j = 0; j < basis_size; ++j)
1343  app_log() << std::abs(omat(i, j)) / std::abs(omat(0, 0)) << " ";
1344  }
1345  app_log() << std::endl;
1346  APP_ABORT("DensityMatrices1B::test_overlap");
1347 }
1348 
1349 
1351 {
1352  app_log() << "DensityMatrices1B::test_derivatives checking drift" << std::endl;
1353 
1354  PosType r, rtmp;
1355 
1356  RealType delta = 1e-5;
1357 
1358  RealType dens, densp, densm;
1359  PosType drift, driftn, drifttmp;
1360 
1361  app_log() << " warming up" << std::endl;
1362  warmup_sampling();
1363  app_log() << " generating samples" << std::endl;
1364  generate_samples(1.0);
1365 
1366  app_log() << " testing derivatives at sample points" << std::endl;
1367  for (int s = 0; s < rsamples.size(); ++s)
1368  {
1369  r = rsamples[s];
1370 
1371  density_drift(r, dens, drift);
1372 
1373  for (int d = 0; d < DIM; ++d)
1374  {
1375  rtmp = r;
1376 
1377  rtmp[d] = r[d] + delta;
1378  density_drift(rtmp, densp, drifttmp);
1379 
1380  rtmp[d] = r[d] - delta;
1381  density_drift(rtmp, densm, drifttmp);
1382 
1383  driftn[d] = (densp - densm) / (2 * delta);
1384  }
1385  driftn *= .5 * timestep / dens;
1386 
1387  app_log() << s << std::endl;
1388  app_log() << " " << driftn << std::endl;
1389  app_log() << " " << drift << std::endl;
1390  }
1391 
1392  APP_ABORT("DensityMatrices1B::test_derivatives");
1393 }
1394 
1395 
1397 {
1398  return std::abs(e1 - e2) < tol;
1399  //return std::abs(2*(e1-e2)/(e1+e2)) < tol;
1400 }
1401 
1402 
1404 {
1405  if (v1.size() != v2.size())
1406  APP_ABORT("DensityMatrices1B::same(vector) vectors differ in size");
1407  bool sm = true;
1408  for (int i = 0; i < v1.size(); ++i)
1409  sm &= match(v1[i], v2[i]);
1410  return sm;
1411 }
1412 
1414 {
1415  if (m1.rows() != m2.rows() || m1.cols() != m2.cols())
1416  APP_ABORT("DensityMatrices1B::same(matrix) matrices differ in size");
1417  bool sm = true;
1418  int n = m1.rows() * m1.cols();
1419  for (int i = 0; i < n; ++i)
1420  sm &= match(m1(i), m2(i));
1421  return sm;
1422 }
1423 
1424 void DensityMatrices1B::compare(const std::string& name, Vector_t& v1, Vector_t& v2, bool write, bool diff_only)
1425 {
1426  bool sm = same(v1, v2);
1427  std::string result = "differ";
1428  if (sm)
1429  result = "agree";
1430  app_log() << name << " " << result << std::endl;
1431  if (write && !sm)
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;
1435 }
1436 
1437 void DensityMatrices1B::compare(const std::string& name, Matrix_t& m1, Matrix_t& m2, bool write, bool diff_only)
1438 {
1439  bool sm = same(m1, m2);
1440  std::string result = "differ";
1441  if (sm)
1442  result = "agree";
1443  app_log() << name << " " << result << std::endl;
1444  if (write && !sm)
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;
1450 }
1451 
1452 
1453 } // namespace qmcplusplus
void resize(size_type n, Type_t val=Type_t())
Resize the container.
Definition: OhmmsVector.h:166
std::vector< Matrix_t * > Phi_NB
std::vector< Value_t > E_samp
int numAttributes() const
return the number of attributes in our list
Definition: SpeciesSet.h:59
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)
QMCTraits::RealType real
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
RealType accum_constant(CombinedTraceSample< TraceReal > *etrace, RealType weight=1.0)
void getRequiredTraces(TraceManager &tm) override
TODO: add docs.
QTBase::RealType RealType
Definition: Configuration.h:58
std::vector< TimerIDName_t< T > > TimerNameList_t
Definition: TimerManager.h:156
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
Definition: ParticleSet.h:493
int my_index_
starting index of this object
Definition: OperatorBase.h:535
std::ostream & app_log()
Definition: OutputManager.h:65
if(c->rank()==0)
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(); ...
Definition: SPOSet.h:75
class to handle hdf file
Definition: hdf_archive.h:51
Vectorized record engine for scalar properties.
void resize(size_type n, size_type m)
Resize the container.
Definition: OhmmsMatrix.h:99
void integrate(ParticleSet &P, int n)
void resize(const std::array< SIZET, D > &dims)
Resize the container.
Definition: OhmmsArray.h:65
TraceSample< TraceReal > * w_trace
int size() const
return the number of species
Definition: SpeciesSet.h:53
DensityMatrices1B::Value_t Value_t
TraceRequest request_
whether traces are being collected
Definition: OperatorBase.h:531
T min(T a, T b)
size_type cols() const
Definition: OhmmsMatrix.h:78
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()
Definition: OpenMP.h:25
std::string name_
name of this object
Definition: OperatorBase.h:527
Specialized paritlce class for atomistic simulations.
Definition: ParticleSet.h:55
float imag(const float &c)
imaginary part of a scalar. Cannot be replaced by std::imag due to AFQMC specific needs...
size_type size() const
return the current size
Definition: OhmmsVector.h:162
void diffusion(RealType sqt, PosType &diff)
std::vector< Matrix_t * > E_BB
TraceSample< TraceComp > * T_trace
void add(T &x)
Definition: PooledData.h:88
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
Definition: ParticleSet.h:527
void generate_sample_basis(Matrix_t &Phi_mb)
std::vector< std::string > species_name
const SPOMap & getSPOMap() const
spomap_ reference accessor
ParticlePos R
Position.
Definition: ParticleSet.h:79
#define APP_ABORT(msg)
Widely used but deprecated fatal error macros from legacy code.
Definition: AppAbort.h:27
RandomBase< FullPrecRealType > * uniform_random
MakeReturn< UnaryNode< FnExp, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t exp(const Vector< T1, C1 > &l)
size_type current() const
Definition: PooledData.h:51
void add(std::unique_ptr< SPOSet > component)
add a sposet component to this composite sposet
Walker_t * t_walker_
reference to the current walker
Definition: OperatorBase.h:541
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
size_type rows() const
Definition: OhmmsMatrix.h:77
void request_array(const std::string &name, bool write=false)
Definition: TraceManager.h:233
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
Definition: ParticleSet.h:126
SpeciesSet & getSpeciesSet()
retrun the SpeciesSet of this particle set
Definition: ParticleSet.h:231
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.
Definition: SpeciesSet.h:44
Declaration of a TrialWaveFunction.
bool putContent(T &a, xmlNodePtr cur)
replaces a&#39;s value with the first "element" in the "string" returned by XMLNodeString{cur}.
Definition: libxmldefs.h:88
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.
Definition: OperatorBase.h:59
FullPrecRealType Return_t
type of return value of evaluate
Definition: OperatorBase.h:64
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)
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.
Definition: Walker.h:102
std::vector< Matrix_t * > Phi_Psi_NB
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.
Definition: SpeciesSet.h:33
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.
Definition: OhmmsArray.h:25
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)
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)
Definition: TraceManager.h:224
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
Definition: OperatorBase.h:521
void makeVirtualMoves(const SingleParticlePos &newpos)
Handles virtual moves for all the particles to a single newpos.
ObservableHelper oh