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