proxsuite-nlp
0.10.0
A primal-dual augmented Lagrangian-type solver for nonlinear programming on manifolds.
Loading...
Searching...
No Matches
logger.hpp
Go to the documentation of this file.
1
3
#pragma once
4
5
#include <vector>
6
#include <array>
7
#include <fmt/color.h>
8
#include <fmt/ranges.h>
9
10
namespace
proxsuite
{
11
namespace
nlp {
12
13
constexpr
int
NUM_KEYS
= 10;
14
const
std::array<std::string, NUM_KEYS>
BASIC_KEYS
= {
15
"iter"
,
"step_size"
,
"inner_crit"
,
"prim_err"
,
"dual_err"
,
16
"xreg"
,
"dphi0"
,
"merit"
,
"dM"
,
"al_iter"
};
17
constexpr
char
int_format
[] =
"{: >{}d}"
;
18
constexpr
char
sci_format
[] =
"{: > {}.{}e}"
;
19
constexpr
char
dbl_format
[] =
"{: > {}.{}g}"
;
20
21
struct
LogRecord
{
22
size_t
iter
;
23
double
step_size
;
24
double
inner_crit
;
25
double
prim_err
;
26
double
dual_err
;
27
double
xreg
;
28
double
dphi0
;
29
double
merit
;
30
double
dM
;
31
size_t
al_iter
;
32
};
33
35
struct
BaseLogger
{
36
unsigned
int
COL_WIDTH_0
= 4;
37
unsigned
int
COL_WIDTH
= 10;
38
bool
active
=
true
;
39
40
constexpr
static
std::size_t
print_outline_every
() {
return
25; }
41
42
const
std::string
join_str
=
"|"
;
43
44
void
start
()
const
{
45
if
(!
active
)
46
return
;
47
static
constexpr
char
fstr[] =
"{:^{}s}"
;
48
std::array<std::string, NUM_KEYS> v;
49
v[0] = fmt::format(fstr,
BASIC_KEYS
[0],
COL_WIDTH_0
);
50
for
(std::size_t i = 1; i <
BASIC_KEYS
.size(); ++i) {
51
v[i] = fmt::format(fstr,
BASIC_KEYS
[i],
COL_WIDTH
);
52
}
53
fmt::print(fmt::emphasis::bold,
"{}\n"
, fmt::join(v,
join_str
));
54
}
55
56
void
log
(
const
LogRecord
&values)
const
{
57
if
(!
active
)
58
return
;
59
std::vector<std::string> v;
60
int
sci_prec = 3;
61
int
dbl_prec = 3;
62
using
fmt::format;
63
if
(values.
iter
%
print_outline_every
() == 0)
64
start
();
65
v.push_back(format(
int_format
, values.
iter
,
COL_WIDTH_0
));
66
v.push_back(format(
sci_format
, values.
step_size
,
COL_WIDTH
, sci_prec));
67
v.push_back(format(
sci_format
, values.
inner_crit
,
COL_WIDTH
, sci_prec));
68
v.push_back(format(
sci_format
, values.
prim_err
,
COL_WIDTH
, sci_prec));
69
v.push_back(format(
sci_format
, values.
dual_err
,
COL_WIDTH
, sci_prec));
70
v.push_back(format(
sci_format
, values.
xreg
,
COL_WIDTH
, sci_prec));
71
v.push_back(format(
sci_format
, values.
dphi0
,
COL_WIDTH
, dbl_prec));
72
v.push_back(format(
sci_format
, values.
merit
,
COL_WIDTH
, sci_prec));
73
v.push_back(format(
dbl_format
, values.
dM
,
COL_WIDTH
, dbl_prec));
74
v.push_back(format(
int_format
, values.
al_iter
,
COL_WIDTH
));
75
76
fmt::print(
"{}\n"
, fmt::join(v,
join_str
));
77
}
78
};
79
80
}
// namespace nlp
81
}
// namespace proxsuite
proxsuite::nlp::sci_format
constexpr char sci_format[]
Definition
logger.hpp:18
proxsuite::nlp::int_format
constexpr char int_format[]
Definition
logger.hpp:17
proxsuite::nlp::BASIC_KEYS
const std::array< std::string, NUM_KEYS > BASIC_KEYS
Definition
logger.hpp:14
proxsuite::nlp::NUM_KEYS
constexpr int NUM_KEYS
Definition
logger.hpp:13
proxsuite::nlp::dbl_format
constexpr char dbl_format[]
Definition
logger.hpp:19
proxsuite
Main package namespace.
Definition
bcl-params.hpp:5
proxsuite::nlp::BaseLogger
A logging utility.
Definition
logger.hpp:35
proxsuite::nlp::BaseLogger::join_str
const std::string join_str
Definition
logger.hpp:42
proxsuite::nlp::BaseLogger::COL_WIDTH
unsigned int COL_WIDTH
Definition
logger.hpp:37
proxsuite::nlp::BaseLogger::print_outline_every
static constexpr std::size_t print_outline_every()
Definition
logger.hpp:40
proxsuite::nlp::BaseLogger::start
void start() const
Definition
logger.hpp:44
proxsuite::nlp::BaseLogger::active
bool active
Definition
logger.hpp:38
proxsuite::nlp::BaseLogger::log
void log(const LogRecord &values) const
Definition
logger.hpp:56
proxsuite::nlp::BaseLogger::COL_WIDTH_0
unsigned int COL_WIDTH_0
Definition
logger.hpp:36
proxsuite::nlp::LogRecord
Definition
logger.hpp:21
proxsuite::nlp::LogRecord::dphi0
double dphi0
Definition
logger.hpp:28
proxsuite::nlp::LogRecord::iter
size_t iter
Definition
logger.hpp:22
proxsuite::nlp::LogRecord::merit
double merit
Definition
logger.hpp:29
proxsuite::nlp::LogRecord::al_iter
size_t al_iter
Definition
logger.hpp:31
proxsuite::nlp::LogRecord::xreg
double xreg
Definition
logger.hpp:27
proxsuite::nlp::LogRecord::prim_err
double prim_err
Definition
logger.hpp:25
proxsuite::nlp::LogRecord::step_size
double step_size
Definition
logger.hpp:23
proxsuite::nlp::LogRecord::dual_err
double dual_err
Definition
logger.hpp:26
proxsuite::nlp::LogRecord::dM
double dM
Definition
logger.hpp:30
proxsuite::nlp::LogRecord::inner_crit
double inner_crit
Definition
logger.hpp:24
include
proxsuite-nlp
logger.hpp
Generated by
1.11.0