-
Notifications
You must be signed in to change notification settings - Fork 16
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
Adding GTPSA.jl
to the interface
#316
Comments
Thanks for contributing! |
For forward-mode AD, it's technically enough to only implement
Traits are used to indicate support for two-argument functions You might want to take a look at how overloads are handled on other backends: https://docs.juliahub.com/General/DifferentiationInterface/stable/overloads/ |
I have written a detailed dev guide in #317 |
You can now read it here: https://gdalle.github.io/DifferentiationInterface.jl/DifferentiationInterface/dev/dev_guide/ |
So are the arguments |
DifferentiationInterface supports functions that take either a scalar or an array as input, and return either a scalar or an array. For some operators, like the Jacobian, there's only one possible combination (array to array). But for the pushforward, there are 4 different combinations, which you must all handle. This can be done either with checks inside the function or with multiple dispatch. |
Note that you don't need to define the mutable version pushforward! when the output y is a number, because dy won't be mutable |
For pushforward where
But |
No, the pushforward is the product of the Jacobian with a given vector, also called JVP. The whole point is to avoid materializing the full matrix if you can.
Each operator has an in-place and an out-of-place version, so we only expect the out-of-place version to work with StaticArrays. The test package DifferentiationInterfaceTest contains a list of Perhaps I could lend a hand if you point me to your code draft? |
Ah I see now, my understanding was completely wrong
Sure! Here is the fork I'm working on. I have derivative, second_derivate, gradient, jacobian, hessian all implemented for onearg |
I strongly recommend adding a test file as outlined in the docs, and running the |
Yes I will soon, I just haven't had enough time to work on this yet |
OK I am having a bit of trouble and could use some help. I'm not the most familiar with how to work with extensions. First I tried defining the AutoGTPSA type in the module in ext, but then ran into problems because exporting AutoGTPSA from DifferentiationInterface leaves AutoGTPSA undefined and weird things happened Then I also dev-ed out ADTypes, and defined AutoGTPSA there following the other backends. This solved the first problem but now I still cannot load AutoGTPSA: If you dev my DifferentiationInterface fork (note branch is called addgtpsa) and my ADTypes fork (branch also called addgtpsa), and then in Julia do: julia> using DifferentiationInterface
julia> import GTPSA
julia> DifferentiationInterface.check_available(AutoGTPSA())
false Any help is much appreciated! |
Can you open a PR to the present repo so that I may modify it? |
Here's the definition for the AutoGTPSA type: """
AutoGTPSA{D}
Struct used to select the [GTPSA.jl](https://github.com/bmad-sim/GTPSA.jl) backend for automatic differentiation.
# Constructors
AutoGTPSA(; descriptor=nothing)
# Fields
- `descriptor::D`: can be either
+ a GTPSA `Descriptor` specifying the number of variables/parameters, parameter
order, individual variable/parameter truncation orders, and maximum order. See
[here](https://bmad-sim.github.io/GTPSA.jl/stable/man/c_descriptor/) for more details.
+ `nothing` to automatically use a `Descriptor` given the context
"""
Base.@kwdef struct AutoGTPSA{D} <: AbstractADType
descriptor::D = nothing
end
mode(::AutoGTPSA) = ForwardMode() |
I'll use this issue for questions I have for implementing this interface into
GTPSA.jl
. I've done some reading of the documentation and those AD packages inext
, and here are some of my first questionsvalue_and_gradient
,value_and_jacobian
, etc, is it safe to assumepushforward
,value_and_pushforward
only receive single variable functions?The text was updated successfully, but these errors were encountered: