ChainRulesCore.jl icon indicating copy to clipboard operation
ChainRulesCore.jl copied to clipboard

document ReverseDiff.jl integration's need to opt-in

Open mzgubic opened this issue 3 years ago • 5 comments

From Slack:

[Fredrik Bagge Carlson](https://app.slack.com/team/UJ7DVTVQ8) [Today at 3:48 PM](https://julialang.slack.com/archives/C6G240ENA/p1646063331166529)
I'm looking at
https://juliadiff.org/ChainRulesCore.jl/stable/index.html#ChainRules-roll-out-status
and it seems like ReverseDiff.jl is supposed to work with ChainRules, but i can't seem to figure out how, my rules are never called


4 replies

[Seth Axen](https://app.slack.com/team/UHDQQ4GN6):axe:  [7 minutes ago](https://julialang.slack.com/archives/C6G240ENA/p1646063442894469?thread_ts=1646063331.166529&cid=C6G240ENA)
By default ReverseDiff opts out of all rules for now. Use https://github.com/JuliaDiff/ReverseDiff.jl/blob/df0067465ca436b05377054ac7a184da691db1a3/src/macros.jl#L298-L315 to opt-in on a per-rule basis.

[Fredrik Bagge Carlson](https://app.slack.com/team/UJ7DVTVQ8)  [6 minutes ago](https://julialang.slack.com/archives/C6G240ENA/p1646063506399249?thread_ts=1646063331.166529&cid=C6G240ENA)
ok thanks for answering :slightly_smiling_face: Perhaps that should be made clear in the docs for chain rules? I couldn't find anything in the docs for RD either

[Seth Axen](https://app.slack.com/team/UHDQQ4GN6):axe:  [5 minutes ago](https://julialang.slack.com/archives/C6G240ENA/p1646063571928219?thread_ts=1646063331.166529&cid=C6G240ENA)
Yeah, the CR docs could be made more specific there. RD should document it. Not certain if this is considered an API macro.

[Fredrik Bagge Carlson](https://app.slack.com/team/UJ7DVTVQ8)  [2 minutes ago](https://julialang.slack.com/archives/C6G240ENA/p1646063717720879?thread_ts=1646063331.166529&cid=C6G240ENA)
It looks like the macro has some scoping issue
julia> ControlSystems
ControlSystems

julia> ReverseDiff.@grad_from_chainrules RobustAndOptimalControl.hinfnorm2(T::ControlSystems.StateSpace{Continuous, ReverseDiff.TrackedReal})
ERROR: UndefVarError: ControlSystems not defined
Stacktrace:
 [1] top-level scope
   @ ~/.julia/packages/ReverseDiff/Y5qec/src/macros.jl:324

mzgubic avatar Feb 28 '22 15:02 mzgubic

It works if I do

@eval ReverseDiff using ControlSystems

which I guess is an indication that the macro is missing some esc

baggepinnen avatar Feb 28 '22 16:02 baggepinnen

Can you open an issue in ReverseDiff? (In general, I'm not surprised, I think I came across some issues with the macros in ReverseDiff a while ago but didn't have time to fix it and could work around it.)

devmotion avatar Feb 28 '22 16:02 devmotion

Maybe the documentation issue is an issue of ReverseDiff (as well)? I.e., maybe the issue should be moved to ReverseDiff?

devmotion avatar Feb 28 '22 16:02 devmotion

It should have a brief mention in the CRC docs, (Since we have now done https://github.com/JuliaDiff/ChainRulesCore.jl/pull/514/files) but most of the docs on it should be in ReverseDiff.jl

oxinabox avatar Feb 28 '22 16:02 oxinabox

A docstring exists but is not included in the documentation: https://github.com/JuliaDiff/ReverseDiff.jl/pull/196

devmotion avatar Feb 28 '22 19:02 devmotion