casadi / casadi

CasADi is a symbolic framework for numeric optimization implementing automatic differentiation in forward and reverse modes on sparse matrix-valued computational graphs. It supports self-contained C-code generation and interfaces state-of-the-art codes such as SUNDIALS, IPOPT etc. It can be used from C++, Python or Matlab/Octave.
http://casadi.org
GNU Lesser General Public License v3.0
1.67k stars 369 forks source link

AD reverse missing for L1 norm #2957

Open winwinashwin opened 2 years ago

winwinashwin commented 2 years ago

Casadi version : 3.5.5 (MATLAB)

To reproduce

import casadi.*

n = 100;
p = 20;
Theta = randn(p,n);  
y = randn(p,1);

opti = casadi.Opti();

s = opti.variable(n,1);

opti.minimize(  norm(s,1)  );
opti.subject_to( Theta*s == y );

opti.solver('ipopt');
sol = opti.solve();

Fails with Error

Error using casadi.Opti/solve (line 253)
Error in Opti::solve [OptiNode] at .../casadi/core/optistack.cpp:159:
.../casadi/core/function_internal.cpp:145: Error calling IpoptInterface::init for 'solver':
Error in Function::factory for 'nlp' [MXFunction] at .../casadi/core/function.cpp:1634:
Failed to create nlp_grad:[x, p, lam:f, lam:g]->[f, g, grad:gamma:x, grad:gamma:p] with {"gamma": [f, g]}:
.../casadi/core/factory.hpp:367: Gradient generation failed:
Error in MX::gradient at .../casadi/core/generic_matrix.hpp:1203:
Error in MX::jtimes at .../casadi/core/generic_matrix.hpp:1191:
Error in MX::reverse at .../casadi/core/mx.cpp:1741:
Error in MXFunction::ad_reverse at .../casadi/core/mx_function.cpp:1042:
Error in MX::ad_reverse for node of type N6casadi5Norm1E at .../casadi/core/mx.cpp:2044:
.../casadi/core/mx_node.cpp:325: 'ad_reverse' not defined for class N6casadi5Norm1E

Error in test_casadi (line 20)
sol = opti.solve();
jowaibel commented 1 month ago

Hello, are there any updates on this? I'm getting still the sam error with casadi-3.6.5-osx64-matlab2018b. Thank you.