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());
134#pragma message "Using std::stod as a fallback to replace std::from_chars"
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());
147 auto cast = [](
auto t) {
return std::chrono::duration_cast<Duration>(t); };
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});
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),
389template <
class A,
class...
Bs>
391 return (std::is_same_v<A, Bs> || ...);
410template <
class... Ts>
413#define ALPAQA_SET_PARAM_INST(...) \
414 template void ALPAQA_EXPORT set_param( \
415 detail::possible_alias_t<__VA_ARGS__> &, ParamString)
436#define ALPAQA_SET_PARAM_INST_INT(...) \
437 ALPAQA_SET_PARAM_INST(__VA_ARGS__, int8_t, uint8_t, int16_t, uint16_t, \
438 int32_t, int64_t, uint32_t, uint64_t)
451 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::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.