QMCPACK
CountingJastrow.h
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: Brett Van Der Goetz, bvdg@berkeley.edu, University of California at Berkeley
8 //
9 // File created by: Brett Van Der Goetz, bvdg@berkeley.edu, University of California at Berkeley
10 //////////////////////////////////////////////////////////////////////////////////////
11 
12 #ifndef QMC_PLUS_PLUS_COUNTING_JASTROW_ORBITAL_H
13 #define QMC_PLUS_PLUS_COUNTING_JASTROW_ORBITAL_H
14 
15 #include "Configuration.h"
16 #include "Particle/ParticleSet.h"
19 
20 namespace qmcplusplus
21 {
22 template<class RegionType>
24 {
25 protected:
26  // number of electrons
27  int num_els;
28  // number of counting regions
30 
31  // debug options
32  bool debug = false;
35 
36  // Jastrow linear coefficients
38 
39  // Counting Regions
40  std::unique_ptr<RegionType> C;
41 
42  // Optimization Flags
43  bool opt_F;
44  //bool opt_G;
45  bool opt_C;
46 
47  // Jastrow intermediate Matrix-vector products
48  std::vector<RealType> FCsum;
51 
52  // grad dot grad and laplacian sums for evaluateDerivatives
53  std::vector<RealType> FCggsum;
54  std::vector<RealType> FClapsum;
55 
56  // Jastrow intermediate Matrix-vector products at proposed position
57  std::vector<RealType> FCsum_t;
58  std::vector<PosType> FCgrad_t;
59  std::vector<RealType> FClap_t;
60 
61  // Jastrow exponent values and gradients (by particle index)
63  std::vector<PosType> Jgrad;
64  std::vector<RealType> Jlap;
65 
66  // Jastrow exponent values and gradients at proposed position
68  std::vector<PosType> Jgrad_t;
69  std::vector<RealType> Jlap_t;
70 
71  // containers for counting function derivative quantities
75  std::vector<RealType> dCsum_t;
76  std::vector<RealType> dCFCggsum;
77  std::vector<int> dCindex;
78 
79  // first array index for opt_index, opt_id
80  enum opt_var
81  {
83  //OPT_G,
85  };
86  // vectors to store indices and names of active optimizable parameters
87  std::array<std::vector<int>, NUM_OPT_VAR> opt_index;
88  std::array<std::vector<std::string>, NUM_OPT_VAR> opt_id;
89 
90  //================================================================================
91 
92 public:
93  // constructor
95  std::unique_ptr<RegionType> c,
96  const Matrix<RealType>& f,
97  bool opt_C_flag,
98  bool opt_F_flag)
99  : OptimizableObject("countingjas"), F(f), C(std::move(c)), opt_F(opt_F_flag), opt_C(opt_C_flag)
100  {
101  num_els = P.getTotalNum();
102  }
103 
104  std::string getClassName() const override { return "CountingJastrow"; }
105 
106  bool isOptimizable() const override { return opt_C || opt_F; }
107 
108  void extractOptimizableObjectRefs(UniqueOptObjRefs& opt_obj_refs) override { opt_obj_refs.push_back(*this); }
109 
111  {
112  active.insertFrom(myVars);
113  C->checkInVariables(active);
114  }
115 
116  void checkOutVariables(const opt_variables_type& active) override
117  {
118  myVars.getIndex(active);
119  C->checkOutVariables(active);
120  }
121 
122 
123  void resetParametersExclusive(const opt_variables_type& active) override
124  {
125  int ia, IJ, JI;
126  std::string id;
127  myVars.getIndex(active);
128  for (int i = 0; i < myVars.size(); ++i)
129  {
130  ia = myVars.where(i);
131  if (ia != -1)
132  myVars[i] = active[ia];
133  }
134  // set F parameters from myVars
135  for (int oi = 0; oi < opt_index[OPT_F].size(); ++oi)
136  {
137  IJ = opt_index[OPT_F][oi];
138  JI = num_regions * (IJ % num_regions) + IJ / num_regions;
139  id = opt_id[OPT_F][oi];
140  ia = active.getLoc(id);
141  myVars[id] = active[ia];
142  F(IJ) = std::real(myVars[id]);
143  F(JI) = std::real(myVars[id]);
144  }
145  // reset parameters for counting regions
146  C->resetParameters(active);
147  }
148 
149 
150  void initialize()
151  {
152  // allocate memory and assign variables
153  num_regions = C->size();
154 
155  FCsum.resize(num_regions);
156  FCgrad.resize(num_regions, num_els);
158 
159  FCggsum.resize(num_regions);
160  FClapsum.resize(num_regions);
161 
162  FCsum_t.resize(num_regions);
163  FCgrad_t.resize(num_regions);
164  FClap_t.resize(num_regions);
165 
166  Jgrad.resize(num_els);
167  Jlap.resize(num_els);
168 
169  Jgrad_t.resize(num_els);
170  Jlap_t.resize(num_els);
171 
172  // check that F, C dimensions match
173  if (F.size() != num_regions * num_regions)
174  {
175  std::ostringstream err;
176  err << "CountingJastrow::initialize: F, C dimension mismatch: F: " << F.size() << ", C: " << num_regions
177  << std::endl;
178  APP_ABORT(err.str());
179  }
180 
181  // for CountingRegion optimization: don't allocate every evalDeriv call
182  int max_num_derivs = C->max_num_derivs();
183  dCsum.resize(max_num_derivs, num_regions);
184  dCggsum.resize(max_num_derivs, num_regions);
185  dClapsum.resize(max_num_derivs, num_regions);
186  dCFCggsum.resize(max_num_derivs);
187  // register optimizable parameters
188  std::ostringstream os;
189  std::string id_F;
190  for (int I = 0; I < num_regions; ++I)
191  for (int J = I, IJ = I * num_regions + I; J < num_regions; ++J, ++IJ)
192  {
193  os.str("");
194  os << "F_" << I << "_" << J;
195  id_F = os.str();
196  myVars.insert(id_F, F(IJ), (opt_F && I < (num_regions - 1)));
197  opt_index[OPT_F].push_back(IJ);
198  opt_id[OPT_F].push_back(id_F);
199  }
200  myVars.resetIndex();
201  }
202 
203 
204  void reportStatus(std::ostream& os) override
205  {
206  os << " Number of counting regions: " << num_regions << std::endl;
207  os << " Total optimizable parameters: " << C->total_num_derivs() + myVars.size_of_active() << std::endl;
208  os << " F matrix optimizable parameters: " << myVars.size_of_active() << std::endl;
209  if (debug)
210  {
211  os << " Debug sample sequence length: " << debug_seqlen << std::endl;
212  os << " Debug sample periodicity: " << debug_period << std::endl;
213  }
214  os << std::endl;
215  myVars.print(os, 6, true);
216  os << std::endl;
217  C->reportStatus(os);
218  }
219 
220 
223  ParticleSet::ParticleLaplacian& L) override
224  {
226  for (int i = 0; i < num_els; ++i)
227  {
228  G[i] += Jgrad[i];
229  L[i] += Jlap[i];
230  }
231  log_value_ = Jval;
232  return log_value_;
233  }
234 
235 
236  void recompute(const ParticleSet& P) override
237  {
239  log_value_ = Jval;
240  }
241 
243  {
244  // evaluate counting regions
245  C->evaluate(P);
246  std::fill(FCsum.begin(), FCsum.end(), 0);
247  std::fill(FCgrad.begin(), FCgrad.end(), 0);
248  std::fill(FClap.begin(), FClap.end(), 0);
249  Jval = 0;
250  std::fill(Jgrad.begin(), Jgrad.end(), 0);
251  std::fill(Jlap.begin(), Jlap.end(), 0);
252 
253  // evaluate FC products
254  for (int I = 0; I < num_regions; ++I)
255  {
256  for (int J = 0; J < num_regions; ++J)
257  {
258  FCsum[I] += F(I, J) * C->sum[J]; // MV
259  for (int i = 0; i < num_els; ++i)
260  {
261  FCgrad(I, i) += F(I, J) * C->grad(J, i); // 3*nels*MV
262  FClap(I, i) += F(I, J) * C->lap(J, i); // nels*MV
263  }
264  }
265  }
266  // evaluate components of J
267  for (int I = 0; I < num_regions; ++I)
268  {
269  Jval += FCsum[I] * C->sum[I]; // VV
270  for (int i = 0; i < num_els; ++i)
271  {
272  Jgrad[i] += 2 * FCsum[I] * C->grad(I, i); // 3*nels*VV
273  Jlap[i] += 2 * FCsum[I] * C->lap(I, i) + 2 * dot(FCgrad(I, i), C->grad(I, i)); // nels*VV
274  }
275  }
276  // print out results every so often
277  if (debug)
278  {
279  static int exp_print_index = 0;
280  if (exp_print_index < debug_seqlen)
282  ++exp_print_index;
283  exp_print_index = exp_print_index % debug_period;
284  }
285  }
286 
287 
288  void evaluateExponents_print(std::ostream& os, const ParticleSet& P)
289  {
290  // print counting regions
291  C->evaluate_print(app_log(), P);
292  // FCsum, FCgrad, FClap
293  os << "CountingJastrow::evaluateExponents_print: ";
294  os << std::endl << "FCsum: ";
295  std::copy(FCsum.begin(), FCsum.end(), std::ostream_iterator<RealType>(os, ", "));
296  os << std::endl << "FCgrad: ";
297  std::copy(FCgrad.begin(), FCgrad.end(), std::ostream_iterator<PosType>(os, ", "));
298  os << std::endl << "FClap: ";
299  std::copy(FClap.begin(), FClap.end(), std::ostream_iterator<RealType>(os, ", "));
300  // Jval, Jgrad, Jlap
301  os << std::endl << "Jval: " << Jval;
302  os << std::endl << "Jgrad: ";
303  std::copy(Jgrad.begin(), Jgrad.end(), std::ostream_iterator<PosType>(os, ", "));
304  os << std::endl << "Jlap: ";
305  std::copy(Jlap.begin(), Jlap.end(), std::ostream_iterator<RealType>(os, ", "));
306  os << std::endl << std::endl;
307  }
308 
309 
311  {
312  // evaluate temporary counting regions
313  C->evaluateTemp(P, iat);
314  Jval_t = 0;
315  std::fill(Jgrad_t.begin(), Jgrad_t.end(), 0);
316  std::fill(Jlap_t.begin(), Jlap_t.end(), 0);
317  std::fill(FCsum_t.begin(), FCsum_t.end(), 0);
318  std::fill(FCgrad_t.begin(), FCgrad_t.end(), 0);
319  std::fill(FClap_t.begin(), FClap_t.end(), 0);
320 
321  // evaluate temp FC arrays
322  for (int I = 0; I < num_regions; ++I)
323  {
324  for (int J = 0; J < num_regions; ++J)
325  {
326  FCsum_t[I] += F(I, J) * C->sum_t[J];
327  FCgrad_t[I] += F(I, J) * C->grad_t[J];
328  FClap_t[I] += F(I, J) * C->lap_t[J];
329  }
330  }
331  // evaluate components of the exponent
332  for (int I = 0; I < num_regions; ++I)
333  {
334  Jval_t += C->sum_t[I] * FCsum_t[I];
335  for (int i = 0; i < num_els; ++i)
336  {
337  if (i == iat)
338  {
339  Jgrad_t[i] += C->grad_t[I] * 2 * FCsum_t[I];
340  Jlap_t[i] += C->lap_t[I] * 2 * FCsum_t[I] + 2 * dot(C->grad_t[I], FCgrad_t[I]);
341  }
342  else
343  {
344  Jgrad_t[i] += C->grad(I, i) * 2 * FCsum_t[I];
345  Jlap_t[i] += C->lap(I, i) * 2 * FCsum_t[I] + 2 * dot(C->grad(I, i), FCgrad(I, i));
346  }
347  }
348  }
349  // print out results every so often
350  if (debug)
351  {
352  static int expt_print_index = 0;
353  if (expt_print_index < debug_seqlen)
355  ++expt_print_index;
356  expt_print_index = expt_print_index % debug_period;
357  }
358  }
359 
360  void evaluateTempExponents_print(std::ostream& os, ParticleSet& P, int iat)
361  {
362  // print counting regions
363  C->evaluateTemp_print(app_log(), P);
364  // FCsum, FCgrad, FClap
365  os << "CountingJastrow::evaluateTempExponents_print: iat: " << iat;
366  os << std::endl << "FCsum_t: ";
367  std::copy(FCsum_t.begin(), FCsum_t.end(), std::ostream_iterator<RealType>(os, ", "));
368  os << std::endl << "FCgrad_t: ";
369  std::copy(FCgrad_t.begin(), FCgrad_t.end(), std::ostream_iterator<PosType>(os, ", "));
370  os << std::endl << "FClap_t: ";
371  std::copy(FClap_t.begin(), FClap_t.end(), std::ostream_iterator<RealType>(os, ", "));
372  // Jval, Jgrad, Jlap
373  os << std::endl << "Jval_t: " << Jval_t;
374  os << std::endl << "Jgrad_t: ";
375  std::copy(Jgrad_t.begin(), Jgrad_t.end(), std::ostream_iterator<PosType>(os, ", "));
376  os << std::endl << "Jlap_t: ";
377  std::copy(Jlap_t.begin(), Jlap_t.end(), std::ostream_iterator<RealType>(os, ", "));
378  os << std::endl << std::endl;
379  }
380 
381  GradType evalGrad(ParticleSet& P, int iat) override
382  {
384  log_value_ = Jval;
385  return Jgrad[iat];
386  }
387 
388  PsiValue ratioGrad(ParticleSet& P, int iat, GradType& grad_iat) override
389  {
390  evaluateTempExponents(P, iat);
391  grad_iat += Jgrad_t[iat];
392  return std::exp(static_cast<PsiValue>(Jval_t - Jval));
393  }
394 
395  void acceptMove(ParticleSet& P, int iat, bool safe_to_delay = false) override
396  {
397  C->acceptMove(P, iat);
398  // update values for C, FC to those at proposed position
399  // copy over temporary values
400  for (int I = 0; I < num_regions; ++I)
401  {
402  FCsum[I] = FCsum_t[I];
403  FCgrad(I, iat) = FCgrad_t[I];
404  FClap(I, iat) = FClap_t[I];
405  }
406  // update exponent values to that at proposed position
407  Jval = Jval_t;
408  log_value_ = Jval;
409  for (int i = 0; i < num_els; ++i)
410  {
411  Jgrad[i] = Jgrad_t[i];
412  Jlap[i] = Jlap_t[i];
413  }
414  }
415 
416  void restore(int iat) override { C->restore(iat); }
417 
418  PsiValue ratio(ParticleSet& P, int iat) override
419  {
420  evaluateTempExponents(P, iat);
421  return std::exp(static_cast<PsiValue>(Jval_t - Jval));
422  }
423 
424  void registerData(ParticleSet& P, WFBufferType& buf) override
425  {
426  LogValue logValue = evaluateLog(P, P.G, P.L);
427  RealType* Jlap_begin = &Jlap[0];
428  RealType* Jlap_end = Jlap_begin + Jlap.size();
429  RealType* Jgrad_begin = &Jgrad[0][0];
430  RealType* Jgrad_end = Jgrad_begin + Jgrad.size() * DIM;
431  DEBUG_PSIBUFFER(" CountingJastrow::registerData", buf.current());
432  buf.add(&Jval, &Jval);
433  buf.add(Jlap_begin, Jlap_end);
434  buf.add(Jgrad_begin, Jgrad_end);
435  DEBUG_PSIBUFFER(" CountingJastrow::registerData", buf.current());
436  }
437 
438  LogValue updateBuffer(ParticleSet& P, WFBufferType& buf, bool fromscratch = false) override
439  {
440  LogValue logValue = evaluateLog(P, P.G, P.L);
441  RealType* Jlap_begin = &Jlap[0];
442  RealType* Jlap_end = Jlap_begin + Jlap.size();
443  RealType* Jgrad_begin = &Jgrad[0][0];
444  RealType* Jgrad_end = Jgrad_begin + Jgrad.size() * DIM;
445  DEBUG_PSIBUFFER(" CountingJastrow::updateBuffer ", buf.current());
446  buf.put(&Jval, &Jval);
447  buf.put(Jlap_begin, Jlap_end);
448  buf.put(Jgrad_begin, Jgrad_end);
449  DEBUG_PSIBUFFER(" CountingJastrow::updateBuffer ", buf.current());
450  return Jval;
451  }
452 
453  void copyFromBuffer(ParticleSet& P, WFBufferType& buf) override
454  {
455  RealType* Jlap_begin = &Jlap[0];
456  RealType* Jlap_end = Jlap_begin + Jlap.size();
457  RealType* Jgrad_begin = &Jgrad[0][0];
458  RealType* Jgrad_end = Jgrad_begin + Jgrad.size() * 3;
459  DEBUG_PSIBUFFER(" CountingJastrow::copyFromBuffer ", buf.current());
460  buf.get(&Jval, &Jval);
461  buf.get(Jlap_begin, Jlap_end);
462  buf.get(Jgrad_begin, Jgrad_end);
463  DEBUG_PSIBUFFER(" CountingJastrow::copyFromBuffer ", buf.current());
464  return;
465  }
466 
467  std::unique_ptr<WaveFunctionComponent> makeClone(ParticleSet& tqp) const override
468  {
469  auto cjc = std::make_unique<CountingJastrow>(tqp, C->makeClone(), F, opt_C, opt_F);
470  cjc->addDebug(debug, debug_seqlen, debug_period);
471  cjc->initialize();
472  return cjc;
473  }
474 
476  const opt_variables_type& active,
477  Vector<ValueType>& dlogpsi,
478  Vector<ValueType>& dhpsioverpsi) override
479  {
480 #ifdef QMC_COMPLEX
481  APP_ABORT("CountingJastrow::evaluateDerivatives is not available on complex builds.");
482 #else
484  // evaluate derivatives of F
485  static int deriv_print_index = 0;
486  if (opt_F)
487  {
488  for (int oi = 0; oi < opt_index[OPT_F].size(); ++oi)
489  {
490  std::string id = opt_id[OPT_F][oi];
491  int ia = myVars.getIndex(id);
492  if (ia == -1)
493  continue; // ignore inactive parameters
494  int IJ = opt_index[OPT_F][oi];
495  int I = IJ / num_regions;
496  int J = IJ % num_regions;
497  // coefficient due to symmetry of F: \sum\limits_{I} F_{II} C_I^2 + \sum\limits_{J > I} 2 F_{IJ}*C_I*C_J
498  RealType x = (I == J) ? 1 : 2;
499  RealType dJF_val = C->sum[I] * C->sum[J] * x;
500  RealType dJF_gg = 0, dJF_lap = 0;
501  for (int i = 0; i < num_els; ++i)
502  {
503  PosType grad_i(P.G[i]);
504  dJF_gg += x * (dot(C->grad(I, i), grad_i) * C->sum[J] + C->sum[I] * dot(C->grad(J, i), grad_i));
505  dJF_lap += x * (C->lap(I, i) * C->sum[J] + 2 * dot(C->grad(I, i), C->grad(J, i)) + C->lap(J, i) * C->sum[I]);
506  }
507  dlogpsi[ia] += dJF_val;
508  dhpsioverpsi[ia] += -0.5 * dJF_lap - dJF_gg;
509  if (debug && deriv_print_index < debug_seqlen)
510  {
511  app_log() << " dJ/dF[" << I << "][" << J << "]; ia: " << ia << ", dlogpsi: " << dlogpsi[ia]
512  << ", dhpsioverpsi: " << dhpsioverpsi[ia] << std::endl;
513  }
514  }
515  }
516 
517  // // evaluate partial derivatives of C
518  if (opt_C)
519  {
520  // containers for CountingRegions' evaluateDerivatives calculations
521  // blocks of dimension n_p x n_C
522  // ex: dNsum = \sum\limits_k [ [dC1 / dp1] [dC2 / dp1] .. ]
523  // Where each [dCi / dpj] block is n_p x 1 vector of derivatives of parameters
524  // for counting region j as summed over electron coordinate k
525 
526  // exception: dNFN ggsum is an n_p x 1 vector since it is an evaluation of a quadratic form:
527  // \sum\limits_{kI} [\nabla_k dC_I/dpj] dot [ (F \nabla_k C)_I ]
528  // since we have the premultiplied (F\nabla_k C) vector on hand.
529  // make a lambda function FCgrad(I,i) which gives the appropriate element of FCgrad[iI]
530 
531  // clear some vectors
532  std::fill(FCggsum.begin(), FCggsum.end(), 0);
533  std::fill(FClapsum.begin(), FClapsum.end(), 0);
534 
535  // evaluate FCggsum
536  for (int I = 0; I < num_regions; ++I)
537  {
538  for (int i = 0; i < num_els; ++i)
539  {
540  PosType grad_i(P.G[i]);
541  FCggsum[I] += dot(FCgrad(I, i), grad_i);
542  FClapsum[I] += FClap(I, i);
543  }
544  }
545  // pointer to C->C[I]->myVars.Index
546  // for pI in { 0 .. C->num_derivs(I) }
547  // dCindex->[pI] is the index that corresponds to this parameter in active.
548  // i.e., active[dCindex->[pI]] <=> C->C[I]->myVars.Index[pI]
549 
550  // external print block
551  if (debug && deriv_print_index < debug_seqlen)
552  {
553  app_log() << std::endl << "=== evaluateDerivatives ===" << std::endl;
554  app_log() << "== print current exponent values ==" << std::endl;
556  app_log() << "== additional counting function terms ==" << std::endl;
557  app_log() << "P.G: ";
558  std::copy(P.G.begin(), P.G.end(), std::ostream_iterator<PosType>(app_log(), ", "));
559  app_log() << std::endl << "FCgrad: ";
560  std::copy(FCgrad.begin(), FCgrad.end(), std::ostream_iterator<PosType>(app_log(), ", "));
561  app_log() << std::endl << "FClap: ";
562  std::copy(FClap.begin(), FClap.end(), std::ostream_iterator<RealType>(app_log(), ", "));
563  app_log() << std::endl << "FCggsum: ";
564  std::copy(FCggsum.begin(), FCggsum.end(), std::ostream_iterator<RealType>(app_log(), ", "));
565  app_log() << std::endl << "FClapsum: ";
566  std::copy(FClapsum.begin(), FClapsum.end(), std::ostream_iterator<RealType>(app_log(), ", "));
567  app_log() << std::endl;
568  }
569 
570  for (int I = 0; I < num_regions; ++I)
571  {
572  // get the number of active parameters for the Ith counting region
573  opt_variables_type I_vars = C->getVars(I);
574  int I_num_derivs = I_vars.size();
575  // clear arrays before each evaluate
576  std::fill(dCsum.begin(), dCsum.end(), 0);
577  std::fill(dCggsum.begin(), dCggsum.end(), 0);
578  std::fill(dClapsum.begin(), dClapsum.end(), 0);
579  std::fill(dCFCggsum.begin(), dCFCggsum.end(), 0);
580  // evaluate all derivatives for the Ith counting function
581  C->evaluateDerivatives(P, I, FCgrad, dCsum, dCggsum, dClapsum, dCFCggsum);
582  if (debug && deriv_print_index < debug_seqlen)
583  {
584  // print out current index information
585  app_log() << std::endl;
586  app_log() << " == evaluateDerivatives for counting region " << I << ", num_derivs: " << I_num_derivs
587  << " ==" << std::endl;
588  app_log() << " Indices: ";
589  std::copy(I_vars.Index.begin(), I_vars.Index.end(), std::ostream_iterator<int>(app_log(), ", "));
590  app_log() << std::endl << " Names: ";
591  for (auto it = I_vars.NameAndValue.begin(); it != I_vars.NameAndValue.end(); ++it)
592  app_log() << (*it).first << ", ";
593  app_log() << std::endl << " Values: ";
594  for (auto it = I_vars.NameAndValue.begin(); it != I_vars.NameAndValue.end(); ++it)
595  app_log() << (*it).second << ", ";
596  // print out values from evaluate derivatives
597  app_log() << std::endl << " dCsum: ";
598  std::copy(dCsum.begin(), dCsum.end(), std::ostream_iterator<RealType>(app_log(), ", "));
599  app_log() << std::endl << " dCggsum: ";
600  std::copy(dCggsum.begin(), dCggsum.end(), std::ostream_iterator<RealType>(app_log(), ", "));
601  app_log() << std::endl << " dClapsum: ";
602  std::copy(dClapsum.begin(), dClapsum.end(), std::ostream_iterator<RealType>(app_log(), ", "));
603  app_log() << std::endl << " dCFCggsum: ";
604  std::copy(dCFCggsum.begin(), dCFCggsum.end(), std::ostream_iterator<RealType>(app_log(), ", "));
605  app_log() << std::endl;
606  }
607  // loop over parameters for the Ith counting function
608  for (int pI = 0; pI < I_num_derivs; ++pI)
609  {
610  // index for active optimizable variables
611  int ia = I_vars.Index[pI];
612  if (ia == -1)
613  continue; // ignore inactive
614  // middle laplacian term:
615  dhpsioverpsi[ia] += -0.5 * (4.0 * dCFCggsum[pI]);
616  if (debug && deriv_print_index < debug_seqlen)
617  {
618  app_log() << " == evaluateDerivatives calculations ==" << std::endl;
619  app_log() << " pI: " << pI << ", name: " << I_vars.name(pI) << ", ia: " << ia << std::endl;
620  app_log() << " dCFCggsum: " << dCFCggsum[pI] << std::endl;
621  }
622  for (int J = 0; J < num_regions; ++J)
623  {
624  dlogpsi[ia] += dCsum(J, pI) * (2 * FCsum[J]);
625  // grad dot grad terms
626  dhpsioverpsi[ia] += -1.0 * (dCggsum(J, pI) * (2.0 * FCsum[J]) + dCsum(J, pI) * 2.0 * FCggsum[J]);
627  // outer laplacian terms
628  dhpsioverpsi[ia] += -0.5 * (2.0 * dCsum(J, pI) * FClapsum[J] + dClapsum(J, pI) * (2.0 * FCsum[J]));
629  if (debug && deriv_print_index < debug_seqlen)
630  {
631  app_log() << " J: " << J << std::endl;
632  app_log() << " dlogpsi term : " << dCsum(J, pI) * (2 * FCsum[J]) << std::endl;
633  app_log() << " dhpsi/psi, graddotgrad: "
634  << -1.0 * (dCggsum(J, pI) * (2.0 * FCsum[J]) + dCsum(J, pI) * 2.0 * FCggsum[J]) << std::endl;
635  app_log() << " dhpsi/psi, laplacian : "
636  << -0.5 * (2.0 * dCsum(J, pI) * FClapsum[J] + dClapsum(J, pI) * (2.0 * FCsum[J])) << std::endl;
637  }
638  }
639  }
640  }
641 
642  } // end opt_C
643  // increment and modulo deriv_print_index
644  if (debug)
645  {
646  app_log() << "Final derivatives: " << std::endl;
647  app_log() << " F derivatives: " << std::endl;
648  for (int oi = 0; oi < opt_index[OPT_F].size(); ++oi)
649  {
650  std::string id = opt_id[OPT_F][oi];
651  int ia = myVars.getIndex(id);
652  if (ia == -1)
653  continue; // ignore inactive parameters
654  app_log() << " ia: " << ia << ", dlogpsi: " << dlogpsi[ia] << ", dhpsioverpsi: " << dhpsioverpsi[ia]
655  << std::endl;
656  }
657  app_log() << " C derivatives: " << std::endl;
658  for (int I = 0; I < num_regions; ++I)
659  {
660  app_log() << " C[" << I << "] derivs: " << std::endl;
661  // get the number of active parameters for the Ith counting region
662  opt_variables_type I_vars = C->getVars(I);
663  int I_num_derivs = I_vars.size();
664  for (int pI = 0; pI < I_num_derivs; ++pI)
665  {
666  // index for active optimizable variables
667  int ia = I_vars.Index[pI];
668  if (ia == -1)
669  continue; // ignore inactive
670  app_log() << " ia: " << ia << ", dlogpsi: " << dlogpsi[ia] << ", dhpsioverpsi: " << dhpsioverpsi[ia]
671  << std::endl;
672  }
673  }
674  deriv_print_index = deriv_print_index % debug_period;
675  deriv_print_index++;
676  }
677 #endif
678  }
679 
680  void addDebug(bool debug_flag, int seqlen, int period)
681  {
682  debug = debug_flag;
683  debug_seqlen = seqlen;
684  debug_period = period;
685  }
686 };
687 
688 } // namespace qmcplusplus
689 
690 #endif
Container_t::iterator begin()
Definition: OhmmsMatrix.h:89
Fixed-size array.
Definition: OhmmsTinyMeta.h:30
PsiValue ratioGrad(ParticleSet &P, int iat, GradType &grad_iat) override
evaluate the ratio of the new to old WaveFunctionComponent value and the new gradient ...
QMCTraits::RealType real
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
std::unique_ptr< RegionType > C
void resetParametersExclusive(const opt_variables_type &active) override
reset the parameters during optimizations.
std::vector< RealType > Jlap_t
void checkInVariablesExclusive(opt_variables_type &active) final
check in variational parameters to the global list of parameters used by the optimizer.
PsiValue ratio(ParticleSet &P, int iat) override
evaluate the ratio of the new to old WaveFunctionComponent value
size_t getTotalNum() const
Definition: ParticleSet.h:493
std::ostream & app_log()
Definition: OutputManager.h:65
GradType evalGrad(ParticleSet &P, int iat) override
return the current gradient for the iat-th particle
void addDebug(bool debug_flag, int seqlen, int period)
std::vector< int > Index
store locator of the named variable
Definition: VariableSet.h:65
int getLoc(const std::string &vname) const
Definition: VariableSet.h:121
void resize(size_type n, size_type m)
Resize the container.
Definition: OhmmsMatrix.h:99
void resetIndex()
reset Index
Attaches a unit to a Vector for IO.
ParticleLaplacian L
laplacians of the particles
Definition: ParticleSet.h:85
void evaluateExponents_print(std::ostream &os, const ParticleSet &P)
void evaluateTempExponents(ParticleSet &P, int iat)
std::string getClassName() const override
return class name
std::unique_ptr< WaveFunctionComponent > makeClone(ParticleSet &tqp) const override
make clone
opt_variables_type myVars
list of variables this WaveFunctionComponent handles
std::complex< QTFull::RealType > LogValue
void copy(const Array< T1, 3 > &src, Array< T2, 3 > &dest)
Definition: Blitz.h:639
std::vector< RealType > dCsum_t
An abstract class for a component of a many-body trial wave function.
Matrix< RealType > dCggsum
void evaluateExponents(const ParticleSet &P)
Specialized paritlce class for atomistic simulations.
Definition: ParticleSet.h:55
size_type size() const
Definition: OhmmsMatrix.h:76
void insert(const std::string &vname, real_type v, bool enable=true, int type=OTHER_P)
Definition: VariableSet.h:133
void acceptMove(ParticleSet &P, int iat, bool safe_to_delay=false) override
a move for iat-th particle is accepted.
void restore(int iat) override
If a move for iat-th particle is rejected, restore to the content.
std::array< std::vector< std::string >, NUM_OPT_VAR > opt_id
ParticleGradient G
gradients of the particles
Definition: ParticleSet.h:83
std::vector< RealType > FCggsum
class to handle a set of variables that can be modified during optimizations
Definition: VariableSet.h:49
int where(int i) const
return the locator of the i-th Index
Definition: VariableSet.h:90
std::vector< RealType > dCFCggsum
std::vector< RealType > FClap_t
#define APP_ABORT(msg)
Widely used but deprecated fatal error macros from legacy code.
Definition: AppAbort.h:27
void recompute(const ParticleSet &P) override
recompute the value of the WaveFunctionComponents which require critical accuracy.
LogValue updateBuffer(ParticleSet &P, WFBufferType &buf, bool fromscratch=false) override
For particle-by-particle move.
int size_of_active() const
return the number of active variables
Definition: VariableSet.h:78
MakeReturn< UnaryNode< FnExp, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t exp(const Vector< T1, C1 > &l)
#define DEBUG_PSIBUFFER(who, msg)
Definition: Configuration.h:40
std::array< std::vector< int >, NUM_OPT_VAR > opt_index
std::vector< PosType > Jgrad_t
size_type size() const
return the size
Definition: VariableSet.h:88
std::vector< RealType > FClapsum
std::complex< double > I
size_type current() const
Definition: PooledMemory.h:76
LogValue evaluateLog(const ParticleSet &P, ParticleSet::ParticleGradient &G, ParticleSet::ParticleLaplacian &L) override
evaluate the value of the WaveFunctionComponent from scratch
std::vector< RealType > FCsum_t
Matrix< RealType > dClapsum
std::vector< int > dCindex
std::vector< pair_type > NameAndValue
Definition: VariableSet.h:66
std::vector< RealType > FCsum
const std::string & name(int i) const
return the name of i-th variable
Definition: VariableSet.h:189
Tensor< typename BinaryReturn< T1, T2, OpMultiply >::Type_t, D > dot(const AntiSymTensor< T1, D > &lhs, const AntiSymTensor< T2, D > &rhs)
CountingJastrow(ParticleSet &P, std::unique_ptr< RegionType > c, const Matrix< RealType > &f, bool opt_C_flag, bool opt_F_flag)
Declaration of WaveFunctionComponent.
void registerData(ParticleSet &P, WFBufferType &buf) override
For particle-by-particle move.
void extractOptimizableObjectRefs(UniqueOptObjRefs &opt_obj_refs) override
extract underlying OptimizableObject references
std::vector< RealType > Jlap
void copyFromBuffer(ParticleSet &P, WFBufferType &buf) override
For particle-by-particle move.
Container_t::iterator end()
Definition: OhmmsMatrix.h:90
bool isOptimizable() const override
if true, this contains optimizable components
void print(std::ostream &os, int leftPadSpaces=0, bool printHeader=false) const
int getIndex(const std::string &vname) const
return the Index vaule for the named parameter
void evaluateDerivatives(ParticleSet &P, const opt_variables_type &active, Vector< ValueType > &dlogpsi, Vector< ValueType > &dhpsioverpsi) override
void push_back(OptimizableObject &obj)
void reportStatus(std::ostream &os) override
print the state, e.g., optimizables
void put(std::complex< T1 > &x)
Definition: PooledMemory.h:165
std::vector< PosType > FCgrad_t
std::vector< PosType > Jgrad
void checkOutVariables(const opt_variables_type &active) override
check out variational optimizable variables
void evaluateTempExponents_print(std::ostream &os, ParticleSet &P, int iat)
void add(std::complex< T1 > &x)
Definition: PooledMemory.h:113
void get(std::complex< T1 > &x)
Definition: PooledMemory.h:132