`@grad` fails for qualified function names (`gensym(::Expr)`)
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 86/100
Research direction
Start in src/macros.jl at the closure = gensym(f) line identified in the issue, then read the surrounding @grad macro logic. Check the existing @grad tests and add a regression case for a qualified function name such as M.f. Done means the rule expands successfully for qualified names while existing unqualified-name behavior still passes.
Written by the indexing model from the issue text.
Description
@grad fails at macro expansion time if the function name is qualified, e.g. M.f or Base.:*:
using ReverseDiff
module M
f(x) = sum(abs2, x)
end
M.f(x::ReverseDiff.TrackedArray) = ReverseDiff.track(M.f, x)
ReverseDiff.@grad function M.f(x)
xv = ReverseDiff.value(x)
return M.f(xv), Δ -> (2 .* Δ .* xv,)
end
ERROR: LoadError: MethodError: no method matching gensym(::Expr)
Stacktrace:
[1] var"@grad"(__source__::LineNumberNode, __module__::Module, expr::Any)
Expected: this defines the rule, like it does for an unqualified name. Qualified names are the normal way to add a rule for a function you don't own, e.g. a Base or LinearAlgebra function for your own array type. @grad_from_chainrules LinearAlgebra.dot(...) already handles them.
Cause: closure = gensym(f) assumes f is a Symbol. A plain gensym(:grad) (or gensym()) would be enough. This is the same line as #135 (callable structs), but a fix for that issue alone won't necessarily cover this case.
ReverseDiff master (b796032, v1.18.4), Julia 1.13.1.
- Dominant language
- Julia
- Stars
- 396
- Forks
- 61
- Avg merge
- 23h 18m
- Merged PRs (30d)
- 16
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from JuliaDiff/ReverseDiff.jl
-
`@grad`/`@grad_from_chainrules` silently reuse a tangent if a pullback returns too few tangentsOpen
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
JuliaDiff/ReverseDiff.jl#315 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
JuliaDiff/ReverseDiff.jl#314 ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 56/100
JuliaDiff/ReverseDiff.jl#321 ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 72/100
JuliaDiff/ReverseDiff.jl#320 ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 68/100
JuliaDiff/ReverseDiff.jl#319 ·
Maintainers usually reply within 1 day
All issues in JuliaDiff/ReverseDiff.jl
Similar issues
-
broken links in docsOpen
Difficulty 1/5 Under an hour Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
JuliaPhysics/BeamletOptics.jl#127 ·
Maintainers usually reply within 1 day
-
Chains resumed from `initial_state` take `num_warmup + 1` warm-up stepsPossibly taken @thevolatilebit claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
TuringLang/AbstractMCMC.jl#220 ·
-
found-by-agent
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
exanauts/SparseDirectSolver.jl#92 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 1 day