Skip to content

Conversation

@ChrisRackauckas-Claude
Copy link

Summary

  • Fixes OptimizationLBFGSB.LBFGSB() produces wrong results with retcode: Success #1094 where OptimizationLBFGSB.LBFGSB() would return Success with incorrect results when the objective function has a singularity at the boundary (e.g., log(0))
  • The L-BFGS-B algorithm evaluates function/gradient at bounds during its Cauchy step, which can produce Inf/NaN values that corrupt the optimization state
  • The fix detects false convergence and returns Failure instead of Success with a helpful warning

Root Cause

The underlying L-BFGS-B Fortran algorithm evaluates the objective and gradient at the exact boundary values during the Cauchy point computation. When a function has a singularity at the boundary (like log(n_exp/n_th) when n_th=0), this produces Inf objective values and NaN gradients. The corrupted values cause the algorithm to incorrectly report convergence.

Changes

  1. Track Inf/NaN values: Wrap the loss and gradient functions to detect non-finite values
  2. Detect false convergence: When Inf/NaN was encountered AND optimizer claims Success BUT solution hasn't moved from starting point, this indicates false convergence
  3. Return Failure with warning: In such cases, override the return code to Failure and emit a helpful warning suggesting users move bounds away from singularities

Test Plan

🤖 Generated with Claude Code

…ciML#1094)

The L-BFGS-B algorithm evaluates the function and gradient at bounds during
its Cauchy step. When a function has a singularity at the boundary (e.g.,
log(0)), this produces Inf/NaN values that corrupt the optimization state.
The Fortran code would then incorrectly report convergence.

This fix:
- Tracks whether Inf/NaN values are encountered in the objective or gradient
- Detects false convergence: when Inf/NaN was encountered, optimizer reports
  Success, but the solution hasn't moved from the starting point
- Returns Failure instead of Success in such cases with a helpful warning

Closes SciML#1094

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@ChrisRackauckas ChrisRackauckas merged commit e65214d into SciML:master Dec 8, 2025
67 of 81 checks passed
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

Successfully merging this pull request may close these issues.

OptimizationLBFGSB.LBFGSB() produces wrong results with retcode: Success

2 participants