CasADi callbacks


I am interested in implementing an NMPC with the acados Python interface with Gaussian process based dynamics, similar to what is discussed in this CasADi blog post: It involves defining custom callbacks in CasADi. Does acados support defining the cost function and/or dynamics using such callback functions?


Hi Martin,

Interesting question!

The acados Python interface relies on two important CasADi features.

  1. the AD capabilities
  2. C code generation

These features are not supported for CasADi callbacks.
Unfortunately, it is thus not straight forward to implement what you described.

The last part of the blog post shows how the reverse AD of tensorflow can be interfaced to the CasADi callback.
However, acados typically uses the forward AD, as far as I know.
And extending this to also support C code generation of the derivatives seems not easy too.


Hi Jonathan,

Thanks for your reply.

That is unfortunate. Then it looks like I will have to stick to CasADi and hope it is fast enough for real-time useā€¦

Thanks for all the great work you do!


@martiabr , you could try to see if this example helps you:

Note that the cost ad dynamics are defined with casadi functions, so perhaps you could re-write your problem accordingly?

Hope it helps!