MADNESS  0.10.1
QCCalculationParametersBase.h
Go to the documentation of this file.
1 /*
2  * QCCalculationParametersBase.h
3  *
4  * Created on: 27 Jun 2019
5  * Author: fbischoff
6  */
7 
8 #ifndef SRC_APPS_CHEM_QCCALCULATIONPARAMETERSBASE_H_
9 #define SRC_APPS_CHEM_QCCALCULATIONPARAMETERSBASE_H_
10 
11 #include <string>
12 #include <algorithm>
13 #include <iomanip>
14 #include <typeindex>
15 #include <map>
16 #include <fstream>
17 #include <typeinfo>
18 #include "madness/misc/misc.h"
19 #include "madness/world/archive.h"
20 #include "madness/world/world.h"
22 #include "madness/external/nlohmann_json/json.hpp"
23 
24 
25 namespace madness {
26 
28 
29 template<typename T>
30 static typename std::enable_if<std::is_floating_point<T>::value, void>::type
31 check_for_inf(const std::string& str, T& arg) {
32  std::string sinf;
33  std::stringstream ss;
34  ss << std::numeric_limits<T>::infinity();
35  sinf=ss.str();
36 
37  if (sinf==str) arg=std::numeric_limits<T>::infinity();
38 }
39 
40 template<typename T>
41 static typename std::enable_if<!std::is_floating_point<T>::value, void>::type
42 check_for_inf(const std::string& str, T& arg) {
43  return;
44 }
45 
46 /// inverting the print method from print.h for std::vector
47 /// TODO: move this where it belongs (into print.h ??)
48 template <typename T, typename A=std::allocator<T> >
49 std::istream& operator>>(std::istream& is, std::vector<T,A>& v) {
50 
51  // get the full line from opening to closing brackets [ .. ]
52  std::string word, line="";
53  while (is >> word) {
54  line+=word;
55  if (word.find(']')!=std::string::npos) break;
56  }
57  if (line.size()!=0) is.clear();
58 
59  // remove enclosing brackets and commas
60  auto find_c = [](char& c){ return ((c==',') or (c=='[') or (c==']')); };
61  std::replace_if (line.begin(), line.end(), find_c, ' '); // 0 2 0 4 0 6 0 8 0
62 
63  // stream the values into the container
64  std::stringstream sline(line);
65  T tmp;
66  while (sline >> word) {
67  std::stringstream sword(word);
68  sword >> tmp;
69  check_for_inf(word,tmp);
70  v.push_back(tmp);
71  }
72  if (sline.bad()) {
73  madness::print("error while reading vector from istream: ");
74  madness::print(line,"\n");
75  throw std::runtime_error("IO error");
76  }
77 
78  return is;
79 }
80 
81 
82 
83 
84 /// inverting the print method from print.h for std::vector
85 /// TODO: move this where it belongs (into print.h ??)
86 template <typename Q, typename T>
87 std::istream& operator>>(std::istream& is, std::pair<T,Q>& p) {
88 
89  // get all words from the line
90  std::string word, line="";
91  while (is >> word) {
92  line+=word + " ";
93  };
94  // have to set this here to account for the error handling later..
95  is.clear();
96 
97  // remove enclosing brackets and commas
98  auto find_c = [](char& c){ return ((c==',') or (c=='(') or (c==')')); };
99  std::replace_if (line.begin(), line.end(), find_c, ' '); // 0 2 0 4 0 6 0 8 0
100 
101  // stream the values into the container
102  std::stringstream sline(line);
103  T tmp1;
104  Q tmp2;
105  sline >> tmp1 >> tmp2;
106  if (sline.bad() or sline.fail()) {
107  madness::print("error while reading vector from istream: ");
108  madness::print(line,"\n");
109  throw std::runtime_error("IO error");
110  }
111  p=std::pair<T,Q>(tmp1,tmp2);
112 
113  return is;
114 }
115 
116 
117 /// structure holding the value for a given parameter
118 
119 /// keeps logic about default, derived and user-defined settings (with increasing priority),
120 /// as well as comments for the user (e.g. a recommended range for a given parameter).
121 ///
122 /// might be extended to hold allowed values for certain parameters, e.g. localization procedures.
123 ///
124 /// all values are stored as strings and must be converted to their respective types by the
125 /// QCCalculationParametersBase class (see below)
126 struct QCParameter {
127 public:
129 
130  QCParameter(const std::string v, const std::string t, const std::string comment="",
131  const std::vector<std::string> allowed_values1={})
132  : default_value(v), type(t), comment(comment), allowed_values(allowed_values1) {
133  static int i=0;
134  print_order=i++;
135  set_all();
136  }
137 
138  void set_derived_value(const std::string val) {
140  derived_value=val;
141  set_all();
142  }
143  void set_user_defined_value(const std::string val) {
145  user_defined_value=val;
146  set_all();
147  }
148 
149  bool is_user_defined() const {
150  return (precedence==defined);
151  }
152 
153  std::string get_value() const {return value;}
154  std::string get_type() const {return type;}
155  std::string get_comment() const {return comment;}
156  std::string print_precedence() const {
157  if (precedence==def) return "default";
158  if (precedence==derived) return "derived";
159  if (precedence==defined) return "defined";
160  std::stringstream sprecedence;
161  sprecedence << precedence;
162  throw std::runtime_error("unknown precedence in QCParameter"+sprecedence.str());
163  return "darn";
164  }
165 
166  int get_print_order() const {return print_order;}
167 
168  std::string print_line(const std::string& key) const {
169 
170  auto fill_left = [](const int size, const std::string word) {
171  int nspaces=std::max(int(0),size-int(word.length()));
172  return std::string(nspaces, ' ')+word;
173  };
174  auto fill_right = [](const int size, const std::string word) {
175  int nspaces=std::max(int(0),size-int(word.length()));
176  return word+std::string(nspaces, ' ');
177  };
178 
179  // key-value block
180  std::string keyval=fill_left(20,key)+" "+fill_right(10,get_value()) + " # " +fill_right(10,print_precedence());
181  std::string empty_keyval(keyval.size(),' ');
182  empty_keyval[33]='#';
183 
184  std::string allowed_val;
185  if (allowed_values.size()>0) {
186  using madness::operators::operator<<;
187  std::stringstream ss;
188  ss << allowed_values;
189  allowed_val+=ss.str();
190  }
191 
192  // split comment into several lines: split onto words and add linebreak
193  bool leave_space_for_allowed_values=(allowed_val.size()>0);
194 
195  // first line breaks after 80 characters, all other lines after 120 (leave space f
196  long keyvalsize=keyval.size(); // length of key, value, precedence
197  std::string comment1=get_comment();
198  auto commentwords=commandlineparser::split(comment1," ");
199  std::vector<std::string> commentlines(1);
200  long nchar=0;
201  for (auto word : commentwords) {
202 
203  bool is_first_line=commentlines.size()==1;
204  long thislinebreak=120;
205  if (is_first_line and leave_space_for_allowed_values) thislinebreak=80;
206  long commentsize=thislinebreak-keyvalsize;
207 
208  nchar+=word.size()+1;
209  if (nchar>commentsize) { // start newline
210  commentlines.push_back("");
211  nchar=word.size()+1;
212  }
213  commentlines.back()+=word+" ";
214  }
215 
216  std::string result;
217  for (size_t i=0; i<commentlines.size(); ++i) {
218  if (i==0) result=keyval+fill_right(40,commentlines[i])+allowed_val;
219  else result+="\n"+empty_keyval+commentlines[i];
220  }
221 
222  // trim result
223  std::size_t last = result.find_last_not_of(' ');
224  return result.substr(0, last+1);
225  }
226 
227  template <typename Archive> void serialize (Archive& ar) {
230  }
231 
233 
234  hashT hash() const {
235  return hash_value(value);
236  }
237 
238 private:
239 
240  void set_all() {
242  if (derived_value!=null) value=derived_value;
244  if (not check_allowed()) throw std::invalid_argument(not_allowed_errmsg());
245  }
246 
247  bool check_allowed() {
248  if (allowed_values.size()==0) return true;
249  auto it = std::find(allowed_values.begin(), allowed_values.end(), value);
250  return (it!=allowed_values.end());
251  }
252 
253  std::string not_allowed_errmsg() const {
254  using madness::operators::operator<<;
255  std::stringstream ss;
256  ss<< allowed_values;
257  std::string errmsg="\ntrying to assign a value that's not allowed\n\n";
258  errmsg+="\tuser-defined value: " + value + "\n";
259  errmsg+="\tallowed values: " + ss.str() + "\n\n";
260  return errmsg;
261  }
262 
263 
264  std::string value;
265  std::string default_value="";
266  std::string derived_value="";
267  std::string user_defined_value="";
268  std::string type="";
269  std::string null="";
270  std::string comment="";
271  std::vector<std::string> allowed_values=std::vector<std::string>();
272  int print_order=0; // use this for printing the parameters in the same order as they are defined
273 
274 };
275 
276 /// class for holding the parameters for calculation
277 
278 /// Actual parameter classes will be derived from this class with a simple constructor
279 /// (see test_QCCalculationParametersBase.cc for an example) and convenience
280 /// getters for the parameters of each parameter class.
281 /// Having the base class will allow consistent parameter input/output handling
282 /// for all madness programs and reuse of the parsing methods.
283 /// Even if the same parameter is used in different programs, default might differ
284 /// (i.e. econv for 3D/6D calculations). The parameter class will effectively serve as
285 /// a factory for the calculation classes (SCF, nemo, mp2, etc)
286 ///
287 /// parameters are kept in a map with key (string) and value (QCParameter),
288 /// types are converted whenever a parameter is accessed (i.e. should not be
289 /// done too frequently in an inner loop)
291 
292 public:
293  /// print all parameters
294  void print(const std::string header="", const std::string footer="") const;
295 
296  std::string print_to_string(bool non_defaults_only=false) const;
297 
298  template<typename T>
299  T get(const std::string key) const {
300  const QCParameter& parameter=get_parameter(key);
301  MADNESS_ASSERT(check_type<T>(key,parameter));
302  if (std::is_same<T,std::string>::value) {
303  return fromstring<T>(add_quotes(parameter.get_value()));
304  }
305  return fromstring<T>(parameter.get_value());
306  }
307 
308  bool is_user_defined(std::string key) const {
309  return get_parameter(key).is_user_defined();
310  }
311 
312  template <typename Archive> void serialize (Archive& ar) {
313  ar & parameters & print_debug;
314  }
315 
316  hashT hash() const {
317  return hash_range(parameters.begin(), parameters.end());
318  }
319 
320 protected:
321 
322  typedef std::map<std::string,QCParameter> ParameterContainerT;
324 
326  const commandlineparser& parser,
327  const std::string tag) {
328  try {
329  // check that user-defined input files actually exist
330  bool file_ok=true;
331  if (parser.key_exists("user_defined_input_file")) file_ok=file_exists(world,parser.value("input"));
332  if (file_ok) read_input(world,parser.value("input"),tag);
333  else {
334  std::string msg="could not find user-defined input file: "+parser.value("input")+"\n";
335  throw std::invalid_argument(msg);
336  }
337  } catch (std::invalid_argument& e) {
338  throw;
339  } catch (std::exception& e) {
340  madness::print(e.what());
341  }
342  read_commandline_options(world,parser,tag);
343  }
344 
345 public:
346  bool file_exists(World& world, std::string filename) const;
347 private:
348  /// read the parameters from file
349 
350  /// only world.rank()==0 reads the input file and broadcasts to all other nodes,
351  /// so we don't need to serialize the ParameterMap
352  void read_input(World& world, const std::string filename, const std::string tag);
353 
354  void read_commandline_options(World& world, const commandlineparser& parser, const std::string tag);
355 
356 protected:
357  bool print_debug=false;
361 
362  /// ctor for testing
364 
365  /// copy ctor
367  : parameters(other.parameters)
368  , print_debug(other.print_debug) {
369  }
370 
371  /// destructor
373 
374  template<typename T>
375  void initialize(const std::string& key, const T& value, const std::string comment="",
376  const std::vector<T> allowed_values={}) {
377 
378  if (parameters.find(key)!=parameters.end()) {
379  madness::print("you cannot initialize a parameter twice: ",key);
380  throw std::runtime_error("initialization error");
381  }
382 
383  std::string svalue=tostring(value);
384  std::string type = std::type_index(typeid(T)).name();
385 
386  // transform everything to lower case
387  std::string key_lower=key;
388  std::transform(key_lower.begin(), key_lower.end(), key_lower.begin(), ::tolower);
389  std::transform(svalue.begin(), svalue.end(), svalue.begin(), ::tolower);
390  std::vector<std::string> av_lower_vec;
391  for (const T& av : allowed_values) {
392  std::string av_lower=tostring(av);
393  std::transform(av_lower.begin(), av_lower.end(), av_lower.begin(), ::tolower);
394  av_lower_vec.push_back(av_lower);
395  }
396 
397  parameters.insert(std::make_pair<std::string, QCParameter>
398  (std::string(key_lower),QCParameter(svalue,type,comment,av_lower_vec)));
399  }
400 
401 public:
402  template<typename T>
403  void set_derived_value(const std::string& key, const T& value) {
404 
405  QCParameter& parameter=get_parameter(key);
406  if (not check_type_silent<T>(parameter)) {
407  throw std::runtime_error("type error in set_derived_value for key "+key);
408  }
409  parameter.set_derived_value(tostring(value));
410  }
411 
413  return parameters;
414  }
415 
416 
417 protected:
418 
419  template<typename T>
420  bool try_setting_user_defined_value(const std::string& key, const std::string& val) {
421 
422  if (not check_type_silent<T>(get_parameter(key))) return false;
423 
424  if (print_debug) ::madness::print("key:",key,"will set type" ,std::type_index(typeid(T)).name());
425  T value=fromstring<T>(val);
426  set_user_defined_value<T>(key,value);
427  return true;
428  }
429 
430 public:
431  void from_json(const json& j) {
432  for (auto [key, value]: j.items()) {
433  QCParameter& parameter = get_parameter(key);
434  // ::print("key: ", key, " value: ", value);
435  parameter.set_user_defined_value(tostring(value));
436  }
437  }
438  json to_json() const {
439  json j_params = {};
440  // TODO Is there a way to the get member for every parameter even though get is a template function?
441  for (auto& p: parameters) {
442  auto param_type = p.second.get_type();
443  if (param_type == "i") {
444  j_params[p.first] = get<int>(p.first);
445  // if vector of double
446  } else if (param_type == "d") {
447  j_params[p.first] = get<double>(p.first);
448 
449  // if vector of bool
450  } else if (param_type == "b") {
451  j_params[p.first] = get<bool>(p.first);
452 
453  // if vector of doubles?
454  } else if (param_type == "St6vectorIdSaIdEE") {
455  j_params[p.first] = get<std::vector<double>>(p.first);
456  } else if (param_type == "NSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE") {
457  auto sval = get<std::string>(p.first);
458  if (!sval.empty()) continue;
459  j_params[p.first] = sval;
460  // size t
461  } else if (p.second.get_type() == "m") {
462  j_params[p.first] = get<size_t>(p.first);
463  }
464  }
465  return j_params;
466  }
467  /**
468  * Adds the response parameters to an existing json under key "parameters"
469  * @param j
470  */
471  void to_json(json& j) const {
472  json j_params = {};
473  // TODO Is there a way to the get member for every parameter even though get is a template function?
474  for (auto& p: parameters) {
475  auto param_type = p.second.get_type();
476  if (param_type == "i") {
477  j_params[p.first] = get<int>(p.first);
478  // if vector of double
479  } else if (param_type == "d") {
480  j_params[p.first] = get<double>(p.first);
481 
482  // if vector of bool
483  } else if (param_type == "b") {
484  j_params[p.first] = get<bool>(p.first);
485 
486  // if vector of doubles?
487  } else if (param_type == "St6vectorIdSaIdEE") {
488  j_params[p.first] = get<std::vector<double>>(p.first);
489  } else if (param_type == "NSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE") {
490  auto sval = get<std::string>(p.first);
491  if (!sval.empty()) continue;
492  j_params[p.first] = sval;
493  // size t
494  } else if (p.second.get_type() == "m") {
495  j_params[p.first] = get<size_t>(p.first);
496  }
497  }
498  j["parameters"] = j_params;
499  }
500 
501  bool operator==(const QCCalculationParametersBase& other) const {
502 
503  for (auto& p: parameters) {
504  auto param_type = p.second.get_type();
505 
506  if (param_type == "i") {
507  if (get<int>(p.first) != other.get<int>(p.first)) { return false; };
508  // if vector of double
509  } else if (param_type == "d") {
510  if (get<double>(p.first) != other.get<double>(p.first)) { return false; };
511  // if vector of bool
512  } else if (param_type == "b") {
513  if (get<bool>(p.first) != other.get<bool>(p.first)) { return false; };
514  // if vector of doubles?
515  } else if (param_type == "St6vectorIdSaIdEE") {
516  if (get<std::vector<double>>(p.first) !=
517  other.get<std::vector<double>>(p.first)) {
518 
519  return false;
520  };
521  } else if (param_type == "NSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE") {
522  if (get<std::string>(p.first) != other.get<std::string>(p.first)) {
523  return false;
524  };
525  } else if (p.second.get_type() == "m") {
526  if (get<size_t>(p.first) != other.get<size_t>(p.first)) { return false; };
527  }
528  }
529  return true;
530  }
531 
532  template<typename T>
533  void set_user_defined_value(const std::string& key, const T& value) {
534 
535  QCParameter& parameter=get_parameter(key);
536  if (not check_type_silent<T>(parameter)) {
537  throw std::runtime_error("type error in set_user_defined_value");
538  }
539 
540  parameter.set_user_defined_value(tostring(value));
541  }
542 protected:
543 
544  const QCParameter& get_parameter(const std::string key) const {
545  if (not parameter_exists(key)) {
546  throw std::runtime_error("could not find parameter for key "+key);
547  }
548  const QCParameter& parameter=parameters.find(key)->second;
549  return parameter;
550  }
551 
552 public:
553  QCParameter& get_parameter(const std::string key) {
554  if (not parameter_exists(key)) {
555  madness::print("\ncould not find parameter for key",key,"\n");
556  throw std::runtime_error("could not find parameter for key "+key);
557  }
558  QCParameter& parameter=parameters.find(key)->second;
559  return parameter;
560  }
561 
562  bool parameter_exists(const std::string& key) const {
563  return (parameters.find(key)!=parameters.end());
564  }
565 
566 
567  template<typename T>
568  static bool check_type(const std::string key, const QCParameter& parameter) {
569  if (check_type_silent<T>(parameter)) return true;
570 
571  madness::print("trying to get the wrong type in QCCalculationParametersBase");
572  madness::print("key ",key);
573  madness::print("parameter type ",parameter.get_type());
574  madness::print("setting type ",std::type_index(typeid(T)).name());
575  madness::print("value ",parameter.get_value());
576  return false;
577  }
578 
579  template<typename T>
580  static bool check_type_silent(const QCParameter& parameter) {
581  return (parameter.get_type()==std::type_index(typeid(T)).name());
582  }
583 
584  /// read the stream, starting from tag
585 
586  /// only parameters that are defined in the constructor will be processed,
587  /// all others will be discarded.
588  virtual void read_internal(World& world, std::string& filecontents, std::string tag);
589 
590 
591  static std::string tostring(const bool& arg) {
592  std::ostringstream ss;
593  ss << std::boolalpha << arg;
594  return ss.str();
595  }
596 
597  template<typename T>
598  static std::string tostring(const T& arg) {
599  using madness::operators::operator<<;
600  std::ostringstream ss;
601  static_assert(not std::is_same<T,bool>::value, "you need to specialize tostring for this type");
602 
603  ss<<std::scientific << std::setprecision(4) << arg;
604  std::string str=ss.str();
605  std::transform(str.begin(), str.end(), str.begin(), ::tolower);
606 
607  overwrite_if_inf(str,arg);
608  return str;
609  }
610 
611  template<typename T>
612  static typename std::enable_if<std::is_floating_point<T>::value, void>::type
613  overwrite_if_inf(std::string& str, const T& arg) {
614  if (std::isinf(arg)) {
615  std::stringstream ss;
616  ss << std::numeric_limits<T>::infinity();
617  str=ss.str();
618  }
619  }
620 
621  template<typename T>
622  static typename std::enable_if<!std::is_floating_point<T>::value, void>::type
623  overwrite_if_inf(std::string& str, const T& arg) {
624  return;
625  }
626 
627  template<typename T>
628  static typename std::enable_if<!std::is_same<T,bool>::value, T>::type
629  fromstring(const std::string& arg) {
630 
631  std::stringstream ssvalue(arg);
632 
633  // if argument is std::string read the everything between possible double quotes
634  T result=read_quotes<T>(ssvalue);
635 
636  bool type_conversion_failed=ssvalue.fail();
637 
638  // check for infinity in floating point conversions
639  if (type_conversion_failed and (std::is_floating_point<T>::value)) {
640 
641  const static T inf=std::numeric_limits<T>::infinity();
642  std::string sinf=tostring(inf); // repeat type conversion from above
643  if (sinf==arg) result=inf;
644  type_conversion_failed=false;
645  }
646 
647  if (type_conversion_failed) {
648 
649  std::string errmsg="error in type conversion for argument >> " + arg
650  + " << to type " + std::type_index(typeid(T)).name();
651  throw std::runtime_error(errmsg);
652  }
653 
654  // check for trailing characters
655  std::string word;
656  while (ssvalue >> word) {
657  std::string errmsg="trailing characters in arguement >> " + arg + " <<";
658  throw std::runtime_error(errmsg);
659  }
660  return result;
661  }
662 
663  template<typename T>
664  static typename std::enable_if<std::is_same<T,std::string>::value, T>::type
665  read_quotes(std::stringstream& ssvalue) {
666  T arg=ssvalue.str();
667  T result;
668 
669  if (arg.find("\"")==std::string::npos) { // no double quotes found
670  ssvalue >> result;
671 
672  } else { // found double quotes
673  int counter=0;
674  while (counter<2) {
675  T tmp;
676  ssvalue >> tmp;
677  if (ssvalue.fail()) {
678  std::string errmsg="missing closing double quote in line >> " + arg;
679  throw std::runtime_error(errmsg);
680  }
681  result+=" "+tmp;
682  counter=std::count(result.begin(), result.end(), '"');
683  }
684 
685  // use only the text between the double quotes
686  result=trim_blanks(trim_quotes(result));
687  }
688  return result;
689  }
690 
691  static std::string trim_blanks(const std::string arg) {
692  std::size_t first=arg.find_first_not_of(' ');
693  std::size_t last=arg.find_last_not_of(' ');
694  return arg.substr(first,last-first+1);
695  }
696 
697  static std::string trim_quotes(const std::string arg) {
698  std::size_t first=arg.find_first_of('"');
699  std::size_t last=arg.find_last_of('"');
700  return arg.substr(first+1,last-first-1);
701  }
702 
703  static std::string add_quotes(const std::string arg) {
704  return "\""+arg+"\"";
705  }
706 
707 
708  template<typename T>
709  static typename std::enable_if<!std::is_same<T,std::string>::value, T>::type
710  read_quotes(std::stringstream& ssvalue) {
711  T result;
712  ssvalue >> result;
713  return result;
714  }
715 
716  template<typename T>
717  static typename std::enable_if<std::is_same<T,bool>::value, T>::type
718  fromstring(const std::string& arg) {
719  std::string str=arg;
720  std::transform(str.begin(), str.end(), str.begin(), ::tolower);
721  if (str=="true" or str=="1" or str=="yes") return true;
722  if (str=="false" or str=="0" or str=="no") return false;
723  std::string errmsg="error in type conversion for argument >> " + arg
724  + " << to type " + std::type_index(typeid(T)).name();
725  throw std::runtime_error(errmsg);
726  return 0;
727  }
728  };
729 
730 
731  bool operator!=(const QCCalculationParametersBase& p1, const QCCalculationParametersBase& p2);
732 
733 
734 } /* namespace madness */
735 
736 #endif /* SRC_APPS_CHEM_QCCALCULATIONPARAMETERSBASE_H_ */
Interface templates for the archives (serialization).
class for holding the parameters for calculation
Definition: QCCalculationParametersBase.h:290
static bool check_type_silent(const QCParameter &parameter)
Definition: QCCalculationParametersBase.h:580
virtual void read_input_and_commandline_options(World &world, const commandlineparser &parser, const std::string tag)
Definition: QCCalculationParametersBase.h:325
ParameterContainerT get_all_parameters() const
Definition: QCCalculationParametersBase.h:412
static std::string tostring(const T &arg)
Definition: QCCalculationParametersBase.h:598
hashT hash() const
Definition: QCCalculationParametersBase.h:316
static std::enable_if< std::is_floating_point< T >::value, void >::type overwrite_if_inf(std::string &str, const T &arg)
Definition: QCCalculationParametersBase.h:613
std::map< std::string, QCParameter > ParameterContainerT
Definition: QCCalculationParametersBase.h:322
QCParameter & get_parameter(const std::string key)
Definition: QCCalculationParametersBase.h:553
bool throw_if_datagroup_not_found
Definition: QCCalculationParametersBase.h:360
static std::enable_if< std::is_same< T, std::string >::value, T >::type read_quotes(std::stringstream &ssvalue)
Definition: QCCalculationParametersBase.h:665
void set_user_defined_value(const std::string &key, const T &value)
Definition: QCCalculationParametersBase.h:533
bool print_debug
Definition: QCCalculationParametersBase.h:357
json to_json() const
Definition: QCCalculationParametersBase.h:438
void to_json(json &j) const
Definition: QCCalculationParametersBase.h:471
virtual void read_internal(World &world, std::string &filecontents, std::string tag)
read the stream, starting from tag
Definition: QCCalculationParametersBase.cc:111
void read_input(World &world, const std::string filename, const std::string tag)
read the parameters from file
Definition: QCCalculationParametersBase.cc:63
static std::enable_if< std::is_same< T, bool >::value, T >::type fromstring(const std::string &arg)
Definition: QCCalculationParametersBase.h:718
const QCParameter & get_parameter(const std::string key) const
Definition: QCCalculationParametersBase.h:544
void read_commandline_options(World &world, const commandlineparser &parser, const std::string tag)
read the parameters from the command line and broadcast
Definition: QCCalculationParametersBase.cc:89
bool parameter_exists(const std::string &key) const
Definition: QCCalculationParametersBase.h:562
T get(const std::string key) const
Definition: QCCalculationParametersBase.h:299
static std::enable_if<!std::is_floating_point< T >::value, void >::type overwrite_if_inf(std::string &str, const T &arg)
Definition: QCCalculationParametersBase.h:623
void initialize(const std::string &key, const T &value, const std::string comment="", const std::vector< T > allowed_values={})
Definition: QCCalculationParametersBase.h:375
void print(const std::string header="", const std::string footer="") const
print all parameters
Definition: QCCalculationParametersBase.cc:22
void from_json(const json &j)
Definition: QCCalculationParametersBase.h:431
bool ignore_unknown_keys
Definition: QCCalculationParametersBase.h:358
bool file_exists(World &world, std::string filename) const
Definition: QCCalculationParametersBase.cc:51
static std::enable_if<!std::is_same< T, bool >::value, T >::type fromstring(const std::string &arg)
Definition: QCCalculationParametersBase.h:629
static std::string tostring(const bool &arg)
Definition: QCCalculationParametersBase.h:591
QCCalculationParametersBase(const QCCalculationParametersBase &other)
copy ctor
Definition: QCCalculationParametersBase.h:366
bool ignore_unknown_keys_silently
Definition: QCCalculationParametersBase.h:359
bool is_user_defined(std::string key) const
Definition: QCCalculationParametersBase.h:308
void serialize(Archive &ar)
Definition: QCCalculationParametersBase.h:312
bool try_setting_user_defined_value(const std::string &key, const std::string &val)
Definition: QCCalculationParametersBase.h:420
static std::string trim_blanks(const std::string arg)
Definition: QCCalculationParametersBase.h:691
static std::enable_if<!std::is_same< T, std::string >::value, T >::type read_quotes(std::stringstream &ssvalue)
Definition: QCCalculationParametersBase.h:710
ParameterContainerT parameters
Definition: QCCalculationParametersBase.h:323
bool operator==(const QCCalculationParametersBase &other) const
Definition: QCCalculationParametersBase.h:501
static bool check_type(const std::string key, const QCParameter &parameter)
Definition: QCCalculationParametersBase.h:568
static std::string add_quotes(const std::string arg)
Definition: QCCalculationParametersBase.h:703
virtual ~QCCalculationParametersBase()
destructor
Definition: QCCalculationParametersBase.h:372
static std::string trim_quotes(const std::string arg)
Definition: QCCalculationParametersBase.h:697
std::string print_to_string(bool non_defaults_only=false) const
Definition: QCCalculationParametersBase.cc:31
void set_derived_value(const std::string &key, const T &value)
Definition: QCCalculationParametersBase.h:403
QCCalculationParametersBase()
ctor for testing
Definition: QCCalculationParametersBase.h:363
A parallel world class.
Definition: world.h:132
char * p(char *buf, const char *name, int k, int initial_level, double thresh, int order)
Definition: derivatives.cc:72
std::vector< Fcwf > transform(World &world, std::vector< Fcwf > &a, Tensor< std::complex< double >> U)
Definition: fcwf.cc:477
auto T(World &world, response_space &f) -> response_space
Definition: global_functions.cc:34
Tensor< typename Tensor< T >::scalar_type > arg(const Tensor< T > &t)
Return a new tensor holding the argument of each element of t (complex types only)
Definition: tensor.h:2502
static const double v
Definition: hatom_sf_dirac.cc:20
#define max(a, b)
Definition: lda.h:51
#define MADNESS_ASSERT(condition)
Assert a condition that should be free of side-effects since in release builds this might be a no-op.
Definition: madness_exception.h:134
void print(const tensorT &t)
Definition: mcpfit.cc:140
Header to declare stuff which has not yet found a home.
File holds all helper structures necessary for the CC_Operator and CC2 class.
Definition: DFParameters.h:10
void hash_range(hashT &seed, It first, It last)
Definition: worldhash.h:280
static const char * filename
Definition: legendre.cc:96
bool operator!=(const ResponseParameters &p1, const ResponseParameters &p2)
Definition: response_parameters.cpp:17
nlohmann::json json
Definition: QCCalculationParametersBase.h:27
static std::enable_if< std::is_floating_point< T >::value, void >::type check_for_inf(const std::string &str, T &arg)
Definition: QCCalculationParametersBase.h:31
void print(const T &t, const Ts &... ts)
Print items to std::cout (items separated by spaces) and terminate with a new line.
Definition: print.h:225
std::istream & operator>>(std::istream &is, PairType &en)
Definition: PNOParameters.cpp:24
std::size_t hashT
The hash value type.
Definition: worldhash.h:145
std::string type(const PairType &n)
Definition: PNOParameters.h:18
std::string name(const FuncType &type, const int ex=-1)
Definition: ccpairfunction.h:28
madness::hashT hash_value(const std::array< T, N > &a)
Hash std::array with madness hash.
Definition: array_addons.h:78
double Q(double a)
Definition: relops.cc:20
static const double c
Definition: relops.cc:10
nlohmann::json json
Definition: response_parameters.cpp:6
structure holding the value for a given parameter
Definition: QCCalculationParametersBase.h:126
int print_order
Definition: QCCalculationParametersBase.h:272
std::vector< std::string > allowed_values
Definition: QCCalculationParametersBase.h:271
std::string print_line(const std::string &key) const
Definition: QCCalculationParametersBase.h:168
QCParameter()
Definition: QCCalculationParametersBase.h:128
enum madness::QCParameter::@0 precedence
QCParameter(const std::string v, const std::string t, const std::string comment="", const std::vector< std::string > allowed_values1={})
Definition: QCCalculationParametersBase.h:130
int get_print_order() const
Definition: QCCalculationParametersBase.h:166
std::string default_value
Definition: QCCalculationParametersBase.h:265
std::string not_allowed_errmsg() const
Definition: QCCalculationParametersBase.h:253
void serialize(Archive &ar)
Definition: QCCalculationParametersBase.h:227
std::string user_defined_value
Definition: QCCalculationParametersBase.h:267
@ derived
Definition: QCCalculationParametersBase.h:232
@ defined
Definition: QCCalculationParametersBase.h:232
@ def
Definition: QCCalculationParametersBase.h:232
void set_all()
Definition: QCCalculationParametersBase.h:240
bool check_allowed()
Definition: QCCalculationParametersBase.h:247
std::string get_comment() const
Definition: QCCalculationParametersBase.h:155
void set_user_defined_value(const std::string val)
Definition: QCCalculationParametersBase.h:143
std::string type
Definition: QCCalculationParametersBase.h:268
std::string print_precedence() const
Definition: QCCalculationParametersBase.h:156
std::string value
Definition: QCCalculationParametersBase.h:264
std::string derived_value
Definition: QCCalculationParametersBase.h:266
std::string get_type() const
Definition: QCCalculationParametersBase.h:154
std::string comment
Definition: QCCalculationParametersBase.h:270
bool is_user_defined() const
Definition: QCCalculationParametersBase.h:149
std::string get_value() const
Definition: QCCalculationParametersBase.h:153
void set_derived_value(const std::string val)
Definition: QCCalculationParametersBase.h:138
hashT hash() const
Definition: QCCalculationParametersBase.h:234
very simple command line parser
Definition: commandlineparser.h:15
std::string value(const std::string key) const
Definition: commandlineparser.h:59
static std::vector< std::string > split(std::string s, const std::string delimiter)
split a string s into a vector of strings, using delimiter
Definition: commandlineparser.h:86
bool key_exists(std::string key) const
Definition: commandlineparser.h:55
void errmsg(const char *msg, int status)
Definition: test_hashthreaded.cc:54
void e()
Definition: test_sig.cc:75
Declares the World class for the parallel runtime environment.