JuliaDiff / JuliaDiff/ChainRulesTestUtils.jl
Cannot test rule for structure where one (non-differentiable) field cannot be vectorized
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 50
- Forks
- 18
- PR merge metrics
- No merged PRs in 30d
Description
I am writing an rrule for *(::Struct, arr) where the structure and function look like,
struct Struct where {T<:Real}
x # stuff that can't be differentiated
y::T
end
*(s::Struct, arr) = y * x(arr)
However, I am unable to test my rrule, even with a manually provided tangent for an instance of Struct that looks like Tangent{Struct}(;x=NoTangent(), y=one(T)).
The reason seems to be that finite differences tries to to_vec the instance of struct. Given that the struct is not completely ignored, only the field x, it ends up trying to to_vec the field x as well. But this field is a reference to a rather crazy mutable structure with circular references, and so I end up with an error, and am unable to test that the rrule is correct w.r.t. y.
(To make it more concrete, the structure in question is a ScaledPlan from AbstractFFTs and the field x refers to a primitive FFT plan from FFTW, which is mutable because of its pinv cache.)
Ideally, it shouldn't matter what value is in the field x, since it is marked as NoTangent in the user-provided tangent? Just as how the entire input gets ignored if it is marked as NoTangent.
Contributor guide
No contributing guide indexed for this repository
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.
Research direction
Start at the finite-difference path that calls to_vec while testing an rrule, and trace how a supplied Tangent{Struct} with x=NoTangent() and a tangent for y is handled. Reproduce the issue with the Struct example, then verify that testing the y component no longer requires vectorizing the ignored x field.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100