Skip to content

Add methods for SDEFunction in case of SciMLOperators v1+ #1072

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 25, 2025

Conversation

albertomercurio
Copy link
Contributor

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

This PR fixes the following issue in running an SDE with a SciMLOperator

using LinearAlgebra
using StochasticDiffEq
using SciMLOperators
using SciMLOperators: AbstractSciMLOperator
using SciMLBase
using OrdinaryDiffEqTsit5

struct MyMatrixOperator{T, AT <: AbstractMatrix{T}} <: AbstractSciMLOperator{T}
    A::AT
end

(L::MyMatrixOperator)(w, v, u, p, t) = mul!(w, L.A, v)

f = MyMatrixOperator(rand(2, 2))
g(du, u, p, t) = lmul!(0.1, du)

x0 = rand(2)
tspan = (0.0, 1.0)

prob = SDEProblem{true}(f, g, x0, tspan)
sol = solve(prob, SRIW1())
ERROR: MethodError: no method matching *(::MyMatrixOperator{Float64, Matrix{Float64}}, ::Vector{Float64})
The function `*` exists, but no method is defined for this combination of argument types.

Closest candidates are:
  *(::Any, ::Any, ::Any, ::Any...)
   @ Base operators.jl:596
  *(::ChainRulesCore.ZeroTangent, ::Any)
   @ ChainRulesCore ~/.julia/packages/ChainRulesCore/XAgYn/src/tangent_arithmetic.jl:104
  *(::Any, ::ChainRulesCore.NotImplemented)
   @ ChainRulesCore ~/.julia/packages/ChainRulesCore/XAgYn/src/tangent_arithmetic.jl:38
  ...

The problem is that it is calling the four-arguments method

function (L::AbstractSciMLOperator)(v, u, p, t; kwargs...)
    update_coefficients(L, u, p, t; kwargs...) * v
end

which is wrong.

This PR fixes SciML/StochasticDiffEq.jl#615. At least the part related to the f function.

@ChrisRackauckas ChrisRackauckas merged commit 15df733 into SciML:master Jul 25, 2025
57 of 64 checks passed
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.

Error with SciMLOperator v1
2 participants