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'");
53 requires((std::floating_point<T> || std::integral<T>) && !std::is_enum_v<T>)
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
76 v.resize(std::count(s.
value.begin(), s.
value.end(),
',') + 1);
87 if (s.
value.starts_with(
'@')) {
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);
97 if (
v.expected_size >= 0 &&
r_size !=
v.expected_size)
98 throw std::invalid_argument(
99 "Incorrect size in '" + std::string(s.
full_key) +
100 "' (got " + std::to_string(r.size()) +
", expected " +
101 std::to_string(
v.expected_size) +
')');
104 throw std::invalid_argument(
105 "Unable to read from file '" +
fpath +
"' in '" +
107 "': alpaqa::csv::read_error: " + e.what());
111 if (
v.expected_size >= 0 &&
v.value->size() !=
v.expected_size)
112 throw std::invalid_argument(
113 "Incorrect size in '" + std::string(s.
full_key) +
"' (got " +
114 std::to_string(
v.value->size()) +
", expected " +
115 std::to_string(
v.expected_size) +
')');
119template <
class Rep,
class Period>
121 using Duration = std::remove_cvref_t<
decltype(t)>;
125#if ALPAQA_USE_FROM_CHARS_FLOAT
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());
137 }
catch (std::exception &e) {
138 throw std::invalid_argument(
139 "Invalid value '" + std::string(s.
value) +
"' for type '" +
141 std::string(s.
full_key) +
"': " + e.what());
146 auto cast = [](
auto t) {
return std::chrono::duration_cast<Duration>(t); };
148 t =
cast(std::chrono::duration<
double, std::ratio<1, 1>>{value});
149 else if (
units ==
"ms")
150 t =
cast(std::chrono::duration<
double, std::ratio<1, 1000>>{value});
152 t =
cast(std::chrono::duration<
double, std::ratio<1, 1000000>>{value});
153 else if (
units ==
"ns")
155 std::chrono::duration<
double, std::ratio<1, 1000000000>>{value});
156 else if (
units ==
"min")
157 t =
cast(std::chrono::duration<
double, std::ratio<60, 1>>{value});
159 throw std::invalid_argument(
"Invalid units '" + std::string(
units) +
160 "' in '" + std::string(s.
full_key) +
"'");
165 if (s.
value ==
"BasedOnExternalStepSize")
167 else if (s.
value ==
"BasedOnCurvature")
170 throw std::invalid_argument(
"Invalid value '" + std::string(s.
value) +
171 "' for type 'LBFGSStepSize' in '" +
177 if (s.
value ==
"ApproxKKT")
179 else if (s.
value ==
"ApproxKKT2")
181 else if (s.
value ==
"ProjGradNorm")
183 else if (s.
value ==
"ProjGradNorm2")
185 else if (s.
value ==
"ProjGradUnitNorm")
187 else if (s.
value ==
"ProjGradUnitNorm2")
189 else if (s.
value ==
"FPRNorm")
191 else if (s.
value ==
"FPRNorm2")
193 else if (s.
value ==
"Ipopt")
195 else if (s.
value ==
"LBFGSBpp")
198 throw std::invalid_argument(
"Invalid value '" + std::string(s.
value) +
199 "' for type 'PANOCStopCrit' in '" +
250 PARAMS_MEMBER(recompute_last_prox_step_after_direction_reset),
271 PARAMS_MEMBER(recompute_last_prox_step_after_stepsize_change),
291 PARAMS_MEMBER(recompute_last_prox_step_after_stepsize_change),
378template <
class A,
class...
Bs>
380 return (std::is_same_v<A, Bs> || ...);
399template <
class... Ts>
402#define ALPAQA_SET_PARAM_INST(...) \
403 template void ALPAQA_EXPORT set_param( \
404 detail::possible_alias_t<__VA_ARGS__> &, ParamString)
425#define ALPAQA_SET_PARAM_INST_INT(...) \
426 ALPAQA_SET_PARAM_INST(__VA_ARGS__, int8_t, uint8_t, int16_t, uint16_t, \
427 int32_t, int64_t, uint32_t, uint64_t)
440 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)
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 estimation of the Lipschitz constant of the gradient of the smooth term of the cos...
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 SteihaugCG.
Parameters for the StructuredNewtonDirection class.
Parameters for the StructuredNewtonDirection class.
Tuning parameters for the ZeroFPR algorithm.
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:
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 , where is the forward-backward splitting step size.
#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.