Skip to content

fix: use findmin_resids for residual vectors in polyalgorithm solve - #780

Merged
ChrisRackauckas merged 2 commits into
SciML:masterfrom
ChrisRackauckas-Claude:fix/issue-779-findmin-resids
Jan 12, 2026
Merged

ChrisRackauckas merged 2 commits into
SciML:masterfrom
ChrisRackauckas-Claude:fix/issue-779-findmin-resids

Conversation

@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member

Summary

  • Fixes regression from PR Fix polyalgorithm cache residual access using get_fu #773 where findmin_caches was incorrectly called with residual vectors instead of cache objects
  • Changes findmin_caches(cache.prob, fus) to findmin_resids(cache.prob, fus) since fus already contains residual vectors from get_fu

Root Cause

PR #773 correctly changed line 386 to use get_fu(cache) instead of cache.resid, but the subsequent call at line 391 still used findmin_caches:

# Line 386: Extract residuals using get_fu
$(resid) = @isdefined($(sym)) ? NonlinearSolveBase.get_fu($(sym)) : nothing

# Line 390-391: fus is now a tuple of residual VECTORS
fus = tuple($(Tuple(resids)...))
minfu, idx = findmin_caches(cache.prob, fus)  # BUG: calls get_fu again on vectors!

findmin_caches internally calls get_fu on each element, expecting cache objects. Since fus contains Vector{Float64} residuals, this caused:

MethodError: no method matching get_fu(::Vector{Float64})

Test Plan

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

🤖 Generated with Claude Code

…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]>
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-Claude

Copy link
Copy Markdown
Member Author

Added regression test for issue #779 in test/issue_tests.jl.

The test exercises the cache-based solve!() path (via init() + solve!()) which is where the bug was triggered. Without the fix, it would fail with:

MethodError: no method matching get_fu(::Vector{Float64})

@ChrisRackauckas
ChrisRackauckas merged commit d04c404 into SciML:master Jan 12, 2026
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.

MethodError: no method matching get_fu(::Vector{Float64})

3 participants