Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

@russelmann

Description

@russelmann

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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions