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

`test_rrule` leads to `MethodError: Base.ArithmeticStyle(::Type{Union{}}) is ambiguous`

Open mcabbott opened this issue 3 years ago • 2 comments

I don't have a MWE, but the original case ~~was here: https://github.com/JuliaDiff/ChainRules.jl/pull/570/files#diff-14d216cb53721d9360bbbcc399d93fff67f2594bd388162abbbe82c59ad1ba9fR236.~~

Maybe https://github.com/JuliaDiff/ChainRules.jl/pull/570/commits/944ccedc52b0fa41d48c04dab4dfa6f5a5565678#diff-14d216cb53721d9360bbbcc399d93fff67f2594bd388162abbbe82c59ad1ba9fR236 is the right link.

mcabbott avatar Jan 17 '22 17:01 mcabbott

Hmm, do you mean the error is

test_rrule: filter on Base.Fix2{typeof(>), Float64},Vector{Float64}: Error During Test at /Users/mzgubic/JuliaEnvs/ChainRules.jl/dev/ChainRulesTestUtils/src/testers.jl:195
  Got exception outside of a @test
  MethodError: no method matching zero(::Base.Fix2{typeof(>), Float64})
  Closest candidates are:
    zero(::Union{Type{P}, P}) where P<:Dates.Period at /Applications/Julia-1.7.app/Contents/Resources/julia/share/julia/stdlib/v1.7/Dates/src/periods.jl:53
    zero(::T) where T<:Dates.TimeType at /Applications/Julia-1.7.app/Contents/Resources/julia/share/julia/stdlib/v1.7/Dates/src/types.jl:450
    zero(::CartesianIndex{N}) where N at /Applications/Julia-1.7.app/Contents/Resources/julia/share/julia/base/multidimensional.jl:106
    ...

I think it comes from the fact that >(0.5) is essentially a closure over 0.5, and CRTU tries to wiggle it. I don't think this is what we want here, but in general I don't think we want to not wiggle closures, so adding the ⊢ NoTangent() is appropriate. IMO. Admittedly, the error message is bad, and I have no ideas on how to improve it.

mzgubic avatar Jan 18 '22 11:01 mzgubic

Oh no, I thought I was linking to a commit, not just a line number.

No, Fix1 is another thing. Ideally it would perturb it, as you say, and deduce that it has no continuous effect, and thus accept Zero as the gradient.

mcabbott avatar Jan 18 '22 11:01 mcabbott