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

Errors when build with latest version of cppad and cppadcg on 3 years old code. #206

Open
xiao-wang007 opened this issue Jun 1, 2024 · 8 comments

Comments

@xiao-wang007
Copy link

Hi

I was trying some old codes from github, which depends on cppad and cppadcg. But when I build it, it got stopped with these errors.
Is this because of the version?
Cheers

In file included from /Users/xiao/0_codes/to-ihc-2/dynamics.cpp:8:
In file included from /Users/xiao/0_codes/to-ihc-2/dynamics.h:8:
In file included from /Users/xiao/0_codes/to-ihc-2/common.h:11:
In file included from /Users/xiao/0_codes/to-ihc-2/hopper/declarations.h:4:
In file included from /Users/xiao/0_codes/to-ihc-2/hopper/rbd_types.h:12:
In file included from /Users/xiao/0_codes/to-ihc-2/hopper/../scalar_traits.h:9:
In file included from /usr/local/include/cppad/cg.hpp:18:
In file included from /usr/local/include/cppad/cg/cppadcg.hpp:81:
In file included from /usr/local/include/cppad/base_require.hpp:159:
/usr/local/include/cppad/core/numeric_limits.hpp:248:58: error: no member named 'max_digits10' in 'CppAD::numeric_limits<cg::CG>'
static const int max_digits10 = numeric_limits::max_digits10;
~~~~~~~~~~~~~~~~~~~~~~^
/usr/local/include/cppad/core/forward/forward.hpp:167:38: note: in instantiation of template class 'CppAD::numeric_limits<CppAD::AD<CppAD::cg::CG>>' requested here
taylor_[C * j + k] = CppAD::numeric_limits::quiet_NaN();
^
/usr/local/include/cppad/core/jacobian.hpp:202:4: note: in instantiation of function template specialization 'CppAD::ADFun<CppAD::AD<CppAD::cg::CG>, CppAD::cg::CG>::Forward<Eigen::Matrix<CppAD::AD<CppAD::cg::CG>, -1, 1>>' requested here
Forward(0, x);
^
/Users/xiao/0_codes/to-ihc-2/common.h:123:63: note: in instantiation of function template specialization 'CppAD::ADFun<CppAD::AD<CppAD::cg::CG>, CppAD::cg::CG>::Jacobian<Eigen::Matrix<CppAD::AD<CppAD::cg::CG>, -1, 1>>' requested here
MATRIX_AS_VECTOR_AD(full_jacobian) = ad_fun.base2ad().Jacobian(ad_x_);
^
/Users/xiao/0_codes/to-ihc-2/dynamics.cpp:146:5: note: in instantiation of member function 'ADBase<Dynamics, 10, 6, 8>::build_jacobian' requested here
build_jacobian();
^
In file included from /Users/xiao/0_codes/to-ihc-2/dynamics.cpp:8:
In file included from /Users/xiao/0_codes/to-ihc-2/dynamics.h:8:
In file included from /Users/xiao/0_codes/to-ihc-2/common.h:11:
In file included from /Users/xiao/0_codes/to-ihc-2/hopper/declarations.h:4:
In file included from /Users/xiao/0_codes/to-ihc-2/hopper/rbd_types.h:12:
In file included from /Users/xiao/0_codes/to-ihc-2/hopper/../scalar_traits.h:9:
In file included from /usr/local/include/cppad/cg.hpp:18:
In file included from /usr/local/include/cppad/cg/cppadcg.hpp:157:
In file included from /usr/local/include/cppad/cppad.hpp:53:
In file included from /usr/local/include/cppad/core/ad_fun.hpp:874:
In file included from /usr/local/include/cppad/core/fun_eval.hpp:9:
/usr/local/include/cppad/core/forward/forward.hpp:167:58: error: incomplete definition of type 'CppAD::numeric_limits<CppAD::AD<CppAD::cg::CG>>'
taylor_[C * j + k] = CppAD::numeric_limits::quiet_NaN();
~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
/usr/local/include/cppad/core/jacobian.hpp:202:4: note: in instantiation of function template specialization 'CppAD::ADFun<CppAD::AD<CppAD::cg::CG>, CppAD::cg::CG>::Forward<Eigen::Matrix<CppAD::AD<CppAD::cg::CG>, -1, 1>>' requested here
Forward(0, x);
^
/Users/xiao/0_codes/to-ihc-2/common.h:123:63: note: in instantiation of function template specialization 'CppAD::ADFun<CppAD::AD<CppAD::cg::CG>, CppAD::cg::CG>::Jacobian<Eigen::Matrix<CppAD::AD<CppAD::cg::CG>, -1, 1>>' requested here
MATRIX_AS_VECTOR_AD(full_jacobian) = ad_fun.base2ad().Jacobian(ad_x_);
^
/Users/xiao/0_codes/to-ihc-2/dynamics.cpp:146:5: note: in instantiation of member function 'ADBase<Dynamics, 10, 6, 8>::build_jacobian' requested here
build_jacobian();
^
In file included from /Users/xiao/0_codes/to-ihc-2/dynamics.cpp:8:
In file included from /Users/xiao/0_codes/to-ihc-2/dynamics.h:8:
In file included from /Users/xiao/0_codes/to-ihc-2/common.h:11:
In file included from /Users/xiao/0_codes/to-ihc-2/hopper/declarations.h:4:
In file included from /Users/xiao/0_codes/to-ihc-2/hopper/rbd_types.h:12:
In file included from /Users/xiao/0_codes/to-ihc-2/hopper/../scalar_traits.h:9:
In file included from /usr/local/include/cppad/cg.hpp:18:
In file included from /usr/local/include/cppad/cg/cppadcg.hpp:157:
In file included from /usr/local/include/cppad/cppad.hpp:53:
In file included from /usr/local/include/cppad/core/ad_fun.hpp:875:
In file included from /usr/local/include/cppad/core/drivers.hpp:8:
/usr/local/include/cppad/core/jacobian.hpp:135:13: error: no matching member function for call to 'Forward'
v = f.Forward(1, u);
~~^~~~~~~
/usr/local/include/cppad/core/jacobian.hpp:221:7: note: in instantiation of function template specialization 'CppAD::JacobianFor<CppAD::AD<CppAD::cg::CG>, CppAD::cg::CG, Eigen::Matrix<CppAD::AD<CppAD::cg::CG>, -1, 1>>' requested here
JacobianFor(*this, x, jac);
^
/Users/xiao/0_codes/to-ihc-2/common.h:123:63: note: in instantiation of function template specialization 'CppAD::ADFun<CppAD::AD<CppAD::cg::CG>, CppAD::cg::CG>::Jacobian<Eigen::Matrix<CppAD::AD<CppAD::cg::CG>, -1, 1>>' requested here
MATRIX_AS_VECTOR_AD(full_jacobian) = ad_fun.base2ad().Jacobian(ad_x_);
^
/Users/xiao/0_codes/to-ihc-2/dynamics.cpp:146:5: note: in instantiation of member function 'ADBase<Dynamics, 10, 6, 8>::build_jacobian' requested here
build_jacobian();
^
/usr/local/include/cppad/core/ad_fun.hpp:357:15: note: candidate template ignored: substitution failure [with BaseVector = Eigen::Matrix<CppAD::AD<CppAD::cg::CG>, -1, 1>]
BaseVector Forward(
^
/usr/local/include/cppad/core/ad_fun.hpp:353:15: note: candidate function template not viable: requires 3 arguments, but 2 were provided
BaseVector Forward(size_t q, size_t r, const BaseVector& x);
^
4 errors generated.
make[2]: *** [CMakeFiles/control.dir/dynamics.cpp.o] Error 1
make[1]: *** [CMakeFiles/control.dir/all] Error 2
make: *** [all] Error 2

@bradbell
Copy link
Contributor

bradbell commented Jun 1, 2024

The first error is

/usr/local/include/cppad/core/numeric_limits.hpp:248:58: error: no member named 'max_digits10' in 'CppAD::numeric_limits<cg::CG>'
static const int max_digits10 = numeric_limits::max_digits10;

Also see the heading API warning on
https://cppad.readthedocs.io/latest/base_require.html#api-warning

It looks to me like you need to update the following files (in CppAD CodeGen)
cppadcg.git/include/cppad/cg/base_double.hpp
cppadcg.git/include/cppad/cg/base_float.hpp

I suggest using the CPPAD_NUMERIC_LIMITS algorithm; see
https://cppad.readthedocs.io/latest/base_limits.html#cppad-numeric-limits
This should already be defined in the base_double.hpp and base_float.hpp includes.

You will then need to run all the CppAD CodeGen tests to see if there are any other problems using the newer version of CppAD. If they pass, and your old code above works, you could make a pull request the CppAD CodeGen project.

One other thing, just so you know about it, there is some code generation built into CppAD and inspired by CppAD CodeGen; see
https://cppad.readthedocs.io/latest/jit_get_started.cpp.html#jit-get-started-cpp-title

@xiao-wang007
Copy link
Author

Thanks for the quick response!
It is a lot for me to take in as I have very limited experience with cppad.
Will try what you suggested and get back to you.

Cheers!

@xiao-wang007
Copy link
Author

Hi
By updating these two headers:
cppadcg.git/include/cppad/cg/base_double.hpp
cppadcg.git/include/cppad/cg/base_float.hpp
do you mean to put the CPPAD_NUMERIC_LIMITS algorithm into both header files instead of what is already there for this part?
# define CPPAD_NUMERIC_LIMITS(Other, Base) \ template <> class numeric_limits<Base>\ {\ public:\ static Base min(void) \ { return static_cast<Base>( std::numeric_limits<Other>::min() ); }\ static Base max(void) \ { return static_cast<Base>( std::numeric_limits<Other>::max() ); }\ static Base epsilon(void) \ { return static_cast<Base>( std::numeric_limits<Other>::epsilon() ); }\ static Base quiet_NaN(void) \ { return static_cast<Base>( std::numeric_limits<Other>::quiet_NaN() ); }\ static Base infinity(void) \ { return static_cast<Base>( std::numeric_limits<Other>::infinity() ); }\ static const int digits10 = std::numeric_limits<Other>::digits10;\ static const int max_digits10 = std::numeric_limits<Other>::max_digits10;\ };

Should I also add this to the base_float.hpp
namespace CppAD { CPPAD_NUMERIC_LIMITS(float, float) } . And the same for base_double.hpp?

I tried the above and run the codegen test. Still the same error.
In addition, I got these warnings when using cmake, does this matter?

-- package dl found
CMake Warning at cmake/FindLLVM.cmake:85 (MESSAGE):
Could NOT find llvm-config
Call Stack (most recent call first):
CMakeLists.txt:52 (FIND_PACKAGE)

CMake Warning at cmake/FindClang.cmake:25 (MESSAGE):
No LLVM and Clang support requires LLVM
Call Stack (most recent call first):
CMakeLists.txt:53 (FIND_PACKAGE)

-- Could NOT find OpenMP_C (missing: OpenMP_C_FLAGS OpenMP_C_LIB_NAMES)
-- Could NOT find OpenMP_CXX (missing: OpenMP_CXX_FLAGS OpenMP_CXX_LIB_NAMES)
-- Could NOT find OpenMP (missing: OpenMP_C_FOUND OpenMP_CXX_FOUND)
-- Found LATEX: /Library/TeX/texbin/latex
-- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE)
-- Could NOT find Valgrind (missing: Valgrind_EXECUTABLE)
CMake Warning at test/CMakeLists.txt:217 (MESSAGE):
Valgrind not found

Thanks!

@bradbell
Copy link
Contributor

bradbell commented Jun 1, 2024

I think CPPAD_NUMERIC_LIMITS is defined when CppAD CodeGen's base_double.hpp is included and all you need to do is

namespace CppAD {
CPPAD_NUMERIC_LIMITS( double, cg::CG )
}

to define all the numeric limits for cg::CG. I think the current version of CppAD CodeGen's base_double.hpp was written before CPPAD_NUMERIC_LIMITS was added to CppAD.

@xiao-wang007
Copy link
Author

Yes! It proceeded, but there is a new error:

In file included from /usr/local/include/cppad/cg/cppadcg.hpp:157:
In file included from /usr/local/include/cppad/cppad.hpp:49:
In file included from /usr/local/include/cppad/core/user_ad.hpp:53:
/usr/local/include/cppad/core/ad_ctor.hpp:190:11: error: no matching conversion for functional-style cast from 'const CppADCodeGenTraits::Scalar' to 'CppAD::cg::CG'
: value_( Base(t) )

Thanks for the patience!

@bradbell
Copy link
Contributor

bradbell commented Jun 2, 2024

Are you able to run the CppADCodeGen test using an old version of CppAD and no changes to CppADCodeGen ? See Testing on
https://github.com/joaoleal/CppADCodeGen

jorisv added a commit to jorisv/CppADCodeGen that referenced this issue Jun 5, 2024
CppAD 2024 add a `max_digits10` member to `CppAD::numeric_limits`.
This member is not defined in CppADCodeGen and this create compilation
issue with clang based compiler.

To avoid future issue, we use `CPPAD_NUMERIC_LIMITS` macro that will
ensure we always have an up to date version of `CppAD::numeric_limits`.

See [CppAD#206](coin-or/CppAD#206).
jorisv added a commit to jorisv/CppADCodeGen that referenced this issue Jun 11, 2024
CppAD 2024 add a `max_digits10` member to `CppAD::numeric_limits`.
This member is not defined in CppADCodeGen and this create compilation
issue with clang based compiler.

To avoid future issue, we use `CPPAD_NUMERIC_LIMITS` macro that will
ensure we always have an up to date version of `CppAD::numeric_limits`.

See [CppAD#206](coin-or/CppAD#206).
@jorisv
Copy link

jorisv commented Jun 17, 2024

Hello @xiao-wang007, @bradbell,

The following CppADCodgeGen PR should have fix this issue.

@bradbell
Copy link
Contributor

bradbell commented Jun 17, 2024

@xiao-wang007 If the new version of CppADCodeGen (see message above) fixes your problem, please close this issue

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

No branches or pull requests

3 participants