QMCPACK
NaNguard.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) 2023 QMCPACK developers.
6 //
7 // File developed by: Ye Luo, yeluo@anl.gov, Argonne National Laboratory
8 //
9 // File created by: Ye Luo, yeluo@anl.gov, Argonne National Laboratory
10 //////////////////////////////////////////////////////////////////////////////////////
11 
12 #include <NaNguard.h>
13 #include "CPU/math.hpp"
14 
15 namespace qmcplusplus
16 {
17 
18 void NaNguard::checkOneParticleRatio(const PsiValue& ratio, const std::string_view info)
19 {
20  if (qmcplusplus::isnan(std::norm(ratio)))
21  {
22  std::ostringstream error_message;
23  error_message << "NaNguard::checkOneParticleRatio error message: " << info << std::endl
24  << " ratio = " << ratio << std::endl;
25  throw std::runtime_error(error_message.str());
26  }
27 }
28 
29 void NaNguard::checkOneParticleGradients(const GradType& grads, const std::string_view info)
30 {
31  if (qmcplusplus::isnan(std::norm(dot(grads, grads))))
32  {
33  std::ostringstream error_message;
34  error_message << "NaNguard::checkOneParticleGradients error message: " << info << std::endl;
35  for (int i = 0; i < grads.size(); ++i)
36  if (qmcplusplus::isnan(std::norm(grads[i])))
37  error_message << " grads[" << i << "] = " << grads[i] << std::endl;
38  throw std::runtime_error(error_message.str());
39  }
40 }
41 
42 } // namespace qmcplusplus
QMCTraits::QTFull::ValueType PsiValue
Definition: NaNguard.h:23
Fixed-size array.
Definition: OhmmsTinyMeta.h:30
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
double norm(const zVec &c)
Definition: VectorOps.h:118
static void checkOneParticleRatio(const PsiValue &ratio, const std::string_view info)
check if ratio is NaN and throw an error if yes.
Definition: NaNguard.cpp:18
static void checkOneParticleGradients(const GradType &grads, const std::string_view info)
check if any gradient component (x,y,z) is NaN and throw an error if yes.
Definition: NaNguard.cpp:29
Tensor< typename BinaryReturn< T1, T2, OpMultiply >::Type_t, D > dot(const AntiSymTensor< T1, D > &lhs, const AntiSymTensor< T2, D > &rhs)
bool isnan(float a)
return true if the value is NaN.
Definition: math.cpp:18