Open
Description
Thanks for working on AbstractDifferentiation
! It tackles a very relevant practical problem.
Unfortunately, I cannot figure out from the Readme how AbstractDifferentiation
should be used.
The Readme says
"To use AbstractDifferentiation, first construct a backend instance ab::AD.AbstractBackend using your favorite differentiation package in Julia that supports AbstractDifferentiation."
but does not explain how to do this, see my failed attempt below (inspired from the test code).
Also,iIt would be nice if I could list all available backends somehow.
using AbstractDifferentiation
import Zygote
import ForwardDiff
# test function
foo(x) = sin(x[1]) + prod(x[2:end].^2)
x = rand(4)
# direct usage works
Zygote.gradient(foo, x)[1]
ForwardDiff.gradient(foo, x)
# Is this the correct way to create a Backend?
struct ForwardDiffBackend1 <: AD.AbstractForwardMode end
const forwarddiff_backend1 = ForwardDiffBackend1()
struct ZygoteBackend1 <: AD.AbstractReverseMode end
const zygote_backend1 = ZygoteBackend1()
# both fail with:
# MethodError: no method matching adjoint(::Nothing)
AD.gradient(zygote_backend1, foo, x)
AD.gradient(forwarddiff_backend1, foo, x)