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

Calling CppAD::ipopt::solve from CppADCodeGen #78

Open
a-jp opened this issue Aug 14, 2022 · 8 comments
Open

Calling CppAD::ipopt::solve from CppADCodeGen #78

a-jp opened this issue Aug 14, 2022 · 8 comments
Labels

Comments

@a-jp
Copy link

a-jp commented Aug 14, 2022

Hi, Would you be able to help me run this ipopt example using CppADCodeGen? What changes should I make to replicate this example but with the AD performed by CppADCodeGen? I have successfully compiled and run this example with my local ipopt and CppAD builds and it works well.

Many thanks,

@a-jp
Copy link
Author

a-jp commented Aug 20, 2022

Hi,

Is there any more info I can provide to help with this question?
Thanks,
Andy

@joaoleal
Copy link
Owner

Hello Andy,

From what I can see from CppAD's support for Ipopt this would require a re-implementation for CppADCodeGen since CppAD uses AD::ADFun and CppADCodeGen uses different types and requires additional steps (compilation step).
Unfortunately, there is no simple way to just start using CppAD's support for Ipopt.

Kind regards,
João

@bradbell
Copy link
Collaborator

bradbell commented Aug 21, 2022

I think that working on a faster than CppAD::ipopt::solve interface to ipopt, along the lines suggested above, is worth while but not a simple effort. If someone is interested in taking the lead on this, I would be willing to will to help.

@a-jp
Copy link
Author

a-jp commented Aug 23, 2022

Thank you for the advice.

@a-jp
Copy link
Author

a-jp commented Sep 5, 2022

@bradbell and @joaoleal what would be the first and simplest step to make progress on using cppadcodegen for ipopt via cppad?

How do we make progress towards converting the example I first linked to so it can work with cppadcodegen?

@bradbell
Copy link
Collaborator

bradbell commented Sep 5, 2022

I suggest you start by programming up the simple ipopt example
https://github.com/bradbell/cppad_mixed/blob/master/example/ipopt_run.cpp
And modifying it so that the derivative functions are calculated using CppADCodeGen.
Once you have done that, you can extend it to work with an arbitrary function.

You will note that the example above is documented using omhelp.
I am working on a program that converts omhelp to sphinx (I do not plan to continue supporting omhelp).
I expect the omhelp to eventually be converted to the following extension of sphinx:
https://bradbell.github.io/xrst/doc/user_guide.html#purpose

@a-jp
Copy link
Author

a-jp commented Sep 6, 2022

@bradbell thanks for the suggestion. @joaoleal can you suggest a good cppadcodegen example that will help with this task?

@joaoleal
Copy link
Owner

joaoleal commented Sep 6, 2022

There is an example that creates a model for a Lagrangian here:
https://github.com/joaoleal/CppADCodeGen/blob/master/example/lagrangian.cpp

I would, however, not do it like this. Nevertheless, it can be used as a starting point.

I would instead create two models:

  • a model for the objective function
  • a model for the NLP with the objective function and the constraints (to determine Lagrangian-related information)

For the NLP model I would configure a custom sparse hessian sparsity with only half of the Hessian (to improve performance).
You can also get away with only the NLP model but there are cases where there is no need to compute information related to the constraints (e.g., eval_grad_f).

If there are any parameters in the model I would also remove them from the sparsity patterns.

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

No branches or pull requests

3 participants