Skip to content

Conversation

AJ0070
Copy link
Contributor

@AJ0070 AJ0070 commented Sep 6, 2025

Checklist

  • Appropriate tests were added
  • Any code changes were done in a way that does not break public API
  • All documentation related to code changes were updated
  • The new code follows the contributor guidelines, in particular the SciML Style Guide and COLPRAC
  • Any new documentation only uses public API

Additional context

Fixed an issue where calling reinit! with AbsTerminationMode would throw:

MethodError: no method matching ndims(::Type{Nothing})
undefined

Root Cause

The NonlinearTerminationModeCache for AbsTerminationMode initializes u as nothing, but reinit! attempted to broadcast into it. The fix ensures we only update cache.u when it's not nothing.

Solution

Added guard clause to skip updating cache.u when it's nothing:

if cache.u !== nothing
    #...existing logic...
end

Verification

Added regression test that creates a termination cache with u_unaliased = nothing and verifies reinit! no longer throws:

@testset "reinit! with AbsTerminationMode" begin
    mode = AbsTerminationMode()
    cache = NonlinearTerminationModeCache(
        nothing, ReturnCode.Default, 1e-8, 1e-8, Inf, mode,
        nothing, nothing, 0, nothing, nothing, nothing, nothing, nothing, false
    )
    @test_nowarn SciMLBase.reinit!(cache, [1.0, 1.0], [1.1, 1.1])
end

Resolves #687.

@ChrisRackauckas ChrisRackauckas merged commit f6c8d01 into SciML:master Sep 7, 2025
93 of 98 checks passed
@AJ0070 AJ0070 deleted the fix/687 branch September 7, 2025 12:53
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.

Calling reinit! with GeneralizedFirstOrderAlgorithmCache using AbsTerminationMode throws an error
2 participants