Hands-on❤️CasADi

Expression graphs & Functions

Graph = symbolic primitive + operation + constant

# no reuse
n = sin(x+y)+(x+y)

# ❤️reuse
s=x+y
sin(s)+s

f: inputs(symbolic) -> outputs(expression graph)

N.B. Use SX (or expand MX) until you run out of RAM

Debugging

Use # %% in Python using VSCode to replace notebook.

Map & MapAccum

Time = Construction time + Evaluation time + Compilation time

Useful tools:

  • single shooting: MapAccum(F,N)
  • multiple shooting: F.map(N)

Serialization

Sparsity

Compressed Column Storage

Internals of CasADi

  • MX internally
  • MX Function internally
  • SX

CasADi virtual machine = a for-loop dispatching virtual function calls to eval.

Benchmarking

Code generation

C API

Parallelization

openmp

Algorithmic differentiation

  • Finit differences
  • Symbolic differentiation using sympy
  • Algorithmic differentiation: Sparsity exploitation

Callbacks

External