34template <
class Rep,
class Period>
37template <
class Duration>
42 "Invalid value " +
to_string(
j) +
" for type '" +
44 std::string value =
j;
49 "Invalid value '" + value +
"' for type '" +
51 std::string(std::string_view(value.data(), e.
result.ptr)));
54 "Invalid units '" + std::string(e.units) +
"' for type '" +
59template <
class Duration>
62 namespace chr = std::chrono;
65 if (
dur.count() == 0) {
69 result += std::to_string(d.count()) +
"h";
73 result += std::to_string(d.count()) +
"min";
77 result += std::to_string(d.count()) +
"s";
81 result += std::to_string(d.count()) +
"ms";
85 result += std::to_string(d.count()) +
"µs";
89 result += std::to_string(d.count()) +
"ns";
93 s = std::move(result);
101 "' (expected an array, but got " +
102 j.type_name() +
')');
107 }
catch (json::exception &e) {
109 " (expected a number, but got " +
110 j.type_name() +
')');
113 std::ranges::transform(
j,
v.begin(),
convert);
120 std::ifstream f(
fpath);
126 auto r = alpaqa::csv::read_row_std_vector<real_t<config_t>>(f);
128 if (
v.expected_size >= 0 &&
r_size !=
v.expected_size)
130 "Incorrect size in '" +
fpath +
"' (expected " +
131 std::to_string(
v.expected_size) +
", but got " +
132 std::to_string(r.size()) +
")");
136 "': alpaqa::csv::read_error: " + e.what());
138 }
else if (
j.is_array()) {
140 if (
v.expected_size >= 0 &&
v.value->size() !=
v.expected_size)
142 "Incorrect size in " +
to_string(
j) +
"' (expected " +
143 std::to_string(
v.expected_size) +
", but got " +
144 std::to_string(
v.value->size()) +
')');
148 "' (expected string or array, but got " +
149 j.type_name() +
')');
158 "' (expected boolean, but got " +
159 j.type_name() +
')');
168 "' (expected string, but got " +
169 j.type_name() +
')');
173template <std::
integral T>
174 requires(!std::same_as<T, bool>)
176 if (std::unsigned_integral<T> && !
j.is_number_unsigned())
179 "' (expected unsigned integer, but got " +
180 j.type_name() +
')');
181 if (!
j.is_number_integer())
184 "' (expected integer, but got " +
185 j.type_name() +
')');
189template <std::
floating_po
int T>
193 t = std::numeric_limits<T>::quiet_NaN();
194 }
else if (
j ==
"inf" ||
j ==
"+inf") {
195 t = std::numeric_limits<T>::infinity();
196 }
else if (
j ==
"-inf") {
197 t = -std::numeric_limits<T>::infinity();
202 "' (expected number or any of "
203 "\"nan\", \"inf\", \"+inf\", \"-inf\")");
205 }
else if (
j.is_number()) {
210 "' (expected number, but got " +
211 j.type_name() +
')');
216 requires(std::integral<T> || std::same_as<T, bool> ||
217 std::same_as<T, std::string>)
222template <std::
floating_po
int T>
226 else if (t == +std::numeric_limits<T>::infinity())
228 else if (t == -std::numeric_limits<T>::infinity())
236 if (
j ==
"BasedOnExternalStepSize")
238 else if (
j ==
"BasedOnCurvature")
242 " for type 'LBFGSStepSize'");
252 if (
j ==
"ApproxKKT")
254 else if (
j ==
"ApproxKKT2")
256 else if (
j ==
"ProjGradNorm")
258 else if (
j ==
"ProjGradNorm2")
260 else if (
j ==
"ProjGradUnitNorm")
262 else if (
j ==
"ProjGradUnitNorm2")
264 else if (
j ==
"FPRNorm")
266 else if (
j ==
"FPRNorm2")
268 else if (
j ==
"Ipopt")
270 else if (
j ==
"LBFGSBpp")
274 " for type 'PANOCStopCrit'");
284template <
class... Ts>
286template <
class... Ts>
289#define ALPAQA_GET_PARAM_INST(...) \
290 template void ALPAQA_EXPORT get_param( \
291 const util::possible_alias_t<__VA_ARGS__> &, json &)
292#define ALPAQA_GETSET_PARAM_INST(...) \
293 template void ALPAQA_EXPORT set_param( \
294 util::possible_alias_t<__VA_ARGS__> &, const json &); \
295 template void ALPAQA_EXPORT get_param( \
296 const util::possible_alias_t<__VA_ARGS__> &, json &)
321#define ALPAQA_GETSET_PARAM_INST_INT(...) \
322 ALPAQA_GETSET_PARAM_INST(__VA_ARGS__, int8_t, uint8_t, int16_t, uint16_t, \
323 int32_t, int64_t, uint32_t, uint64_t)
336 unsigned int,
unsigned short);
std::string demangled_typename(const std::type_info &t)
Get the pretty name of the given type as a string.
Parameters for the Augmented Lagrangian solver.
Parameters for the AndersonAccel class.
Parameters for the AndersonDirection class.
Tuning parameters for the FISTA algorithm.
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.
#define ALPAQA_GETSET_PARAM_INST(...)
#define ALPAQA_GETSET_PARAM_INST_INT(...)
#define ALPAQA_GET_PARAM_INST(...)
void get_param(const T &t, json &s)
Get the first argument as a JSON object j.
constexpr bool is_duration
void set_param(T &t, const json &j)
Update/overwrite the first argument based on the JSON object j.
Unused unique type tag for template specializations that were rejected because some types were not di...
void parse_duration(std::chrono::duration< Rep, Period > &t, std::string_view s)
Adds the sum of the durations in the string s to the duration t.
@ 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::real_t real_t
typename Conf::length_t length_t
typename Conf::cmvec cmvec
constexpr const char * enum_name(LBFGSStepSize s)
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.
Parameters for the StructuredLBFGSDirection class.
Custom parameter parsing exception.
std::from_chars_result result