Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prototype/Request: Dynamic parameters in CppAD cost functions #147

Open
wants to merge 1 commit into
base: v3.0.3-devel
Choose a base branch
from

Conversation

PPeltzer
Copy link

This PR results from a conversation I had with Michael Neunert back in May via the CT Devs mail group. Sorry for the delay, I finally found the time to open a PR.


This is only a prototype, i.e. no merge is desired! I hope the problem and my workaround can help to develop a proper implementation in the future.


  • Problem: I'm running a MPC with a custom cost function where I want CppAD to generate the derivatives for me. However, in this cost function, environment data must be considered. This data is passive w.r.t. differentiation - CppAD does not need to actually generate derivative code for these variables but only use it in its generated code in such a way that it can be updated between optimization calls. However, this is currently not supported by CppADCodeGen.

  • Ideal solution: I was pointed to this issue over at CppADCodeGen's git repo by Michael. The feature itself appears to be available in CppAD; however, it's not yet available for code generation.

  • Workaround: As suggested by Michael, I've implemented a workaround which you can find in this PR. I've added a new CostFunctionADParams class which extends the state vector by the passive parameters. This addition is ignored by 1st and 2nd derivative extraction functions - therefore the parameters are passive as desired. They can be updated using the new setCurrentParameters function.

  • Drawbacks: This workaround has some rather big drawbacks:

    • Although no derivative information is extracted later, CppADCodeGen still generates the corresponding code. This results in larger executables and in very poor JIT-compilation times.
    • Since the control toolbox currently only uses Eigen static matrices, the total size of the parameters is limited by the stack size.
    • The resulting interface is very ugly, i.e. custom datatypes can not be used and everything must be mapped to a CppAD Scalar.

Although my workaround did the job for me on a smaller project, using it in the long-term is no option due to these drawbacks. I would really like to see this problem addressed at some point as I really enjoy using AD for the cost functions as it makes rapid-prototyping way easier.

Best regards,

Patrick

…mic parameters in a CppAD cost function (parameters passive w.r.t. differentiation). Rather an ugly hack to use as a starting point to add proper support.
@markusgft
Copy link
Member

@neunertm, fyi!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants