Skip to content

Commit 8dcd924

Browse files
Add the GTPSA.jl backend (#329)
* add extension directory * derivative,second derivative, gradient * jacobian, hessian * add GTPSA to Project.toml, move AutoGTPSA to ADTypes * Fix tests * Lighter workflow * pushforward * trigger workflow * fix tests? * fix typo * hvp done and two args done * fix typo * Update Test.yml * no code coverage * add GTPSA test * almost all tests passing, bugs in pushforward * all tests passing * latest GTPSA version specified, docs updated * no coverage test * Fix formatting and docs * Exclude GTPSA from LTS testing * Reactivate coverage * Reactivate all tests * Test group * simplified code and removed derivative * Adapt to new Tangents * Tangents import * Fix da fixes * Remove temporary backend * Fixes * Docs * GTPSAExt devel in progress * one arg done * all tests except hvp passing, should have full code cov * bump gtpsa version * fix hvp functions and docs update * fix typo * one more typo (sorry) * JuliaFormatter * Update DifferentiationInterface/docs/Project.toml Co-authored-by: Guillaume Dalle <22795598+gdalle@users.noreply.github.com> * Better clarification of "variables" in GTPSA * address comments * no implicit imports test * fixes and formatting --------- Co-authored-by: Guillaume Dalle <22795598+gdalle@users.noreply.github.com>
1 parent 59dc865 commit 8dcd924

9 files changed

Lines changed: 856 additions & 0 deletions

File tree

.github/workflows/Test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ jobs:
4242
- Back/FiniteDiff
4343
- Back/FiniteDifferences
4444
- Back/ForwardDiff
45+
- Back/GTPSA
4546
- Back/Mooncake
4647
- Back/PolyesterForwardDiff
4748
- Back/ReverseDiff

DifferentiationInterface/Project.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ FastDifferentiation = "eb9bf01b-bf85-4b60-bf87-ee5de06c00be"
1717
FiniteDiff = "6a86dc24-6348-571c-b903-95158fe2bd41"
1818
FiniteDifferences = "26cc04aa-876d-5657-8c51-4c34ba976000"
1919
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
20+
GTPSA = "b27dd330-f138-47c5-815b-40db9dd9b6e8"
2021
Mooncake = "da2b9cff-9c12-43a0-ae48-6db2b0edb7d6"
2122
PolyesterForwardDiff = "98d1487c-24ca-40b6-b7ab-df2af84e126b"
2223
ReverseDiff = "37e2e3b7-166d-5795-8a7a-e32c996b4267"
@@ -35,6 +36,7 @@ DifferentiationInterfaceFastDifferentiationExt = "FastDifferentiation"
3536
DifferentiationInterfaceFiniteDiffExt = "FiniteDiff"
3637
DifferentiationInterfaceFiniteDifferencesExt = "FiniteDifferences"
3738
DifferentiationInterfaceForwardDiffExt = ["ForwardDiff", "DiffResults"]
39+
DifferentiationInterfaceGTPSAExt = "GTPSA"
3840
DifferentiationInterfaceMooncakeExt = "Mooncake"
3941
DifferentiationInterfacePolyesterForwardDiffExt = "PolyesterForwardDiff"
4042
DifferentiationInterfaceReverseDiffExt = ["ReverseDiff", "DiffResults"]
@@ -57,6 +59,7 @@ FastDifferentiation = "0.4.1"
5759
FiniteDiff = "2.23.1"
5860
FiniteDifferences = "0.12.31"
5961
ForwardDiff = "0.10.36"
62+
GTPSA = "1.4.0"
6063
JuliaFormatter = "1"
6164
LinearAlgebra = "<0.0.1,1"
6265
Mooncake = "0.4.52"
@@ -84,6 +87,7 @@ FastDifferentiation = "eb9bf01b-bf85-4b60-bf87-ee5de06c00be"
8487
FiniteDiff = "6a86dc24-6348-571c-b903-95158fe2bd41"
8588
FiniteDifferences = "26cc04aa-876d-5657-8c51-4c34ba976000"
8689
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
90+
GTPSA = "b27dd330-f138-47c5-815b-40db9dd9b6e8"
8791
JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b"
8892
JLArrays = "27aeb0d3-9eb9-45fb-866b-73c2ecf80fcb"
8993
JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899"

DifferentiationInterface/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ We support the following backends defined by [ADTypes.jl](https://github.com/Sci
3737
- [FiniteDiff.jl](https://github.com/JuliaDiff/FiniteDiff.jl)
3838
- [FiniteDifferences.jl](https://github.com/JuliaDiff/FiniteDifferences.jl)
3939
- [ForwardDiff.jl](https://github.com/JuliaDiff/ForwardDiff.jl)
40+
- [GTPSA.jl](https://github.com/bmad-sim/GTPSA.jl)
4041
- [Mooncake.jl](https://github.com/compintell/Mooncake.jl)
4142
- [PolyesterForwardDiff.jl](https://github.com/JuliaDiff/PolyesterForwardDiff.jl)
4243
- [ReverseDiff.jl](https://github.com/JuliaDiff/ReverseDiff.jl)

DifferentiationInterface/docs/src/explanation/backends.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ We support the following dense backend choices from [ADTypes.jl](https://github.
1111
- [`AutoFiniteDiff`](@extref ADTypes.AutoFiniteDiff)
1212
- [`AutoFiniteDifferences`](@extref ADTypes.AutoFiniteDifferences)
1313
- [`AutoForwardDiff`](@extref ADTypes.AutoForwardDiff)
14+
- [`AutoGTPSA`](@extref ADTypes.AutoGTPSA)
1415
- [`AutoMooncake`](@extref ADTypes.AutoMooncake)
1516
- [`AutoPolyesterForwardDiff`](@extref ADTypes.AutoPolyesterForwardDiff)
1617
- [`AutoReverseDiff`](@extref ADTypes.AutoReverseDiff)
@@ -45,6 +46,7 @@ In practice, many AD backends have custom implementations for high-level operato
4546
| `AutoFiniteDiff` | 🔀 | ❌ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ |
4647
| `AutoFiniteDifferences` | 🔀 | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ |
4748
| `AutoForwardDiff` | ✅ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
49+
| `AutoGTPSA` | ✅ | ❌ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ |
4850
| `AutoMooncake` | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
4951
| `AutoPolyesterForwardDiff` | 🔀 | ❌ | 🔀 | ✅ | ✅ | 🔀 | 🔀 | 🔀 |
5052
| `AutoReverseDiff` | ❌ | 🔀 | ❌ | ✅ | ✅ | ✅ | ❌ | ❌ |
@@ -64,6 +66,7 @@ Moreover, each context type is supported by a specific subset of backends:
6466
| `AutoFiniteDiff` ||
6567
| `AutoFiniteDifferences` ||
6668
| `AutoForwardDiff` ||
69+
| `AutoGTPSA` ||
6770
| `AutoMooncake` ||
6871
| `AutoPolyesterForwardDiff` ||
6972
| `AutoReverseDiff` ||
@@ -138,6 +141,15 @@ Nothing specific to mention.
138141
We implement [`pushforward`](@ref) directly using [`Dual` numbers](https://juliadiff.org/ForwardDiff.jl/stable/dev/how_it_works/), and preparation allocates the necessary space.
139142
For higher level operators, preparation creates a [config object](https://juliadiff.org/ForwardDiff.jl/stable/user/api/#Preallocating/Configuring-Work-Buffers), which can be type-unstable.
140143

144+
### GTPSA
145+
146+
For all operators, preparation preallocates the input [`TPS`s](https://bmad-sim.github.io/GTPSA.jl/stable/man/c_tps/), and for in-place functions the output `TPS`s as well. For minimal allocations of `TPS` temporaries inside of a function, the [`@FastGTPSA`/`@FastGTPSA!`](https://bmad-sim.github.io/GTPSA.jl/stable/man/j_fastgtpsa/) macros are recommended.
147+
148+
If a GTPSA [`Descriptor`](https://bmad-sim.github.io/GTPSA.jl/stable/man/b_descriptor/) is not provided to `AutoGTPSA`, then a `Descriptor` will be generated in preparation based on the context.
149+
150+
!!! danger
151+
When providing a custom GTPSA `Descriptor` to `AutoGTPSA`, it is the responsibility of the user to ensure that the number of [GTPSA "variables"](https://bmad-sim.github.io/GTPSA.jl/stable/quickstart/#Calculating-a-Truncated-Power-Series) specified in the `Descriptor` is consistent with the number of inputs of the provided function. Undefined behavior and crashes may occur if this is not the case.
152+
141153
### PolyesterForwardDiff
142154

143155
Most operators fall back on `AutoForwardDiff`.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module DifferentiationInterfaceGTPSAExt
2+
3+
import DifferentiationInterface as DI
4+
using ADTypes: AutoGTPSA
5+
using GTPSA: GTPSA, TPS, Descriptor
6+
7+
DI.check_available(::AutoGTPSA) = true
8+
9+
include("onearg.jl")
10+
include("twoarg.jl")
11+
12+
end

0 commit comments

Comments
 (0)