Skip to content

FAQ: how to resolve 'eval_sx' not defined?

Joris Gillis edited this page Jan 24, 2024 · 8 revisions

Short answer

Don't do expand true, or don't do SX.sym (but rather MX.sym)

Longer answer

CasADi has two types of expressions graphs:

  • SX, tuned for speed, but quite restricted in what it can do
  • MX, tuned for compact memory use, and no restrictions on usage.

You can model in SX directly, or model in MX (Opti also uses this for variables/parameters), and expand.

You can perform expansion by passing an option expand true to the solver, or calling f.expand() on a Function f defined with M symbols.

You cannot mix MX and SX expressions, but you can call an MX-defined Function with SX (this triggers expansion), or call an SX-defined Function with MX (this creates a call node in the MX graph).

Whenever you encounter the error "'eval_sx' not defined ...", it means you are directly/indirectly requesting MX to be expanded into SX for an MX node that does not allow it.

Check for the source of expansion in the description above, and adapt your code to an expandable form, or such that no expansion is performed.

Examples of unexpandable things:

  • A third-party library call like a Lapack factorization or matrix exponential (written in fortran), or a call to Cvodes. The default call to solve (as in A\B) and inv (as in A^(-1)) use an unexpandable algorithm. To change to an expandable algorithm, introduced'symbolicqr' as second argument (e.g. inv(M,'symbolicqr')).

I really, really need to expand.

There is an open issue to introduce call-nodes in SX. Don't hold your breath..

Clone this wiki locally