Open cpfiffer opened 3 months ago
Add test for handling non-finite gradients in WolfeLineSearch
linesearch_testfunc_nonfinite
class to simulate non-finite gradientswolfeLineSearch_nonfinite_gradient
test to verify that the optimization process can handle non-finite gradientsFor more details, open the Copilot Workspace session.
For what it's worth, this was a vague attempt at solving this problem using Copilot Workspace. It'd be very cool if this was all it took. Close this if it's garbage because I'm not that familiar with stan's internals. If the robot did a good job I'm happy to investigate this more.
The fix looks OK in that it will do the same thing for a non-finite return now as for an error code. I kicked off the integration testing.
It'd be nice if the test tested all the ways things could fail. The new test is testing a 1 return, but I didn't see how that was being triggered. The easiest is just plugging in three different functions for testing:
All these should then return a 1 from the line search.
Alright, let's give that a try. Apologies in advance, very new to the whole stan toolchain and I'll likely be pretty clumsy.
Thanks, @cpfiffer. We're happy to help, as our C++ is pretty complicated in a lot of places.
The test wolfeLineSearch_nonfinite_gradient
fails because the functor linesearch_testfunc_nonfinite
has a finite gradient, and thus does not exercise the expected error path. Actually, none of the new tests notice if I undo the fix in this PR.
The single-line fix looks correct but I'm puzzled as to why it is needed. At the previous line, func
should be an instance of ModelAdaptor
which already checks for non-finite gradient:
Related to #3306
Modify the
WolfeLineSearch
function insrc/stan/optimization/bfgs_linesearch.hpp
to handle non-finite gradients.func_val
is finite.gradx1
is finite.For more details, open the Copilot Workspace session.