Releases: casadi/casadi
nightly-release-3.7.2
issue #4175: custom temporary directories
nightly-rn5
Harden unittest for py2.7
nightly-debug5
Harden unittest for py2.7
nightly-py3.14
automated commit by docs target [skip ci]
3.7.1
Install
Grab a binary from the table:
| Windows | Linux | Mac classic (High Sierra or above) | Mac M1 | |
|---|---|---|---|---|
| Matlab | R2018b or later | R2018b or later | R2018b or later | R2023b or later (Apple Silicon) R2018b or later (Rosetta) |
| Octave | 6.2.0 or later | 6.2.0 or later | 6.2.0 or later | 6.2.0 or later |
| Python | pip install casadi (needs pip -V>=8.1) |
|||
For Matlab/Octave, unzip in your home directory and adapt the path:
addpath('<yourpath>/casadi-3.7.1-windows64-matlab2018b')
Check your installation:
| Matlab/Octave | Python |
|---|---|
|
|
Get started with the example pack. Onboarding pointers have been gathered by the community at our wiki.
Troubleshooting
- KNITRO on linux crashes with a segmentation fault without
LD_PRELOAD=<knitro_lin_path>/libiomp5.so. - Callbacks with one argument are broken in Matlab CasADi
Release notes
Symbolic expressions
-
A uniform
sumoperation is now exposed to the user, next to existingsum1/sum2. In Python, it behaves exactly likenp.sum. In Matlab, it follows the conventions of the builtin Matlabsum. breaking If you have been doingfrom casadi import *, you'll find thatsumno longer refers to the builtin Pythonsum. You may useimport builtins;builtins.sumto access that variant. -
You can now put Function calls (e.g. bsplines/lookup tables, Callbacks) into SX graphs. Consequently, you can more often perform
expandon an MX graph (still it may not always be a good idea). You can force Functions to end up as SX call nodes with optionnever_inlinetrue. -
You can now make call SX Functions with MX in an inlining fashion, y setting
always_inlinetrue. -
New functionality
extract_parametric. The purpose ofextract_parametricis ultimately to save on evaluation time of an expression, by extracting out the parts that are only solely dependent on parameters.
Here is an example of CasADi Function with a contraction of a 100-by-100 input in its graph, dependent only on parameters:
x = MX.sym('x');
p = MX.sym('p',100,100);
q = MX.sym('q');
expr = sin(x*sumsqr(p))*q;
f = Function('f',{x,p,q},{expr}) % f:(i0,i1[100x100],i2)->(o0) MXFunction
% Suppose we call this Function a lot of times with different values for x but equal values for p and q
% Recomputing sumsqr(p) every time would be a waste.
% Distill out the parts of the expression that only dependent on parameters p and q.
[expr_ret, symbols, parametric] = extract_parametric(expr, {p,q}, struct('extract_trivial', true));
% Construct now a hot function, called every time
f_compact = Function('f_compact',[{x} symbols],{expr_ret}) % f_compact:(i0,i1,i2)->(o0) MXFunction
% And a precompute that can be evaluated at initalization / outside a hot loop.
f_precompute = Function('f_precompute',{p,q},parametric) % f_precompute:(i0[100x100],i1)->(o0,o1) MXFunction
% Numerical check
rng(1)
x_num = rand(1);
p_num = rand(100,100);
q_num = rand(1);
[e_0, e_1] = f_precompute(p_num,q_num);
f_compact(x_num,e_0,e_1) % -0.116384
f(x_num,p_num,q_num) % -0.116384- New functionality
separate_linear. The purpose is to separate out parts of an expression graph that are constant or linear. Note that the partitioning is done with a straightforward pass through the graph. There are no computer-algebra-system type of transformations performed to influence the partitioning.
[expr_const,expr_lin,expr_nonlin] = separate_linear(cos(p)+7*x+x*y, [x,y], p)
expr_const: cos(p)
expr_lin: 7*x
expr_nonlin: x*y
-
Several bugfixes related to arguments shaped (0-by-n) or (n-by-0). breaking Your code may be relying on broken implementations of
diagcatandjtimes. -
A bug was fixed related to
0^0in MX.
breaking The fix may impact you if you used**(-1)(Python) or.^(-1)(Matlab) (element-wise power) on sparse matrices, e.g. for scaling matrices.
v = DM.rand(10,1)
print(diag(v)) # Sparse matrix with only diagonal entries
# Used to return a sparse matrix with diagonal entries inverted
# Now returns a dense matrix full of infs on the off-diagonals.
print(diag(v)**(-1))
# If you had this use case before, you can do the element-wise power on the vector progenitor:
print(diag(v**(-1)))
# Or use matrix-wise operations
print(inv(diag(v)))
print(mpower(diag(v),-1))AD
- The ability to perform algorithmic differentiation on nlp solvers incurs some overhead and surprises for novice users, even when unused. breaking The default settings of
calc_lam_pandno_nlp_gradfornlpsolhave now been madefalseandtruerespectively, eliminating that overhead.
Code-generation
- We now avoid copying over input arguments into a local workvector before acting upon them.
This very relevant if you perform sublinear operations on large inputs (e.g. parametric lookup tables, #3962). Influenced byGlobalOptions'ssetCopyElisionMinSize. - Breaking Dense sparsity patterns in the input/output scheme of generated functions are now compactly represented. You can use option
force_canonicaltrue to revert to old behaviour. - Added a 'memory pool' feature #3812
Solvers/plugins
- Important bugfixes to fatrop interface
- breaking Rootfinder was refactored internally to use a different naming convention. When you use the expression-oriented interface, no changes are needed. If you use the Function-based interface, you will need changes. For example, a code that read:
rfp = ca.Function('rfp', [X_unknown, X[0], U], [g], ['V0', 'X0', 'U'], ['V'])
ca.rootfinder('ifcn', 'kinsol', rfp) # output (V0[6],X0[2],U)->(V[6])Should be adapted to:
# For the unknown, drop the trailing '0' from the label
# For the residual output, pick anything as long as there is no name collision
rfp = ca.Function('rfp', [X_unknown, X[0], U], [g], ['V', 'X0', 'U'], ['res'])
ca.rootfinder('ifcn', 'kinsol', rfp) # still outputs (V0[6],X0[2],U)->(V[6])Opti Stack
- New
set_linear_scalesyntax for decision variables, and alinear_scaleargument tosubject_to. show_infeasibilitiesis now easier to interpret whendetect_simple_boundsis active.
Function
- breaking Serialization: Functions that include an Integrator, Rootfinder or FMU Function.
dumpdump_indump_outoptions now create directories when needed.
Thread safety
- CasADi used to be thread-safe for numerical evaluation. Now it is thread-safe for symbolic manipulation too.
C++
- breaking The casadi cmake target now has a namespace. The preferred way of configuring your cmake is:
find_package(casadi CONFIG REQUIRED)
add_executable(casadi_demo casadi_demo.cpp)
target_link_libraries(casadi_demo casadi::casadi)
Python
- CasADi-Python interfaces now releases the GIL. This is a preparation for eventually post python 3.13 GIL free releases.
DaeBuilder / FMI interoperability
- DaeBuilder can now accept the name of an fmu file, unzip it in a temporary folder and clean up that folder when it is no longer needed.
- The DaeBuilder class has had a major revision, both in terms of syntax and in functionality. With the new release, the syntax stays much closer to FMI/Modelica. If you are using or planning to use this class, we recommend you to read the updated section on DaeBuilder in the user guide.
- FMU import now supports FMI 3.0 (in addition to FMI 2.0). The FMU export, as before, only supports FMI 3.0. In addition, additional derivative information is handled by the interface including adjoints (FMI 3 only) and forward directional derivatives (which were previously only used to construct sparse Jacobians).
- The interface to formulate DaeBuilder symbolically has been updated with the goal of eventually supporting the proposed Base Modelica standard in terms of functionality. We are currently not planning to distribute a Modelica parser with CasADi, but we are coordinating the Base Modelica effort with developers of the open-source [Rumoca](https://github.com/cognipilot...
nightly-temp
automated commit by docs target [skip ci]
nightly-codegen_multithreaded
automated commit by docs target [skip ci]
nightly-release-3.7.1: issue #3889: fix broken link IPOPT in 90 minutes
Author: ivrolan
nightly-fatropv1
issue #4152: drop support for python 3.5
nightly-ge9
automated commit by docs target [skip ci]