There is a newer version of the record available.

Published March 30, 2025 | Version 3.7.0
Software Open

CasADi - A software framework for nonlinear optimization and optimal control

Description

Install

Grab a binary from the table:

<table> <tr><th></th><th>Windows</th><th>Linux</th><th>Mac classic (High Sierra or above)</th><th>Mac M1</th></tr> <tr> <th>Matlab</th> <td><a href="https://github.com/casadi/casadi/releases/download/3.7.0/casadi-3.7.0-windows64-matlab2018b.zip">R2018b</a> or later</td> <td><a href="https://github.com/casadi/casadi/releases/download/3.7.0/casadi-3.7.0-linux64-matlab2018b.zip">R2018b</a> or later</td> <td><a href="https://github.com/casadi/casadi/releases/download/3.7.0/casadi-3.7.0-osx64-matlab2018b.zip">R2018b</a> or later</td> <td><a href="https://github.com/casadi/casadi/releases/download/3.7.0/casadi-3.7.0-osx_arm64-matlab2018b.zip">R2023b</a> or later (Apple Silicon)<br/><a href="https://github.com/casadi/casadi/releases/download/3.7.0/casadi-3.7.0-osx64-matlab2018b.zip">R2018b</a> or later (Rosetta)</td> </tr> <tr> <th>Octave</th> <td><a href="https://github.com/casadi/casadi/releases/download/3.7.0/casadi-3.7.0-windows64-octave7.3.0.zip">6.2.0</a> or later</td> <td><a href="https://github.com/casadi/casadi/releases/download/3.7.0/casadi-3.7.0-linux64-octave7.3.0.zip">6.2.0</a> or later</td> <td><a href="https://github.com/casadi/casadi/releases/download/3.7.0/casadi-3.7.0-osx64-octave7.3.0.zip">6.2.0</a> or later</td> <td><a href="https://github.com/casadi/casadi/releases/download/3.7.0/casadi-3.7.0-osx_arm64-octave7.3.0.zip">6.2.0</a> or later</td> </tr> <tr> <th>Python</th> <td colspan="4"><code>pip install casadi</code> (needs <code>pip -V</code>>=8.1)</td> </tr> </table>

For Matlab/Octave, unzip in your home directory and adapt the path:

<pre> <code> addpath('&lt;yourpath>/casadi-3.7.0-windows64-matlab2018b') </code> </pre>

Check your installation:

<table> <tr><th>Matlab/Octave</th><th>Python</th><tr> <tr><td> <pre> <code> import casadi.* x = MX.sym('x') disp(jacobian(sin(x),x)) </code> </pre> </td><td>

<pre> <code> from casadi import * x = MX.sym("x") print(jacobian(sin(x),x)) </code> </pre>

</td></tr> </table>

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 sum operation is now exposed to the user, next to existing sum1/sum2. In Python, it behaves exactly like np.sum. In Matlab, it follows the conventions of the builtin Matlab sum. breaking If you have been doing from casadi import *, you'll find that sum no longer refers to the builtin Python sum. You may use import builtins;builtins.sum to access that variant.

  • You can now put Function calls (e.g. bsplines/lookup tables, Callbacks) into SX graphs. Consequently, you can more often perform expand on an MX graph (still it may not always be a good idea). You can force Functions to end up as SX call nodes with option never_inline true.

  • You can now make call SX Functions with MX in an inlining fashion, y setting always_inline true.

  • New functionality extract_parametric. The purpose of extract_parametric is 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 diagcat and jtimes.

  • A bug was fixed related to 0^0 in 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_p and no_nlp_grad for nlpsol have now been made false and true respectively, 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, https://github.com/casadi/casadi/issues/3962). Influenced by GlobalOptions's setCopyElisionMinSize.
  • Breaking Dense sparsity patterns in the input/output scheme of generated functions are now compactly represented. You can use option force_canonical true 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_scale syntax for decision variables, and a linear_scale argument to subject_to.
  • show_infeasibilities is now easier to interpret when detect_simple_bounds is active.

Function

  • breaking Serialization: Functions that include an Integrator, Rootfinder or FMU Function.
  • dump dump_in dump_out options 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 tool. Rumoca includes a proof-of-concept implementation for converting Modelica into CasADi/DaeBuilder Python scripts.
  • The FMU export has been improved and the CasADi examples collection now contains two examples (vdp and bouncing ball, the latter with event support) where the generated FMUs can be simulated with FMPy.
  • DaeBuilder has been extended to support events defined via when-equations, for now only compatible with symbolic modeling (not using standard FMUs), including for FMU export. The event systems can be simulated and have sensitivities analytically calculated, as discussed below.
  • After numerous fixes to the interface, the FMU import has now been successfully used to import model exchange FMUs generated with multiple tools, including MATLAB/Simulink, OpenModelica, Dymola and Modelon Impact/OCT. For a list of FMI-compatible tools, see the FMI website.

Hybrid simulation and sensitivity analysis

The integrator class has been extended to support state events. This is a prototype implementation, currently only tested with Sundials/CVODES. First order analytic sensitivity calculations (but not yet other forms of sensitivity analysis) is possible for systems with events, including propagation of sensitivities through zero-crossing functions and events dynamics. The approach is compatible with when equations formulated in DaeBuilder (see above), but can also be used stand-alone. For details, see the implementation paper.

Building and distribution

  • CMake install now observes CMAKE_INSTALL_LIBDIR, etc..
  • There is now a RELOCATABLE option in CMake (default ON) that avoids spilling absolute paths into CasADi. #3896
  • To cater for C++ users, we started a vcpkg port for casadi. For now, just AD though, no plugins yet.
  • The CMake presets have been updated to allow for an easier source build on Windows or Linux, especially when using VS Code. Just select a preset in VS Code and use the CMake GUI in VS Code to select build options.

Misc

  • Various bugfixes and patches listed in https://github.com/casadi/casadi/milestone/22

Plugin versions used in binaries

3.7.0

  • sundials-interface, Interface to the ODE/DAE integrator suite SUNDIALS.
  • csparse-interface, Interface to the sparse direct linear solver CSparse.
  • superscs-interface, Interface to QP solver SUPERSCS.
  • osqp-interface, Interface to QP solver OSQP.
  • tinyxml-interface, Interface to the XML parser TinyXML.
  • qpoases-interface, Interface to the active-set QP solver qpOASES.
  • blocksqp-interface, Interface to the NLP solver blockSQP.
  • cplex-mockup-build, Use mockup CPLEX (BUILD_MOCKUPS_VERSION=master) from downloaded source (BUILD_MOCKUPS_GIT_REPO=https://github.com/casadi/mockups.git).
  • snopt-mockup-build, Use mockup SNOPT (BUILD_MOCKUPS_VERSION=master) from downloaded source (BUILD_MOCKUPS_GIT_REPO=https://github.com/casadi/mockups.git).
  • knitro-mockup-build, Use mockup KNITRO (BUILD_MOCKUPS_VERSION=master) from downloaded source (BUILD_MOCKUPS_GIT_REPO=https://github.com/casadi/mockups.git).
  • gurobi-mockup-build, Use mockup GUROBI (BUILD_MOCKUPS_VERSION=master) from downloaded source (BUILD_MOCKUPS_GIT_REPO=https://github.com/casadi/mockups.git).
  • worhp-mockup-build, Use mockup WORHP (BUILD_MOCKUPS_VERSION=master) from downloaded source (BUILD_MOCKUPS_GIT_REPO=https://github.com/casadi/mockups.git).
  • hsl-mockup-build, Use mockup WORHP (BUILD_MOCKUPS_VERSION=master) from downloaded source (BUILD_MOCKUPS_GIT_REPO=https://github.com/casadi/mockups.git).
  • madnlp-mockup-build, Use mockup MadNLP (BUILD_MOCKUPS_VERSION=master) from downloaded source (BUILD_MOCKUPS_GIT_REPO=https://github.com/casadi/mockups.git).
  • alpaqa-sourcebuild, Build Alpaqa (BUILD_ALPAQA_VERSION=develop) from downloaded source (BUILD_ALPAQA_GIT_REPO=https://github.com/jgillis/alpaqa).
  • highs-sourcebuild, Build HiGHS (BUILD_HIGHS_VERSION=v1.10.0) from downloaded source (BUILD_HIGHS_GIT_REPO=https://github.com/ERGO-Code/HiGHS).
  • daqp-sourcebuild, Build DAQP (BUILD_DAQP_VERSION=master) from downloaded source (BUILD_DAQP_GIT_REPO=https://github.com/jgillis/daqp.git).
  • proxqp-sourcebuild, Build PROXQP (BUILD_PROXQP_VERSION=v0.3.2) from downloaded source (BUILD_PROXQP_GIT_REPO=https://github.com/Simple-Robotics/proxsuite.git).
  • osqp-sourcebuild, Build OSQP (BUILD_OSQP_VERSION=v0.6.3) from downloaded source (BUILD_OSQP_GIT_REPO=https://github.com/osqp/osqp.git).
  • superscs-sourcebuild, Build SuperSCS (BUILD_SUPERSCS_VERSION=4d2d1bd03ed4cf93e684a880b233760ce34ca69c) from downloaded source (BUILD_SUPERSCS_GIT_REPO=https://github.com/jgillis/scs.git).
  • sleqp-sourcebuild, Build SLEQP (BUILD_SLEQP_VERSION=patch-1) from downloaded source (BUILD_SLEQP_GIT_REPO=https://github.com/jgillis/sleqp.git).
  • bonmin-sourcebuild, Build BONMIN (BUILD_BONMIN_VERSION=releases/1.8.9) from downloaded source (BUILD_BONMIN_GIT_REPO=https://github.com/coin-or/Bonmin.git).
  • ipopt-sourcebuild, Build IPOPT (BUILD_IPOPT_VERSION=3.14.11.mod) from downloaded source (BUILD_IPOPT_GIT_REPO=https://github.com/jgillis/Ipopt-1.git).
  • cbc-sourcebuild, Build CBC (BUILD_CBC_VERSION=releases/2.10.11) from downloaded source.
  • clp-sourcebuild, Build CLP (BUILD_CLP_VERSION=releases/1.17.9) from downloaded source (BUILD_CLP_GIT_REPO=https://github.com/coin-or/Clp.git).
  • mumps-sourcebuild, Build MUMPS (BUILD_MUMPS_TP_VERSION=releases/3.0.2) from downloaded source (BUILD_MUMPS_TP_GIT_REPO=https://github.com/coin-or-tools/ThirdParty-Mumps.git).
  • spral-sourcebuild, Build SPRAL (BUILD_SPRAL_VERSION=d385d2c9e858366d257cafaaf05760ffa6543e26) from downloaded source (BUILD_SPRAL_GIT_REPO=https://github.com/ralna/spral.git).
  • metis-sourcebuild, Build METIS (BUILD_METIS_TP_VERSION=6997f64) from downloaded source.
  • fatrop-sourcebuild, Build FATROP (BUILD_FATROP_VERSION=v0.0.4.post1) from downloaded source (BUILD_FATROP_GIT_REPO=https://github.com/meco-group/fatrop.git).
  • hpipm-sourcebuild, Build HPIPM (BUILD_HPIPM_VERSION=0e0c9f4e0d4081dceafa9b37c396db50bce0e81a) from downloaded source (BUILD_HPIPM_GIT_REPO=https://github.com/jgillis/hpipm.git).
  • trlib-sourcebuild, Build TRLIB (BUILD_TRLIB_VERSION=c7632b8b14152e78bc21721a3bd1a2432586b824) from downloaded source (BUILD_TRLIB_GIT_REPO=https://github.com/jgillis/trlib.git).
  • blasfeo-sourcebuild, Build BLASFEO (BUILD_BLASFEO_VERSION=edf92b396adddd9e548b9786f87ad290a0971329) from downloaded source (BUILD_BLASFEO_GIT_REPO=https://github.com/giaf/blasfeo.git).
  • lapack-sourcebuild, Download and install OpenBLAS for LAPACK+BLAS
  • eigen3-sourcebuild, Build Eigen (BUILD_EIGEN3_VERSION=3.4.0) from downloaded source (BUILD_EIGEN3_GIT_REPO=https://gitlab.com/libeigen/eigen.git).
  • simde-sourcebuild, Build Simde (BUILD_SIMDE_VERSION=v0.7.2) from downloaded source.
  • libzip-sourcebuild, Build LIBZIP (BUILD_LIBZIP_VERSION=v1.11.3) from downloaded source (BUILD_LIBZIP_GIT_REPO=https://github.com/nih-at/libzip).
  • zlib-sourcebuild, Build ZLIB (BUILD_ZLIB_VERSION=v1.3.1) from downloaded source (BUILD_ZLIB_GIT_REPO=https://github.com/madler/zlib).
  • cplex-interface, Interface to the QP solver CPLEX.
  • gurobi-interface, Interface to the (mixed-integer) QP solver GUROBI
  • knitro-interface, Interface to the NLP solver KNITRO.
  • madnlp-interface, Interface to the NLP solver MadNLP.
  • snopt-interface, Interface to the NLP solver KNITRO.
  • worhp-interface, Interface to the NLP solver Worhp (requires gfortran, gomp).
  • lapack-interface, Interface to LAPACK.
  • mumps-interface, Interface to MUMPS.
  • spral-interface, Interface to SPRAL.
  • coinutils-sourcebuild, Build COINUTILS (BUILD_COINUTILS_VERSION=releases/2.11.10) from downloaded source.
  • osi-sourcebuild, Build OSI (BUILD_OSI_VERSION=releases/0.108.9) from downloaded source.
  • clp-interface, Interface to the LP solver CLP.
  • cgl-sourcebuild, Build CGL (BUILD_CGL_VERSION=releases/0.60.8) from downloaded source.
  • cbc-interface, Interface to the LP solver CBC.
  • ipopt-interface, Interface to the NLP solver Ipopt.
  • bonmin-interface, Interface to the MINLP framework Bonmin.
  • highs-interface, Interface to the MILP / QP solver HiGHS.
  • daqp-interface, Interface to the MILP / QP solver HiGHS.
  • sleqp-interface, Interface to the NLP solver SLEQP.
  • alpaqa-interface, Interface to the NLP solver Alpaqa.
  • proxqp-interface, Interface to QP solver PROXQP.
  • ampl-interface, Interface to the AMPL solver library.
  • zlib-interface, Interface to the zlib.
  • libzip-interface, Interface to the libzip.
  • ghc-filesystem-interface, Interface to the ghc.

Notes

If you use this software, please cite it as below.

Files

casadi/casadi-3.7.0.zip

Files (5.1 MB)

Name Size Download all
md5:641fa4a02e64d3d811a4389e9d956d18
5.1 MB Preview Download

Additional details

Related works

Is supplement to
Software: https://github.com/casadi/casadi/tree/3.7.0 (URL)

Software