Skip to content

Run fit_scipy with L-BFGS-B, as its docstring says - #840

Open
sandeshbagmare wants to merge 2 commits into
QuantClimate:mainfrom
sandeshbagmare:fix/fit-scipy-use-lbfgsb
Open

sandeshbagmare wants to merge 2 commits into
QuantClimate:mainfrom
sandeshbagmare:fix/fit-scipy-use-lbfgsb

Conversation

@sandeshbagmare

Copy link
Copy Markdown

Fixes #837

fit_scipy called minimize with no method, no bounds and no constraints, so SciPy picked BFGS while the docstring promised L-BFGS-B. Two consequences, both from the report: a well-scaled regression diverges to obs_stddev ≈ 1.8e7 with a nan objective and no signal, and BFGS holds a dense inverse Hessian, which does not scale to a variational family with many inducing points.

Proposed Changes

  • Name method="L-BFGS-B".
  • Drop disp from options: L-BFGS-B does not accept it (it was only accepted because the call reached BFGS), and verbose now reports the iteration count, the final objective and SciPy's own message.
  • Warn with OptimizeWarning when SciPy reports success=False, so a solver that gave up is not read as a converged fit. This is the "can diverge without an error" half of the report.

Tests

  • New test_fit_scipy_uses_lbfgsb records the keyword arguments fit_scipy hands to scipy.optimize.minimize and asserts the method is L-BFGS-B.
  • test_fit_scipy_error_raises kept its iteration-limit case (max_iters=1 still warns) and lost the crazy-mean case, which only ever warned because of BFGS's "precision loss" OptimizeWarning; L-BFGS-B converges there instead of warning.

pytest tests/test_fit.py passes (106 tests) and ruff check / ruff format --check are clean on both files.

minimize was called without method or bounds, so SciPy picked BFGS while the
docstring promised L-BFGS-B. Name the method, drop the disp option that
L-BFGS-B does not accept (it was reaching BFGS), print the outcome when
verbose, and warn when SciPy reports that it did not converge, so a fit that
gave up is not mistaken for one that converged.

The crazy-mean case in test_fit_scipy_error_raises relied on BFGS's
precision-loss warning, which L-BFGS-B does not emit; that half of the test is
replaced by a test asserting the method that reaches SciPy.

Fixes QuantClimate#837
@github-actions github-actions Bot added tests optimization size/s ci Continuous Integration documentation Improvements or additions to documentation labels Nov 22, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continuous Integration documentation Improvements or additions to documentation optimization size/s tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: fit_scipy runs BFGS, not the L-BFGS-B its docstring names, and can diverge without an error

2 participants