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 when computing jacobian for broadcasted function #209

Open
mattiasvillani opened this issue Aug 22, 2023 · 4 comments
Open

Error when computing jacobian for broadcasted function #209

mattiasvillani opened this issue Aug 22, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@mattiasvillani
Copy link
Contributor

mattiasvillani commented Aug 22, 2023

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.

@oxinabox oxinabox added the bug Something isn't working label Aug 23, 2023
@mattiasvillani
Copy link
Contributor Author

mattiasvillani commented Aug 26, 2023

Just noted that the following works

using Diffractor
Diffractor.gradient(θ -> sum(sin.(θ)), [0.3, 0.8])

but

using Diffractor
Diffractor.jacobian(θ -> sum(sin.(θ)), [0.3, 0.8])

errors with message

julia> Diffractor.jacobian(θ -> sum(sin.(θ)), [0.3, 0.8])
ERROR: UndefVarError: jacobian not defined
Stacktrace:
[1] getproperty(x::Module, f::Symbol)
@ Base ./Base.jl:31

@oxinabox
Copy link
Member

There is no function Diffractor.jacobian only AbstractDifferentiation.jacobian.
Diffractor.gradient is not part of the public API, we make zero stability promises for it.

@mattiasvillani
Copy link
Contributor Author

Ok, thanks. I take it as the original issue is still a (potential) bug.

@oxinabox
Copy link
Member

This may or may not be fixed in #224

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants