Xped
Loading...
Searching...
No Matches
CTMOpts.hpp
Go to the documentation of this file.
1#ifndef XPED_CTM_OPTS_HPP
2#define XPED_CTM_OPTS_HPP
3
4#include "toml.hpp"
5
6#include "yas/serialize.hpp"
7#include "yas/std_types.hpp"
8
9#include "fmt/color.h"
10#include "fmt/core.h"
11
12#include <boost/describe.hpp>
13
14#include "Xped/Util/Logging.hpp"
16
17namespace Xped::Opts {
18
19BOOST_DEFINE_ENUM_CLASS(DIRECTION, LEFT, RIGHT, TOP, BOTTOM)
20
21BOOST_DEFINE_ENUM_CLASS(CORNER, UPPER_LEFT, UPPER_RIGHT, LOWER_LEFT, LOWER_RIGHT)
22
23BOOST_DEFINE_ENUM_CLASS(PROJECTION, CORNER, HALF, FULL)
24
25BOOST_DEFINE_ENUM_CLASS(CTM_INIT, FROM_TRIVIAL, FROM_A)
26
27struct CTM
28{
29 std::size_t chi;
30
31 std::size_t max_presteps = 100;
32 std::size_t track_steps = 4;
33
34 double tol_E = 1.e-10;
35 double tol_N = 1.e-10;
36
37 double reinit_env_tol = 1.e-1;
38
39 CTM_INIT init = CTM_INIT::FROM_A;
40
41 Verbosity verbosity = Verbosity::ON_ENTRY;
42
43 std::string load = "";
44 int qn_scale = 1;
45
46 template <typename Ar>
47 void serialize(Ar& ar)
48 {
49 ar& YAS_OBJECT_NVP("CTMOpts",
50 ("chi", chi),
51 ("max_presteps", max_presteps),
52 ("track_steps", track_steps),
53 ("tol_E", tol_E),
54 ("tol_N", tol_N),
55 ("reinit_env_tol", reinit_env_tol),
56 ("init", init),
57 ("verbosity", verbosity),
58 ("load", load),
59 ("qn_scale", qn_scale));
60 }
61
62 inline auto info()
63 {
64 std::string res;
65 fmt::format_to(std::back_inserter(res), "{}:\n", fmt::styled("CTM options", fmt::emphasis::bold));
66 fmt::format_to(std::back_inserter(res), " {:<30} {}\n", "• chi:", chi);
67 fmt::format_to(std::back_inserter(res), " {:<30} {}\n", "• init:", fmt::streamed(init));
68 fmt::format_to(std::back_inserter(res), " {:<30} {}\n", "• maximum pre-steps:", max_presteps);
69 fmt::format_to(std::back_inserter(res), " {:<30} {}\n", "• tracked steps:", track_steps);
70 fmt::format_to(std::back_inserter(res), " {:<30} {}\n", "• energy tolerance:", tol_E);
71 fmt::format_to(std::back_inserter(res), " {:<30} {}\n", "• norm tolerance:", tol_N);
72 fmt::format_to(std::back_inserter(res), " {:<30} {}\n", "• reinit_env_tol:", reinit_env_tol);
73 if(load.size() > 0) { fmt::format_to(std::back_inserter(res), " {:<30} {}\n", "• load from:", load); }
74 if(load.size() > 0) { fmt::format_to(std::back_inserter(res), " {:<30} {}\n", "• scale loaded qn by:", qn_scale); }
75 fmt::format_to(std::back_inserter(res), " {:<30} {}", "• verbosity:", fmt::streamed(verbosity));
76 return res;
77 }
78};
79
80inline CTM ctm_from_toml(const toml::value& t)
81{
82 CTM res{};
83 res.chi = t.contains("chi") ? t.at("chi").as_integer() : res.chi;
84 if(t.contains("init")) { res.init = util::enum_from_toml<CTM_INIT>(t.at("init")); }
85 res.max_presteps = t.contains("max_presteps") ? t.at("max_presteps").as_integer() : res.max_presteps;
86 res.track_steps = t.contains("track_steps") ? t.at("track_steps").as_integer() : res.track_steps;
87 res.tol_E = t.contains("tol_E") ? t.at("tol_E").as_floating() : res.tol_E;
88 res.reinit_env_tol = t.contains("reinit_env_tol") ? t.at("reinit_env_tol").as_floating() : res.reinit_env_tol;
89 if(t.contains("verbosity")) { res.verbosity = util::enum_from_toml<Verbosity>(t.at("verbosity")); }
90 res.load = t.contains("load") ? static_cast<std::string>(t.at("load").as_string()) : res.load;
91 res.qn_scale = t.contains("qn_scale") ? (t.at("qn_scale").as_integer()) : res.qn_scale;
92 return res;
93}
94
96{
97 bool GROW_ALL = false;
98 bool MOVE = false;
99 bool CORNER = false;
100 bool PROJECTORS = false;
101 bool RENORMALIZE = false;
102 bool RDM = false;
103
104 auto info() const
105 {
106 std::string res;
107 fmt::format_to(std::back_inserter(res), "{}:\n", fmt::styled("Checkpointing settings", fmt::emphasis::bold));
108 fmt::format_to(std::back_inserter(res), " {:<30} {}\n", "• grow_all:", GROW_ALL);
109 fmt::format_to(std::back_inserter(res), " {:<30} {}\n", "• move:", MOVE);
110 fmt::format_to(std::back_inserter(res), " {:<30} {}\n", "• corner contraction:", CORNER);
111 fmt::format_to(std::back_inserter(res), " {:<30} {}\n", "• projector computation:", PROJECTORS);
112 fmt::format_to(std::back_inserter(res), " {:<30} {}\n", "• Renormalization step:", RENORMALIZE);
113 fmt::format_to(std::back_inserter(res), " {:<30} {}", "• RDM contraction:", RDM);
114 return res;
115 }
116};
117
118} // namespace Xped::Opts
119#endif
Definition: bench.cpp:62
CTM ctm_from_toml(const toml::value &t)
Definition: CTMOpts.hpp:80
Definition: CTMOpts.hpp:96
bool PROJECTORS
Definition: CTMOpts.hpp:100
bool CORNER
Definition: CTMOpts.hpp:99
bool GROW_ALL
Definition: CTMOpts.hpp:97
bool RENORMALIZE
Definition: CTMOpts.hpp:101
bool RDM
Definition: CTMOpts.hpp:102
bool MOVE
Definition: CTMOpts.hpp:98
auto info() const
Definition: CTMOpts.hpp:104
Definition: CTMOpts.hpp:28
auto info()
Definition: CTMOpts.hpp:62
std::size_t chi
Definition: CTMOpts.hpp:29
void serialize(Ar &ar)
Definition: CTMOpts.hpp:47