22 assert_key_empty<bool>(s);
28 throw std::invalid_argument(
29 "Invalid value '" + std::string(s.
value) +
30 "' for type 'bool' in '" + std::string(s.
full_key) +
32 "possible values are: '0', '1', 'true', 'false'");
37 assert_key_empty<bool>(s);
43 assert_key_empty<bool>(s);
48 requires((std::floating_point<T> || std::integral<T>) && !std::is_enum_v<T>)
50 assert_key_empty<T>(s);
51 const auto *val_end = s.
value.data() + s.
value.size();
52 auto [ptr, ec] = std::from_chars(s.
value.data(), val_end, f);
53 if (ec != std::errc())
54 throw std::invalid_argument(
55 "Invalid value '" + std::string(s.
value) +
"' for type '" +
57 "': " + std::make_error_code(ec).message());
59 throw std::invalid_argument(
"Invalid suffix '" +
60 std::string(ptr, val_end) +
"' for type '" +
67 v.resize(std::count(s.
value.begin(), s.
value.end(),
',') + 1);
68 std::string_view value, remainder = s.
value;
70 std::tie(value, remainder) =
split_key(remainder,
',');
75template <
class Rep,
class Period>
77 using Duration = std::remove_cvref_t<
decltype(t)>;
78 assert_key_empty<Duration>(s);
79 const auto *val_end = s.
value.data() + s.
value.size();
81 auto [ptr, ec] = std::from_chars(s.
value.data(), val_end, value);
82 if (ec != std::errc())
83 throw std::invalid_argument(
"Invalid value '" +
84 std::string(ptr, val_end) +
"' for type '" +
87 "': " + std::make_error_code(ec).message());
88 std::string_view units{ptr, val_end};
89 auto cast = [](
auto t) {
return std::chrono::duration_cast<Duration>(t); };
90 if (units ==
"s" || units.empty())
91 t = cast(std::chrono::duration<
double, std::ratio<1, 1>>{value});
92 else if (units ==
"ms")
93 t = cast(std::chrono::duration<
double, std::ratio<1, 1000>>{value});
94 else if (units ==
"us" || units ==
"µs")
95 t = cast(std::chrono::duration<
double, std::ratio<1, 1000000>>{value});
96 else if (units ==
"ns")
98 std::chrono::duration<
double, std::ratio<1, 1000000000>>{value});
99 else if (units ==
"min")
100 t = cast(std::chrono::duration<
double, std::ratio<60, 1>>{value});
102 throw std::invalid_argument(
"Invalid units '" + std::string(units) +
103 "' in '" + std::string(s.
full_key) +
"'");
109 if (s.
value ==
"BasedOnExternalStepSize")
111 else if (s.
value ==
"BasedOnCurvature")
114 throw std::invalid_argument(
"Invalid value '" + std::string(s.
value) +
115 "' for type 'LBFGSStepSize' in '" +
122 if (s.
value ==
"ApproxKKT")
124 else if (s.
value ==
"ApproxKKT2")
126 else if (s.
value ==
"ProjGradNorm")
128 else if (s.
value ==
"ProjGradNorm2")
130 else if (s.
value ==
"ProjGradUnitNorm")
132 else if (s.
value ==
"ProjGradUnitNorm2")
134 else if (s.
value ==
"FPRNorm")
136 else if (s.
value ==
"FPRNorm2")
138 else if (s.
value ==
"Ipopt")
140 else if (s.
value ==
"LBFGSBpp")
143 throw std::invalid_argument(
"Invalid value '" + std::string(s.
value) +
144 "' for type 'PANOCStopCrit' in '" +
195 PARAMS_MEMBER(recompute_last_prox_step_after_direction_reset),
331template <
class A,
class... Bs>
333 return (std::is_same_v<A, Bs> || ...);
345template <
class NewAlias,
class... PossibleAliases>
347 std::conditional_t<
any_is_same<NewAlias, PossibleAliases...>(),
348 _dummy<NewAlias, PossibleAliases...>, NewAlias>;
352template <
class... Ts>
355#define ALPAQA_SET_PARAM_INST(...) \
356 template void ALPAQA_EXPORT set_param( \
357 detail::possible_alias_t<__VA_ARGS__> &, ParamString)
378#define ALPAQA_SET_PARAM_INST_INT(...) \
379 ALPAQA_SET_PARAM_INST(__VA_ARGS__, int8_t, uint8_t, int16_t, uint16_t, \
380 int32_t, int64_t, uint32_t, uint64_t)
393 unsigned int,
unsigned short);
std::string demangled_typename(const std::type_info &t)
Get the pretty name of the given type as a string.
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::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:
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.