Skip to content

Commit

Permalink
Merge pull request #1179 from cmastalli/devel
Browse files Browse the repository at this point in the history
  • Loading branch information
cmastalli authored Nov 10, 2023
2 parents 73acfe6 + 3a09a57 commit bf22806
Show file tree
Hide file tree
Showing 56 changed files with 2,169 additions and 2,122 deletions.
12 changes: 6 additions & 6 deletions bindings/python/crocoddyl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,8 +566,8 @@ def __init__(self):
self.costs = []
self.stops = []
self.grads = []
self.u_regs = []
self.x_regs = []
self.pregs = []
self.dregs = []
self.steps = []
self.ffeass = []
self.hfeass = []
Expand All @@ -582,8 +582,8 @@ def __call__(self, solver):
self.costs.append(solver.cost)
self.stops.append(solver.stoppingCriteria())
self.grads.append(-solver.expectedImprovement()[1].item())
self.u_regs.append(solver.u_reg)
self.x_regs.append(solver.x_reg)
self.pregs.append(solver.preg)
self.dregs.append(solver.dreg)
self.steps.append(solver.stepLength)
self.ffeass.append(solver.ffeas)
self.hfeass.append(solver.hfeas)
Expand Down Expand Up @@ -724,8 +724,8 @@ def saveLogfile(filename, log):
"steps": log.steps,
"iters": log.iters,
"costs": log.costs,
"muLM": log.u_regs,
"muV": log.x_regs,
"primal-reg": log.pregs,
"dual-reg": log.dregs,
"stops": log.stops,
"grads": log.grads,
}
Expand Down
84 changes: 62 additions & 22 deletions bindings/python/crocoddyl/core/solver-base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "python/crocoddyl/core/solver-base.hpp"

#include "python/crocoddyl/utils/copyable.hpp"
#include "python/crocoddyl/utils/deprecate.hpp"
#include "python/crocoddyl/utils/vector-converter.hpp"

namespace crocoddyl {
Expand Down Expand Up @@ -173,22 +174,70 @@ void exposeSolverAbstract() {
.def_readwrite("fs", &SolverAbstract_wrap::fs_, "dynamics gaps")
.def_readwrite("isFeasible", &SolverAbstract_wrap::is_feasible_,
"feasible (xs,us)")
.def_readwrite("cost", &SolverAbstract_wrap::cost_, "total cost")
.def_readwrite("cost", &SolverAbstract_wrap::cost_,
"cost for the current guess")
.def_readwrite("merit", &SolverAbstract_wrap::merit_,
"merit for the current guess")
.def_readwrite("stop", &SolverAbstract_wrap::stop_,
"stopping criteria value")
.def_readwrite("d", &SolverAbstract_wrap::d_, "expected improvement")
.add_property("x_reg", bp::make_function(&SolverAbstract_wrap::get_xreg),
bp::make_function(&SolverAbstract_wrap::set_xreg),
"state regularization")
.add_property("u_reg", bp::make_function(&SolverAbstract_wrap::get_ureg),
bp::make_function(&SolverAbstract_wrap::set_ureg),
"control regularization")
.def_readwrite("stepLength", &SolverAbstract_wrap::steplength_,
"applied step length")
.def_readwrite("d", &SolverAbstract_wrap::d_,
"linear and quadratic terms of the expected improvement")
.def_readwrite("dV", &SolverAbstract_wrap::dV_,
"reduction in the cost function")
"reduction in the cost function computed by `tryStep()`")
.def_readwrite("dPhi", &SolverAbstract_wrap::dPhi_,
"reduction in the merit function computed by `tryStep()`")
.def_readwrite("dVexp", &SolverAbstract_wrap::dVexp_,
"expected reduction in the cost function")
.def_readwrite("dPhiexp", &SolverAbstract_wrap::dPhiexp_,
"expected reduction in the merit function")
.def_readwrite("dfeas", &SolverAbstract_wrap::dfeas_,
"reduction in the feasibility")
.def_readwrite("feas", &SolverAbstract_wrap::feas_,
"total feasibility for the current guess")
.def_readwrite(
"ffeas", &SolverAbstract_wrap::ffeas_,
"feasibility of the dynamic constraint for the current guess")
.def_readwrite(
"gfeas", &SolverAbstract_wrap::gfeas_,
"feasibility of the inequality constraint for the current guess")
.def_readwrite(
"hfeas", &SolverAbstract_wrap::hfeas_,
"feasibility of the equality constraint for the current guess")
.def_readwrite(
"ffeas_try", &SolverAbstract_wrap::ffeas_try_,
"feasibility of the dynamic constraint for the current step length")
.def_readwrite("gfeas_try", &SolverAbstract_wrap::gfeas_try_,
"feasibility of the inequality constraint for the current "
"step length")
.def_readwrite(
"hfeas_try", &SolverAbstract_wrap::hfeas_try_,
"feasibility of the equality constraint for the current step length")
.add_property("preg", bp::make_function(&SolverAbstract_wrap::get_preg),
bp::make_function(&SolverAbstract_wrap::set_preg),
"primal-variable regularization")
.add_property("dreg", bp::make_function(&SolverAbstract_wrap::get_dreg),
bp::make_function(&SolverAbstract_wrap::set_dreg),
"dual-variable regularization")
.add_property(
"x_reg",
bp::make_function(
&SolverAbstract_wrap::get_xreg,
deprecated<bp::return_value_policy<bp::return_by_value> >(
"Deprecated. Use preg")),
bp::make_function(&SolverAbstract_wrap::set_xreg,
deprecated<>("Deprecated. Use preg.")),
"state regularization")
.add_property(
"u_reg",
bp::make_function(
&SolverAbstract_wrap::get_ureg,
deprecated<bp::return_value_policy<bp::return_by_value> >(
"Deprecated. Use preg")),
bp::make_function(&SolverAbstract_wrap::set_ureg,
deprecated<>("Deprecated. Use preg.")),
"control regularization")
.def_readwrite("stepLength", &SolverAbstract_wrap::steplength_,
"applied step length")
.add_property("th_acceptStep",
bp::make_function(&SolverAbstract_wrap::get_th_acceptstep),
bp::make_function(&SolverAbstract_wrap::set_th_acceptstep),
Expand All @@ -197,25 +246,16 @@ void exposeSolverAbstract() {
bp::make_function(&SolverAbstract_wrap::get_th_stop),
bp::make_function(&SolverAbstract_wrap::set_th_stop),
"threshold for stopping criteria")
.def_readwrite("iter", &SolverAbstract_wrap::iter_,
"number of iterations runned in solve()")
.add_property("th_gapTol",
bp::make_function(&SolverAbstract_wrap::get_th_gaptol),
bp::make_function(&SolverAbstract_wrap::set_th_gaptol),
"threshold for accepting a gap as non-zero")
.def_readwrite(
"ffeas", &SolverAbstract_wrap::ffeas_,
"feasibility of the dynamic constraint for the current guess")
.def_readwrite(
"gfeas", &SolverAbstract_wrap::gfeas_,
"feasibility of the inequality constraint for the current guess")
.def_readwrite(
"hfeas", &SolverAbstract_wrap::hfeas_,
"feasibility of the equality constraint for the current guess")
.add_property(
"feasNorm", bp::make_function(&SolverAbstract_wrap::get_feasnorm),
bp::make_function(&SolverAbstract_wrap::set_feasnorm),
"norm used to compute the dynamic and constraints feasibility")
.def_readwrite("iter", &SolverAbstract_wrap::iter_,
"number of iterations runned in solve()")
.def(CopyableVisitor<SolverAbstract_wrap>());

bp::class_<CallbackAbstract_wrap, boost::noncopyable>(
Expand Down
11 changes: 10 additions & 1 deletion bindings/python/crocoddyl/core/solver-base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
///////////////////////////////////////////////////////////////////////////////
// BSD 3-Clause License
//
// Copyright (C) 2019-2021, LAAS-CNRS, University of Edinburgh
// Copyright (C) 2019-2023, LAAS-CNRS, University of Edinburgh,
// Heriot-Watt University
// Copyright note valid unless otherwise stated in individual files.
// All rights reserved.
///////////////////////////////////////////////////////////////////////////////
Expand All @@ -24,14 +25,22 @@ class SolverAbstract_wrap : public SolverAbstract,
public:
using SolverAbstract::cost_;
using SolverAbstract::d_;
using SolverAbstract::dfeas_;
using SolverAbstract::dPhi_;
using SolverAbstract::dPhiexp_;
using SolverAbstract::dV_;
using SolverAbstract::dVexp_;
using SolverAbstract::feas_;
using SolverAbstract::ffeas_;
using SolverAbstract::ffeas_try_;
using SolverAbstract::fs_;
using SolverAbstract::gfeas_;
using SolverAbstract::gfeas_try_;
using SolverAbstract::hfeas_;
using SolverAbstract::hfeas_try_;
using SolverAbstract::is_feasible_;
using SolverAbstract::iter_;
using SolverAbstract::merit_;
using SolverAbstract::steplength_;
using SolverAbstract::stop_;
using SolverAbstract::us_;
Expand Down
4 changes: 0 additions & 4 deletions bindings/python/crocoddyl/core/solvers/intro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,6 @@ void exposeSolverIntro() {
bp::make_function(&SolverIntro::set_rho),
"parameter used in the merit function to predict the "
"expected reduction.")
.add_property("dPhi", bp::make_function(&SolverIntro::get_dPhi),
"reduction in the merit function.")
.add_property("dPhiexp", bp::make_function(&SolverIntro::get_dPhiexp),
"expected reduction in the merit function.")
.add_property("upsilon", bp::make_function(&SolverIntro::get_upsilon),
"estimated penalty parameter that balances relative "
"contribution of the cost function and equality "
Expand Down
9 changes: 7 additions & 2 deletions bindings/python/crocoddyl/core/utils/callbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,19 @@ namespace python {
void exposeCallbacks() {
bp::register_ptr_to_python<boost::shared_ptr<CallbackAbstract> >();

bp::enum_<VerboseLevel>("VerboseLevel").value("_1", _1).value("_2", _2);
bp::enum_<VerboseLevel>("VerboseLevel")
.value("_0", _0)
.value("_1", _1)
.value("_2", _2)
.value("_3", _3)
.value("_4", _4);

bp::class_<CallbackVerbose, bp::bases<CallbackAbstract> >(
"CallbackVerbose", "Callback function for printing the solver values.",
bp::init<bp::optional<VerboseLevel, int> >(
bp::args("self", "level", "precision"),
"Initialize the differential verbose callback.\n\n"
":param level: verbose level (default _1)\n"
":param level: verbose level (default _4)\n"
":param precision: precision of floating point output (default 5)"))
.def("__call__", &CallbackVerbose::operator(), bp::args("self", "solver"),
"Run the callback function given a solver.\n\n"
Expand Down
34 changes: 10 additions & 24 deletions examples/arm_manipulation_fwddyn.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,27 +78,6 @@

# Creating the DDP solver for this OC problem, defining a logger
solver = crocoddyl.SolverFDDP(problem)
cameraTF = [2.0, 2.68, 0.54, 0.2, 0.62, 0.72, 0.22]
if WITHDISPLAY:
try:
import gepetto

gepetto.corbaserver.Client()
display = crocoddyl.GepettoDisplay(kinova, 4, 4, cameraTF, floor=False)
if WITHPLOT:
solver.setCallbacks(
[
crocoddyl.CallbackVerbose(),
crocoddyl.CallbackLogger(),
crocoddyl.CallbackDisplay(display),
]
)
else:
solver.setCallbacks(
[crocoddyl.CallbackVerbose(), crocoddyl.CallbackDisplay(display)]
)
except Exception:
display = crocoddyl.MeshcatDisplay(kinova)
if WITHPLOT:
solver.setCallbacks(
[
Expand All @@ -108,8 +87,6 @@
)
else:
solver.setCallbacks([crocoddyl.CallbackVerbose()])
solver.getCallbacks()[0].precision = 3
solver.getCallbacks()[0].level = crocoddyl.VerboseLevel._2

# Solving it with the solver algorithm
solver.solve()
Expand All @@ -126,11 +103,20 @@
log = solver.getCallbacks()[1]
crocoddyl.plotOCSolution(log.xs, log.us, figIndex=1, show=False)
crocoddyl.plotConvergence(
log.costs, log.u_regs, log.x_regs, log.grads, log.stops, log.steps, figIndex=2
log.costs, log.pregs, log.dregs, log.grads, log.stops, log.steps, figIndex=2
)

# Visualizing the solution in gepetto-viewer
if WITHDISPLAY:
try:
import gepetto

cameraTF = [2.0, 2.68, 0.54, 0.2, 0.62, 0.72, 0.22]
gepetto.corbaserver.Client()
display = crocoddyl.GepettoDisplay(kinova, 4, 4, cameraTF, floor=False)
except Exception:
display = crocoddyl.MeshcatDisplay(kinova)

display.rate = -1
display.freq = 1
while True:
Expand Down
34 changes: 10 additions & 24 deletions examples/arm_manipulation_invdyn.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,27 +78,6 @@

# Creating the solver for this OC problem, defining a logger
solver = crocoddyl.SolverIntro(problem)
cameraTF = [2.0, 2.68, 0.54, 0.2, 0.62, 0.72, 0.22]
if WITHDISPLAY:
try:
import gepetto

gepetto.corbaserver.Client()
display = crocoddyl.GepettoDisplay(kinova, 4, 4, cameraTF, floor=False)
if WITHPLOT:
solver.setCallbacks(
[
crocoddyl.CallbackVerbose(),
crocoddyl.CallbackLogger(),
crocoddyl.CallbackDisplay(display),
]
)
else:
solver.setCallbacks(
[crocoddyl.CallbackVerbose(), crocoddyl.CallbackDisplay(display)]
)
except Exception:
display = crocoddyl.MeshcatDisplay(kinova)
if WITHPLOT:
solver.setCallbacks(
[
Expand All @@ -108,8 +87,6 @@
)
else:
solver.setCallbacks([crocoddyl.CallbackVerbose()])
solver.getCallbacks()[0].precision = 3
solver.getCallbacks()[0].level = crocoddyl.VerboseLevel._2

# Solving it with the solver algorithm
solver.solve()
Expand All @@ -131,11 +108,20 @@
show=False,
)
crocoddyl.plotConvergence(
log.costs, log.u_regs, log.x_regs, log.grads, log.stops, log.steps, figIndex=2
log.costs, log.pregs, log.dregs, log.grads, log.stops, log.steps, figIndex=2
)

# Visualizing the solution in gepetto-viewer
if WITHDISPLAY:
try:
import gepetto

cameraTF = [2.0, 2.68, 0.54, 0.2, 0.62, 0.72, 0.22]
gepetto.corbaserver.Client()
display = crocoddyl.GepettoDisplay(kinova, 4, 4, cameraTF, floor=False)
except Exception:
display = crocoddyl.MeshcatDisplay(kinova)

display.rate = -1
display.freq = 1
while True:
Expand Down
Loading

0 comments on commit bf22806

Please sign in to comment.