FAQ: How to debug regressions in numerical solvers when updating CasADi?
Some CasADi versions (e.g. 3.6.0) come with an upgrade in third-party numerical solvers (e.g. Ipopt).
When your optimization problem has difficulty converging after such an upgrade, it's not immediately obvious what would be the cause.
The cause could be in:
- algorithmic changes in the third-party solver
- changes in CasADi that result in different sparsity patterns or numerical values (order of operations)
- a combination of both
Here is a strategy to figure out if the cause lies with CasADi:
Instrument your code with options to dump inputs and outputs
from casadi import *
x = MX.sym("x",5)
A = DM.rand(5,5)
Q = A.T@A
nlp = {"x":x,"f":bilin(Q,x-2)}
options = {"common_options":{"final_options" : {"dump_in":True, "dump_out":True}}}
solver = nlpsol("solver","ipopt",nlp,options)
solver(x0=0)
Do this both for old and new CasADi in different folders (or use dump_dir
) and do a diff between those directories (e.g. using meld
).
If CasADi provides identical sparsity and numerical values for typical outputs of the first iteration (e.g. nlp_grad_f.000000.out.f.mtx
), you should look at the release notes of the third party solvers for possible explanations.
warning: In 3.6.0 and up, Function outputs that are not used (passed a null pointer internally) will be logged as nan
instead of earlier 0
. E.g. Ipopt nlp_grad_f
has two outputs, f
and grad_f_x
. The f
output is not used internally, so will be logged as nan
.