Skip to content

Add scaling = :auto to MoreTrustRegionDescent - #1300

Merged
ChrisRackauckas merged 3 commits into
SciML:masterfrom
ChrisRackauckas-Claude:auto-jacobian-scaling
Sep 22, 2026
Merged

ChrisRackauckas merged 3 commits into
SciML:masterfrom
ChrisRackauckas-Claude:auto-jacobian-scaling

Conversation

@ChrisRackauckas-Claude

@ChrisRackauckas-Claude ChrisRackauckas-Claude commented Sep 17, 2026 •

Copy link
Copy Markdown
Member

Summary

scaling = :jacobian (Moré column-norm scaling) is a large win on badly scaled least-squares problems — on the MGH/HS benchmark tail it cut tp293 223→134 and tp292 135→41 steps — but it hurts well-conditioned ones (tp299 126→197), so it cannot be a blanket default. scaling = TrustRegionScaling.Auto makes it adaptive instead:

  • The first Jacobian's nonzero column norms are gated on maxⱼ‖J[:,j]‖ / minⱼ‖J[:,j]‖ > 20 (implemented on stored squared norms as hi/lo > 20²). Above the threshold the solve proceeds exactly as Jacobian; below it exactly as None.
  • The decision is taken once per solve and latched — rejected-step retries never re-gate — and is re-decided after reinit!. Fewer than 2 nonzero columns or an all-zero Jacobian → off.
  • Matrix-free Jacobians expose no column norms, so Auto degrades to scaling off (Jacobian still throws for them).
  • Inference-safe: Auto sets has_scaling = Val(true) and always allocates a concrete dtd; an inactive gate is dtd == 1, which multiplies through as the identity — no runtime Union{Nothing,Vector} and no new allocations on the None/Jacobian paths.
  • A reused first Jacobian still settles a pending gate via an elseif in solve!.

The scaling argument is a new EnumX.@enumx TrustRegionScaling (None/Jacobian/Auto), matching the TrustRegionSubproblem convention. The :none/:jacobian symbol spellings shipped in NonlinearSolveBase v2.52 are still accepted — the constructor converts them; other values raise ArgumentError.

TrustRegionScaling.None remains the default — Auto is opt-in, so no existing trajectory changes.

Test plan

  • New 33-assertion "More subproblem: Auto scaling" testset in least_squares_tests__item6.jl: direct lmpar and LU/normal-form paths, bitwise-equal trajectory vs None on a well-conditioned problem, gate engagement on a badly scaled one (14 → 3 steps), reinit! re-gating, Krylov LSMR/GMRES matrix-free fallback, scalar and StaticArray cases, @inferred init/solve!.
  • API-surface coverage: enum values stored concretely, legacy :none/:jacobian/:auto symbols convert, :bogus/"auto" throw ArgumentError.
  • Discrimination: MoreTrustRegionDescent(scaling = TrustRegionScaling.Auto) throws ArgumentError on unfixed master.
  • least_squares_tests__item6.jl: 117/117 pass. inference_tests__item1.jl clean; operator_jacobian.jl 14/14; conditioning_tests__item1/2.jl 38/38; umbrella core_tests__item3.jl 16/16.
  • Runic --check clean; typos clean.
  • Not run locally: full Core group (long) and GPU/Julia-pre CI lanes. misc_tests__item9.jl has 4 pre-existing master failures at lines 253–258 (reproduced on unmodified master; unrelated to this diff — fixed in Update tests authored against the Dogleg trust-region default #1302).

🤖 Generated with Devin — Agent-Harness: Devin CLI 3000.10.21, Agent-Model: SWE-2 Max. Session transcript (local): /home/crackauc/.local/share/devin/cli/summaries/history_75aaeac8e79744c6.md

Co-Authored-By: Chris Rackauckas [email protected]

Comment on lines +77 to +87
# `scaling = :none`/`:jacobian` shipped as symbols in NonlinearSolveBase v2.52;
# keep accepting them so that spelling keeps working.
_more_scaling(s::TrustRegionScaling.T) = s
function _more_scaling(s::Symbol)
s === :none && return TrustRegionScaling.None
s === :jacobian && return TrustRegionScaling.Jacobian
s === :auto && return TrustRegionScaling.Auto
return throw(
ArgumentError("`scaling` must be a `TrustRegionScaling` (`None`, `Jacobian`, \
or `Auto`), got `$(s)`.")
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Get rid of all symbol use

@ChrisRackauckas-Claude ChrisRackauckas-Claude Sep 18, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in a87fb15b2 — _more_scaling(::Symbol) is gone; scaling takes TrustRegionScaling and nothing else (:auto/:jacobian/:none now throw ArgumentError, covered by tests). This intentionally breaks the scaling = :jacobian spelling that shipped in NonlinearSolveBase v2.52.

ChrisRackauckas-Claude pushed a commit to ChrisRackauckas-Claude/NonlinearSolve.jl that referenced this pull request Sep 18, 2026
Per review on SciML#1300: `scaling` now takes `TrustRegionScaling` and nothing
else — `:none`/`:jacobian`/`:auto` throw `ArgumentError` like any other
non-enum value. This knowingly breaks the `scaling = :jacobian` spelling
released in NonlinearSolveBase v2.52.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Agent-Harness: Devin CLI 3000.10.21
Agent-Model: SWE-2 Max
Agent-Session: /home/crackauc/.local/share/devin/cli/summaries/history_7b3b1ba7a18f464e.md (local transcript)
ChrisRackauckas-Claude pushed a commit to ChrisRackauckas-Claude/NonlinearSolve.jl that referenced this pull request Sep 18, 2026
Per review on SciML#1300: `scaling` now takes `TrustRegionScaling` and nothing
else — `:none`/`:jacobian`/`:auto` throw `ArgumentError` like any other
non-enum value. This knowingly breaks the `scaling = :jacobian` spelling
released in NonlinearSolveBase v2.52.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Agent-Harness: Devin CLI 3000.10.21
Agent-Model: SWE-2 Max
Agent-Session: /home/crackauc/.local/share/devin/cli/summaries/history_7b3b1ba7a18f464e.md (local transcript)
ChrisRackauckas and others added 3 commits September 19, 2026 18:59
Moré's column-norm Jacobian scaling is a large win on badly scaled
least-squares problems but can hurt well-conditioned ones, so a blanket
default is unsafe. `scaling = :auto` makes it adaptive instead: the first
Jacobian's nonzero column norms are gated on a ratio
`maxⱼ‖J[:, j]‖ / minⱼ‖J[:, j]‖ > 20` — above it the solve proceeds exactly
as `:jacobian`, below it exactly as `:none`. The decision latches for the
solve and is re-decided after `reinit!`. Matrix-free Jacobians expose no
column norms, so `:auto` degrades to scaling off there (while `:jacobian`
continues to throw).

The gate is inference-safe: `:auto` sets `has_scaling = Val(true)` and
always allocates a concrete `dtd` diagonal; an inactive gate is `dtd == 1`,
which multiplies through as the identity, so there is no runtime
`Union{Nothing,Vector}` and no new allocations on the `:none`/`:jacobian`
paths. Three Bool fields (`auto_scaling`, `scaling_decided`,
`scaling_active`) carry the gate state, and all `dtd === nothing` /
`has_scaling` branches are audited.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Agent-Harness: Devin CLI 3000.10.21
Agent-Model: SWE-2 Max
Agent-Session: /home/crackauc/.local/share/devin/cli/summaries/history_7603fae7ce93404f.md (local transcript)
Match the TrustRegionSubproblem convention: scaling is now a
`EnumX.@enumx TrustRegionScaling` with `None`, `Jacobian`, and `Auto`
values, stored concretely as `TrustRegionScaling.T` on the algorithm.

The `:none`/`:jacobian` symbol spellings shipped in NonlinearSolveBase
v2.52, so the constructor still converts them; other values raise
ArgumentError. Tests cover the enum API, the legacy spellings, and
invalid inputs.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Agent-Harness: Devin CLI 3000.10.21
Agent-Model: SWE-2 Max
Agent-Session: /home/crackauc/.local/share/devin/cli/summaries/history_7603fae7ce93404f.md (local transcript)
Per review on SciML#1300: `scaling` now takes `TrustRegionScaling` and nothing
else — `:none`/`:jacobian`/`:auto` throw `ArgumentError` like any other
non-enum value. This knowingly breaks the `scaling = :jacobian` spelling
released in NonlinearSolveBase v2.52.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Agent-Harness: Devin CLI 3000.10.21
Agent-Model: SWE-2 Max
Agent-Session: /home/crackauc/.local/share/devin/cli/summaries/history_7b3b1ba7a18f464e.md (local transcript)
@ChrisRackauckas
ChrisRackauckas merged commit c79e63a into SciML:master Sep 22, 2026
96 of 104 checks passed
ChrisRackauckas added a commit that referenced this pull request Sep 23, 2026
Ships scaling = :auto for MoreTrustRegionDescent (#1300) and the new TrustRegionRobust kappa-preserving sparse subproblem solves (#1305). Minor because both add API that NonlinearSolveFirstOrder 2.10.0 consumes.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Claude <[email protected]>
Agent-Harness: Claude Code 2.1.273
Agent-Model: claude-opus-5[1m]
Agent-Session: 6a01e420-3436-4518-83cc-6cd853283cfb (local transcript; this harness publishes no conversation URL)
ChrisRackauckas added a commit that referenced this pull request Sep 23, 2026
Ships scaling = :auto for MoreTrustRegionDescent (#1300) and the new TrustRegionRobust kappa-preserving sparse subproblem solves (#1305). Minor because both add API that NonlinearSolveFirstOrder 2.10.0 consumes.



Agent-Harness: Claude Code 2.1.273
Agent-Model: claude-opus-5[1m]
Agent-Session: 6a01e420-3436-4518-83cc-6cd853283cfb (local transcript; this harness publishes no conversation URL)

Co-authored-by: Claude <[email protected]>
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.

2 participants