Dear all,
We are happy to announce the release of CasADi 2.4! It is a major release that we have worked intensively on the last couple of month.
The new release introduces a new, more compact syntax for both constructors and function evaluation. For constructors, the syntax changes from e.g.:
f = SXFunction([x],[sin(x)])
f.setOption('verbose', True)
to
f = SXFunction('f', [x],[sin(x)], {'verbose':True})
And similarly for other "Function" classes of CasADi (MXFunction, NlpSolver, Integrator, etc.). Note that it is now always required to name function objects (this name will be used to produce more informative output and error messages). The options argument is optional.
For numerical evaluation, the syntax changes from:
f.setInput(2.4)
f.evaluate()
y = f.getOutput(0)
to simply:
For named inputs, the syntax is dictionary-in-dictionary-out, so instead of:
nlp_solver.setInput([2.5,3.0,0.75], 'x0')
nlp_solver.setInput(-inf, 'lbx')
nlp_solver.setInput( inf, 'ubx')
nlp_solver.setInput( 0, 'lbg')
nlp_solver.setInput( 0, 'ubg')
nlp_solver.evaluate()
x_opt = nlp_solver.getOutput('x')
simply write:
arg = {'x0':[2.5,3.0,0.75], 'lbx':-inf, 'ubx':inf, 'lbg':0, 'ubg':0}
res = nlp_solver(arg)
x_opt = res['x']
This is part of an effort to make CasADi more efficient and easier to learn. To make migration to the new syntax easier for existing users, this release will support both the old and the new syntax side-by-side, but support for the old syntax will be dropped in future releases. This means that migrating from say 2.3 to (the future) 2.5, will be go much smoother if you first migrate to 2.4.
The other main novelty in terms of functionality is that the MATLAB front-end is now ready to use. Together with the above syntax change, solving an NLP in MATLAB, relying on CasADi to automatically and efficiently calculate first and second order derivative information can now be as simple as:
% Create NLP solver instance
x = SX.sym('x'); % Cf. 'sym' in symbolic toolbox
y = SX.sym('y');
z = SX.sym('z');
v = [x;y;z];
f = x^2 + 100*z^2; % minimize x^2 + 100*z^2
g = z + (1-x)^2 - y; % subject to z + (1-x)^2 - y == 0
solver = NlpSolver('solver', 'ipopt', struct('x', v, 'f', f, 'g', g));
% Pass initial guess, bounds and solve the NLP
res = solver(struct('x0',[2.5 3.0 0.75],...
'lbx',-inf,'ubx',inf,'lbg',0,'ubg',0));
x_optimal = full(res.x)
lam_g_optimal = full(res.lam_g)
Or equivalently from Python:
Import CasADi
from casadi import *
# Create NLP solver instance
x = SX.sym('x')
y = SX.sym('y')
z = SX.sym('z')
v = vertcat([x,y,z])
f = x**2 + 100*z**2 # minimize x^2 + 100*z^2
g = z + (1-x)**2 - y # subject to z + (1-x)^2 - y == 0
solver = NlpSolver('solver', 'ipopt', {'x':v, 'f':f, 'g': g})
# Pass initial guess, bounds and solve the NLP
res = solver({'x0':[2.5,3.0,0.75],'lbx':-inf,'ubx':inf,'lbg':0,'ubg':0})
print res['x']
print res['lam_g']
CasADi 2.4 also comes with a number of other news, including a refactored and vastly improved support for C code generation, support for just-in-time compilation and large improvements in the installation procedure of CasADi: Feature-complete binaries of CasADi is now available for Windows, Mac and OSX (OSX binary currently lacks MATLAB support).
For a list of other changes, see:
Best regards,
The CasADi team: Joris, Joel and Greg