Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
0a9edee
fixed compilation issue in python3.7 env
AndrePatri Aug 2, 2023
46a540e
added specific utility to evaluate torque contraints
AndrePatri Aug 2, 2023
32d8838
added lagrange mult, opt cost, cost values thorugh iterations and ite…
AndrePatri Aug 3, 2023
1d3b00b
added callback to get additional solution info
AndrePatri Aug 3, 2023
064c43f
added mission getter for lagrange multipliers
AndrePatri Aug 4, 2023
6be2e62
removed hugely expensive run-time recreation of inverse dynamics object
AndrePatri Aug 4, 2023
877b8e0
made profiling optional and fixed missing update of fmap with last so…
AndrePatri Aug 16, 2023
3b98429
Merge branch 'speed' into add_nodes_rl
AndrePatri Nov 6, 2023
30114a7
bug in setweight of task
FrancescoRuscelli Nov 6, 2023
3e0e82a
added missing debug and verbose inputs
AndrePatri Nov 6, 2023
b3f3227
if in conda env, by default install in it
AndrePatri Nov 6, 2023
19f9987
removed a couple of spaces
AndrePatri Nov 7, 2023
2401539
commented replay trajectory. taskInterface should not be ros-dependent
AndrePatri Nov 23, 2023
a1b8143
fixed wrong nodes used for mpc torque computation and added solver n …
AndrePatri Nov 30, 2023
b86575e
Merge branch 'devel' into add_nodes_rl
AndrePatri Nov 30, 2023
ed9e46e
added debug flag in options, now cost/constraints values dictionary f…
AndrePatri Dec 5, 2023
d1c03f3
exposed ilqr debug flag to horizon solver interface
AndrePatri Dec 5, 2023
d423404
infeasibility warning now printed only if in debug mode
AndrePatri Jan 5, 2024
163a4f9
minor comments and added backup for bootstrap
AndrePatri Jan 5, 2024
2a19459
added simple reset method
AndrePatri Jan 8, 2024
2519b99
fix typo
AndrePatri Jan 8, 2024
669baaf
exposed reset method for hxx regularization
AndrePatri Feb 7, 2024
0b0397e
exposed ilqr reset method to horizon's solver interface
AndrePatri Feb 7, 2024
cada639
added missing rti option passed to ilqr solver
AndrePatri Feb 7, 2024
b96653c
exposed residual norm1 getter
AndrePatri Feb 7, 2024
6fc269d
now logging iterations only if flag enabled
AndrePatri Feb 21, 2024
a1906f6
disabled ilqr iteration logging to avoid RAM saturation
AndrePatri Feb 21, 2024
17ff2ee
removed memory debug changes
AndrePatri Feb 21, 2024
fa833fe
exposed flag to suppress codegen generation/loading output
AndrePatri Feb 21, 2024
4ed4dd7
removed prints in should stop is verbose is false
AndrePatri Feb 21, 2024
3f031f6
exposed codegen dir argument
AndrePatri Feb 21, 2024
1350f51
Signed-off-by: Andrea Patrizi <andreapatrizi1b6e6@gmail.com>
AndrePatri Feb 21, 2024
4fcfa0b
fixed unused ilq config for bootstrap
AndrePatri Feb 26, 2024
de8be8d
removed unnecessary verbose arg
AndrePatri Mar 22, 2024
10678f2
added back verbosity flag
AndrePatri Mar 25, 2024
90a1aae
Signed-off-by: Andrea Patrizi <andreapatrizi1b6e6@gmail.com>
AndrePatri Mar 25, 2024
bfc1215
removed constr viol db print if not in verbose mode
AndrePatri Mar 25, 2024
f5f74a6
added vector for holding tot cost on each node
AndrePatri Apr 16, 2024
35e2be4
added getters for tot costs and constr viol on nodes
AndrePatri Apr 16, 2024
336b47b
exposes methods for getting TOT cost and constr viol on nodes
AndrePatri Apr 19, 2024
543a8f6
removed arch spec. compilation flag to allow a bit more of cross comp…
Jul 22, 2024
77ffe3f
added soft i state update method
AndrePatri Jul 31, 2024
055df02
Merge branch 'andrepatri_devel' of github.com:ADVRHumanoids/horizon i…
AndrePatri Jul 31, 2024
7e65699
added sanity check on supported cartesian task types
AndrePatri Aug 5, 2024
2d7cabf
now always returning list, fixed handling of subtasks for contact task
AndrePatri Aug 5, 2024
2962cd2
ilqr now allows to use float instead of double if required (casadi co…
AndrePatri Aug 8, 2024
2345547
fixed some typos, float still not working due to casadi::function
AndrePatri Aug 8, 2024
9ec62c4
getNodes now returning a list of both active and feasible nodes
AndrePatri Aug 9, 2024
769a8e6
added method to get derivative of polynomial traj
AndrePatri Aug 13, 2024
1a51606
added options to also specify second derivate
AndrePatri Aug 13, 2024
345d43c
fixed 7 being always reported when getting CartesianTask dimension (c…
AndrePatri Aug 13, 2024
fda5258
solved bug: now reporting 7 in case of position task, otherwise indic…
AndrePatri Aug 23, 2024
4d710a2
renamed flag for compilation with float instead of double
Aug 27, 2024
7fc30ec
temporarily removed setup.py to avoid running builds
AndrePatri Aug 30, 2024
6df865a
allowing evaluation of effort on any node now
AndrePatri Sep 13, 2024
f143cb6
fixed efforts evaluation
AndrePatri Oct 3, 2024
70ff0e6
cleaned imports: in particular, removed matplotlib import from ilqr s…
AndrePatri Oct 3, 2024
23a71da
minor changes
AndrePatri Oct 3, 2024
4970cfd
added vertex frames to attributes
AndrePatri Oct 23, 2024
b642950
added reset of fp_res data
AndrePatri Oct 28, 2024
17dab1a
fixed eigen method being called on a scalar
AndrePatri Oct 28, 2024
61b6685
bug fix
AndrePatri Oct 30, 2024
6e66da1
added indeces for regularization task
AndrePatri Nov 3, 2024
250283e
removed initial state setting in task interface
AndrePatri Nov 12, 2024
e88973a
removing unil barrier if thresh is low "enough"
AndrePatri Nov 18, 2024
5b736e9
added safety clip when evaluating efforts
AndrePatri Nov 18, 2024
546508b
properly hadnling nonfinite values when evaluating torques
AndrePatri Nov 18, 2024
bad10e3
Signed-off-by: Andrea Patrizi <andreapatrizi1b6e6@gmail.com>
AndrePatri Nov 18, 2024
bdcd666
Merge branch 'receding_horizon' into andrepatri_devel
AndrePatri Nov 20, 2024
73e2738
moved global np setting
AndrePatri Nov 27, 2024
cd47a05
added third derivative specification
AndrePatri Dec 16, 2024
8d207e2
added back -march native flag
AndrePatri Dec 26, 2024
c33029a
fixed wrong license file
AndrePatri Feb 24, 2025
ea75c81
raised minimum cmake version to avoid compilation error (cmake 3.5 no…
AndrePatri Apr 3, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions horizon/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
project(horizon)
cmake_minimum_required(VERSION 3.0)
cmake_minimum_required(VERSION 3.10)
if(DEFINED ENV{CONDA_PREFIX})

set(CMAKE_INSTALL_PREFIX $ENV{CONDA_PREFIX}/ CACHE PATH "bindings install prefix" FORCE)

endif()

# options
option(HORIZON_PROFILING OFF "enable profiling features")
option(ILQR_FLOAT OFF "use float for data representation instead of double")

if(${HORIZON_PROFILING})
add_definitions(-DHORIZON_PROFILING)
endif()
if(${ILQR_FLOAT})
add_definitions(-DILQR_FLOAT)
endif()


find_package(Eigen3 REQUIRED)
find_package(casadi 3.5.5 REQUIRED)
find_package(yaml-cpp REQUIRED)

set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD 17)

# ilqr library
add_library(horizon STATIC
Expand All @@ -39,7 +49,6 @@ add_library(sqp STATIC
src/sqp.cpp
)


target_link_libraries(ilqr Eigen3::Eigen casadi pthread)
target_link_libraries(sqp Eigen3::Eigen casadi ilqr)

Expand Down
4 changes: 4 additions & 0 deletions horizon/cpp/pyilqr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,13 @@ PYBIND11_MODULE(pyilqr, m) {
.def("getInputTrajectory", &IterativeLQR::getInputTrajectory)
.def("getConstraintsValues", &IterativeLQR::getConstraintsValues)
.def("getCostsValues", &IterativeLQR::getCostsValues)
.def("getResidualNorm", &IterativeLQR::getResidualNorm)
.def("getConstrValOnNodes", &IterativeLQR::getConstrValOnNodes)
.def("getCostValOnNodes", &IterativeLQR::getCostValOnNodes)
.def("setInitialState", &IterativeLQR::setInitialState)
.def("setInputInitialGuess", &IterativeLQR::setInputInitialGuess)
.def("setStateInitialGuess", &IterativeLQR::setStateInitialGuess)
.def("reset", &IterativeLQR::reset)
;

}
Expand Down
4 changes: 3 additions & 1 deletion horizon/cpp/pyilqr_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <pybind11/stl.h>
#include <pybind11/functional.h>

#include "src/typedefs.h"

namespace py = pybind11;
using namespace horizon;

Expand Down Expand Up @@ -56,7 +58,7 @@ auto set_final_constraint_wrapper(IterativeLQR& self, py::object pyfn)
auto set_inter_constraint_wrapper_single(IterativeLQR& self,
std::vector<int> k,
py::object f,
std::vector<Eigen::VectorXd> tgt)
std::vector<VectorXr> tgt)
{
self.setConstraint(k, to_cpp(f), tgt);
}
Expand Down
106 changes: 53 additions & 53 deletions horizon/cpp/pysqp_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,25 @@
#include <pybind11/stl.h>
#include <pybind11/functional.h>
#include <typeinfo>
#include "src/typedefs.h"

namespace py = pybind11;
using namespace horizon;


py::dict get_qpoases_options_mpc()
{
py::dict opts;
opts["enableEqualities"] = true;
opts["initialStatusBounds"] = "inactive";
opts["numRefinementSteps"] = 0;
opts["enableDriftCorrection"] = 0;
opts["terminationTolerance"] = 10e9 * std::numeric_limits<double>::epsilon();
opts["terminationTolerance"] = 10e9 * std::numeric_limits<Real>::epsilon();
opts["enableFlippingBounds"] = false;
opts["enableNZCTests"] = false;
opts["enableRamping"] = false;
opts["enableRegularisation"] = true;
opts["numRegularisationSteps"] = 2;
opts["epsRegularisation"] = 5. * 10e3 * std::numeric_limits<double>::epsilon();
opts["epsRegularisation"] = 5. * 10e3 * std::numeric_limits<Real>::epsilon();
return opts;
}

Expand All @@ -38,7 +38,7 @@ py::dict get_qpoases_options_reliable()
opts["enableEqualities"] = false;
opts["numRefinementSteps"] = 2;
opts["enableFullLITest"] = true;
opts["epsLITests"] = 10e5 * std::numeric_limits<double>::epsilon();
opts["epsLITests"] = 10e5 * std::numeric_limits<Real>::epsilon();
opts["maxDualJump"] = 10e8;
opts["enableCholeskyRefactorisation"] = 1;
return opts;
Expand All @@ -61,15 +61,15 @@ bool setOption(const std::string& key, const std::string& solver_key, py::handle
bool checkOptions(const std::string& key, py::handle& value, casadi::Dict& dict)
{
// -- sqp options --//
if(setOption <double> (key, "beta", value, dict)) return true;
if(setOption <double> (key, "eps_regularization", value, dict)) return true;
if(setOption <double> (key, "alpha_min", value, dict)) return true;
if(setOption <Real> (key, "beta", value, dict)) return true;
if(setOption <Real> (key, "eps_regularization", value, dict)) return true;
if(setOption <Real> (key, "alpha_min", value, dict)) return true;
if(setOption <int> (key, "max_iter", value, dict)) return true;
if(setOption <bool> (key, "reinitialize_qpsolver", value, dict)) return true;
if(setOption <double> (key, "merit_derivative_tolerance", value, dict)) return true;
if(setOption <double> (key, "merit_eps", value, dict)) return true;
if(setOption <double> (key, "constraint_violation_tolerance", value, dict)) return true;
if(setOption <double> (key, "solution_convergence", value, dict)) return true;
if(setOption <Real> (key, "merit_derivative_tolerance", value, dict)) return true;
if(setOption <Real> (key, "merit_eps", value, dict)) return true;
if(setOption <Real> (key, "constraint_violation_tolerance", value, dict)) return true;
if(setOption <Real> (key, "solution_convergence", value, dict)) return true;
if(setOption <bool> (key, "use_golden_ratio_update", value, dict)) return true;
// -- qpoases options --//
if(setOption <bool> (key, "sparse", value, dict)) return true;
Expand All @@ -78,7 +78,7 @@ bool checkOptions(const std::string& key, py::handle& value, casadi::Dict& dict)
if(setOption <int> (key, "max_schur", value, dict)) return true;
if(setOption <std::string> (key, "linsol_plugin", value, dict)) return true;
if(setOption <int> (key, "nWSR", value, dict)) return true;
if(setOption <double> (key, "CPUtime", value, dict)) return true;
if(setOption <Real> (key, "CPUtime", value, dict)) return true;
if(setOption <std::string> (key, "printLevel", value, dict)) return true;
if(setOption <bool> (key, "enableRamping", value, dict)) return true;
if(setOption <bool> (key, "enableFarBounds", value, dict)) return true;
Expand All @@ -89,42 +89,42 @@ bool checkOptions(const std::string& key, py::handle& value, casadi::Dict& dict)
if(setOption <int> (key, "enableDriftCorrection", value, dict)) return true;
if(setOption <int> (key, "enableCholeskyRefactorisation", value, dict)) return true;
if(setOption <bool> (key, "enableEqualities", value, dict)) return true;
if(setOption <double> (key, "terminationTolerance", value, dict)) return true;
if(setOption <double> (key, "boundTolerance", value, dict)) return true;
if(setOption <double> (key, "boundRelaxation", value, dict)) return true;
if(setOption <double> (key, "epsNum", value, dict)) return true;
if(setOption <double> (key, "epsDen", value, dict)) return true;
if(setOption <double> (key, "maxPrimalJump", value, dict)) return true;
if(setOption <double> (key, "maxDualJump", value, dict)) return true;
if(setOption <double> (key, "initialRamping", value, dict)) return true;
if(setOption <double> (key, "finalRamping", value, dict)) return true;
if(setOption <double> (key, "initialFarBounds", value, dict)) return true;
if(setOption <double> (key, "growFarBounds", value, dict)) return true;
if(setOption <Real> (key, "terminationTolerance", value, dict)) return true;
if(setOption <Real> (key, "boundTolerance", value, dict)) return true;
if(setOption <Real> (key, "boundRelaxation", value, dict)) return true;
if(setOption <Real> (key, "epsNum", value, dict)) return true;
if(setOption <Real> (key, "epsDen", value, dict)) return true;
if(setOption <Real> (key, "maxPrimalJump", value, dict)) return true;
if(setOption <Real> (key, "maxDualJump", value, dict)) return true;
if(setOption <Real> (key, "initialRamping", value, dict)) return true;
if(setOption <Real> (key, "finalRamping", value, dict)) return true;
if(setOption <Real> (key, "initialFarBounds", value, dict)) return true;
if(setOption <Real> (key, "growFarBounds", value, dict)) return true;
if(setOption <std::string> (key, "initialStatusBounds", value, dict)) return true;
if(setOption <double> (key, "epsFlipping", value, dict)) return true;
if(setOption <Real> (key, "epsFlipping", value, dict)) return true;
if(setOption <int> (key, "numRegularisationSteps", value, dict)) return true;
if(setOption <double> (key, "epsRegularisation", value, dict)) return true;
if(setOption <Real> (key, "epsRegularisation", value, dict)) return true;
if(setOption <int> (key, "numRefinementSteps", value, dict)) return true;
if(setOption <double> (key, "epsIterRef", value, dict)) return true;
if(setOption <double> (key, "epsLITests", value, dict)) return true;
if(setOption <double> (key, "epsNZCTests", value, dict)) return true;
if(setOption <Real> (key, "epsIterRef", value, dict)) return true;
if(setOption <Real> (key, "epsLITests", value, dict)) return true;
if(setOption <Real> (key, "epsNZCTests", value, dict)) return true;
if(setOption <bool> (key, "enableInertiaCorrection", value, dict)) return true;
// -- osqp options --//
if(setOption <bool> (key, "warm_start_primal", value, dict)) return true;
if(setOption <bool> (key, "warm_start_dual", value, dict)) return true;
if(setOption <double> (key, "osqp.rho", value, dict)) return true;
if(setOption <double> (key, "osqp.sigma", value, dict)) return true;
if(setOption <Real> (key, "osqp.rho", value, dict)) return true;
if(setOption <Real> (key, "osqp.sigma", value, dict)) return true;
if(setOption <int> (key, "osqp.scaling", value, dict)) return true;
if(setOption <int> (key, "osqp.adaptive_rho", value, dict)) return true;
if(setOption <int> (key, "osqp.adaptive_rho_interval", value, dict)) return true;
if(setOption <double> (key, "osqp.adaptive_rho_tolerance", value, dict)) return true;
if(setOption <Real> (key, "osqp.adaptive_rho_tolerance", value, dict)) return true;
if(setOption <int> (key, "osqp.max_iter", value, dict)) return true;
if(setOption <double> (key, "osqp.eps_abs", value, dict)) return true;
if(setOption <double> (key, "osqp.eps_rel", value, dict)) return true;
if(setOption <double> (key, "osqp.eps_prim_inf", value, dict)) return true;
if(setOption <double> (key, "osqp.eps_dual_inf", value, dict)) return true;
if(setOption <double> (key, "osqp.alpha", value, dict)) return true;
if(setOption <double> (key, "osqp.delta", value, dict)) return true;
if(setOption <Real> (key, "osqp.eps_abs", value, dict)) return true;
if(setOption <Real> (key, "osqp.eps_rel", value, dict)) return true;
if(setOption <Real> (key, "osqp.eps_prim_inf", value, dict)) return true;
if(setOption <Real> (key, "osqp.eps_dual_inf", value, dict)) return true;
if(setOption <Real> (key, "osqp.alpha", value, dict)) return true;
if(setOption <Real> (key, "osqp.delta", value, dict)) return true;
if(setOption <int> (key, "osqp.polish", value, dict)) return true;
if(setOption <int> (key, "osqp.polish_refine_iter", value, dict)) return true;
if(setOption <int> (key, "osqp.verbose", value, dict)) return true;
Expand Down Expand Up @@ -189,10 +189,10 @@ bool gSX(SQPGaussNewton<casadi::SX>& self, py::object g, bool reinitialize_qp_so
}

auto callMX(SQPGaussNewton<casadi::MX>& self,
const Eigen::VectorXd& x0,
const Eigen::VectorXd& p,
const Eigen::VectorXd& lbx, const Eigen::VectorXd& ubx,
const Eigen::VectorXd& lbg, const Eigen::VectorXd& ubg)
const VectorXr& x0,
const VectorXr& p,
const VectorXr& lbx, const VectorXr& ubx,
const VectorXr& lbg, const VectorXr& ubg)
{
casadi::DM _x0_, _p_, _lbx_, _ubx_, _lbg_, _ubg_;
casadi_utils::toCasadiMatrix(x0, _x0_);
Expand All @@ -204,22 +204,22 @@ auto callMX(SQPGaussNewton<casadi::MX>& self,
casadi::DMDict tmp = self.solve(_x0_, _p_, _lbx_, _ubx_, _lbg_, _ubg_);

py::dict solution;
Eigen::VectorXd x;
VectorXr x;
casadi_utils::toEigen(tmp.at("x"), x);
solution["x"] = x;
solution["f"] = double(tmp.at("f")(0));
solution["g"] = double(tmp.at("g")(0));
solution["f"] = Real(tmp.at("f")(0));
solution["g"] = Real(tmp.at("g")(0));
return solution;
}


auto callSX(SQPGaussNewton<casadi::SX>& self,
const Eigen::VectorXd& x0,
const Eigen::VectorXd& p,
const Eigen::VectorXd& lbx,
const Eigen::VectorXd& ubx,
const Eigen::VectorXd& lbg,
const Eigen::VectorXd& ubg)
const VectorXr& x0,
const VectorXr& p,
const VectorXr& lbx,
const VectorXr& ubx,
const VectorXr& lbg,
const VectorXr& ubg)
{
casadi::DM _x0_, _p_, _lbx_, _ubx_, _lbg_, _ubg_;
casadi_utils::toCasadiMatrix(x0, _x0_);
Expand All @@ -231,11 +231,11 @@ auto callSX(SQPGaussNewton<casadi::SX>& self,
casadi::DMDict tmp = self.solve(_x0_, _p_, _lbx_, _ubx_, _lbg_, _ubg_);

py::dict solution;
Eigen::VectorXd x;
VectorXr x;
casadi_utils::toEigen(tmp.at("x"), x);
solution["x"] = x;
solution["f"] = double(tmp.at("f")(0));
solution["g"] = double(tmp.at("g")(0));
solution["f"] = Real(tmp.at("f")(0));
solution["g"] = Real(tmp.at("g")(0));
return solution;
}

Expand Down
43 changes: 31 additions & 12 deletions horizon/cpp/src/codegen_function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@
#include <dlfcn.h>

#include "wrapped_function.h"
#include "typedefs.h"

namespace
{

using Real=horizon::Real;
using MatrixXr=horizon::MatrixXr;
using VectorXr=horizon::VectorXr;

class RestoreCwd
{
public:
Expand All @@ -36,14 +41,14 @@ bool check_function_consistency(const casadi::Function &f, const casadi::Functio
casadi_utils::WrappedFunction fw = f;
casadi_utils::WrappedFunction gw = g;

std::vector<Eigen::VectorXd> input(f.n_in());
std::vector<VectorXr> input(f.n_in());

for(int iter = 0; iter < 10; iter++)
{

for(int i = 0; i < f.n_in(); i++)
{
Eigen::VectorXd u;
VectorXr u;
u.setRandom(f.size1_in(i));
input[i] = 100*u;
}
Expand All @@ -59,7 +64,7 @@ bool check_function_consistency(const casadi::Function &f, const casadi::Functio

for(int i = 0; i < f.n_out(); i++)
{
double err = (fw.getOutput(i) - gw.getOutput(i)).lpNorm<Eigen::Infinity>();
Real err = (fw.getOutput(i) - gw.getOutput(i)).lpNorm<Eigen::Infinity>();

if(err > 1e-16)
{
Expand All @@ -80,7 +85,8 @@ bool check_function_consistency(const casadi::Function &f, const casadi::Functio



casadi::Function horizon::utils::codegen(const casadi::Function &f, std::string dir)
casadi::Function horizon::utils::codegen(const casadi::Function &f, std::string dir,
bool verbose)
{
// save cwd
RestoreCwd rcwd = get_current_dir_name();
Expand All @@ -102,9 +108,11 @@ casadi::Function horizon::utils::codegen(const casadi::Function &f, std::string
std::string fname = f.name() + "_generated_" + std::to_string(hash);

if(access((fname + ".so").c_str(), F_OK) == 0)
{
std::cout << "exists: loading " << fname << "... \n";

{
if (verbose) {
std::cout << "exists: loading " << fname << "... \n";
}

auto handle = dlopen(("./" + fname + ".so").c_str(), RTLD_NOW);

if(!handle)
Expand All @@ -126,20 +134,31 @@ casadi::Function horizon::utils::codegen(const casadi::Function &f, std::string
}

// else, generate and compile
f.generate(fname + ".c");

std::cout << "not found: compiling " << fname << "... \n";
#ifdef ILQR_FLOAT
casadi::Dict opts={{"casadi_real", "float"}};
#else
casadi::Dict opts={{"casadi_real", "double"}};
#endif
f.generate(fname + ".c",opts);

if (verbose) {
std::cout << "not found: compiling " << fname << "... \n";
}

int ret = system(("clang -fPIC -shared -O3 -march=native " + fname + ".c -o " + fname + ".so").c_str());
// removed -march=native to allow (maybe) more cross compatibility
// int ret = system(("clang -fPIC -shared -O3 " + fname + ".c -o " + fname + ".so").c_str());

if(ret != 0)
{
std::cout << "failed to compile generated function " << fname << "\n";
return f;
}

std::cout << "loading " << fname << "... \n";

if (verbose) {
std::cout << "loading " << fname << "... \n";
}

auto handle = dlopen(("./" + fname + ".so").c_str(), RTLD_NOW);

if(!handle)
Expand Down
3 changes: 2 additions & 1 deletion horizon/cpp/src/codegen_function.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
namespace horizon { namespace utils {

casadi::Function codegen(const casadi::Function& f,
std::string dir=".");
std::string dir=".",
bool verbose = false);

} }

Expand Down
Loading