27 assert_key_empty<bool>(s);
33 throw std::invalid_argument(
34 "Invalid value '" + std::string(s.
value) +
35 "' for type 'bool' in '" + std::string(s.
full_key) +
37 "possible values are: '0', '1', 'true', 'false'");
42 assert_key_empty<bool>(s);
48 assert_key_empty<bool>(s);
53 requires((std::floating_point<T> || std::integral<T>) && !std::is_enum_v<T>)
55 assert_key_empty<T>(s);
56 const auto *val_end = s.
value.data() + s.
value.size();
57 const auto *ptr = set_param_float_int(f, s);
59 throw std::invalid_argument(
"Invalid suffix '" +
60 std::string(ptr, val_end) +
"' for type '" +
65#ifdef ALPAQA_WITH_QUAD_PRECISION
70 f =
static_cast<__float128
>(ld);
76 v.resize(std::count(s.
value.begin(), s.
value.end(),
',') + 1);
77 std::string_view value, remainder = s.
value;
79 std::tie(value, remainder) =
split_key(remainder,
',');
86 assert_key_empty<vec_from_file<config_t>>(s);
87 if (s.
value.starts_with(
'@')) {
88 std::string fpath{s.
value.substr(1)};
89 std::ifstream f(fpath);
91 throw std::invalid_argument(
"Unable to open file '" + fpath +
95 auto r = alpaqa::csv::read_row_std_vector<real_t<config_t>>(f);
98 throw std::invalid_argument(
99 "Incorrect size in '" + std::string(s.
full_key) +
100 "' (got " + std::to_string(r.size()) +
", expected " +
104 throw std::invalid_argument(
105 "Unable to read from file '" + fpath +
"' in '" +
107 "': alpaqa::csv::read_error: " + e.what());
112 throw std::invalid_argument(
113 "Incorrect size in '" + std::string(s.
full_key) +
"' (got " +
114 std::to_string(v.
value->size()) +
", expected " +
119template <
class Rep,
class Period>
121 using Duration = std::remove_cvref_t<
decltype(t)>;
122 assert_key_empty<Duration>(s);
123 const auto *val_end = s.
value.data() + s.
value.size();
125#if ALPAQA_USE_FROM_CHARS_FLOAT
126 auto [ptr, ec] = std::from_chars(s.
value.data(), val_end, value);
127 if (ec != std::errc())
128 throw std::invalid_argument(
"Invalid value '" +
129 std::string(ptr, val_end) +
"' for type '" +
131 "' in '" + std::string(s.
full_key) +
132 "': " + std::make_error_code(ec).message());
134#pragma message "Using std::stod as a fallback to replace std::from_chars"
137 value = std::stod(std::string(s.
value), &end_index);
138 }
catch (std::exception &e) {
139 throw std::invalid_argument(
140 "Invalid value '" + std::string(s.
value) +
"' for type '" +
142 std::string(s.
full_key) +
"': " + e.what());
144 const char *ptr = s.
value.data() + end_index;
146 std::string_view units{ptr, val_end};
147 auto cast = [](
auto t) {
return std::chrono::duration_cast<Duration>(t); };
148 if (units ==
"s" || units.empty())
149 t = cast(std::chrono::duration<
double, std::ratio<1, 1>>{value});
150 else if (units ==
"ms")
151 t = cast(std::chrono::duration<
double, std::ratio<1, 1000>>{value});
152 else if (units ==
"us" || units ==
"µs")
153 t = cast(std::chrono::duration<
double, std::ratio<1, 1000000>>{value});
154 else if (units ==
"ns")
156 std::chrono::duration<
double, std::ratio<1, 1000000000>>{value});
157 else if (units ==
"min")
158 t = cast(std::chrono::duration<
double, std::ratio<60, 1>>{value});
160 throw std::invalid_argument(
"Invalid units '" + std::string(units) +
161 "' in '" + std::string(s.
full_key) +
"'");
166 if (s.
value ==
"BasedOnExternalStepSize")
168 else if (s.
value ==
"BasedOnCurvature")
171 throw std::invalid_argument(
"Invalid value '" + std::string(s.
value) +
172 "' for type 'LBFGSStepSize' in '" +
178 if (s.
value ==
"ApproxKKT")
180 else if (s.
value ==
"ApproxKKT2")
182 else if (s.
value ==
"ProjGradNorm")
184 else if (s.
value ==
"ProjGradNorm2")
186 else if (s.
value ==
"ProjGradUnitNorm")
188 else if (s.
value ==
"ProjGradUnitNorm2")
190 else if (s.
value ==
"FPRNorm")
192 else if (s.
value ==
"FPRNorm2")
194 else if (s.
value ==
"Ipopt")
196 else if (s.
value ==
"LBFGSBpp")
199 throw std::invalid_argument(
"Invalid value '" + std::string(s.
value) +
200 "' for type 'PANOCStopCrit' in '" +
251 PARAMS_MEMBER(recompute_last_prox_step_after_direction_reset),
388template <
class A,
class... Bs>
390 return (std::is_same_v<A, Bs> || ...);
402template <
class NewAlias,
class... PossibleAliases>
404 std::conditional_t<
any_is_same<NewAlias, PossibleAliases...>(),
405 _dummy<NewAlias, PossibleAliases...>, NewAlias>;
409template <
class... Ts>
412#define ALPAQA_SET_PARAM_INST(...) \
413 template void ALPAQA_EXPORT set_param( \
414 detail::possible_alias_t<__VA_ARGS__> &, ParamString)
435#define ALPAQA_SET_PARAM_INST_INT(...) \
436 ALPAQA_SET_PARAM_INST(__VA_ARGS__, int8_t, uint8_t, int16_t, uint16_t, \
437 int32_t, int64_t, uint32_t, uint64_t)
450 unsigned int,
unsigned short);
std::string demangled_typename(const std::type_info &t)
Get the pretty name of the given type as a string.
vec finite_diff(const std::function< real_t(crvec)> &f, crvec x)
std::conditional_t< any_is_same< NewAlias, PossibleAliases... >(), _dummy< NewAlias, PossibleAliases... >, NewAlias > possible_alias_t
If NewAlias is not the same type as any of PossibleAliases, the result is NewAlias.
constexpr bool any_is_same()
Check if A is equal to any of Bs.
void set_param(bool &b, ParamString s)
std::string_view full_key
Full key string, used for diagnostics.
auto split_key(std::string_view full, char tok='.')
Split the string full on the first occurrence of tok.
std::optional< vec > value
std::string_view value
The value of the parameter to store.
Represents a parameter value encoded as a string in the format abc.def.key=value.
@ LBFGSBpp
The stopping criterion used by LBFGS++, see https://lbfgspp.statr.me/doc/classLBFGSpp_1_1LBFGSBParam....
@ ProjGradUnitNorm
∞-norm of the projected gradient with unit step size:
@ ProjGradNorm
∞-norm of the projected gradient with step size γ:
@ Ipopt
The stopping criterion used by Ipopt, see https://link.springer.com/article/10.1007/s10107-004-0559-y...
@ FPRNorm2
2-norm of fixed point residual:
@ ProjGradNorm2
2-norm of the projected gradient with step size γ:
@ ApproxKKT
Find an ε-approximate KKT point in the ∞-norm:
@ FPRNorm
∞-norm of fixed point residual:
@ ApproxKKT2
Find an ε-approximate KKT point in the 2-norm:
@ ProjGradUnitNorm2
2-norm of the projected gradient with unit step size:
typename Conf::length_t length_t
typename Conf::cmvec cmvec
LBFGSStepSize
Which method to use to select the L-BFGS step size.
@ BasedOnCurvature
Initial inverse Hessian approximation is set to .
@ BasedOnExternalStepSize
Initial inverse Hessian approximation is set to .
Parameters for the Augmented Lagrangian solver.
Parameters for the AndersonAccel class.
Parameters for the AndersonDirection class.
Parameters for the LBFGSDirection class.
Parameters for the LBFGS class.
Parameters for the NewtonTRDirection class.
Tuning parameters for the PANOC algorithm.
Tuning parameters for the PANOC algorithm.
Tuning parameters for the PANTR algorithm.
Parameters for the StructuredNewtonDirection class.
Parameters for the StructuredNewtonDirection class.
Tuning parameters for the ZeroFPR algorithm.
#define ALPAQA_SET_PARAM_INST(...)
#define ALPAQA_SET_PARAM_INST_INT(...)
#define PARAMS_MEMBER(name)
Helper macro to easily initialize a alpaqa::params::dict_to_struct_table_t.
#define PARAMS_TABLE(type_,...)
Helper macro to easily specialize alpaqa::params::dict_to_struct_table.
Parameters for the StructuredLBFGSDirection class.