Skip to content

Fix polyalgorithm cache residual access using get_fu - #773

Merged
ChrisRackauckas merged 3 commits into
SciML:masterfrom
ChrisRackauckas-Claude:fix-polyalg-cache-resid-access
Jan 11, 2026
Merged

ChrisRackauckas merged 3 commits into
SciML:masterfrom
ChrisRackauckas-Claude:fix-polyalg-cache-resid-access

Conversation

@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member

Summary

  • Fixed bug in polyalgorithm solve!() where cache.resid was accessed directly instead of using get_fu(cache)
  • Cache objects have a fu field, not resid - this caused intermittent errors when all sub-algorithms failed to converge early
  • The fix is consistent with how the early success path (line 367) already correctly accesses the residual

Root Cause

The error "type GeneralizedFirstOrderAlgorithmCache has no field resid" occurred in the fallback path of the polyalgorithm (line 385) when none of the sub-algorithms achieved early success. The code tried to access cache.resid but caches use fu for storing residuals.

This was an intermittent issue because:

  1. When any sub-algorithm succeeds early (common case), the code returns at line 367-372 using get_fu() correctly
  2. Only when ALL sub-algorithms fail does the code reach line 385, triggering the bug

Test plan

Fixes SciML/CurveFit.jl#76

🤖 Generated with Claude Code

The polyalgorithm solve!() generated function was incorrectly accessing
`.resid` directly on cache objects, but caches have a `fu` field not
`resid`. This caused intermittent errors with the message "type
GeneralizedFirstOrderAlgorithmCache has no field resid" when all
sub-algorithms of the polyalgorithm failed to converge early and the
code fell through to find the best result among failures.

The fix uses NonlinearSolveBase.get_fu(cache) instead of cache.resid,
which is consistent with how the early success path at line 367 already
correctly accesses the residual.

Fixes SciML/CurveFit.jl#76

Co-Authored-By: Claude Opus 4.5 <[email protected]>
claude and others added 2 commits January 11, 2026 07:45
This test exercises the code path in solve!() where all sub-algorithms
of the polyalgorithm fail to converge early, forcing the fallback path
that selects the best result among failures.

Previously this path incorrectly accessed cache.resid (which doesn't
exist) instead of using get_fu(cache).

Related: SciML/CurveFit.jl#76

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@ChrisRackauckas
ChrisRackauckas merged commit 84ab15b into SciML:master Jan 11, 2026
ChrisRackauckas-Claude pushed a commit to ChrisRackauckas-Claude/NonlinearSolve.jl that referenced this pull request Jan 12, 2026
…ciML#779)

PR SciML#773 introduced a regression where `findmin_caches` was called with
residual vectors (results of `get_fu`) instead of cache objects. This
caused `MethodError: no method matching get_fu(::Vector{Float64})`
because `findmin_caches` internally calls `get_fu` on each element,
expecting cache objects.

The fix uses `findmin_resids` directly since the `fus` tuple already
contains residual vectors extracted by `get_fu` at line 386.

Fixes SciML#779
Related: SciML/CurveFit.jl#76

Co-Authored-By: Claude Opus 4.5 <[email protected]>
ChrisRackauckas-Claude pushed a commit to ChrisRackauckas-Claude/NonlinearSolve.jl that referenced this pull request Jan 12, 2026
Adds a test that exercises the polyalgorithm cache-based solve! path
which was broken by PR SciML#773. The test uses init() + solve!() to ensure
the code path through __generated_solve_cache! is exercised.

Without the fix, this test would fail with:
  MethodError: no method matching get_fu(::Vector{Float64})

Co-Authored-By: Claude Opus 4.5 <[email protected]>
ChrisRackauckas pushed a commit that referenced this pull request Jan 12, 2026
…780)

* fix: use findmin_resids for residual vectors in polyalgorithm solve (#779)

PR #773 introduced a regression where `findmin_caches` was called with
residual vectors (results of `get_fu`) instead of cache objects. This
caused `MethodError: no method matching get_fu(::Vector{Float64})`
because `findmin_caches` internally calls `get_fu` on each element,
expecting cache objects.

The fix uses `findmin_resids` directly since the `fus` tuple already
contains residual vectors extracted by `get_fu` at line 386.

Fixes #779
Related: SciML/CurveFit.jl#76

Co-Authored-By: Claude Opus 4.5 <[email protected]>

* test: add regression test for issue #779

Adds a test that exercises the polyalgorithm cache-based solve! path
which was broken by PR #773. The test uses init() + solve!() to ensure
the code path through __generated_solve_cache! is exercised.

Without the fix, this test would fail with:
  MethodError: no method matching get_fu(::Vector{Float64})

Co-Authored-By: Claude Opus 4.5 <[email protected]>

---------

Co-authored-by: ChrisRackauckas-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.

type GeneralizedFirstOrderAlgorithmCache has no field resid

3 participants