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

Failure to handle nothing output from Zygote.jl #662

Open
MilesCranmer opened this issue Dec 8, 2024 · 0 comments
Open

Failure to handle nothing output from Zygote.jl #662

MilesCranmer opened this issue Dec 8, 2024 · 0 comments

Comments

@MilesCranmer
Copy link

MilesCranmer commented Dec 8, 2024

julia> using Zygote, DifferentiationInterface

julia> safe_log(x) = x > zero(x) ? log(x) : convert(typeof(x), NaN)
safe_log (generic function with 1 method)

julia> derivative(safe_log, AutoZygote(), 0.0)
ERROR: MethodError: no method matching iterate(::Nothing)
The function `iterate` exists, but no method is defined for this combination of argument types.

Closest candidates are:
  iterate(::Combinatorics.Combinations)
   @ Combinatorics ~/.julia/packages/Combinatorics/Udg6X/src/combinations.jl:13
  iterate(::Combinatorics.Combinations, ::Any)
   @ Combinatorics ~/.julia/packages/Combinatorics/Udg6X/src/combinations.jl:13
  iterate(::Tables.DictRowTable)
   @ Tables ~/.julia/packages/Tables/8p03y/src/dicts.jl:122
  ...

Stacktrace:
 [1] dot(x::Float64, y::Nothing)
   @ LinearAlgebra ~/.julia/juliaup/julia-1.11.2+0.aarch64.apple.darwin14/share/julia/stdlib/v1.11/LinearAlgebra/src/generic.jl:855
 [2] 
   @ DifferentiationInterface ~/.julia/packages/DifferentiationInterface/gjT8p/src/first_order/pushforward.jl:161
 [3] #6
   @ ~/.julia/packages/DifferentiationInterface/gjT8p/src/first_order/pushforward.jl:192 [inlined]
 [4] ntuple
   @ ./ntuple.jl:48 [inlined]
 [5] value_and_pushforward
   @ ~/.julia/packages/DifferentiationInterface/gjT8p/src/first_order/pushforward.jl:191 [inlined]
 [6] pushforward
   @ ~/.julia/packages/DifferentiationInterface/gjT8p/src/first_order/pushforward.jl:220 [inlined]
 [7] derivative
   @ ~/.julia/packages/DifferentiationInterface/gjT8p/src/first_order/derivative.jl:124 [inlined]
 [8] derivative(::typeof(safe_log), ::AutoZygote, ::Float64)
   @ DifferentiationInterface ~/.julia/packages/DifferentiationInterface/gjT8p/src/fallbacks/no_prep.jl:49
 [9] top-level scope
   @ REPL[13]:1
Some type information was truncated. Use `show(err)` to see complete types.

Zygote.jl returns a nothing given an invalid input, so I think this should be correctly handled. Returning a NaN seems like an option?

For AutoForwardDiff, this gives us:

julia> derivative(safe_log, AutoForwardDiff(), 0.0)
0.0
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

1 participant