JuliaDiff / JuliaDiff/Diffractor.jl
Error when computing jacobian for broadcasted function
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 453
- Forks
- 33
- PR merge metrics
- No merged PRs in 30d
Description
Simple broadcasting errors for me. See below.
I am on Julia 1.10.0-beta2+0.x64.linux.gnu
within the following environment:
Status ~/.julia/environments/v1.10/Project.toml
[c29ec348] AbstractDifferentiation v0.5.2
[9f5e2b26] Diffractor v0.2.1
[31c24e10] Distributions v0.25.100
This shows the issue (verified that I get the same problem with gradient from AbstractDifferentiation.jl):
using Diffractor: DiffractorForwardBackend
using AbstractDifferentiation: derivative, jacobian
jacobian(DiffractorForwardBackend(), θ -> sin(θ[1]) + sin(θ[2]), [0.3, 0.8]) # works
jacobian(DiffractorForwardBackend(), θ -> sum(sin, θ), [0.3, 0.8]) # works
jacobian(DiffractorForwardBackend(), θ -> sum(sin.(θ)), [0.3, 0.8]) # errors
last command errors with (truncated error):
ERROR: MethodError: no method matching Diffractor.TangentBundle{1, Float64, Diffractor.TaylorTangent{Tuple{Float64}}}(::Float64, ::Tuple{Float64})
Stacktrace:
[1] createinstance(::Type{Diffractor.TangentBundle{1, Float64, Diffractor.TaylorTangent{Tuple{Float64}}}}, ::Float64, ::Vararg{Float64})
@ Diffractor ~/.julia/packages/Diffractor/vzpvE/src/tangent.jl:351
[2] _getindex
@ Diffractor ~/.julia/packages/StructArrays/dNQpc/src/structarray.jl:353 [inlined]
[3] getindex
@ Diffractor ~/.julia/packages/StructArrays/dNQpc/src/structarray.jl:348 [inlined]
[4] iterate
@ Diffractor ./abstractarray.jl:1212 [inlined]
[5] iterate
@ Diffractor ./abstractarray.jl:1210 [inlined]
[6] iterate
@ Diffractor ./generator.jl:44 [inlined]
[7] _collect
@ Diffractor ./array.jl:852 [inlined]
[8] collect_similar
@ Diffractor ./array.jl:761 [inlined]
[9] map
@ Diffractor ./abstractarray.jl:3273 [inlined]
[10] rebundle(A::StructArrays.StructVector{Diffractor.TangentBundle{1, Float64, Diffractor.TaylorTangent{Tuple{Float64}}}, Tuple{Vector{Float64}, Vector{Float64}}, Int64})
@ Diffractor ~/.julia/packages/Diffractor/vzpvE/src/tangent.jl:375
[11] (::Diffractor.∂☆{1})(zc::ZeroBundle{1, typeof(copy)}, bc::Diffractor.CompositeBundle{1, Base.Broadcast.Broadcasted{…}, Tuple{…}})
@ Diffractor ~/.julia/packages/Diffractor/vzpvE/src/stage1/broadcast.jl:27
[12] materialize
@ Diffractor ./broadcast.jl:903 [inlined]
[13] (::Diffractor.∂☆internal{1})(::ZeroBundle{1, Type{Base.Broadcast.Broadcasted}}, ::Vararg{Diffractor.AbstractTangentBundle{1}})
@ Diffractor ~/.julia/packages/Diffractor/vzpvE/src/stage1/forward.jl:121 [inlined]
[14] ∂☆
@ Diffractor ~/.julia/packages/Diffractor/vzpvE/src/stage1/forward.jl:160 [inlined]
[15] #61
@ Diffractor ./REPL[45]:1 [inlined]
[16] (::Diffractor.∂☆recurse{1})(::ZeroBundle{1, var"#61#62"}, ::Diffractor.TangentBundle{1, Vector{Float64}, Diffractor.TaylorTangent{Tuple{Vector{Float64}}}})
@ Diffractor ~/.julia/packages/Diffractor/vzpvE/src/stage1/recurse_fwd.jl:0
[17] (::Diffractor.∂☆internal{1})(::ZeroBundle{1, var"#61#62"}, ::Vararg{Diffractor.AbstractTangentBundle{1}})
@ Diffractor ~/.julia/packages/Diffractor/vzpvE/src/stage1/forward.jl:121
[18] (::Diffractor.∂☆{1})(::ZeroBundle{1, var"#61#62"}, ::Vararg{Diffractor.AbstractTangentBundle{1}})
@ Diffractor ~/.julia/packages/Diffractor/vzpvE/src/stage1/forward.jl:160
[19] (::Diffractor.var"#pushforward#359"{var"#61#62", Tuple{Vector{Float64}}})(vs::Tuple{Vector{Float64}})
@ Diffractor ~/.julia/packages/Diffractor/vzpvE/src/AbstractDifferentiation.jl:13
[20] (::Diffractor.var"#358#362"{Diffractor.var"#pushforward#359"{var"#61#62", Tuple{Vector{Float64}}}})(cols::Vector{Float64})
@ Diffractor ~/.julia/packages/AbstractDifferentiation/eEkWP/src/AbstractDifferentiation.jl:526
[21] mapslices(f::Diffractor.var"#358#362"{Diffractor.var"#pushforward#359"{var"#61#62", Tuple{Vector{Float64}}}}, A::Matrix{Float64}; dims::Int64)
@ Base ./abstractarray.jl:3179
[22] jacobian(b::DiffractorForwardBackend, f::Function, args::Vector{Float64})
@ Diffractor ~/.julia/packages/AbstractDifferentiation/eEkWP/src/AbstractDifferentiation.jl:524
[23] top-level scope
@ REPL[45]:1
Some type information was truncated. Use show(err) to see complete types.
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
Reproduce the three jacobian calls with Julia 1.10.0-beta2 and the listed AbstractDifferentiation and Diffractor versions. Start with src/stage1/broadcast.jl:27 and the createinstance/rebundle paths at src/tangent.jl:351 and :375, then compare the working and failing broadcast cases. Done means the elementwise broadcasted sin expression computes its jacobian without the reported TangentBundle MethodError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100