Skip to content

Pass the tolerances and options to the scipy solvers - #6

Open
pchanial wants to merge 1 commit into
mainfrom
scipy-options
Open

pchanial wants to merge 1 commit into
mainfrom
scipy-options

Conversation

@pchanial

@pchanial pchanial commented Nov 9, 2026

Copy link
Copy Markdown
Member

What

The scipy solvers of minimize (scipy_tnc, scipy_cobyqa) silently ignored rtol, atol and options. The scipy branch built the options of the scipy method — ftol, gtol and xtol from atol/rtol for TNC, final_tr_radius for COBYQA — but never handed them to scipy_minimize, which always ran the solver with {"disp": False}. The branch also wrote those tolerances into the caller's options dict (options = _opts is an alias).

  • scipy_minimize takes options, the options of the scipy method. They are copied into a fresh dict at each callback call: jaxopt adds maxiter to the dict it is given, so reusing one dict would make the second call under vmap fail.
  • minimize builds them from a copy of its options; rtol/atol apply through setdefault, so options given explicitly win (the same precedence as scipy's own tol argument).
  • The options docstring of minimize documents the scipy case.

Behaviour change

Callers of the scipy solvers now get the tolerances they ask for, including the defaults rtol = atol = 1e-8, instead of scipy's own defaults. Results can therefore change for code that relied on the tolerances being ignored.

Tests

tests/test_scipy_minimize.py (6 tests): convergence, tolerances reaching scipy (loose stops earlier than tight), options reaching scipy (an unknown option is reported by scipy), explicit options winning over the tolerances, the caller's dict left untouched, options under vmap. Four of them fail on main; the full suite passes (15 tests), and so do the pre-commit hooks (ruff-format, ruff, pyright).

Not addressed here

jaxopt always injects maxiter into the scipy options, but TNC does not know it — its limit is maxfun, the number of function evaluations — so max_iter has no effect with scipy_tnc (scipy warns Unknown solver options: maxiter). Mapping max_iter to maxfun would change what the limit counts, so it is left for a separate decision.

Context: Megabuster runs the scipy solvers through its own wrapper (to evaluate them on the calling thread, see the follow-up PR), aligned on these semantics, so that the two agree.

🤖 Generated with Claude Code

The scipy branch of minimize built the options of the scipy method
(ftol, gtol and xtol from atol and rtol for TNC, final_tr_radius for
COBYQA) but never handed them to scipy_minimize, which ran the solver
with {"disp": False} only: rtol, atol and options were silently
ignored by the scipy solvers. The branch also wrote these tolerances
into the caller's options dict.

scipy_minimize takes the options of the scipy method, copied into a
fresh dict at each callback call (jaxopt adds maxiter to it, which
would make a second call under vmap fail). minimize builds them from a
copy of its options, the tolerances applying unless the options give
them explicitly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant