EnzymeAD / Enzyme.jl

Julia bindings for the Enzyme automatic differentiator
https://enzyme.mit.edu
MIT License
428 stars 59 forks source link

FiniteDifferences method fails #1406

Open just-walk opened 2 months ago

just-walk commented 2 months ago

(If I need to post this over at FiniteDifferences.jl, then let me know.)

This is the result from a (intermediate) function call

    return FiniteDifferenceMethod(lbound:ubound, diffOrder)

where lbound, ubound, and diffOrder are Int:

Enzyme: Augmented forward pass custom rule Tuple{EnzymeCore.EnzymeRules.ConfigWidth{1, true, true, (false, true, true)}, Const{typeof(\)}, Type{Duplicated{Union{Vector{Rational{BigInt}}, Vector{BigFloat}}}}, Const{Matrix{Rational{BigInt}}}, Const{Vector{Rational{BigInt}}}} return type mismatch, expected EnzymeCore.EnzymeRules.AugmentedReturn{Union{Vector{Rational{BigInt}}, Vector{BigFloat}}, Union{Vector{Rational{BigInt}}, Vector{BigFloat}}, Any} found EnzymeCore.EnzymeRules.AugmentedReturn{_A, _B, NamedTuple{_A1, T}} where {_A, _B, _A1, T<:Tuple}
  Stacktrace:
   [1] _coefs
     @ ~/.julia/packages/FiniteDifferences/zWRHl/src/methods.jl:283

  Stacktrace:
    [1] throwerr(cstr::Cstring)
      @ Enzyme.Compiler ~/.julia/packages/Enzyme/l4FS0/src/compiler.jl:1289
    [2] _coefs
      @ ~/.julia/packages/FiniteDifferences/zWRHl/src/methods.jl:283
    [3] #11
      @ ~/.julia/packages/FiniteDifferences/zWRHl/src/methods.jl:296
    [4] get!
      @ ./dict.jl:479
    [5] _coefs_mults
      @ ~/.julia/packages/FiniteDifferences/zWRHl/src/methods.jl:294 [inlined]
    [6] #FiniteDifferenceMethod#7
      @ ~/.julia/packages/FiniteDifferences/zWRHl/src/methods.jl:139
    [7] FiniteDifferenceMethod
      @ ~/.julia/packages/FiniteDifferences/zWRHl/src/methods.jl:131 [inlined]
    [8] FiniteDifferenceMethod
      @ ~/.julia/packages/FiniteDifferences/zWRHl/src/methods.jl:0 [inlined]
    [9] augmented_julia_FiniteDifferenceMethod_10076_inner_1wrap
      @ ~/.julia/packages/FiniteDifferences/zWRHl/src/methods.jl:0
   [10] macro expansion
      @ ~/.julia/packages/Enzyme/l4FS0/src/compiler.jl:5378 [inlined]

Is this an indication of a bug, or that this method needs a custom rule in FiniteDifferences.jl?

wsmoses commented 2 months ago

Can you paste a full runnable code snippet that produces this error?

just-walk commented 2 months ago

This is with 0.11.20, BTW, since I ran into another issue on 0.12.

using Enzyme
using FiniteDifferences

function sum_coeffs(lbound, ubound, diffOrder)
    fdm = FiniteDifferenceMethod(lbound:ubound, diffOrder)
    return sum(fdm.coefs)
end

@show autodiff(ReverseWithPrimal, sum_coeffs, Active, Const(1), Const(3), Const(2))

All arguments have activity Const here because, in my use, the inputs to this method are all derived from parameters marked as Const.

wsmoses commented 1 week ago

This now no longer fails on the \ rule, but on the constructor of a BigFloat used within FiniteDifferences