0

I am trying to implement some auto-differentation jacobians for verification of analytical jacobians. These are the functions in question being tested. When I compile them with g++ I get the following error:

In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__functional/perfect_forward.h:14:
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/tuple:1546:5: error: no matching function for call to '__apply_tuple_impl'
    _VSTD::__apply_tuple_impl(
    ^~~~~~~~~~~~~~~~~~~~~~~~~~
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__config:858:15: note: expanded from macro '_VSTD'
#define _VSTD std::_LIBCPP_ABI_NAMESPACE
              ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/tuple:1530:79: note: expanded from macro '_LIBCPP_NOEXCEPT_RETURN'
#define _LIBCPP_NOEXCEPT_RETURN(...) noexcept(noexcept(__VA_ARGS__)) { return __VA_ARGS__; }
                                                                              ^~~~~~~~~~~
/Users/walkerant/mambaforge3/envs/ct-build/include/autodiff/forward/utils/derivative.hpp:161:19: note: in instantiation of function template specialization 'std::apply<Eigen::Matrix<autodiff::detail::Real<1, double>, -1, 1, 0> (Cantera::Reactor::*const &)(Eigen::Matrix<autodiff::detail::Real<1, double>, -1, 1, 0> &), const std::tuple<Eigen::Matrix<autodiff::detail::Real<1, double>, -1, 1, 0> &> &>' requested here
    auto u = std::apply(f, at.args);
                  ^
/Users/walkerant/mambaforge3/envs/ct-build/include/autodiff/forward/utils/gradient.hpp:138:13: note: in instantiation of function template specialization 'autodiff::detail::eval<Eigen::Matrix<autodiff::detail::Real<1, double>, -1, 1, 0> (Cantera::Reactor::*)(Eigen::Matrix<autodiff::detail::Real<1, double>, -1, 1, 0> &), Eigen::Matrix<autodiff::detail::Real<1, double>, -1, 1, 0> &, autodiff::detail::Real<1, double> &>' requested here
        F = eval(f, at, detail::wrt(xi)); // evaluate F with xi seeded so that dF/dxi is also computed
            ^
/Users/walkerant/mambaforge3/envs/ct-build/include/autodiff/forward/utils/gradient.hpp:75:21: note: in instantiation of function template specialization 'autodiff::detail::jacobian(Eigen::Matrix<autodiff::detail::Real<1, double>, -1, 1, 0> (Cantera::Reactor::*const &)(Eigen::Matrix<autodiff::detail::Real<1, double>, -1, 1, 0> &), const Wrt<Eigen::Matrix<autodiff::detail::Real<1, double>, -1, 1, 0> &> &, const At<Eigen::Matrix<autodiff::detail::Real<1, double>, -1, 1, 0> &> &, Eigen::Matrix<autodiff::detail::Real<1, double>, -1, 1, 0> &, Eigen::Matrix<double, -1, -1, 0> &)::(anonymous class)::operator()<int, autodiff::detail::Real<1, double> &>' requested here
                    f(i++, item[j]);
                    ^
/Users/walkerant/mambaforge3/envs/ct-build/include/autodiff/common/meta.hpp:138:9: note: in instantiation of function template specialization 'autodiff::detail::ForEachWrtVar(const Wrt<Eigen::Matrix<autodiff::detail::Real<1, double>, -1, 1, 0> &> &, (lambda at /Users/walkerant/mambaforge3/envs/ct-build/include/autodiff/forward/utils/gradient.hpp:136:24) &&)::(anonymous class)::operator()<Eigen::Matrix<autodiff::detail::Real<1, double>, -1, 1, 0>>' requested here
        f(std::get<i>(tuple));
        ^
/Users/walkerant/mambaforge3/envs/ct-build/include/autodiff/common/meta.hpp:94:9: note: in instantiation of function template specialization 'autodiff::detail::ForEach(const std::tuple<Eigen::Matrix<autodiff::detail::Real<1, double>, -1, 1, 0> &> &, (lambda at /Users/walkerant/mambaforge3/envs/ct-build/include/autodiff/forward/utils/gradient.hpp:67:23) &&)::(anonymous class)::operator()<autodiff::detail::Index<0>>' requested here
        f(Index<i>{});
        ^
/Users/walkerant/mambaforge3/envs/ct-build/include/autodiff/common/meta.hpp:102:5: note: (skipping 1 context in backtrace; use -ftemplate-backtrace-limit=0 to see all)
    AuxFor<ibegin, ibegin, iend>(std::forward<Function>(f));
    ^
/Users/walkerant/mambaforge3/envs/ct-build/include/autodiff/common/meta.hpp:108:5: note: in instantiation of function template specialization 'autodiff::detail::For<0UL, 1UL, (lambda at /Users/walkerant/mambaforge3/envs/ct-build/include/autodiff/common/meta.hpp:137:12)>' requested here
    For<0, iend>(std::forward<Function>(f));
    ^
/Users/walkerant/mambaforge3/envs/ct-build/include/autodiff/common/meta.hpp:137:5: note: in instantiation of function template specialization 'autodiff::detail::For<1UL, (lambda at /Users/walkerant/mambaforge3/envs/ct-build/include/autodiff/common/meta.hpp:137:12)>' requested here
    For<N>([&](auto i) constexpr {
    ^
/Users/walkerant/mambaforge3/envs/ct-build/include/autodiff/forward/utils/gradient.hpp:67:5: note: in instantiation of function template specialization 'autodiff::detail::ForEach<const std::tuple<Eigen::Matrix<autodiff::detail::Real<1, double>, -1, 1, 0> &> &, (lambda at /Users/walkerant/mambaforge3/envs/ct-build/include/autodiff/forward/utils/gradient.hpp:67:23)>' requested here
    ForEach(wrt.args, [&](auto& item) constexpr
    ^
/Users/walkerant/mambaforge3/envs/ct-build/include/autodiff/forward/utils/gradient.hpp:136:5: note: in instantiation of function template specialization 'autodiff::detail::ForEachWrtVar<(lambda at /Users/walkerant/mambaforge3/envs/ct-build/include/autodiff/forward/utils/gradient.hpp:136:24), Eigen::Matrix<autodiff::detail::Real<1, double>, -1, 1, 0> &>' requested here
    ForEachWrtVar(wrt, [&](auto&& i, auto&& xi) constexpr {
    ^
src/zeroD/Reactor.cpp:569:15: note: in instantiation of function template specialization 'autodiff::detail::jacobian<Eigen::Matrix<autodiff::detail::Real<1, double>, -1, 1, 0> (Cantera::Reactor::*)(Eigen::Matrix<autodiff::detail::Real<1, double>, -1, 1, 0> &), Eigen::Matrix<autodiff::detail::Real<1, double>, -1, 1, 0> &, Eigen::Matrix<autodiff::detail::Real<1, double>, -1, 1, 0> &, Eigen::Matrix<autodiff::detail::Real<1, double>, -1, 1, 0>, Eigen::Matrix<double, -1, -1, 0>>' requested here
    autodiff::jacobian(&Reactor::_autodiffEval, autodiff::wrt(yV), autodiff::at(yV), ydot, jac);
              ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/tuple:1534:26: note: candidate template ignored: substitution failure [with _Fn = Eigen::Matrix<autodiff::detail::Real<1, double>, -1, 1, 0> (Cantera::Reactor::*const &)(Eigen::Matrix<autodiff::detail::Real<1, double>, -1, 1, 0> &), _Tuple = const std::tuple<Eigen::Matrix<autodiff::detail::Real<1, double>, -1, 1, 0> &> &, _Id = <0>]
constexpr decltype(auto) __apply_tuple_impl(_Fn && __f, _Tuple && __t,
                         ^
3 errors generated.
scons: *** [build/src/zeroD/Reactor.os] Error 1
scons: building terminated because of errors.

I have checked out deleted functions but the code is not explicitly deleting any functions. This issue only arises with the call of autodiff::jacobian, if I comment that line out and recompile, everything runs just fine. Is there a way I can try to track down why the compiler is saying these functions are deleted? I am using this auto-differentiation package called autodiff.

The code in question is:

#include <autodiff/forward/real.hpp>
#include <autodiff/forward/real/eigen.hpp>

Eigen::SparseMatrix<double> Reactor::autodiffJacobian()
{
    double y[m_nv];
    getState(y);
    autodiff::VectorXreal yV(Eigen::Map<Eigen::VectorXd>(y, m_nv));
    Eigen::MatrixXd jac(m_nv, m_nv);
    autodiff::VectorXreal ydot;
    autodiff::jacobian(&Reactor::_autodiffEval, autodiff::wrt(yV), autodiff::at(yV), ydot, jac);
    return jac.sparseView();
    // return jac;
}

autodiff::VectorXreal Reactor::_autodiffEval(autodiff::VectorXreal& y)
{
    vector_fp yT(m_nv);
    for (size_t i = 0; i < m_nv; i++) {
        yT[i] = y[i].val();
    }
    updateState(yT.data());
    vector_fp lhs(m_nv, 1);
    vector_fp rhs(m_nv, 0);
    eval(0, lhs.data(), rhs.data());
    autodiff::VectorXreal ydot(m_nv);
    for (size_t i = 0; i < m_nv; i++) {
        ydot[i] = rhs[i]/lhs[i];
    }
    return ydot;
}

The code is compiled with:

g++ -o build/src/zeroD/Reactor.os -c --std=c++17 -I/ext/eigen/Eigen -I/ext/eigen -O3 -Wno-inline -g -Wall -include src/pch/system.h -fPIC -DNDEBUG -Iinclude -I/ext -Ibuild/src -Ict-build/include src/zeroD/Reactor.cpp

Edit

The error has to something to do with it being in a class. I created a very simple example to replicate the process from an accepted example in autodiff.

// C++ includes
#include <iostream>

// autodiff include
#include <autodiff/forward/real.hpp>
#include <autodiff/forward/real/eigen.hpp>
using namespace autodiff;

VectorXreal ft(const VectorXreal& x, const VectorXreal& p, const real& q)
{
    return x * p.sum() * exp(q);
}

class scratch
{
private:
    /* data */
public:
    scratch(/* args */);
    ~scratch();
    VectorXreal f(const VectorXreal& x, const VectorXreal& p, 
const real& q);
    Eigen::MatrixXd jac();
};

VectorXreal scratch::f(const VectorXreal& x, const VectorXreal& p, const real& q)
{
    return x * p.sum() * exp(q);
}

Eigen::MatrixXd scratch::jac()
{
    VectorXreal x(5);    // the input vector x with 5 variables
    x << 1, 2, 3, 4, 5;  // x = [1, 2, 3, 4, 5]
    VectorXreal p(3);    
    p << 1, 2, 3;        // p = [1, 2, 3]
    real q = -2;         
    VectorXreal F;       
    Eigen::MatrixXd Jqpx = jacobian(ft, wrt(q, p, x), at(x, p, q), F); 
    return Jqpx;
}

int main()
{
    scratch sobj;
    Eigen::MatrixXd Jqpx = sobj.jac();
    std::cout << "Jqpx = \n" << Jqpx << std::endl; 
}
sokato
  • 354
  • 4
  • 14
  • 2
    Please [edit] your code to be a [mre] (make sure all necessary `#include`s are present, but remove unrelated code). Which autodiff library are you using? – chtz Oct 26 '22 at 09:22

0 Answers0