Skip to content

NLNewton OOP: handle AbstractSciMLOperator W instead of erroring - #3796

Merged
ChrisRackauckas merged 4 commits into
SciML:masterfrom
singhharsh1708:fix/oop-nlnewton-sciml-operator
Jul 6, 2026
Merged

ChrisRackauckas merged 4 commits into
SciML:masterfrom
singhharsh1708:fix/oop-nlnewton-sciml-operator

Conversation

@singhharsh1708

Copy link
Copy Markdown
Member

The OOP NLNewton compute_step! hard-errors when W is an AbstractSciMLOperator that isn't a WOperator / StaticWOperator:

elseif W isa AbstractSciMLOperator
    error("Non-concrete Jacobian not yet supported by out-of-place Newton solve.")
end

This case is reachable in practice — e.g. an ImplicitEuler(nlsolve = NLNewton(...)) solve on an OOP ODEProblem whose mass matrix is a state-dependent MatrixOperator lands here.

Fix

Mirror the IIP NLNewton handling of AbstractSciMLOperator W (already at line 304):

elseif W isa AbstractSciMLOperator
    update_coefficients!(W, ustep, p, tstep; gamma = γW, transform = true)
    W = convert(AbstractMatrix, W)
end

update_coefficients!(W, ustep, p, tstep; gamma = γW, transform = true) refreshes the operator against the current Newton iterate, and convert(AbstractMatrix, W) materializes the result for the \ solve that follows. convert(AbstractMatrix, ::AbstractSciMLOperator) is defined for MatrixOperator, ScaledOperator, AddedOperator, ComposedOperator, IdentityOperator, etc., so this covers the common cases.

Scope

This removes the hard error and makes the OOP NLNewton path functional for SciMLOperator W. The pre-existing failing Dependent Mass Matrix Tests / iip = false in mass_matrix_tests.jl was reaching this error path — after this fix it no longer hard-errors, though the test may still surface a separate numerical issue tied to the test RHS mutating the same mm_A it carries as its mass matrix (the IIP version passes, so the integrator path was OK; only this OOP error was blocking).

elseif W isa AbstractSciMLOperator
error("Non-concrete Jacobian not yet supported by out-of-place Newton solve.")
update_coefficients!(W, ustep, p, tstep; gamma = γW, transform = true)
W = convert(AbstractMatrix, W)

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.

No we shouldn't convert W operators.

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.

I guess for out of place.

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.

Ehh probably a bad idea though to \ an operator... better to just give an informative error.

@singhharsh1708

Copy link
Copy Markdown
Member Author

fair — reverted the convert, just kept an informative error pointing users at IIP form or jac_prototype

@singhharsh1708
singhharsh1708 force-pushed the fix/oop-nlnewton-sciml-operator branch from 84de2f8 to 15387e3 Compare July 5, 2026 03:42
@ChrisRackauckas
ChrisRackauckas merged commit 89a0029 into SciML:master Jul 6, 2026
152 of 166 checks passed
@singhharsh1708
singhharsh1708 deleted the fix/oop-nlnewton-sciml-operator branch July 6, 2026 10:15
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