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: Ken Esler, kpesler@gmail.com, University of Illinois at Urbana-Champaign
8 //                    Miguel Morales, moralessilva2@llnl.gov, Lawrence Livermore National Laboratory
9 //                    Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
10 //                    Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
11 //                    Mark Dewing, markdewing@gmail.com, University of Illinois at Urbana-Champaign
12 //                    Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
13 //
14 // File created by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
15 //////////////////////////////////////////////////////////////////////////////////////
16 
17 
18 #ifndef QMCPLUSPLUS_WAVEFUNCTIONTEST_H
19 #define QMCPLUSPLUS_WAVEFUNCTIONTEST_H
20 
21 #include "QMCDrivers/QMCDriver.h"
22 #include "Particle/ParticleSetPool.h"
23 namespace qmcplusplus
24 {
25 /** Information for output of relative error in wavefunction derivatives
26   vs. finite difference delta.
27 */
28 class FiniteDiffErrData : public QMCTraits
29 {
30 public:
31   FiniteDiffErrData();
32   bool put(xmlNodePtr q);
33 
34   int particleIndex;
35   int gradientComponentIndex;
36   std::string outputFile;
37 };
38 
39 /** Test the correctness of TrialWaveFunction for the values,
40     gradients and laplacians
41 */
42 class WaveFunctionTester : public QMCDriver
43 {
44 public:
45   /// type definition
46   using LogValueType = WaveFunctionComponent::LogValueType;
47 
48   /// Constructor.
49   WaveFunctionTester(MCWalkerConfiguration& w,
50                      TrialWaveFunction& psi,
51                      QMCHamiltonian& h,
52                      ParticleSetPool& ptclPool,
53                      Communicate* comm);
54 
55   ~WaveFunctionTester();
56 
57   bool run();
58   bool put(xmlNodePtr q);
59 
60 private:
61   ParticleSetPool& PtclPool;
62   ParticleSet::ParticlePos_t deltaR;
63   std::string checkRatio, checkClone, checkHamPbyP, sourceName, wftricks, checkEloc;
64   std::string checkBasic, checkRatioV;
65   xmlNodePtr myNode;
66   double deltaParam;
67   double toleranceParam;
68   bool outputDeltaVsError;
69   bool checkSlaterDet; // flag to perform determinant-resolved test of SlaterDet
70   std::string checkSlaterDetOption;
71   FiniteDiffErrData DeltaVsError;
72 
73   /// Copy Constructor (disabled)
74   WaveFunctionTester(const WaveFunctionTester&) = delete;
75   /// Copy Operator (disabled)
76   WaveFunctionTester& operator=(const WaveFunctionTester&) = delete;
77 
78   /** basic tests for G and L */
79   void runBasicTest();
80   /** the basic ratios check */
81   void runRatioTest();
82   void runRatioTest2();
83   /** test ratios with virtual moves */
84   void runRatioV();
85   /** test clone implementations of new wavefunctions and operators */
86   void runCloneTest();
87   void runDerivTest();
88   void runDerivNLPPTest();
89   void runDerivCloneTest();
90   void runGradSourceTest();
91   void runZeroVarianceTest();
92   void runwftricks();
93   void runNodePlot();
94   void printEloc();
95 
96   // compute numerical gradient and laplacian
97   void computeNumericalGrad(RealType delta,
98                             ParticleSet::ParticleGradient_t& G_fd,
99                             ParticleSet::ParticleLaplacian_t& L_fd);
100 
101   bool checkGradients(int lower_iat,
102                       int upper_iat,
103                       ParticleSet::ParticleGradient_t& G,
104                       ParticleSet::ParticleLaplacian_t& L,
105                       ParticleSet::ParticleGradient_t& G_fd,
106                       ParticleSet::ParticleLaplacian_t& L_fd,
107                       std::stringstream& log,
108                       int indent = 0);
109 
110   bool checkGradientAtConfiguration(MCWalkerConfiguration::Walker_t* W1, std::stringstream& fail_log, bool& ignore);
111 
getRunType()112   QMCRunType getRunType() { return QMCRunType::WF_TEST; }
113   //vector<RealType> Mv3(std::vector<std::vector<RealType> >& M, std::vector<RealType>& v);
114 
115   std::ofstream fout;
116 };
117 } // namespace qmcplusplus
118 #endif
119