alpaqa 1.0.0a11
Nonconvex constrained optimization
Loading...
Searching...
No Matches
dl-problem.cpp
Go to the documentation of this file.
2
3#include <dlfcn.h>
4#include <algorithm>
5#include <cassert>
6#include <charconv>
7#include <list>
8#include <memory>
9#include <mutex>
10#include <stdexcept>
11
12namespace alpaqa::dl {
13
14namespace {
15
16std::string format_abi_version(uint64_t version) {
17 std::string s(16, '0');
18 auto begin = s.data(), end = begin + s.size();
19 auto [ptr, ec] = std::to_chars(begin, end, version, 16);
20 if (ec != std::errc())
21 throw std::logic_error(std::make_error_code(ec).message());
22 std::rotate(begin, ptr, end);
23 return s;
24}
25
26void check_abi_version(uint64_t abi_version) {
27 if (abi_version != ALPAQA_DL_ABI_VERSION) {
28 auto prob_version = format_abi_version(abi_version);
29 auto alpaqa_version = format_abi_version(ALPAQA_DL_ABI_VERSION);
30 throw std::runtime_error(
31 "alpaqa::dl::DLProblem::DLProblem: "
32 "Incompatible problem definition (problem ABI version 0x" +
33 prob_version + ", this version of alpaqa supports 0x" +
34 alpaqa_version + ")");
35 }
36}
37
38std::shared_ptr<void> load_lib(const std::string &so_filename) {
39 assert(!so_filename.empty());
40 ::dlerror();
41 void *h = ::dlopen(so_filename.c_str(), RTLD_LOCAL | RTLD_NOW);
42 if (auto *err = ::dlerror())
43 throw std::runtime_error(err);
44 return std::shared_ptr<void>{h, &::dlclose};
45}
46
47template <class F>
48F *load_func(void *handle, std::string symbol_prefix, std::string_view name) {
49 assert(handle);
50 auto &full_name = symbol_prefix;
51 full_name += '_';
52 full_name += name;
53 ::dlerror();
54 auto *h = ::dlsym(handle, full_name.c_str());
55 if (auto *err = ::dlerror())
56 throw std::runtime_error(err);
57 // We can only hope that the user got the signature right ...
58 return reinterpret_cast<F *>(h);
59}
60
61std::mutex leaked_modules_mutex;
62std::list<std::shared_ptr<void>> leaked_modules;
63void leak_lib(std::shared_ptr<void> handle) {
64 std::lock_guard lck{leaked_modules_mutex};
65 leaked_modules.emplace_back(std::move(handle));
66}
67
68} // namespace
69
70DLProblem::DLProblem(const std::string &so_filename, std::string symbol_prefix,
71 void *user_param)
72 : BoxConstrProblem{0, 0} {
73 handle = load_lib(so_filename);
74 auto *register_func = load_func<problem_register_t(void *)>(
75 handle.get(), std::move(symbol_prefix), "register");
76 auto r = register_func(user_param);
77 // Avoid leaking if we throw (or if std::shared_ptr constructor throws)
78 std::unique_ptr<void, void (*)(void *)> unique_inst{r.instance, r.cleanup};
79 std::unique_ptr<alpaqa_function_dict_t> unique_extra{r.extra_functions};
80 std::unique_ptr<alpaqa_exception_ptr_t> unique_exception{r.exception};
81 check_abi_version(r.abi_version);
82 // Check exception thrown by plugin
83 if (unique_exception) {
84 // Here we're facing an interesting problem: the exception we throw
85 // might propagate upwards to a point where this instance is destroyed.
86 // This would cause the shared module to be closed using dlclose.
87 // However, the exception is still stored somewhere in the memory of
88 // that module, causing a segmentation fault when accessed.
89 // To get around this issue, we need to ensure that the shared module
90 // is not closed. Here we simply leak it by storing a shared_ptr to it
91 // in a global variable.
92 leak_lib(handle);
93 std::rethrow_exception(unique_exception->exc);
94 }
95 if (!r.functions)
96 throw std::logic_error("alpaqa::dl::DLProblem::DLProblem: plugin did "
97 "not return any functions");
98 // Store data returned by plugin
99 instance = std::shared_ptr<void>{std::move(unique_inst)};
100 functions = r.functions;
101 extra_funcs = std::shared_ptr<function_dict_t>{std::move(unique_extra)};
102
103 this->n = functions->n;
104 this->m = functions->m;
105 this->C = Box{this->n};
106 this->D = Box{this->m};
108 functions->initialize_box_C(instance.get(), this->C.lowerbound.data(),
109 this->C.upperbound.data());
111 functions->initialize_box_D(instance.get(), this->D.lowerbound.data(),
112 this->D.upperbound.data());
114 length_t nλ = 0;
115 functions->initialize_l1_reg(instance.get(), nullptr, &nλ);
116 if (nλ > 0) {
117 this->l1_reg.resize(nλ);
118 functions->initialize_l1_reg(instance.get(), this->l1_reg.data(),
119 &nλ);
120 }
121 }
122}
123
125 rvec p) const -> real_t {
126 if (functions->eval_prox_grad_step)
127 return functions->eval_prox_grad_step(
128 instance.get(), γ, x.data(), grad_ψ.data(), x̂.data(), p.data());
129 return BoxConstrProblem<config_t>::eval_prox_grad_step(γ, x, grad_ψ, x̂, p);
130}
131
132// clang-format off
133auto DLProblem::eval_f(crvec x) const -> real_t { return functions->eval_f(instance.get(), x.data()); }
134auto DLProblem::eval_grad_f(crvec x, rvec grad_fx) const -> void { return functions->eval_grad_f(instance.get(), x.data(), grad_fx.data()); }
135auto DLProblem::eval_g(crvec x, rvec gx) const -> void { return functions->eval_g(instance.get(), x.data(), gx.data()); }
136auto DLProblem::eval_grad_g_prod(crvec x, crvec y, rvec grad_gxy) const -> void { return functions->eval_grad_g_prod(instance.get(), x.data(), y.data(), grad_gxy.data()); }
137auto DLProblem::eval_grad_gi(crvec x, index_t i, rvec grad_gi) const -> void { return functions->eval_grad_gi(instance.get(), x.data(), i, grad_gi.data()); }
138auto DLProblem::eval_jac_g(crvec x, rindexvec inner_idx, rindexvec outer_ptr, rvec J_values) const -> void { return functions->eval_jac_g(instance.get(), x.data(), inner_idx.data(), outer_ptr.data(), J_values.size() == 0 ? nullptr : J_values.data()); }
140auto DLProblem::eval_hess_L_prod(crvec x, crvec y, real_t scale, crvec v, rvec Hv) const -> void { return functions->eval_hess_L_prod(instance.get(), x.data(), y.data(), scale, v.data(), Hv.data()); }
141auto DLProblem::eval_hess_L(crvec x, crvec y, real_t scale, rindexvec inner_idx, rindexvec outer_ptr, rvec H_values) const -> void { return functions->eval_hess_L(instance.get(), x.data(), y.data(), scale, inner_idx.data(), outer_ptr.data(), H_values.size() == 0 ? nullptr : H_values.data()); }
143auto DLProblem::eval_hess_ψ_prod(crvec x, crvec y, crvec Σ, real_t scale, crvec v, rvec Hv) const -> void { return functions->eval_hess_ψ_prod(instance.get(), x.data(), y.data(), Σ.data(), scale, D.lowerbound.data(), D.upperbound.data(), v.data(), Hv.data()); }
144auto DLProblem::eval_hess_ψ(crvec x, crvec y, crvec Σ, real_t scale, rindexvec inner_idx, rindexvec outer_ptr, rvec H_values) const -> void { return functions->eval_hess_ψ(instance.get(), x.data(), y.data(), Σ.data(), scale, D.lowerbound.data(), D.upperbound.data(), inner_idx.data(), outer_ptr.data(), H_values.size() == 0 ? nullptr : H_values.data()); }
146auto DLProblem::eval_f_grad_f(crvec x, rvec grad_fx) const -> real_t { return functions->eval_f_grad_f(instance.get(), x.data(), grad_fx.data()); }
147auto DLProblem::eval_f_g(crvec x, rvec g) const -> real_t { return functions->eval_f_g(instance.get(), x.data(), g.data()); }
148auto DLProblem::eval_grad_f_grad_g_prod(crvec x, crvec y, rvec grad_f, rvec grad_gxy) const -> void { return functions->eval_grad_f_grad_g_prod(instance.get(), x.data(), y.data(), grad_f.data(), grad_gxy.data()); }
149auto DLProblem::eval_grad_L(crvec x, crvec y, rvec grad_L, rvec work_n) const -> void { return functions->eval_grad_L(instance.get(), x.data(), y.data(), grad_L.data(), work_n.data()); }
150auto DLProblem::eval_ψ(crvec x, crvec y, crvec Σ, rvec ŷ) const -> real_t { return functions->eval_ψ(instance.get(), x.data(), y.data(), Σ.data(), D.lowerbound.data(), D.upperbound.data(), ŷ.data()); }
151auto DLProblem::eval_grad_ψ(crvec x, crvec y, crvec Σ, rvec grad_ψ, rvec work_n, rvec work_m) const -> void { return functions->eval_grad_ψ(instance.get(), x.data(), y.data(), Σ.data(), D.lowerbound.data(), D.upperbound.data(), grad_ψ.data(), work_n.data(), work_m.data()); }
152auto DLProblem::eval_ψ_grad_ψ(crvec x, crvec y, crvec Σ, rvec grad_ψ, rvec work_n, rvec work_m) const -> real_t { return functions->eval_ψ_grad_ψ(instance.get(), x.data(), y.data(), Σ.data(), D.lowerbound.data(), D.upperbound.data(), grad_ψ.data(), work_n.data(), work_m.data()); }
153
154bool DLProblem::provides_eval_f() const { return functions->eval_f != nullptr; }
155bool DLProblem::provides_eval_grad_f() const { return functions->eval_grad_f != nullptr; }
156bool DLProblem::provides_eval_g() const { return functions->eval_g != nullptr; }
158bool DLProblem::provides_eval_jac_g() const { return functions->eval_jac_g != nullptr; }
160bool DLProblem::provides_eval_grad_gi() const { return functions->eval_grad_gi != nullptr; }
162bool DLProblem::provides_eval_hess_L() const { return functions->eval_hess_L != nullptr; }
165bool DLProblem::provides_eval_hess_ψ() const { return functions->eval_hess_ψ != nullptr; }
168bool DLProblem::provides_eval_f_g() const { return functions->eval_f_g != nullptr; }
170bool DLProblem::provides_eval_grad_L() const { return functions->eval_grad_L != nullptr; }
171bool DLProblem::provides_eval_ψ() const { return functions->eval_ψ != nullptr; }
172bool DLProblem::provides_eval_grad_ψ() const { return functions->eval_grad_ψ != nullptr; }
175// clang-format on
176
177#if ALPAQA_WITH_OCP
178
179DLControlProblem::DLControlProblem(const std::string &so_filename,
180 std::string symbol_prefix,
181 void *user_param) {
182 handle = load_lib(so_filename);
183 auto *register_func = load_func<control_problem_register_t(void *)>(
184 handle.get(), std::move(symbol_prefix), "register");
185 auto r = register_func(user_param);
186 // Avoid leaking if we throw (or if std::shared_ptr constructor throws)
187 std::unique_ptr<void, void (*)(void *)> unique_inst{r.instance, r.cleanup};
188 std::unique_ptr<alpaqa_function_dict_t> unique_extra{r.extra_functions};
189 std::unique_ptr<alpaqa_exception_ptr_t> unique_exception{r.exception};
190 check_abi_version(r.abi_version);
191 // Check exception thrown by plugin
192 if (unique_exception) {
193 // Here we're facing an interesting problem: the exception we throw
194 // might propagate upwards to a point where this instance is destroyed.
195 // This would cause the shared module to be closed using dlclose.
196 // However, the exception is still stored somewhere in the memory of
197 // that module, causing a segmentation fault when accessed.
198 // To get around this issue, we need to ensure that the shared module
199 // is not closed. Here we simply leak it by storing a shared_ptr to it
200 // in a global variable.
201 leak_lib(handle);
202 std::rethrow_exception(unique_exception->exc);
203 }
204 if (!functions)
205 throw std::logic_error("alpaqa::dl::DLControlProblem::DLControlProblem:"
206 " plugin did not return any functions");
207 // Store data returned by plugin
208 instance = std::shared_ptr<void>{std::move(unique_inst)};
209 functions = r.functions;
210 extra_funcs = std::shared_ptr<function_dict_t>{std::move(unique_extra)};
211}
212
213// clang-format off
214auto DLControlProblem::get_U(Box &U) const -> void { return functions->get_U(instance.get(), U.lowerbound.data(), U.upperbound.data()); }
215auto DLControlProblem::get_D(Box &D) const -> void { return functions->get_D(instance.get(), D.lowerbound.data(), D.upperbound.data()); }
216auto DLControlProblem::get_D_N(Box &D) const -> void { return functions->get_D_N(instance.get(), D.lowerbound.data(), D.upperbound.data()); }
217auto DLControlProblem::get_x_init(rvec x_init) const -> void { return functions->get_x_init(instance.get(), x_init.data()); }
218auto DLControlProblem::eval_f(index_t timestep, crvec x, crvec u, rvec fxu) const -> void { return functions->eval_f(instance.get(), timestep, x.data(), u.data(), fxu.data()); }
219auto DLControlProblem::eval_jac_f(index_t timestep, crvec x, crvec u, rmat J_fxu) const -> void { return functions->eval_jac_f(instance.get(), timestep, x.data(), u.data(), J_fxu.data()); }
220auto DLControlProblem::eval_grad_f_prod(index_t timestep, crvec x, crvec u, crvec p, rvec grad_fxu_p) const -> void { return functions->eval_grad_f_prod(instance.get(), timestep, x.data(), u.data(), p.data(), grad_fxu_p.data()); }
221auto DLControlProblem::eval_h(index_t timestep, crvec x, crvec u, rvec h) const -> void { return functions->eval_h(instance.get(), timestep, x.data(), u.data(), h.data()); }
222auto DLControlProblem::eval_h_N(crvec x, rvec h) const -> void { return functions->eval_h_N(instance.get(), x.data(), h.data()); }
223auto DLControlProblem::eval_l(index_t timestep, crvec h) const -> real_t { return functions->eval_l(instance.get(), timestep, h.data()); }
224auto DLControlProblem::eval_l_N(crvec h) const -> real_t { return functions->eval_l_N(instance.get(), h.data()); }
225auto DLControlProblem::eval_qr(index_t timestep, crvec xu, crvec h, rvec qr) const -> void { return functions->eval_qr(instance.get(), timestep, xu.data(), h.data(), qr.data()); }
226auto DLControlProblem::eval_q_N(crvec x, crvec h, rvec q) const -> void { return functions->eval_q_N(instance.get(), x.data(), h.data(), q.data()); }
227auto DLControlProblem::eval_add_Q(index_t timestep, crvec xu, crvec h, rmat Q) const -> void { return functions->eval_add_Q(instance.get(), timestep, xu.data(), h.data(), Q.data()); }
228auto DLControlProblem::eval_add_Q_N(crvec x, crvec h, rmat Q) const -> void { return functions->eval_add_Q_N(instance.get(), x.data(), h.data(), Q.data()); }
229auto DLControlProblem::eval_add_R_masked(index_t timestep, crvec xu, crvec h, crindexvec mask, rmat R, rvec work) const -> void { return functions->eval_add_R_masked(instance.get(), timestep, xu.data(), h.data(), mask.data(), R.data(), work.data()); }
230auto DLControlProblem::eval_add_S_masked(index_t timestep, crvec xu, crvec h, crindexvec mask, rmat S, rvec work) const -> void { return functions->eval_add_S_masked(instance.get(), timestep, xu.data(), h.data(), mask.data(), S.data(), work.data()); }
231auto DLControlProblem::eval_add_R_prod_masked(index_t timestep, crvec xu, crvec h, crindexvec mask_J, crindexvec mask_K, crvec v, rvec out, rvec work) const -> void { return functions->eval_add_R_prod_masked(instance.get(), timestep, xu.data(), h.data(), mask_J.data(), mask_K.data(), v.data(), out.data(), work.data()); }
232auto DLControlProblem::eval_add_S_prod_masked(index_t timestep, crvec xu, crvec h, crindexvec mask_K, crvec v, rvec out, rvec work) const -> void { return functions->eval_add_S_prod_masked(instance.get(), timestep, xu.data(), h.data(), mask_K.data(), v.data(), out.data(), work.data()); }
235auto DLControlProblem::eval_constr(index_t timestep, crvec x, rvec c) const -> void { return functions->eval_constr(instance.get(), timestep, x.data(), c.data()); }
236auto DLControlProblem::eval_constr_N(crvec x, rvec c) const -> void { return functions->eval_constr_N(instance.get(), x.data(), c.data()); }
237auto DLControlProblem::eval_grad_constr_prod(index_t timestep, crvec x, crvec p, rvec grad_cx_p) const -> void { return functions->eval_grad_constr_prod(instance.get(), timestep, x.data(), p.data(), grad_cx_p.data()); }
238auto DLControlProblem::eval_grad_constr_prod_N(crvec x, crvec p, rvec grad_cx_p) const -> void { return functions->eval_grad_constr_prod_N(instance.get(), x.data(), p.data(), grad_cx_p.data()); }
239auto DLControlProblem::eval_add_gn_hess_constr(index_t timestep, crvec x, crvec M, rmat out) const -> void { return functions->eval_add_gn_hess_constr(instance.get(), timestep, x.data(), M.data(), out.data()); }
240auto DLControlProblem::eval_add_gn_hess_constr_N(crvec x, crvec M, rmat out) const -> void { return functions->eval_add_gn_hess_constr_N(instance.get(), x.data(), M.data(), out.data()); }
241
242bool DLControlProblem::provides_get_D() const { return functions->get_D != nullptr; }
243bool DLControlProblem::provides_get_D_N() const { return functions->get_D_N != nullptr; }
255// clang-format on
256
257#endif
258
259} // namespace alpaqa::dl
Implements common problem functions for minimization problems with box constraints.
Box C
Constraints of the decision variables, .
length_t m
Number of constraints, dimension of g(x) and z.
length_t n
Number of decision variables, dimension of x.
real_t eval_prox_grad_step(real_t γ, crvec x, crvec grad_ψ, rvec x̂, rvec p) const
vec l1_reg
(1-norm) regularization parameter.
DLControlProblem(const std::string &so_filename, std::string symbol_prefix="alpaqa_control_problem", void *user_param=nullptr)
Load a problem from a shared library.
Definition: dl-problem.cpp:179
void eval_add_S_masked(index_t timestep, crvec xu, crvec h, crindexvec mask, rmat S, rvec work) const
Definition: dl-problem.cpp:230
bool provides_eval_grad_constr_prod() const
Definition: dl-problem.cpp:251
void eval_add_Q_N(crvec x, crvec h, rmat Q) const
Definition: dl-problem.cpp:228
bool provides_eval_add_gn_hess_constr() const
Definition: dl-problem.cpp:253
void eval_q_N(crvec x, crvec h, rvec q) const
Definition: dl-problem.cpp:226
void eval_add_gn_hess_constr(index_t timestep, crvec x, crvec M, rmat out) const
Definition: dl-problem.cpp:239
void eval_grad_constr_prod(index_t timestep, crvec x, crvec p, rvec grad_cx_p) const
Definition: dl-problem.cpp:237
void eval_add_R_prod_masked(index_t timestep, crvec xu, crvec h, crindexvec mask_J, crindexvec mask_K, crvec v, rvec out, rvec work) const
Definition: dl-problem.cpp:231
bool provides_eval_add_R_prod_masked() const
Definition: dl-problem.cpp:245
length_t get_S_work_size() const
Definition: dl-problem.cpp:234
void eval_constr_N(crvec x, rvec c) const
Definition: dl-problem.cpp:236
void get_D_N(Box &D) const
Definition: dl-problem.cpp:216
bool provides_get_S_work_size() const
Definition: dl-problem.cpp:248
void eval_grad_f_prod(index_t timestep, crvec x, crvec u, crvec p, rvec grad_fxu_p) const
Definition: dl-problem.cpp:220
bool provides_eval_add_Q_N() const
Definition: dl-problem.cpp:244
std::shared_ptr< void > instance
Problem instance created by the registration function, including the deleter to destroy it.
Definition: dl-problem.hpp:216
void eval_jac_f(index_t timestep, crvec x, crvec u, rmat J_fxu) const
Definition: dl-problem.cpp:219
real_t eval_l_N(crvec h) const
Definition: dl-problem.cpp:224
void eval_h_N(crvec x, rvec h) const
Definition: dl-problem.cpp:222
real_t eval_l(index_t timestep, crvec h) const
Definition: dl-problem.cpp:223
void eval_grad_constr_prod_N(crvec x, crvec p, rvec grad_cx_p) const
Definition: dl-problem.cpp:238
control_problem_functions_t * functions
Pointer to the struct of function pointers for evaluating the objective, constraints,...
Definition: dl-problem.hpp:219
void eval_add_gn_hess_constr_N(crvec x, crvec M, rmat out) const
Definition: dl-problem.cpp:240
void get_U(Box &U) const
Definition: dl-problem.cpp:214
void eval_f(index_t timestep, crvec x, crvec u, rvec fxu) const
Definition: dl-problem.cpp:218
bool provides_eval_grad_constr_prod_N() const
Definition: dl-problem.cpp:252
length_t get_R_work_size() const
Definition: dl-problem.cpp:233
void eval_add_S_prod_masked(index_t timestep, crvec xu, crvec h, crindexvec mask_K, crvec v, rvec out, rvec work) const
Definition: dl-problem.cpp:232
bool provides_eval_add_S_prod_masked() const
Definition: dl-problem.cpp:246
void get_x_init(rvec x_init) const
Definition: dl-problem.cpp:217
void eval_h(index_t timestep, crvec x, crvec u, rvec h) const
Definition: dl-problem.cpp:221
void eval_add_R_masked(index_t timestep, crvec xu, crvec h, crindexvec mask, rmat R, rvec work) const
Definition: dl-problem.cpp:229
std::shared_ptr< void > handle
Handle to the shared module defining the problem.
Definition: dl-problem.hpp:213
void eval_qr(index_t timestep, crvec xu, crvec h, rvec qr) const
Definition: dl-problem.cpp:225
ExtraFuncs extra_funcs
Dictionary of extra functions that were registered by the problem.
Definition: dl-problem.hpp:221
void get_D(Box &D) const
Definition: dl-problem.cpp:215
bool provides_eval_constr_N() const
Definition: dl-problem.cpp:250
void eval_add_Q(index_t timestep, crvec xu, crvec h, rmat Q) const
Definition: dl-problem.cpp:227
bool provides_get_R_work_size() const
Definition: dl-problem.cpp:247
bool provides_eval_add_gn_hess_constr_N() const
Definition: dl-problem.cpp:254
void eval_constr(index_t timestep, crvec x, rvec c) const
Definition: dl-problem.cpp:235
bool provides_eval_hess_L() const
Definition: dl-problem.cpp:162
real_t eval_prox_grad_step(real_t γ, crvec x, crvec grad_ψ, rvec x̂, rvec p) const
Definition: dl-problem.cpp:124
real_t eval_ψ_grad_ψ(crvec x, crvec y, crvec Σ, rvec grad_ψ, rvec work_n, rvec work_m) const
Definition: dl-problem.cpp:152
void eval_grad_gi(crvec x, index_t i, rvec grad_gi) const
Definition: dl-problem.cpp:137
void eval_hess_L_prod(crvec x, crvec y, real_t scale, crvec v, rvec Hv) const
Definition: dl-problem.cpp:140
bool provides_eval_hess_ψ_prod() const
Definition: dl-problem.cpp:164
void eval_hess_ψ_prod(crvec x, crvec y, crvec Σ, real_t scale, crvec v, rvec Hv) const
Definition: dl-problem.cpp:143
bool provides_eval_ψ_grad_ψ() const
Definition: dl-problem.cpp:173
bool provides_get_box_C() const
Definition: dl-problem.cpp:174
real_t eval_f_g(crvec x, rvec g) const
Definition: dl-problem.cpp:147
bool provides_get_hess_L_num_nonzeros() const
Definition: dl-problem.cpp:163
void eval_hess_L(crvec x, crvec y, real_t scale, rindexvec inner_idx, rindexvec outer_ptr, rvec H_values) const
Definition: dl-problem.cpp:141
void eval_grad_f(crvec x, rvec grad_fx) const
Definition: dl-problem.cpp:134
bool provides_get_jac_g_num_nonzeros() const
Definition: dl-problem.cpp:159
bool provides_eval_jac_g() const
Definition: dl-problem.cpp:158
DLProblem(const std::string &so_filename, std::string symbol_prefix="alpaqa_problem", void *user_param=nullptr)
Load a problem from a shared library.
Definition: dl-problem.cpp:70
void eval_grad_f_grad_g_prod(crvec x, crvec y, rvec grad_f, rvec grad_gxy) const
Definition: dl-problem.cpp:148
real_t eval_ψ(crvec x, crvec y, crvec Σ, rvec ŷ) const
Definition: dl-problem.cpp:150
std::shared_ptr< void > instance
Problem instance created by the registration function, including the deleter to destroy it.
Definition: dl-problem.hpp:110
bool provides_eval_g() const
Definition: dl-problem.cpp:156
void eval_grad_ψ(crvec x, crvec y, crvec Σ, rvec grad_ψ, rvec work_n, rvec work_m) const
Definition: dl-problem.cpp:151
bool provides_eval_grad_f_grad_g_prod() const
Definition: dl-problem.cpp:169
bool provides_eval_f() const
Definition: dl-problem.cpp:154
bool provides_eval_hess_L_prod() const
Definition: dl-problem.cpp:161
bool provides_eval_grad_g_prod() const
Definition: dl-problem.cpp:157
bool provides_get_hess_ψ_num_nonzeros() const
Definition: dl-problem.cpp:166
real_t eval_f_grad_f(crvec x, rvec grad_fx) const
Definition: dl-problem.cpp:146
bool provides_eval_f_grad_f() const
Definition: dl-problem.cpp:167
bool provides_eval_grad_f() const
Definition: dl-problem.cpp:155
bool provides_eval_grad_gi() const
Definition: dl-problem.cpp:160
bool provides_eval_f_g() const
Definition: dl-problem.cpp:168
problem_functions_t * functions
Pointer to the struct of function pointers for evaluating the objective, constraints,...
Definition: dl-problem.hpp:113
real_t eval_f(crvec x) const
Definition: dl-problem.cpp:133
void eval_jac_g(crvec x, rindexvec inner_idx, rindexvec outer_ptr, rvec J_values) const
Definition: dl-problem.cpp:138
bool provides_eval_grad_L() const
Definition: dl-problem.cpp:170
void eval_grad_g_prod(crvec x, crvec y, rvec grad_gxy) const
Definition: dl-problem.cpp:136
bool provides_eval_grad_ψ() const
Definition: dl-problem.cpp:172
length_t get_jac_g_num_nonzeros() const
Definition: dl-problem.cpp:139
std::shared_ptr< void > handle
Handle to the shared module defining the problem.
Definition: dl-problem.hpp:107
ExtraFuncs extra_funcs
Dictionary of extra functions that were registered by the problem.
Definition: dl-problem.hpp:115
bool provides_eval_hess_ψ() const
Definition: dl-problem.cpp:165
void eval_grad_L(crvec x, crvec y, rvec grad_L, rvec work_n) const
Definition: dl-problem.cpp:149
void eval_g(crvec x, rvec gx) const
Definition: dl-problem.cpp:135
void eval_hess_ψ(crvec x, crvec y, crvec Σ, real_t scale, rindexvec inner_idx, rindexvec outer_ptr, rvec H_values) const
Definition: dl-problem.cpp:144
bool provides_eval_ψ() const
Definition: dl-problem.cpp:171
length_t get_hess_ψ_num_nonzeros() const
Definition: dl-problem.cpp:145
length_t get_hess_L_num_nonzeros() const
Definition: dl-problem.cpp:142
#define ALPAQA_DL_ABI_VERSION
Definition: dl-problem.h:9
typename Conf::rmat rmat
Definition: config.hpp:72
typename Conf::real_t real_t
Definition: config.hpp:63
typename Conf::rindexvec rindexvec
Definition: config.hpp:77
typename Conf::index_t index_t
Definition: config.hpp:75
typename Conf::length_t length_t
Definition: config.hpp:74
typename Conf::rvec rvec
Definition: config.hpp:67
typename Conf::crvec crvec
Definition: config.hpp:68
typename Conf::crindexvec crindexvec
Definition: config.hpp:78
void(* eval_add_gn_hess_constr)(void *instance, alpaqa_index_t timestep, const alpaqa_real_t *x, const alpaqa_real_t *M, alpaqa_real_t *out)
Definition: dl-problem.h:393
alpaqa_length_t(* get_S_work_size)(void *instance)
Definition: dl-problem.h:371
void(* eval_grad_constr_prod_N)(void *instance, const alpaqa_real_t *x, const alpaqa_real_t *p, alpaqa_real_t *grad_cx_p)
Definition: dl-problem.h:388
void(* get_D)(void *instance, alpaqa_real_t *lb, alpaqa_real_t *ub)
Definition: dl-problem.h:265
void(* eval_grad_constr_prod)(void *instance, alpaqa_index_t timestep, const alpaqa_real_t *x, const alpaqa_real_t *p, alpaqa_real_t *grad_cx_p)
Definition: dl-problem.h:382
void(* eval_add_R_prod_masked)(void *instance, alpaqa_index_t timestep, const alpaqa_real_t *xu, const alpaqa_real_t *h, const alpaqa_index_t *mask_J, const alpaqa_index_t *mask_K, const alpaqa_real_t *v, alpaqa_real_t *out, alpaqa_real_t *work)
Definition: dl-problem.h:350
void(* eval_add_gn_hess_constr_N)(void *instance, const alpaqa_real_t *x, const alpaqa_real_t *M, alpaqa_real_t *out)
Definition: dl-problem.h:399
alpaqa_length_t(* get_R_work_size)(void *instance)
Definition: dl-problem.h:369
void(* get_D_N)(void *instance, alpaqa_real_t *lb, alpaqa_real_t *ub)
Definition: dl-problem.h:269
void(* eval_constr)(void *instance, alpaqa_index_t timestep, const alpaqa_real_t *x, alpaqa_real_t *c)
Definition: dl-problem.h:373
void(* eval_add_Q_N)(void *instance, const alpaqa_real_t *x, const alpaqa_real_t *h, alpaqa_real_t *Q)
Definition: dl-problem.h:329
void(* eval_add_S_prod_masked)(void *instance, alpaqa_index_t timestep, const alpaqa_real_t *xu, const alpaqa_real_t *h, const alpaqa_index_t *mask_K, const alpaqa_real_t *v, alpaqa_real_t *out, alpaqa_real_t *work)
Definition: dl-problem.h:360
void(* eval_constr_N)(void *instance, const alpaqa_real_t *x, alpaqa_real_t *c)
Definition: dl-problem.h:378
void(* eval_grad_f)(void *instance, const alpaqa_real_t *x, alpaqa_real_t *grad_fx)
Gradient of the cost function.
Definition: dl-problem.h:41
alpaqa_real_t(* eval_ψ)(void *instance, const alpaqa_real_t *x, const alpaqa_real_t *y, const alpaqa_real_t *Σ, const alpaqa_real_t *zl, const alpaqa_real_t *zu, alpaqa_real_t *ŷ)
Augmented Lagrangian.
Definition: dl-problem.h:159
void(* eval_hess_ψ_prod)(void *instance, const alpaqa_real_t *x, const alpaqa_real_t *y, const alpaqa_real_t *Σ, alpaqa_real_t scale, const alpaqa_real_t *zl, const alpaqa_real_t *zu, const alpaqa_real_t *v, alpaqa_real_t *Hv)
Hessian-vector product of the augmented Lagrangian.
Definition: dl-problem.h:102
void(* initialize_box_C)(void *instance, alpaqa_real_t *lb, alpaqa_real_t *ub)
Provide the initial values for the bounds of alpaqa::BoxConstrProblem::C, i.e.
Definition: dl-problem.h:205
alpaqa_real_t(* eval_prox_grad_step)(void *instance, alpaqa_real_t γ, const alpaqa_real_t *x, const alpaqa_real_t *grad_ψ, alpaqa_real_t *x̂, alpaqa_real_t *p)
Proximal gradient step.
Definition: dl-problem.h:195
alpaqa_real_t(* eval_f_g)(void *instance, const alpaqa_real_t *x, alpaqa_real_t *g)
Cost and constraints.
Definition: dl-problem.h:137
void(* eval_grad_f_grad_g_prod)(void *instance, const alpaqa_real_t *x, const alpaqa_real_t *y, alpaqa_real_t *grad_f, alpaqa_real_t *grad_gxy)
Gradient of the cost and gradient-vector product of the constraints.
Definition: dl-problem.h:143
alpaqa_length_t(* get_hess_ψ_num_nonzeros)(void *instance)
Number of nonzeros of the sparse Hessian of the augmented Lagrangian.
Definition: dl-problem.h:127
void(* eval_grad_L)(void *instance, const alpaqa_real_t *x, const alpaqa_real_t *y, alpaqa_real_t *grad_L, alpaqa_real_t *work_n)
Gradient of the Lagrangian.
Definition: dl-problem.h:151
alpaqa_real_t(* eval_f_grad_f)(void *instance, const alpaqa_real_t *x, alpaqa_real_t *grad_fx)
Cost and its gradient.
Definition: dl-problem.h:131
alpaqa_real_t(* eval_f)(void *instance, const alpaqa_real_t *x)
Cost function.
Definition: dl-problem.h:36
void(* eval_hess_L)(void *instance, const alpaqa_real_t *x, const alpaqa_real_t *y, alpaqa_real_t scale, alpaqa_index_t *inner_idx, alpaqa_index_t *outer_ptr, alpaqa_real_t *H_values)
Hessian of the Lagrangian.
Definition: dl-problem.h:88
alpaqa_length_t m
Number of constraints.
Definition: dl-problem.h:31
void(* eval_grad_ψ)(void *instance, const alpaqa_real_t *x, const alpaqa_real_t *y, const alpaqa_real_t *Σ, const alpaqa_real_t *zl, const alpaqa_real_t *zu, alpaqa_real_t *grad_ψ, alpaqa_real_t *work_n, alpaqa_real_t *work_m)
Gradient of the augmented Lagrangian.
Definition: dl-problem.h:169
alpaqa_length_t n
Number of decision variables.
Definition: dl-problem.h:28
void(* eval_grad_gi)(void *instance, const alpaqa_real_t *x, alpaqa_index_t i, alpaqa_real_t *grad_gi)
Gradient of specific constraint function.
Definition: dl-problem.h:72
void(* eval_hess_ψ)(void *instance, const alpaqa_real_t *x, const alpaqa_real_t *y, const alpaqa_real_t *Σ, alpaqa_real_t scale, const alpaqa_real_t *zl, const alpaqa_real_t *zu, alpaqa_index_t *inner_idx, alpaqa_index_t *outer_ptr, alpaqa_real_t *H_values)
Hessian of the augmented Lagrangian.
Definition: dl-problem.h:114
void(* initialize_l1_reg)(void *instance, alpaqa_real_t *lambda, alpaqa_length_t *size)
Provide the initial values for alpaqa::BoxConstrProblem::l1_reg, the ℓ₁-regularization factor.
Definition: dl-problem.h:221
alpaqa_length_t(* get_jac_g_num_nonzeros)(void *instance)
Number of nonzeros of the sparse Jacobian of the constraints function.
Definition: dl-problem.h:68
void(* eval_hess_L_prod)(void *instance, const alpaqa_real_t *x, const alpaqa_real_t *y, alpaqa_real_t scale, const alpaqa_real_t *v, alpaqa_real_t *Hv)
Hessian-vector product of the Lagrangian.
Definition: dl-problem.h:79
void(* eval_g)(void *instance, const alpaqa_real_t *x, alpaqa_real_t *gx)
Constraints function.
Definition: dl-problem.h:47
void(* initialize_box_D)(void *instance, alpaqa_real_t *lb, alpaqa_real_t *ub)
Provide the initial values for the bounds of alpaqa::BoxConstrProblem::D, i.e.
Definition: dl-problem.h:211
void(* eval_jac_g)(void *instance, const alpaqa_real_t *x, alpaqa_index_t *inner_idx, alpaqa_index_t *outer_ptr, alpaqa_real_t *J_values)
Jacobian of the constraints function.
Definition: dl-problem.h:60
alpaqa_length_t(* get_hess_L_num_nonzeros)(void *instance)
Number of nonzeros of the sparse Hessian of the Lagrangian.
Definition: dl-problem.h:98
alpaqa_real_t(* eval_ψ_grad_ψ)(void *instance, const alpaqa_real_t *x, const alpaqa_real_t *y, const alpaqa_real_t *Σ, const alpaqa_real_t *zl, const alpaqa_real_t *zu, alpaqa_real_t *grad_ψ, alpaqa_real_t *work_n, alpaqa_real_t *work_m)
Augmented Lagrangian and its gradient.
Definition: dl-problem.h:181
void(* eval_grad_g_prod)(void *instance, const alpaqa_real_t *x, const alpaqa_real_t *y, alpaqa_real_t *grad_gxy)
Gradient-vector product of the constraints function.
Definition: dl-problem.h:53