aligator  0.6.1
A primal-dual augmented Lagrangian-type solver for nonlinear trajectory optimization.
Loading...
Searching...
No Matches
expose-solver-prox.cpp
Go to the documentation of this file.
1
6
8
9#include <eigenpy/std-unique-ptr.hpp>
10
11namespace aligator {
12namespace python {
13
14BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(prox_run_overloads, run, 1, 4)
15
17 using context::ConstVectorRef;
18 using context::Results;
19 using context::Scalar;
21 using context::VectorRef;
23
24 eigenpy::register_symbolic_link_to_registered_type<
25 Linesearch<Scalar>::Options>();
26 eigenpy::register_symbolic_link_to_registered_type<LinesearchStrategy>();
27 eigenpy::register_symbolic_link_to_registered_type<
28 proxsuite::nlp::LSInterpolation>();
29 eigenpy::register_symbolic_link_to_registered_type<context::BCLParams>();
30
31 bp::enum_<LQSolverChoice>("LQSolverChoice")
32 .value("LQ_SOLVER_SERIAL", LQSolverChoice::SERIAL)
33 .value("LQ_SOLVER_PARALLEL", LQSolverChoice::PARALLEL)
34 .value("LQ_SOLVER_STAGEDENSE", LQSolverChoice::STAGEDENSE)
35 .export_values();
36
37 using ProxScaler = ConstraintProximalScalerTpl<Scalar>;
38 bp::class_<ProxScaler, boost::noncopyable>("ProxScaler", bp::no_init)
39 .def(
40 "set_weight",
41 +[](ProxScaler &s, Scalar v, std::size_t j) {
42 if (j >= s.size()) {
43 PyErr_SetString(PyExc_IndexError, "Index out of bounds.");
44 bp::throw_error_already_set();
45 }
46 s.setWeight(v, j);
47 },
48 ("self"_a, "value", "j"))
49 .add_property("size", &ProxScaler::size,
50 "Get the number of constraint blocks.")
51 .def(
52 "setWeights",
53 +[](ProxScaler &s, const ConstVectorRef &w) {
54 if (s.size() != std::size_t(w.size())) {
55 PyErr_SetString(PyExc_ValueError, "Input has wrong dimension.");
56 }
57 s.setWeights(w);
58 },
59 "Vector of weights for each constraint in the stack.")
60 .add_property(
61 "matrix", +[](ProxScaler &sc) -> ConstVectorRef {
62 return sc.diagMatrix().toDenseMatrix();
63 });
64
65 bp::class_<Workspace, bp::bases<WorkspaceBaseTpl<Scalar>>,
66 boost::noncopyable>(
67 "Workspace", "Workspace for ProxDDP.",
68 bp::init<const TrajOptProblem &>(("self"_a, "problem")))
69 .def(
70 "getConstraintScaler",
71 +[](const Workspace &ws, std::size_t j) -> const ProxScaler & {
72 if (j >= ws.cstr_scalers.size()) {
73 PyErr_SetString(PyExc_IndexError, "Index out of bounds.");
74 bp::throw_error_already_set();
75 }
76 return ws.cstr_scalers[j];
77 },
78 ("self"_a, "j"), bp::return_internal_reference<>(),
79 "Scalers of the constraints in the proximal algorithm.")
80 .def_readonly("lqr_problem", &Workspace::lqr_problem,
81 "Buffers for the LQ subproblem.")
82 .def_readonly("Lxs", &Workspace::Lxs)
83 .def_readonly("Lus", &Workspace::Lus)
84 .def_readonly("Lds", &Workspace::Lds)
85 .def_readonly("Lvs", &Workspace::Lvs)
86 .def_readonly("dxs", &Workspace::dxs)
87 .def_readonly("dus", &Workspace::dus)
88 .def_readonly("dvs", &Workspace::dvs)
89 .def_readonly("dlams", &Workspace::dlams)
90 .def_readonly("trial_vs", &Workspace::trial_vs)
91 .def_readonly("trial_lams", &Workspace::trial_lams)
92 .def_readonly("lams_plus", &Workspace::lams_plus)
93 .def_readonly("lams_pdal", &Workspace::lams_pdal)
94 .def_readonly("vs_plus", &Workspace::vs_plus)
95 .def_readonly("vs_pdal", &Workspace::vs_pdal)
96 .def_readonly("shifted_constraints", &Workspace::shifted_constraints)
97 .def_readonly("cstr_proj_jacs", &Workspace::cstr_proj_jacs)
98 .def_readonly("inner_crit", &Workspace::inner_criterion)
99 .def_readonly("active_constraints", &Workspace::active_constraints)
100 .def_readonly("prev_xs", &Workspace::prev_xs)
101 .def_readonly("prev_us", &Workspace::prev_us)
102 .def_readonly("prev_lams", &Workspace::prev_lams)
103 .def_readonly("prev_vs", &Workspace::prev_vs)
104 .def_readonly("stage_infeasibilities", &Workspace::stage_infeasibilities)
105 .def_readonly("state_dual_infeas", &Workspace::state_dual_infeas)
106 .def_readonly("control_dual_infeas", &Workspace::control_dual_infeas)
107 .def(PrintableVisitor<Workspace>());
108
109 bp::class_<Results, bp::bases<ResultsBaseTpl<Scalar>>, boost::noncopyable>(
110 "Results", "Results struct for proxDDP.",
111 bp::init<const TrajOptProblem &>(("self"_a, "problem")))
112 .def_readonly("al_iter", &Results::al_iter)
113 .def_readonly("lams", &Results::lams)
114 .def(PrintableVisitor<Results>());
115
116 using SolverType = SolverProxDDPTpl<Scalar>;
117
118 bp::class_<SolverType, boost::noncopyable>(
119 "SolverProxDDP",
120 "A proximal, augmented Lagrangian solver, using a DDP-type scheme to "
121 "compute "
122 "search directions and feedforward, feedback gains."
123 " The solver instance initializes both a Workspace and a Results struct.",
124 bp::init<Scalar, Scalar, Scalar, std::size_t, VerboseLevel,
125 HessianApprox>(("self"_a, "tol", "mu_init"_a = 1e-2,
126 "rho_init"_a = 0., "max_iters"_a = 1000,
127 "verbose"_a = VerboseLevel::QUIET,
128 "hess_approx"_a = HessianApprox::GAUSS_NEWTON)))
129 .def_readwrite("bcl_params", &SolverType::bcl_params, "BCL parameters.")
130 .def_readwrite("max_refinement_steps", &SolverType::maxRefinementSteps_)
131 .def_readwrite("refinement_threshold", &SolverType::refinementThreshold_)
132 .def_readwrite("linear_solver_choice", &SolverType::linear_solver_choice)
133 .def_readwrite("multiplier_update_mode",
134 &SolverType::multiplier_update_mode)
135 .def_readwrite("mu_init", &SolverType::mu_init,
136 "Initial AL penalty parameter.")
137 .add_property("mu", &SolverType::mu)
138 .def_readwrite("rho_init", &SolverType::rho_init,
139 "Initial proximal regularization.")
140 .def_readwrite("mu_min", &SolverType::mu_lower_bound,
141 "Lower bound on the AL penalty parameter.")
142 .def_readwrite(
143 "rollout_max_iters", &SolverType::rollout_max_iters,
144 "Maximum number of iterations when solving the forward dynamics.")
145 .def_readwrite("max_al_iters", &SolverType::max_al_iters,
146 "Maximum number of AL iterations.")
147 .def_readwrite("ls_mode", &SolverType::ls_mode, "Linesearch mode.")
148 .def_readwrite("sa_strategy", &SolverType::sa_strategy,
149 "StepAcceptance strategy.")
150 .def_readwrite("rollout_type", &SolverType::rollout_type_,
151 "Rollout type.")
152 .def_readwrite("dual_weight", &SolverType::dual_weight,
153 "Dual penalty weight.")
154 .def_readwrite("reg_min", &SolverType::reg_min,
155 "Minimum regularization value.")
156 .def_readwrite("reg_max", &SolverType::reg_max,
157 "Maximum regularization value.")
158 .def_readwrite("preg", &SolverType::preg_,
159 "Primal regularization parameter.")
160 .def_readwrite("lq_print_detailed", &SolverType::lq_print_detailed)
161 .def("updateLQSubproblem", &SolverType::updateLQSubproblem, "self"_a)
162 .def("computeCriterion", &SolverType::computeCriterion, "self"_a,
163 "Compute problem stationarity.")
164 .add_property("linearSolver",
165 bp::make_getter(&SolverType::linearSolver_,
166 eigenpy::ReturnInternalStdUniquePtr{}),
167 "Linear solver for the semismooth Newton method.")
168 .def_readwrite("filter", &SolverType::filter_,
169 "Pair filter used to accept a step.")
170 .def("computeInfeasibilities", &SolverType::computeInfeasibilities,
171 ("self"_a, "problem"), "Compute problem infeasibilities.")
172 .def(SolverVisitor<SolverType>())
173 .def("run", &SolverType::run,
174 prox_run_overloads(
175 ("self"_a, "problem", "xs_init", "us_init", "lams_init"),
176 "Run the algorithm. Can receive initial guess for "
177 "multiplier trajectory."));
178}
179
180} // namespace python
181} // namespace aligator
WorkspaceTpl< Scalar > Workspace
Definition context.hpp:44
TrajOptProblemTpl< Scalar > TrajOptProblem
Definition context.hpp:34
Main package namespace.
HessianApprox
Definition enums.hpp:14
@ GAUSS_NEWTON
Use the Gauss-Newton approximation.
Definitions for the proximal trajectory optimization algorithm.