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

Hessian computation via CGAtomicGenericModel nested in a larger CppAD::ADFun #32

Open
russelmann opened this issue Nov 28, 2019 · 1 comment

Comments

@russelmann
Copy link

russelmann commented Nov 28, 2019

I am trying to use a cg::CGAtomicGenericModel to compute the Hessian of a CppAD::ADFun. For example in this schematic code:

...
CGAtomicGenericModel<double> atomic_model;
ADFun<double> fun;
...
std::vector<AD<double>> X, Y, Z;
Y = atomic_model(X, Y);
Z = Y * Y; // some nonlinear function
fun(X, Z);
...
fun.sparse_hes(x, w, hess_subset, hess_pattern, "cppad.general", hes_work);

This would result in the following error:

cppad-20190806 error from a known source:
Second-order reverse mode failed: py[2*i] (i=0...m) must be zero.
Error detected by false result for
    ret != 1
at line 552 in the file 
    /Users/rguseino/sdk/cppadcodegen/include/cppad/cg/model/functor_generic_model.hpp
Assertion failed: (false), function Default, file /Users/rguseino/sdk/cppad/include/cppad/utility/error_handler.hpp, line 206.

In case Z is linear in Y, the error is not reproduced.
Does this mean that for now CGAtomicGenericModel is not supposed to be used in such scenario? Is there a workaround for this problem?
P.S. This happens in my large project but, if necessary, I can write simple code to reproduce this behavior.

@joaoleal
Copy link
Owner

joaoleal commented Dec 1, 2019

Hello Ruslan,

This is not implemented yet.
This would have to be done in ModelCSourceGen::generateReverseTwoSources().
There is an explicit check for this in the generated code.

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

No branches or pull requests

2 participants