/home/runner/work/DiFfRG_current/DiFfRG_current/DiFfRG/include/DiFfRG/common/run_reporter.hh Source File#

DiFfRG: /home/runner/work/DiFfRG_current/DiFfRG_current/DiFfRG/include/DiFfRG/common/run_reporter.hh Source File
DiFfRG
Discretization Framework for functional Renormalization Group flows
run_reporter.hh
Go to the documentation of this file.
1#pragma once
2
5
6#include <spdlog/common.h>
7
8#include <array>
9#include <cstddef>
10#include <filesystem>
11#include <memory>
12#include <optional>
13#include <string>
14#include <string_view>
15#include <utility>
16
17namespace DiFfRG
18{
24 std::string_view tag;
25 std::string_view stage;
26 auto operator<=>(const ProgressTopic &) const = default;
27 };
28
29 namespace progress_topics
30 {
31 inline constexpr ProgressTopic timestep{"step", {}};
32 inline constexpr ProgressTopic explicit_residual{"res", "explicit"};
33 inline constexpr ProgressTopic implicit_residual{"res", "implicit"};
34 inline constexpr ProgressTopic variables{"vars", {}};
35 inline constexpr ProgressTopic jacobian{"jac", {}};
36 inline constexpr ProgressTopic trapezoidal_jacobian{"jac", "TR"};
37 inline constexpr ProgressTopic bdf2_jacobian{"jac", "BDF2"};
38 inline constexpr ProgressTopic factorization{"fac", {}};
39 inline constexpr ProgressTopic implicit_linear_solve{"lin", "implicit"};
40 inline constexpr ProgressTopic output{"out", {}};
41 } // namespace progress_topics
42
44 std::string_view name;
45 double value = 0.;
47 };
48
52 double time = 0.;
53 double duration_ms = -1.;
54 long int iterations = -1;
56 std::array<ProgressField, 16> fields{};
57 std::size_t field_count = 0;
58
59 ProgressEvent &field(const std::string_view name, const double value, const int minimum_verbosity = 1)
60 {
61 if (field_count < fields.size()) fields[field_count++] = {name, value, minimum_verbosity};
62 return *this;
63 }
64 };
65
67 std::string_view name;
68 double average_ms = 0.;
69 std::size_t calls = 0;
70 };
71
73 struct SummaryEvent {
74 std::string_view component;
75 std::array<SummaryMetric, 4> metrics{};
76 std::size_t metric_count = 0;
77
78 SummaryEvent &timing(const std::string_view name, const double average_ms, const std::size_t calls)
79 {
80 if (metric_count < metrics.size()) metrics[metric_count++] = {name, average_ms, calls};
81 return *this;
82 }
83 };
84
85 namespace internal
86 {
87 class ReporterState;
88 class ReporterSlot;
89 } // namespace internal
90
96 {
97 public:
100 ReportPort(const ReportPort &) = default;
101 ReportPort &operator=(const ReportPort &) = default;
102
103 template <typename... Args> void info(spdlog::format_string_t<Args...> format, Args &&...args) const
104 {
105 info(spdlog::fmt_lib::format(format, std::forward<Args>(args)...));
106 }
107 template <typename... Args> void warn(spdlog::format_string_t<Args...> format, Args &&...args) const
108 {
109 warn(spdlog::fmt_lib::format(format, std::forward<Args>(args)...));
110 }
111 template <typename... Args> void error(spdlog::format_string_t<Args...> format, Args &&...args) const
112 {
113 error(spdlog::fmt_lib::format(format, std::forward<Args>(args)...));
114 }
115 template <typename... Args> void debug(spdlog::format_string_t<Args...> format, Args &&...args) const
116 {
117 debug(spdlog::fmt_lib::format(format, std::forward<Args>(args)...));
118 }
119
120 void info(const std::string &message) const;
121 void warn(const std::string &message) const;
122 void error(const std::string &message) const;
123 void debug(const std::string &message) const;
124 void progress(const ProgressEvent &event) const;
125 void summary(const SummaryEvent &event) const;
126 void flush() const;
128 std::optional<std::filesystem::path> log_file() const;
129
130 int verbosity() const noexcept;
131 double Lambda() const noexcept;
132 explicit operator bool() const noexcept;
133
134 private:
135 explicit ReportPort(std::shared_ptr<internal::ReporterState> state);
136 std::shared_ptr<internal::ReporterSlot> slot;
137 friend class RunReporter;
138 };
139
142 std::string reporter_name = "run";
145 bool console = true;
146 };
147
156 {
157 public:
158 RunReporter() = default;
159 RunReporter(OutputPath path, const Config::OutputSettings &settings, bool active, RunReporterOptions options = {});
160 ~RunReporter() noexcept;
161
162 RunReporter(const RunReporter &) = delete;
163 RunReporter &operator=(const RunReporter &) = delete;
164 RunReporter(RunReporter &&) noexcept = default;
165 RunReporter &operator=(RunReporter &&) noexcept = default;
166
167 ReportPort port() const;
168 void finish();
169
170 private:
171 std::shared_ptr<internal::ReporterState> state;
172 };
173} // namespace DiFfRG
Definition output_path.hh:16
Definition run_reporter.hh:96
std::shared_ptr< internal::ReporterSlot > slot
Definition run_reporter.hh:136
int verbosity() const noexcept
void warn(const std::string &message) const
void flush() const
void info(const std::string &message) const
void error(const std::string &message) const
ReportPort(const ReportPort &)=default
double Lambda() const noexcept
void debug(const std::string &message) const
void warn(spdlog::format_string_t< Args... > format, Args &&...args) const
Definition run_reporter.hh:107
ReportPort & operator=(const ReportPort &)=default
void debug(spdlog::format_string_t< Args... > format, Args &&...args) const
Definition run_reporter.hh:115
std::optional< std::filesystem::path > log_file() const
void progress(const ProgressEvent &event) const
void summary(const SummaryEvent &event) const
void info(spdlog::format_string_t< Args... > format, Args &&...args) const
Definition run_reporter.hh:103
void error(spdlog::format_string_t< Args... > format, Args &&...args) const
Definition run_reporter.hh:111
Definition run_reporter.hh:156
RunReporter(OutputPath path, const Config::OutputSettings &settings, bool active, RunReporterOptions options={})
~RunReporter() noexcept
constexpr ProgressTopic implicit_residual
Definition run_reporter.hh:33
constexpr ProgressTopic explicit_residual
Definition run_reporter.hh:32
constexpr ProgressTopic timestep
Definition run_reporter.hh:31
constexpr ProgressTopic output
Definition run_reporter.hh:40
constexpr ProgressTopic factorization
Definition run_reporter.hh:38
constexpr ProgressTopic variables
Definition run_reporter.hh:34
constexpr ProgressTopic bdf2_jacobian
Definition run_reporter.hh:37
constexpr ProgressTopic jacobian
Definition run_reporter.hh:35
constexpr ProgressTopic implicit_linear_solve
Definition run_reporter.hh:39
constexpr ProgressTopic trapezoidal_jacobian
Definition run_reporter.hh:36
Definition complex_math.hh:10
Definition output_settings.hh:15
Definition run_reporter.hh:50
std::size_t field_count
Definition run_reporter.hh:57
std::array< ProgressField, 16 > fields
Definition run_reporter.hh:56
ProgressTopic topic
Definition run_reporter.hh:51
ProgressEvent & field(const std::string_view name, const double value, const int minimum_verbosity=1)
Definition run_reporter.hh:59
double duration_ms
Definition run_reporter.hh:53
double time
Definition run_reporter.hh:52
int minimum_verbosity
Definition run_reporter.hh:55
long int iterations
Definition run_reporter.hh:54
Definition run_reporter.hh:43
std::string_view name
Definition run_reporter.hh:44
double value
Definition run_reporter.hh:45
int minimum_verbosity
Definition run_reporter.hh:46
Definition run_reporter.hh:23
std::string_view tag
Definition run_reporter.hh:24
std::string_view stage
Definition run_reporter.hh:25
auto operator<=>(const ProgressTopic &) const =default
Definition run_reporter.hh:140
Definition run_reporter.hh:73
std::array< SummaryMetric, 4 > metrics
Definition run_reporter.hh:75
std::size_t metric_count
Definition run_reporter.hh:76
std::string_view component
Definition run_reporter.hh:74
SummaryEvent & timing(const std::string_view name, const double average_ms, const std::size_t calls)
Definition run_reporter.hh:78
Definition run_reporter.hh:66
double average_ms
Definition run_reporter.hh:68
std::size_t calls
Definition run_reporter.hh:69
std::string_view name
Definition run_reporter.hh:67