Skip to content

Commit 82238a2

Browse files
docs: add comment explaining added rrule
Co-authored-by: Dhairya Gandhi <[email protected]>
1 parent aced3e8 commit 82238a2

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

ext/SciMLBaseChainRulesCoreExt.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ function ChainRulesCore.rrule(
137137
SciMLBase.IntervalNonlinearProblem(args...; kwargs...), IntervalNonlinearProblemAdjoint
138138
end
139139

140+
# This is a workaround for the fact `NonlinearProblem` is a mutable struct. In SciMLSensitivity, we call
141+
# `back` explicitly while already in a reverse pass causing a nested gradient call. The mutable struct
142+
# causes accumulation anytime `getfield/property` is called, accumulating multiple times. This tries to treat
143+
# AbstractDEProblem as immutable for the purposes of reverse mode AD.
140144
function ChainRulesCore.rrule(::ChainRulesCore.RuleConfig{>:ChainRulesCore.HasReverseMode}, ::typeof(Base.getproperty), x::NonlinearProblem, f::Symbol)
141145
val = getfield(x, f)
142146
function back(der)

0 commit comments

Comments
 (0)