Skip to content

Commit

Permalink
Merge pull request #708 from m-bossart/enzyme-compat-nonlinearproblem
Browse files Browse the repository at this point in the history
make nonlinear problem mutable
  • Loading branch information
ChrisRackauckas authored Jun 9, 2024
2 parents 79c1b04 + 5146f38 commit c312fd8
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/problems/basic_problems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ For specifying Jacobians and mass matrices, see the
* `p`: The parameters for the problem. Defaults to `NullParameters`.
* `kwargs`: The keyword arguments passed on to the solvers.
"""
struct NonlinearProblem{uType, isinplace, P, F, K, PT} <:
mutable struct NonlinearProblem{uType, isinplace, P, F, K, PT} <:
AbstractNonlinearProblem{uType, isinplace}
f::F
u0::uType
Expand Down Expand Up @@ -312,6 +312,18 @@ function NonlinearProblem(prob::AbstractODEProblem)
NonlinearProblem{isinplace(prob)}(prob.f, prob.u0, prob.p; prob.kwargs...)
end

function Base.setproperty!(prob::NonlinearProblem, s::Symbol, v)
@warn "Mutation of NonlinearProblem detected. SciMLBase v2.0 has made NonlinearProblem temporarily mutable in order to allow for interfacing with EnzymeRules due to a current limitation in the rule system. This change is only intended to be temporary and NonlinearProblem will return to being a struct in a later non-breaking release. Do not rely on this behavior, use with caution."
Base.setfield!(prob, s, v)
end

function Base.setproperty!(prob::NonlinearProblem, s::Symbol, v, order::Symbol)
@warn "Mutation of NonlinearProblem detected. SciMLBase v2.0 has made NonlinearProblem temporarily mutable in order to allow for interfacing with EnzymeRules due to a current limitation in the rule system. This change is only intended to be temporary and NonlinearProblem will return to being a struct in a later non-breaking release. Do not rely on this behavior, use with caution."
Base.setfield!(prob, s, v, order)
end



@doc doc"""
Defines a nonlinear least squares problem.
Expand Down

0 comments on commit c312fd8

Please sign in to comment.