[CppAD] Bug in optimize()?

Brad Bell bradbell at seanet.com
Mon Jul 25 13:39:15 EDT 2011


Oliver:
Thanks for the bug report !

I have reproduced the assertion error message. This seems to be a 
problem with the error detection, and not the actual optimization. I 
think that you are correct  in that the order of the additions and 
subtractions may not be the same in the optimized code as in the 
original code. For now, you could comment out the assertion that 
check[i] == y[i]. I will look into how to best fix this.

Here is the output I get when compiling with debugging, setting a break 
point in error_handler.hpp where the error occurs, and then going up in 
the stack to the optimize routine (a technique that is useful when 
tracking down the cause of CppAD error messages):

Error during check of f.optimize().
Error detected by false result for
     check[i] == y[i]
at line 1570 in the file
     /home/bradbell/prefix/cppad/include/cppad/local/optimize.hpp

Breakpoint 1, _fu18___ZSt4cerr ()
     at /home/bradbell/prefix/cppad/include/cppad/error_handler.hpp:198
198                             assert(false);
(gdb) up
#1  0x0040340a in CppAD::ErrorHandler::Call (known=true, line=1570,
     file=0x45d0d0 
"/home/bradbell/prefix/cppad/include/cppad/local/optimize.hpp"
, exp=0x45f1e4 "check[i] == y[i]",
     msg=0x45f1c0 "Error during check of f.optimize().")
     at /home/bradbell/prefix/cppad/include/cppad/error_handler.hpp:158
158                     handler(known, line, file, exp, msg);
(gdb) up
#2  0x00410039 in CppAD::ADFun<double>::optimize (this=0x22cbec)
     at /home/bradbell/prefix/cppad/include/cppad/local/optimize.hpp:1567
1567                    for(i = 0; i < m; i++) CPPAD_ASSERT_KNOWN(
(gdb) p y[i]
$4 = (const double &) @0x55a1d0: 9.9999999999999998e-17
(gdb) p check[i]
$5 = (const double &) @0x559f60: 1.0000000000000005e-16
(gdb)


On 7/25/2011 8:44 AM, Oliver Ruepp wrote:
> Hi all,
>
> I recently ran into a problem using the optimize() method of a CppADFun
> object. The problem occurs when evaluating a sequence of additions and
> subtractions. As soon as the method is called, the program aborts with
> the following message:
>
> Error during check of f.optimize().
> Error detected by false result for
>      check[i] == y[i]
> at line 1729 in the file
>      /usr/local/include/cppad/local/optimize.hpp
> cppad_sum_test: /usr/local/include/cppad/error_handler.hpp:198: static
> void CppAD::ErrorHandler::Default(bool, int, const char*, const char*,
> const char*): Assertion `false' failed.
>
> This is basically due to CppAD realizing that the optimized computation
> does not yield the same result as the original one.
> I tried to get to the root of the problem, but couldn't quite figure out
> how the 'optimize' method works.
> Could it be that it rearranges the sequence of additions/subtractions? I
> was thinking that this could be the problem, since floating-point
> addition is not always commutative due to rounding.
>
> I was able to reproduce the problem with a very simple example, which is
> available here:
> <http://www6.in.tum.de/~ruepp/cppad_sum_test.cpp>
> I am using cppad-20110701 with g++ 4.5.2 under Linux.
>
>
> Regards
> Oliver Ruepp
>
> _______________________________________________
> CppAD mailing list
> CppAD at list.coin-or.org
> http://list.coin-or.org/mailman/listinfo/cppad
>



More information about the CppAD mailing list