Prototype/Request: Dynamic parameters in CppAD cost functions#147
Draft
PPeltzer wants to merge 1 commit intoethz-adrl:v3.0.3-develfrom
Draft
Prototype/Request: Dynamic parameters in CppAD cost functions#147PPeltzer wants to merge 1 commit intoethz-adrl:v3.0.3-develfrom
PPeltzer wants to merge 1 commit intoethz-adrl:v3.0.3-develfrom
Conversation
…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.
Member
|
@neunertm, fyi! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
CostFunctionADParamsclass 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 newsetCurrentParametersfunction.Drawbacks: This workaround has some rather big drawbacks:
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