15 using context::ConstVectorRef;
17 using context::VectorRef;
18 using eigenpy::deprecated_member;
19 using eigenpy::DeprecationType;
20 using eigenpy::ReturnInternalStdUniquePtr;
22 bp::enum_<VerboseLevel>(
"VerboseLevel",
"Verbose level for the solver.")
23 .value(
"QUIET",
QUIET)
28 bp::enum_<LinesearchStrategy>(
30 "Linesearch strategy. Only Armijo linesearch is implemented for now.")
33 bp::enum_<HessianApprox>(
"HessianApprox",
34 "Type of approximation of the Lagrangian Hessian.")
39 bp::enum_<MultiplierUpdateMode>(
"MultiplierUpdateMode",
40 "Type of multiplier update.")
46 bp::enum_<LSInterpolation>(
"LSInterpolation",
47 "Linesearch interpolation scheme.")
52 bp::enum_<LDLTChoice>(
"LDLTChoice",
"Choice of LDLT solver.")
62 bp::class_<Linesearch>(
"Linesearch", bp::no_init)
63 .def(bp::init<const LinesearchOptions &>((
"self"_a,
"options")))
65 bp::class_<ArmijoLinesearch<Scalar>, bp::bases<Linesearch>>(
66 "ArmijoLinesearch", bp::no_init)
67 .def(bp::init<const LinesearchOptions &>((
"self"_a,
"options")));
68 bp::class_<LinesearchOptions>(
"LinesearchOptions",
"Linesearch options.",
69 bp::init<>((
"self"_a),
"Default constructor."))
70 .def_readwrite(
"armijo_c1", &LinesearchOptions::armijo_c1)
71 .def_readwrite(
"wolfe_c2", &LinesearchOptions::wolfe_c2)
73 "dphi_thresh", &LinesearchOptions::dphi_thresh,
74 "Threshold on the derivative at the initial point; the linesearch "
75 "will be early-terminated if the derivative is below this threshold.")
76 .def_readwrite(
"alpha_min", &LinesearchOptions::alpha_min,
78 .def_readwrite(
"max_num_steps", &LinesearchOptions::max_num_steps)
79 .def_readwrite(
"interp_type", &LinesearchOptions::interp_type,
80 "Interpolation type: bisection, quadratic or cubic.")
81 .def_readwrite(
"contraction_min", &LinesearchOptions::contraction_min,
82 "Minimum step contraction.")
83 .def_readwrite(
"contraction_max", &LinesearchOptions::contraction_max,
84 "Maximum step contraction.")
85 .def(bp::self_ns::str(bp::self));
90 const ConstVectorRef &,
const std::vector<VectorRef> &);
92 const ConstVectorRef &,
const ConstVectorRef &);
94#pragma GCC diagnostic push
95#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
97 bp::class_<ProxNLPSolver, boost::noncopyable>(
99 "Semi-smooth Newton-based solver for nonlinear optimization using a "
100 "primal-dual method of multipliers. This solver works by approximately "
101 "solving the proximal subproblems in the method of multipliers.",
102 bp::init<Problem &, Scalar, Scalar, Scalar,
VerboseLevel, Scalar, Scalar,
104 (
"self"_a,
"problem",
"tol"_a = 1e-6,
"mu_init"_a = 1e-2,
106 "mu_min"_a = 1e-9,
"prim_alpha"_a = 0.1,
"prim_beta"_a = 0.9,
107 "dual_alpha"_a = 1.,
"dual_beta"_a = 1.,
109 .add_property(
"problem",
110 bp::make_function(&ProxNLPSolver::problem,
111 bp::return_internal_reference<>()),
112 "The general nonlinear program to solve.")
113 .add_property(
"manifold",
114 bp::make_function(&ProxNLPSolver::manifold,
115 bp::return_internal_reference<>()),
116 "The solver's working manifold.")
117 .def_readwrite(
"hess_approx", &ProxNLPSolver::hess_approx)
118 .def_readwrite(
"ls_strat", &ProxNLPSolver::ls_strat)
119 .def(
"register_callback", &ProxNLPSolver::registerCallback,
120 (
"self"_a,
"cb"),
"Add a callback to the solver.")
121 .def(
"clear_callbacks", &ProxNLPSolver::clearCallbacks,
122 "Clear callbacks.", (
"self"_a))
123 .def_readwrite(
"verbose", &ProxNLPSolver::verbose,
124 "Solver verbose setting.")
125 .def_readwrite(
"ldlt_choice", &ProxNLPSolver::ldlt_choice_,
126 "Use the BlockLDLT solver.")
127 .def(
"setup", &ProxNLPSolver::setup, (
"self"_a),
128 "Initialize the solver workspace and results.")
129 .def(
"getResults", &ProxNLPSolver::getResults, (
"self"_a),
130 deprecated_member<DeprecationType::DEPRECATION,
131 bp::return_internal_reference<>>(
132 "This getter has been deprecated."),
133 "Get a reference to the results object.")
134 .def(
"getWorkspace", &ProxNLPSolver::getWorkspace, (
"self"_a),
135 deprecated_member<DeprecationType::DEPRECATION,
136 bp::return_internal_reference<>>(
137 "This getter has been deprecated."),
138 "Get a reference to the workspace object.")
139 .add_property(
"workspace", bp::make_getter(&ProxNLPSolver::workspace_,
140 ReturnInternalStdUniquePtr{}))
141 .add_property(
"results", bp::make_getter(&ProxNLPSolver::results_,
142 ReturnInternalStdUniquePtr{}))
143 .def<solve_std_vec_ins_t>(
144 "solve", &ProxNLPSolver::solve, (
"self"_a,
"x0",
"lams0"),
145 "Run the solver (multiplier guesses given as a list).")
146 .def<solve_eig_vec_ins_t>(
147 "solve", &ProxNLPSolver::solve,
148 (
"self"_a,
"x0",
"lams0"_a = context::VectorXs(0)),
"Run the solver.")
149 .def(
"setPenalty", &ProxNLPSolver::setPenalty, (
"self"_a,
"mu"),
150 "Set the augmented Lagrangian penalty parameter.")
151 .def(
"setDualPenalty", &ProxNLPSolver::setDualPenalty,
153 "Set the dual variable penalty for the linesearch merit "
155 .def(
"setProxParameter", &ProxNLPSolver::setProxParameter,
156 (
"self"_a,
"rho"),
"Set the primal proximal penalty parameter.")
157 .def_readwrite(
"mu_init", &ProxNLPSolver::mu_init_,
158 "Initial AL parameter value.")
159 .def_readwrite(
"rho_init", &ProxNLPSolver::rho_init_,
160 "Initial proximal parameter value.")
161 .def_readwrite(
"mu_lower", &ProxNLPSolver::mu_lower_,
162 "Lower bound :math:`\\underline{\\mu} > 0` for the "
164 .def_readwrite(
"mu_upper", &ProxNLPSolver::mu_upper_,
165 "Upper bound :math:`\\bar{\\mu}` for the AL parameter. "
166 "The tolerances for "
167 "each subproblem will be updated as :math:`\\eta^0 (\\mu "
168 "/ \\bar{\\mu})^\\gamma`")
170 .def_readwrite(
"bcl_params", &ProxNLPSolver::bcl_params,
172 .def_readwrite(
"target_tol", &ProxNLPSolver::target_tol,
174 .def_readwrite(
"ls_options", &ProxNLPSolver::ls_options,
175 "Linesearch options.")
176 .def_readwrite(
"mul_update_mode", &ProxNLPSolver::mul_update_mode,
177 "Type of multiplier update.")
178 .def_readwrite(
"kkt_system", &ProxNLPSolver::kkt_system_,
180 .def_readwrite(
"max_refinement_steps",
181 &ProxNLPSolver::max_refinement_steps_,
182 "Maximum number of iterative refinement steps.")
183 .def_readwrite(
"kkt_tolerance", &ProxNLPSolver::kkt_tolerance_,
184 "Acceptable tolerance for the KKT linear system "
185 "(threshold for iterative refinement).")
186 .def_readwrite(
"max_iters", &ProxNLPSolver::max_iters,
187 "Maximum number of iterations.")
188 .def_readwrite(
"max_al_iters", &ProxNLPSolver::max_al_iters,
189 "Max augmented Lagrangian iterations.")
190 .def_readwrite(
"reg_init", &ProxNLPSolver::DELTA_INIT,
191 "Initial regularization.");
192#pragma GCC diagnostic pop
194 bp::enum_<KktSystem>(
"KktSystem")
199 bp::class_<BCLParams>(
"BCLParams",
200 "Parameters for the bound-constrained Lagrangian (BCL) "
201 "penalty update strategy.",
202 bp::init<>((
"self"_a)))
203 .def_readwrite(
"prim_alpha", &BCLParams::prim_alpha)
204 .def_readwrite(
"prim_beta", &BCLParams::prim_beta)
205 .def_readwrite(
"dual_alpha", &BCLParams::dual_alpha)
206 .def_readwrite(
"dual_beta", &BCLParams::dual_beta)
207 .def_readwrite(
"mu_factor", &BCLParams::mu_update_factor,
208 "Multiplier update factor.")
209 .def_readwrite(
"rho_factor", &BCLParams::rho_update_factor,
210 "Proximal penalty update factor.");