Repository navigation
mma, ccsa: halt with NLOPT_ROUNDOFF_LIMITED when the step is zero - #650
Merged
Merged
Conversation
dd.wval is 0 when every step of the inner iteration is 0 or so small that its square underflows. This happens, e.g., when minimizing x'x with ftol_rel: since the minimum is 0, the run only stops once f underflows. The rho and rhoc updates then divided (fcur - gval) by 0, which raised a floating-point division-by-zero exception (stevengj#635). The quotient was +inf, so MIN() picked the 10x increase anyway; use that value directly when dd.wval is 0. The iterates are unchanged. Add a test that runs LD_MMA and LD_CCSAQ on this problem and checks the division-by-zero flag.
Owner
|
Seems like we should simply halt the optimization with |
…ivision As suggested in review: when rho or rhoc must increase but dd.wval is 0 (every step is 0 or its square underflows), no increase can change the step, so stop with NLOPT_ROUNDOFF_LIMITED. The rho updates are back to their original form. The halt is placed after "if (inner_done) break;", so a run whose step is 0 because it starts at a stationary point (fcur == gval) still ends as before.
Contributor
Author
|
Done in db2deba: when |
stevengj
approved these changes
Oct 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #635.
In the inner iterations of MMA and CCSA, when the approximation is not conservative,
rhoandrhoc[i]are increased bydd.wvalis a sum of0.5 * dx^2 / (sigma^2 - dx^2)terms. It is 0 when every step is 0 or so small that its square underflows. In the example of #635 (x'xon [-1,1]^2 from (0.5, 0.5) withftol_rel), the minimum is 0, so the relative test on f does not stop the run before that happens. MMA runs down to x = 5.1e-163 and divides bydd.wval = 0; with floating-point exceptions enabled, as in the report, the division traps.When
dd.wvalis 0, no increase ofrhocan change the step. As suggested in the review, this PR stops the run there withNLOPT_ROUNDOFF_LIMITED, inmma.candccsa_quadratic.c. The check is placed right afterif (inner_done) break;, whererhoorrhocmust increase. A run whose step is 0 because it starts at a stationary point hasfcur == dd.gval, so it is done there and still ends as before.The new test
test/t_ccsa_zero_step.cxxruns the example of #635 withLD_MMAandLD_CCSAQ. It checks theFE_DIVBYZEROflag withfetestexcept, acceptsNLOPT_ROUNDOFF_LIMITED, and checks that the minimum is found. On master theLD_MMAcase fails on the flag. With this change,LD_MMAstops withNLOPT_ROUNDOFF_LIMITEDat the same point, f = 0;LD_CCSAQdoes not reach the check in this example and still returnsNLOPT_FTOL_REACHED.Checks, with MSVC 2022 on Windows:
ctest: 79 of 79 tests pass.testoptwith MMA and CCSAQ on all 22 objectives, seeds 0 to 2, and three stopping rules (-e 1000,-e 0 -f 1e-8,-e 0 -x 1e-10): the output (minimum, evaluation count, minimizer) is identical on master and on this branch for all 396 runs.