Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error trying to differentiate eachindex #280

Open
gdalle opened this issue Mar 11, 2024 · 1 comment
Open

Error trying to differentiate eachindex #280

gdalle opened this issue Mar 11, 2024 · 1 comment

Comments

@gdalle
Copy link
Member

gdalle commented Mar 11, 2024

This came up in a test suite:

julia> import AbstractDifferentiation as AD

julia> import Diffractor: DiffractorForwardBackend

julia> h(x::AbstractVector) = eachindex(x) .* x
h (generic function with 1 method)

julia> AD.jacobian(DiffractorForwardBackend(), h, [1, 2])
ERROR: MethodError: no method matching size(::ChainRulesCore.Tangent{Base.OneTo{Int64}, @NamedTuple{stop::Int64}})

Closest candidates are:
  size(::Base.MethodList)
   @ Base reflection.jl:1042
  size(::BitVector)
   @ Base bitarray.jl:104
  size(::BitVector, ::Integer)
   @ Base bitarray.jl:107
  ...

Stacktrace:
  [1] axes
    @ ./abstractarray.jl:98 [inlined]
  [2] call_composed(fs::Tuple{typeof(axes)}, x::Tuple{ChainRulesCore.Tangent{Base.OneTo{…}, @NamedTuple{…}}}, kw::@Kwargs{})
    @ Base ./operators.jl:1045
  [3] call_composed
    @ ./operators.jl:1044 [inlined]
  [4] (::ComposedFunction{…})(x::ChainRulesCore.Tangent{…}; kw::@Kwargs{})
    @ Base ./operators.jl:1041
  [5] map
    @ ./tuple.jl:292 [inlined]
  [6] findconsistentvalue(f::typeof(axes), cols::Tuple{Base.OneTo{…}, ChainRulesCore.Tangent{…}})
    @ StructArrays ~/.julia/packages/StructArrays/CjQ4L/src/utils.jl:208
  [7] (StructArrays.StructVector{})(c::Tuple{…})
    @ StructArrays ~/.julia/packages/StructArrays/CjQ4L/src/structarray.jl:18
  [8] (StructArrays.StructArray{Diffractor.TangentBundle{} where P})(c::Tuple{Base.OneTo{…}, ChainRulesCore.Tangent{…}})
    @ StructArrays ~/.julia/packages/StructArrays/CjQ4L/src/structarray.jl:94
  [9] unbundle(atb::Diffractor.TangentBundle{1, Base.OneTo{Int64}, Diffractor.TaylorTangent{Tuple{…}}})
    @ Diffractor ~/.julia/packages/Diffractor/v1WuP/src/tangent.jl:365
 [10] (::Diffractor.var"#205#206"{1, Diffractor.∂☆{}, Diffractor.TangentBundle{}})(i::Int64)
    @ Diffractor ~/.julia/packages/Diffractor/v1WuP/src/stage1/broadcast.jl:23
 [11] ntuple(f::Diffractor.var"#205#206"{1, Diffractor.∂☆{}, Diffractor.TangentBundle{}}, n::Int64)
    @ Base ./ntuple.jl:19
 [12] (::Diffractor.∂☆{})(zc::Diffractor.TangentBundle{…}, bc::Diffractor.TangentBundle{…})
    @ Diffractor ~/.julia/packages/Diffractor/v1WuP/src/stage1/broadcast.jl:16
 [13] materialize
    @ ./broadcast.jl:903 [inlined]
 [14] (::Diffractor.∂☆recurse{})(::Diffractor.TangentBundle{…}, ::Diffractor.TangentBundle{…})
    @ Diffractor ~/.julia/packages/Diffractor/v1WuP/src/stage1/recurse_fwd.jl:0
 [15] (::Diffractor.∂☆internal{})(::Diffractor.TangentBundle{…}, ::Vararg{…})
    @ Diffractor ~/.julia/packages/Diffractor/v1WuP/src/stage1/forward.jl:114
 [16] ∂☆
    @ ~/.julia/packages/Diffractor/v1WuP/src/stage1/forward.jl:161 [inlined]
 [17] h
    @ ~/Work/GitHub/Julia/DifferentiationInterface.jl/test/diffractor.jl:13 [inlined]
 [18] ∂☆internal
    @ ~/.julia/packages/Diffractor/v1WuP/src/stage1/forward.jl:114 [inlined]
 [19] ∂☆
    @ ~/.julia/packages/Diffractor/v1WuP/src/stage1/forward.jl:161 [inlined]
 [20] (::Diffractor.var"#pushforward#370"{typeof(h), Tuple{Vector{Int64}}})(vs::Tuple{Vector{Int64}})
    @ Diffractor ~/.julia/packages/Diffractor/v1WuP/src/AbstractDifferentiation.jl:17
 [21] #369
    @ ~/.julia/packages/AbstractDifferentiation/RGmzD/src/AbstractDifferentiation.jl:644 [inlined]
 [22] mapslices(f::Diffractor.var"#369#373"{Diffractor.var"#pushforward#370"{}}, A::Matrix{Int64}; dims::Int64)
    @ Base ./abstractarray.jl:3191
 [23] jacobian(b::DiffractorForwardBackend, f::Function, args::Vector{Int64})
    @ Diffractor ~/.julia/packages/AbstractDifferentiation/RGmzD/src/AbstractDifferentiation.jl:642
 [24] top-level scope
    @ ~/Work/GitHub/Julia/DifferentiationInterface.jl/test/diffractor.jl:15
Some type information was truncated. Use `show(err)` to see complete types.
@oxinabox
Copy link
Member

I suspect this would be resolved by #276
though really we need to make it so that we don't try to AD things like this, off the active path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants