-
Notifications
You must be signed in to change notification settings - Fork 779
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
Print statements cause changes in optimization behavior. #1341
Comments
Wow, crazy! We pride ourselves on const correctness, but this could be a subtle memory bug. Unfortunately, it seems you are currently in the best position to uncover the bug. Maybe run with memory checking software, or do some print debugging? Printing a bunch of stuff and then doing a diff on both output files could uncover where the issue is introduced. |
@DanMcGann I was able to reproduce this. On My MAc I can't run valgrind, though. Could you try this? |
Interestingly, only occurs in Release mode, not in debug mode. |
@DanMcGann, I tracked down the issue with Xcode. Turns out auto and Eigen do not play well together. Changing this line: auto error = -gtsam::traits<VALUE>::Local(val, prior_); to
will fix the issue. FYI, address sanitizer said:
Closing as not a GTSAM issue. |
Interesting! Glad its not a deeper problem. Also looks like this is well documented by Eigen which I will link here for posterity (https://eigen.tuxfamily.org/dox/TopicPitfalls.html). Although, given this documentation I'm surprised to see the issue crop up here as the definition of |
Description
Printing involved variables of a factor during calls to
evaluateError
causes changes in optimization behavior.Steps to reproduce
mkdir build && cd build
cmake ..
make
./run-test
Expected behavior
Prints are
const
and output to stdout should not have any affect on the behavior of optimization. However, we observe that adding these prints causes unexpected optimization results.Ex.
Running the following script (see additional info for all code to run this script)
If we use a prior factor without print statements we get the following output
If we use a prior factor that prints both the value and the prior on each call to
evaluateError
we get ...Where the optimizer output is not at the minimum of the cost function.
Environment
This bug was observed under 3 different environments.
Environmens
Additional information
Minimal Working Example
CMakeLists.txt
factors.h
run-test.cpp
`CMakeLists.txt`
`factors.h`
`run-test.cpp`
The text was updated successfully, but these errors were encountered: