Skip to content

Conversation

@ChrisRackauckas-Claude
Copy link

Summary

This PR fixes issue SciML/DifferentialEquations.jl#1109 where SplitFunction was not using user-provided jvp (Jacobian-vector product) functions even when supplied.

Problem

When a user provides a jvp function to SplitFunction, it should be used instead of falling back to automatic differentiation. However, the has_jvp check for SplitFunction was only checking f.f1 instead of first checking the SplitFunction's own jvp field.

# Old behavior
has_jvp(f::Union{SplitFunction, SplitSDEFunction}) = has_jvp(f.f1)

This caused the solver to use ForwardDiff with Dual numbers even when an analytical jvp was provided, leading to MethodErrors when the function signatures were restricted to Vector{Float64}.

Solution

Modified the has_* functions for SplitFunction and SplitSDEFunction to check their own fields first before delegating to f.f1. This allows user-provided analytical derivatives (jvp, vjp, jac, tgrad, Wfact, etc.) to be properly detected and used with matrix-free Krylov solvers.

# New behavior
function has_jvp(f::Union{SplitFunction, SplitSDEFunction})
    (__has_jvp(f) && f.jvp !== nothing) || has_jvp(f.f1)
end

Testing

  • ✅ All existing SciMLBase tests pass
  • ✅ Tested with the MRE from the issue - now works without errors
  • ✅ Code formatted with JuliaFormatter using SciMLStyle

Related Issue

Fixes SciML/DifferentialEquations.jl#1109

🤖 Generated with Claude Code

Co-Authored-By: Claude [email protected]

ChrisRackauckas and others added 2 commits October 27, 2025 03:04
When a user provides a jvp function to SplitFunction, it should be used
instead of falling back to automatic differentiation. The has_jvp check
was only checking f.f1 instead of first checking the SplitFunction's
own jvp field.

This fix checks the SplitFunction's own fields (jvp, vjp, jac, etc.)
first before delegating to f.f1, which allows user-provided analytical
derivatives to be used properly with matrix-free Krylov solvers.

Fixes SciML/DifferentialEquations.jl#1109

🤖 Generated with [Claude Code](https://claude.com/claude-code)

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.

SplitODEProblem is using numerical differentiation even when analytical jacobian vector product is provided with a Krylov solver.

2 participants