Large problem does not compile

Hi, i’m reporting the error that i have when i generate a problem with many parameters.
As stated in: Error on the s-function block
when i generate a nlp problem with more than 10000 parameters, it will return me an error.

I share the code.

clear all

clc

is_parametric = 1;

import casadi.*; % Import CasADi library

Theta=ones(10000,7);

dXdt=ones(10000,1);

% Step 2: Define problem variables

eps=casadi.SX.sym(‘eps’,7);

if is_parametric

dXdtcas = SX.sym(‘dXdt’,size(dXdt));

end

if is_parametric

Thetacas = SX.sym(‘Theta’,size(Theta));

end

% Cost function with regularization

lambda = 1e-3; % Regularization term

f = abs((Thetacas * eps - dXdtcas)’ * (Thetacas * eps - dXdtcas));

% Constraint bounds

g = [eps(1);eps(2);eps(3);eps(4);eps(5);eps(6);eps(7)];

glb = [0.001;50;-5000;70000;-700000;-0.05;-0.001];

gub = [0.002;100;-3000;100000;-500000;-0.01;0];

% Step 3: Model setup

model = AcadosModel();

model.name = ‘Constr_SINDy_7’;

model.x = eps;

model.f_expl_expr = casadi.SX.zeros(length(model.x),1);

if is_parametric

model.p = vertcat(Thetacas(:),dXdtcas(:));

end

% Cost and constraints

ocp = AcadosOcp();

ocp.name = ‘SINDy7_solver’;

ocp.model = model;

ocp.cost.cost_type_e = ‘EXTERNAL’;

ocp.model.cost_expr_ext_cost_e = f;

ocp.model.con_h_expr_e = g;

ocp.constraints.lh_e = glb;

ocp.constraints.uh_e = gub;

ocp.cost.cost_type_0 = ‘EXTERNAL’;

ocp.model.cost_expr_ext_cost_0 = 0;

ocp.cost.cost_type = ‘EXTERNAL’;

ocp.model.cost_expr_ext_cost = 0;

% Solver options

ocp.solver_options.tf = 1;

ocp.solver_options.N_horizon = 1;

ocp.solver_options.nlp_solver_type = ‘SQP’;

ocp.solver_options.nlp_solver_max_iter = 1000;

ocp.solver_options.nlp_solver_tol_stat = 1e-2;

ocp.solver_options.nlp_solver_tol_eq = 1e-2;

ocp.solver_options.nlp_solver_tol_comp = 1e-2;

simulink_opts = get_acados_simulink_opts;

simulink_opts.inputs.x_init = 1;

simulink_opts.outputs.cost_value = 1;

simulink_opts.outputs.KKT_residual = 0;

simulink_opts.outputs.KKT_residuals = 1;

ocp.simulink_opts = simulink_opts;

% Solver creation

ocp_solver = AcadosOcpSolver(ocp);

Now if the Theta and dXdt matricies have rispectively a dimension of (1000x7) and (1000x1) it will works, instead with the dimensions in the code it will give me this error:

Warning: self.parameter_values are not set.
Using zeros(np,1) by default.
You can update them later using set().

In AcadosOcp/make_consistent (line 131)
In AcadosOcpSolver (line 51)
In CSINDy_7 (line 73)
OCP without constraints on initial state detected.
found compiled acados MEX interface
Successfully rendered acados templates!
Error using acados_template_mex.compile_ocp_shared_lib
Building templated code as shared library failed.
Got status 2, result: [ 6%] Building C object
CMakeFiles/model_Constr_SINDy_7.dir/Constr_SINDy_7_model/Constr_SINDy_7_expl_ode_fun.c.obj
[ 12%] Building C object CMakeFiles/model_Constr_SINDy_7.dir/Constr_SINDy_7_model/Constr_SINDy_7_expl_vde_forw.c.obj
[ 18%] Building C object CMakeFiles/model_Constr_SINDy_7.dir/Constr_SINDy_7_model/Constr_SINDy_7_expl_vde_adj.c.obj
[ 18%] Built target model_Constr_SINDy_7
[ 25%] Building C object CMakeFiles/ocp_Constr_SINDy_7.dir/Constr_SINDy_7_cost/Constr_SINDy_7_cost_ext_cost_0_fun.c.obj
[ 31%] Building C object CMakeFiles/ocp_Constr_SINDy_7.dir/Constr_SINDy_7_cost/Constr_SINDy_7_cost_ext_cost_0_fun_jac.c.obj
[ 37%] Building C object CMakeFiles/ocp_Constr_SINDy_7.dir/Constr_SINDy_7_cost/Constr_SINDy_7_cost_ext_cost_0_fun_jac_hess.c.obj
[ 43%] Building C object CMakeFiles/ocp_Constr_SINDy_7.dir/Constr_SINDy_7_cost/Constr_SINDy_7_cost_ext_cost_fun.c.obj
[ 50%] Building C object CMakeFiles/ocp_Constr_SINDy_7.dir/Constr_SINDy_7_cost/Constr_SINDy_7_cost_ext_cost_fun_jac.c.obj
[ 56%] Building C object CMakeFiles/ocp_Constr_SINDy_7.dir/Constr_SINDy_7_cost/Constr_SINDy_7_cost_ext_cost_fun_jac_hess.c.obj
[ 62%] Building C object CMakeFiles/ocp_Constr_SINDy_7.dir/Constr_SINDy_7_cost/Constr_SINDy_7_cost_ext_cost_e_fun.c.obj
mingw32-make.exe[2]: *** [CMakeFiles\ocp_Constr_SINDy_7.dir\build.make:166:
CMakeFiles/ocp_Constr_SINDy_7.dir/Constr_SINDy_7_cost/Constr_SINDy_7_cost_ext_cost_e_fun.c.obj] Error 1
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:112: CMakeFiles/ocp_Constr_SINDy_7.dir/all] Error 2
mingw32-make.exe: *** [Makefile:135: all] Error 2

Error in AcadosOcpSolver (line 64)
acados_template_mex.compile_ocp_shared_lib(ocp.code_export_directory)

Error in CSINDy_7 (line 73)
ocp_solver = AcadosOcpSolver(ocp);

Thank in advance.

Hi,
please format your code snippets better next time.
I briefly had a look.
Indeed the code does not compile anymore for this size.
I don’t think this optimization problem is particularly suited for acados, as there is no OCP structure.
Also the objective is not phrased nicely.
I believe the abs is redundant and a nonlinear least-squares formulation would be better for acados.
Also, it might be better to use MX symbolics for large problem dimension.
Cheers