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 '" +
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,
',');
77 assert_key_empty<vec_from_file<config_t>>(s);
78 if (s.
value.starts_with(
'@')) {
79 std::string fpath{s.
value.substr(1)};
80 std::ifstream f(fpath);
82 throw std::invalid_argument(
"Unable to open file '" + fpath +
86 auto r = alpaqa::csv::read_row_std_vector<real_t<config_t>>(f);
89 throw std::invalid_argument(
90 "Incorrect size in '" + std::string(s.
full_key) +
91 "' (got " + std::to_string(r.size()) +
", expected " +
95 throw std::invalid_argument(
96 "Unable to read from file '" + fpath +
"' in '" +
98 "': alpaqa::csv::read_error: " + e.what());
103 throw std::invalid_argument(
104 "Incorrect size in '" + std::string(s.
full_key) +
"' (got " +
105 std::to_string(v.
value->size()) +
", expected " +
110template <
class Rep,
class Period>
112 using Duration = std::remove_cvref_t<
decltype(t)>;
113 assert_key_empty<Duration>(s);
114 const auto *val_end = s.
value.data() + s.
value.size();
116#if ALPAQA_USE_FROM_CHARS_FLOAT
117 auto [ptr, ec] = std::from_chars(s.
value.data(), val_end, value);
118 if (ec != std::errc())
119 throw std::invalid_argument(
"Invalid value '" +
120 std::string(ptr, val_end) +
"' for type '" +
122 "' in '" + std::string(s.
full_key) +
123 "': " + std::make_error_code(ec).message());
125#pragma message "Using std::stod as a fallback to replace std::from_chars"
128 value = std::stod(std::string(s.
value), &end_index);
129 }
catch (std::exception &e) {
130 throw std::invalid_argument(
131 "Invalid value '" + std::string(s.
value) +
"' for type '" +
133 std::string(s.
full_key) +
"': " + e.what());
135 const char *ptr = s.
value.data() + end_index;
137 std::string_view units{ptr, val_end};
138 auto cast = [](
auto t) {
return std::chrono::duration_cast<Duration>(t); };
139 if (units ==
"s" || units.empty())
140 t = cast(std::chrono::duration<
double, std::ratio<1, 1>>{value});
141 else if (units ==
"ms")
142 t = cast(std::chrono::duration<
double, std::ratio<1, 1000>>{value});
143 else if (units ==
"us" || units ==
"µs")
144 t = cast(std::chrono::duration<
double, std::ratio<1, 1000000>>{value});
145 else if (units ==
"ns")
147 std::chrono::duration<
double, std::ratio<1, 1000000000>>{value});
148 else if (units ==
"min")
149 t = cast(std::chrono::duration<
double, std::ratio<60, 1>>{value});
151 throw std::invalid_argument(
"Invalid units '" + std::string(units) +
152 "' in '" + std::string(s.
full_key) +
"'");
157 if (s.
value ==
"BasedOnExternalStepSize")
159 else if (s.
value ==
"BasedOnCurvature")
162 throw std::invalid_argument(
"Invalid value '" + std::string(s.
value) +
163 "' for type 'LBFGSStepSize' in '" +
169 if (s.
value ==
"ApproxKKT")
171 else if (s.
value ==
"ApproxKKT2")
173 else if (s.
value ==
"ProjGradNorm")
175 else if (s.
value ==
"ProjGradNorm2")
177 else if (s.
value ==
"ProjGradUnitNorm")
179 else if (s.
value ==
"ProjGradUnitNorm2")
181 else if (s.
value ==
"FPRNorm")
183 else if (s.
value ==
"FPRNorm2")
185 else if (s.
value ==
"Ipopt")
187 else if (s.
value ==
"LBFGSBpp")
190 throw std::invalid_argument(
"Invalid value '" + std::string(s.
value) +
191 "' for type 'PANOCStopCrit' in '" +
242 PARAMS_MEMBER(recompute_last_prox_step_after_direction_reset),
379template <
class A,
class... Bs>
381 return (std::is_same_v<A, Bs> || ...);
393template <
class NewAlias,
class... PossibleAliases>
395 std::conditional_t<
any_is_same<NewAlias, PossibleAliases...>(),
396 _dummy<NewAlias, PossibleAliases...>, NewAlias>;
400template <
class... Ts>
403#define ALPAQA_SET_PARAM_INST(...) \
404 template void ALPAQA_EXPORT set_param( \
405 detail::possible_alias_t<__VA_ARGS__> &, ParamString)
426#define ALPAQA_SET_PARAM_INST_INT(...) \
427 ALPAQA_SET_PARAM_INST(__VA_ARGS__, int8_t, uint8_t, int16_t, uint16_t, \
428 int32_t, int64_t, uint32_t, uint64_t)
441 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::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.