Skip to content

Commit 1d39604

Browse files
authored
Upgrade to ADTypes v1.0 (#194)
* Upgrade to ADTypes v1.0 * Fix docs * Fix docs * Aqua * Fix tests * Fix CI * Revert version bump for now * Add manifests * Fix compat * Fix tuto * Re-add Symbolics * Add coloring algorithms * Fix CI * Rev * Resolve * Remove downloads in favor of manifests * Don't force latest version * Sparsity works * Deactivate workflows * SciMLBase update * Remove playground * Reactivate workflows * Rely on registered versions * Remove warnonly in docs * Push preview * Rm SciMLBase
1 parent 4fa52a2 commit 1d39604

52 files changed

Lines changed: 784 additions & 578 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/CI.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ jobs:
5656
- uses: julia-actions/julia-runtest@v1
5757
with:
5858
project: ${{ matrix.pkg.dir }}
59-
force_latest_compatible_version: true
6059
- uses: julia-actions/julia-processcoverage@v1
6160
with:
6261
directories: ${{ matrix.pkg.dir }}/src,${{ matrix.pkg.dir }}/ext

DifferentiationInterface/Project.toml

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "DifferentiationInterface"
22
uuid = "a0c0ee7d-e4b9-4e03-894e-1c5f64a51d63"
33
authors = ["Guillaume Dalle", "Adrian Hill"]
4-
version = "0.2.1"
4+
version = "0.3.0"
55

66
[deps]
77
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
@@ -35,14 +35,13 @@ DifferentiationInterfaceFiniteDifferencesExt = "FiniteDifferences"
3535
DifferentiationInterfaceForwardDiffExt = "ForwardDiff"
3636
DifferentiationInterfacePolyesterForwardDiffExt = "PolyesterForwardDiff"
3737
DifferentiationInterfaceReverseDiffExt = "ReverseDiff"
38-
DifferentiationInterfaceSparseDiffToolsExt = ["SparseDiffTools", "Symbolics"]
3938
DifferentiationInterfaceSymbolicsExt = "Symbolics"
4039
DifferentiationInterfaceTapirExt = "Tapir"
4140
DifferentiationInterfaceTrackerExt = "Tracker"
4241
DifferentiationInterfaceZygoteExt = "Zygote"
4342

4443
[compat]
45-
ADTypes = "0.2.7"
44+
ADTypes = "1.0.0"
4645
ChainRulesCore = "1.23.0"
4746
Diffractor = "=0.2.6"
4847
DocStringExtensions = "0.9.3"
@@ -55,7 +54,6 @@ ForwardDiff = "0.10.36"
5554
LinearAlgebra = "1"
5655
PolyesterForwardDiff = "0.1.1"
5756
ReverseDiff = "1.15.1"
58-
SparseDiffTools = "2.17.0"
5957
Symbolics = "5.27.1"
6058
Tapir = "0.1.2"
6159
Test = "1"
@@ -79,34 +77,11 @@ Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
7977
PolyesterForwardDiff = "98d1487c-24ca-40b6-b7ab-df2af84e126b"
8078
ReverseDiff = "37e2e3b7-166d-5795-8a7a-e32c996b4267"
8179
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
82-
SparseDiffTools = "47a9eef4-7e08-11e9-0b38-333d64bd3804"
8380
Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7"
8481
Tapir = "07d77754-e150-4737-8c94-cd238a1fb45b"
8582
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
8683
Tracker = "9f7883ad-71c0-57eb-9f7f-b5c9e6d3789c"
8784
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"
8885

8986
[targets]
90-
test = [
91-
"ADTypes",
92-
"Aqua",
93-
"Diffractor",
94-
"Documenter",
95-
"Enzyme",
96-
"FastDifferentiation",
97-
"FiniteDiff",
98-
"FiniteDifferences",
99-
"ForwardDiff",
100-
"JET",
101-
"JuliaFormatter",
102-
"Pkg",
103-
"PolyesterForwardDiff",
104-
"ReverseDiff",
105-
"SparseArrays",
106-
"SparseDiffTools",
107-
"Symbolics",
108-
"Tapir",
109-
"Test",
110-
"Tracker",
111-
"Zygote",
112-
]
87+
test = ["ADTypes", "Aqua", "Diffractor", "Documenter", "Enzyme", "FastDifferentiation", "FiniteDiff", "FiniteDifferences", "ForwardDiff", "JET", "JuliaFormatter", "Pkg", "PolyesterForwardDiff", "ReverseDiff", "SparseArrays", "Symbolics", "Tapir", "Test", "Tracker", "Zygote"]

DifferentiationInterface/README.md

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -28,29 +28,22 @@ This package provides a backend-agnostic syntax to differentiate functions of th
2828

2929
## Compatibility
3030

31-
We support most of the backends defined by [ADTypes.jl](https://github.com/SciML/ADTypes.jl):
32-
33-
| Backend | Object |
34-
| :------------------------------------------------------------------------------ | :----------------------------------------------------------------------- |
35-
| [ChainRulesCore.jl](https://github.com/JuliaDiff/ChainRulesCore.jl) | `AutoChainRules(; ruleconfig)` |
36-
| [Diffractor.jl](https://github.com/JuliaDiff/Diffractor.jl) | `AutoDiffractor()` |
37-
| [Enzyme.jl](https://github.com/EnzymeAD/Enzyme.jl) | `AutoEnzyme(; mode=Enzyme.Forward)`, `AutoEnzyme(; mode=Enzyme.Reverse)` |
38-
| [FiniteDiff.jl](https://github.com/JuliaDiff/FiniteDiff.jl) | `AutoFiniteDiff()` |
39-
| [FiniteDifferences.jl](https://github.com/JuliaDiff/FiniteDifferences.jl) | `AutoFiniteDifferences(; fdm)` |
40-
| [ForwardDiff.jl](https://github.com/JuliaDiff/ForwardDiff.jl) | `AutoForwardDiff()` |
41-
| [PolyesterForwardDiff.jl](https://github.com/JuliaDiff/PolyesterForwardDiff.jl) | `AutoPolyesterForwardDiff(; chunksize)` |
42-
| [ReverseDiff.jl](https://github.com/JuliaDiff/ReverseDiff.jl) | `AutoReverseDiff()` |
43-
| [SparseDiffTools.jl](https://github.com/JuliaDiff/SparseDiffTools.jl) | `AutoSparseForwardDiff()`, `AutoSparseFiniteDiff()` |
44-
| [Tracker.jl](https://github.com/FluxML/Tracker.jl) | `AutoTracker()` |
45-
| [Zygote.jl](https://github.com/FluxML/Zygote.jl) | `AutoZygote()` |
46-
47-
We also provide some experimental backends ourselves:
48-
49-
| Backend | Object |
50-
| :------------------------------------------------------------------------------- | :------------------------------------------------------------- |
51-
| [FastDifferentiation.jl](https://github.com/brianguenter/FastDifferentiation.jl) | `AutoFastDifferentiation()`, `AutoSparseFastDifferentiation()` |
52-
| [Symbolics.jl](https://github.com/JuliaSymbolics/Symbolics.jl) | `AutoSymbolics()`, `AutoSparseSymbolics()` |
53-
| [Tapir.jl](https://github.com/withbayes/Tapir.jl) | `AutoTapir()` |
31+
We support all of the backends defined by [ADTypes.jl](https://github.com/SciML/ADTypes.jl) v1.0:
32+
33+
- [ChainRulesCore.jl](https://github.com/JuliaDiff/ChainRulesCore.jl)
34+
- [Diffractor.jl](https://github.com/JuliaDiff/Diffractor.jl)
35+
- [Enzyme.jl](https://github.com/EnzymeAD/Enzyme.jl)
36+
- [FastDifferentiation.jl](https://github.com/brianguenter/FastDifferentiation.jl)
37+
- [FiniteDiff.jl](https://github.com/JuliaDiff/FiniteDiff.jl)
38+
- [FiniteDifferences.jl](https://github.com/JuliaDiff/FiniteDifferences.jl)
39+
- [ForwardDiff.jl](https://github.com/JuliaDiff/ForwardDiff.jl)
40+
- [PolyesterForwardDiff.jl](https://github.com/JuliaDiff/PolyesterForwardDiff.jl)
41+
- [ReverseDiff.jl](https://github.com/JuliaDiff/ReverseDiff.jl)
42+
- [SparseDiffTools.jl](https://github.com/JuliaDiff/SparseDiffTools.jl)
43+
- [Symbolics.jl](https://github.com/JuliaSymbolics/Symbolics.jl) (currently broken)
44+
- [Tapir.jl](https://github.com/withbayes/Tapir.jl)
45+
- [Tracker.jl](https://github.com/FluxML/Tracker.jl)
46+
- [Zygote.jl](https://github.com/FluxML/Zygote.jl)
5447

5548
## Installation
5649

@@ -76,11 +69,11 @@ julia> Pkg.add(
7669
## Example
7770

7871
```jldoctest readme
79-
julia> import ForwardDiff
72+
julia> import ADTypes, ForwardDiff
8073
8174
julia> using DifferentiationInterface
8275
83-
julia> backend = AutoForwardDiff();
76+
julia> backend = ADTypes.AutoForwardDiff();
8477
8578
julia> f(x) = sum(abs2, x);
8679

DifferentiationInterface/docs/Project.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,11 @@ Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"
1616
PolyesterForwardDiff = "98d1487c-24ca-40b6-b7ab-df2af84e126b"
1717
PrettyTables = "08abe8d2-0d0c-5749-adfa-8a2ac140af0d"
1818
ReverseDiff = "37e2e3b7-166d-5795-8a7a-e32c996b4267"
19-
SparseDiffTools = "47a9eef4-7e08-11e9-0b38-333d64bd3804"
2019
Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7"
2120
Tapir = "07d77754-e150-4737-8c94-cd238a1fb45b"
2221
Tracker = "9f7883ad-71c0-57eb-9f7f-b5c9e6d3789c"
2322
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"
2423

2524
[compat]
26-
ADTypes = "0.2.7"
25+
DifferentiationInterface = "0.3"
2726
Documenter = "1"

DifferentiationInterface/docs/make.jl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ using ForwardDiff: ForwardDiff
1414
using PolyesterForwardDiff: PolyesterForwardDiff
1515
using ReverseDiff: ReverseDiff
1616
using Symbolics: Symbolics
17-
using SparseDiffTools: SparseDiffTools
1817
using Tapir: Tapir
1918
using Tracker: Tracker
2019
using Zygote: Zygote
@@ -31,14 +30,14 @@ extensions = [
3130
get_extension(DI, :DifferentiationInterfaceForwardDiffExt),
3231
get_extension(DI, :DifferentiationInterfacePolyesterForwardDiffExt),
3332
get_extension(DI, :DifferentiationInterfaceReverseDiffExt),
34-
get_extension(DI, :DifferentiationInterfaceSparseDiffToolsExt),
33+
get_extension(DI, :DifferentiationInterfaceSymbolicsExt),
3534
get_extension(DI, :DifferentiationInterfaceTapirExt),
3635
get_extension(DI, :DifferentiationInterfaceTrackerExt),
3736
get_extension(DI, :DifferentiationInterfaceZygoteExt),
3837
]
3938

4039
makedocs(;
41-
modules=[ADTypes, DifferentiationInterface, extensions...],
40+
modules=[DifferentiationInterface, extensions...],
4241
authors="Guillaume Dalle, Adrian Hill",
4342
sitename="DifferentiationInterface.jl",
4443
format=Documenter.HTML(),
@@ -48,7 +47,6 @@ makedocs(;
4847
"API reference" => "api.md",
4948
"Advanced" => ["design.md", "extensions.md"],
5049
],
51-
warnonly=:missing_docs, # missing docs for ADTypes.jl are normal
5250
)
5351

5452
deploydocs(;

DifferentiationInterface/docs/src/backends.md

Lines changed: 5 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ CollapsedDocStrings = true
44
```
55

66
```@setup backends
7+
using ADTypes
78
using DifferentiationInterface
89
using DifferentiationInterface: backend_string
910
import Markdown
@@ -12,72 +13,29 @@ import Diffractor, Enzyme, FastDifferentiation, FiniteDiff, FiniteDifferences, F
1213
function all_backends()
1314
return [
1415
AutoDiffractor(),
15-
AutoEnzyme(Enzyme.Forward),
16-
AutoEnzyme(Enzyme.Reverse),
16+
AutoEnzyme(; mode=Enzyme.Forward),
17+
AutoEnzyme(; mode=Enzyme.Reverse),
1718
AutoFastDifferentiation(),
1819
AutoFiniteDiff(),
19-
AutoFiniteDifferences(FiniteDifferences.central_fdm(3, 1)),
20+
AutoFiniteDifferences(; fdm=FiniteDifferences.central_fdm(3, 1)),
2021
AutoForwardDiff(),
2122
AutoPolyesterForwardDiff(; chunksize=1),
2223
AutoReverseDiff(),
23-
AutoSymbolics(),
2424
AutoTapir(),
2525
AutoTracker(),
2626
AutoZygote(),
2727
]
2828
end
29-
30-
function all_backends_without_enzyme()
31-
return filter(all_backends()) do b
32-
!isa(b, AutoEnzyme)
33-
end
34-
end
3529
```
3630

3731
# Backends
3832

3933
## Types
4034

41-
We support (and re-export) most backend choices from [ADTypes.jl](https://github.com/SciML/ADTypes.jl), and we provide a few more of our own.
42-
43-
!!! warning
44-
Only the backends listed below are supported by DifferentiationInterface.jl, even though ADTypes.jl defines more.
45-
46-
### Dense
47-
48-
```@docs
49-
AutoChainRules
50-
AutoDiffractor
51-
AutoEnzyme
52-
AutoFastDifferentiation
53-
AutoForwardDiff
54-
AutoForwardDiff()
55-
AutoFiniteDiff
56-
AutoFiniteDifferences
57-
AutoPolyesterForwardDiff
58-
AutoPolyesterForwardDiff()
59-
AutoReverseDiff
60-
AutoSymbolics
61-
AutoTapir
62-
AutoTracker
63-
AutoZygote
64-
```
65-
66-
### Sparse
35+
We support all dense backend choices from [ADTypes.jl](https://github.com/SciML/ADTypes.jl), as well as their sparse wrapper `AutoSparse`.
6736

6837
For sparse backends, only the Jacobian and Hessian operators are implemented differently, the other operators behave the same as for the corresponding dense backend.
6938

70-
```@docs
71-
AutoSparseFastDifferentiation
72-
AutoSparseFiniteDiff
73-
AutoSparseForwardDiff
74-
AutoSparseForwardDiff()
75-
AutoSparsePolyesterForwardDiff
76-
AutoSparseReverseDiff
77-
AutoSparseSymbolics
78-
AutoSparseZygote
79-
```
80-
8139
## Availability
8240

8341
You can use [`check_available`](@ref) to verify whether a given backend is loaded, like we did below:

DifferentiationInterface/docs/src/design.md

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,11 @@
55
To be usable with DifferentiationInterface.jl, an AD backend needs an object subtyping `ADTypes.AbstractADType`.
66
In addition, some operators must be defined:
77

8-
| backend subtype | pushforward necessary | pullback necessary |
9-
| :-------------------------------------------- | :-------------------- | :----------------- |
10-
| `ADTypes.AbstractForwardMode` | yes | no |
11-
| `ADTypes.AbstractFiniteDifferencesMode` | yes | no |
12-
| `ADTypes.AbstractReverseMode` | no | yes |
13-
| `ADTypes.AbstractSymbolicDifferentiationMode` | yes | yes |
8+
| backend subtype | pushforward necessary | pullback necessary |
9+
| :--------------------- | :-------------------- | :----------------- |
10+
| `ADTypes.ForwardMode` | yes | no |
11+
| `ADTypes.ReverseMode` | no | yes |
12+
| `ADTypes.SymbolicMode` | yes | yes |
1413

1514
Every backend we support corresponds to a package extension of DifferentiationInterface.jl (located in the `ext` subfolder).
1615
Advanced users are welcome to code more backends and submit pull requests!
17-
18-
## Fallback call structure
19-
20-
!!! warning
21-
This is still in flux, come back later!

DifferentiationInterface/docs/src/extensions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
CurrentModule = DifferentiationInterface
55
```
66

7-
Backend-specific extension content is not part of the public API.
7+
Package extension content is not part of the public API.
88
If any docstrings are present in an extension, they will appear below.
99

1010
```@autodocs
@@ -18,7 +18,7 @@ Modules = [
1818
Base.get_extension(DifferentiationInterface, :DifferentiationInterfaceForwardDiffExt),
1919
Base.get_extension(DifferentiationInterface, :DifferentiationInterfacePolyesterForwardDiffExt),
2020
Base.get_extension(DifferentiationInterface, :DifferentiationInterfaceReverseDiffExt),
21-
Base.get_extension(DifferentiationInterface, :DifferentiationInterfaceSparseDiffToolsExt),
21+
Base.get_extension(DifferentiationInterface, :DifferentiationInterfaceSymbolicsExt),
2222
Base.get_extension(DifferentiationInterface, :DifferentiationInterfaceTapirExt),
2323
Base.get_extension(DifferentiationInterface, :DifferentiationInterfaceTrackerExt),
2424
Base.get_extension(DifferentiationInterface, :DifferentiationInterfaceZygoteExt)

DifferentiationInterface/docs/src/overview.md

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,10 @@ We offer two ways to perform second-order differentiation (for [`second_derivati
109109

110110
### Sparsity
111111

112-
[ADTypes.jl](https://github.com/SciML/ADTypes.jl) provides [sparse versions](@ref Sparse) of many common AD backends.
113-
They can accelerate the computation of sparse Jacobians and Hessians:
112+
[ADTypes.jl](https://github.com/SciML/ADTypes.jl) provides `AutoSparse` to accelerate the computation of sparse Jacobians and Hessians:
114113

115-
- for sparse Jacobians, just select one of them as your first-order backend.
116-
- for sparse Hessians, select one of them as the _outer part_ of a [`SecondOrder`](@ref) backend (in that case, the Hessian is obtained as the sparse Jacobian of the gradient).
117-
118-
The sparsity pattern is computed automatically with [Symbolics.jl](https://github.com/JuliaSymbolics/Symbolics.jl) during the preparation step.
119-
120-
!!! info "Planned feature"
121-
Modular sparsity pattern computation, with other algorithms beyond those from Symbolics.jl.
114+
- for sparse Jacobians, wrap `AutoSparse` around a first-order backend.
115+
- for sparse Hessians, wrap `AutoSparse` around a [`SecondOrder`](@ref) backend.
122116

123117
### Split reverse mode
124118

@@ -129,12 +123,7 @@ We make this available for all backends with the following operators:
129123
| :--------------------------------- | :---------------------------------- |
130124
| [`value_and_pullback_split`](@ref) | [`value_and_pullback!_split`](@ref) |
131125

132-
## Not supported
133-
134-
### Batched evaluation
135-
136-
!!! info "Planned feature"
137-
Interface for providing several pushforward / pullback seeds at once, similar to the chunking in ForwardDiff.jl or the batches in Enzyme.jl.
126+
## Going further
138127

139128
### Non-standard types
140129

@@ -147,3 +136,7 @@ We voluntarily keep the type annotations minimal, so that passing more complex o
147136

148137
Restricting the API to one input and one output has many coding advantages, but it is not very flexible.
149138
If you need more than that, use [ComponentArrays.jl](https://github.com/jonniedie/ComponentArrays.jl) to wrap several objects inside a single `ComponentVector`.
139+
140+
### Batched evaluation
141+
142+
This is not supported at the moment, but we plan to allow several pushforward / pullback seeds at once (similar to the chunking in ForwardDiff.jl or the batches in Enzyme.jl).

DifferentiationInterface/docs/src/tutorial.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ We present a typical workflow with DifferentiationInterface.jl and showcase its
88

99
```@repl tuto
1010
using DifferentiationInterface
11-
import ForwardDiff, Enzyme
11+
import ADTypes, ForwardDiff, Enzyme
1212
using BenchmarkTools
1313
```
1414

@@ -32,7 +32,7 @@ Most backend types are defined by [ADTypes.jl](https://github.com/SciML/ADTypes.
3232
[ForwardDiff.jl](https://github.com/JuliaDiff/ForwardDiff.jl) is very generic and efficient for low-dimensional inputs, so it's a good starting point:
3333

3434
```@repl tuto
35-
backend = AutoForwardDiff()
35+
backend = ADTypes.AutoForwardDiff()
3636
```
3737

3838
Now you can use DifferentiationInterface.jl to get the gradient:
@@ -116,7 +116,7 @@ So let's try the state-of-the-art [Enzyme.jl](https://github.com/EnzymeAD/Enzyme
116116
For this one, the backend definition is slightly more involved, because you need to feed the "mode" to the object from ADTypes.jl:
117117

118118
```@repl tuto
119-
backend2 = AutoEnzyme(Enzyme.Reverse)
119+
backend2 = ADTypes.AutoEnzyme(; mode=Enzyme.Reverse)
120120
```
121121

122122
But once it is done, things run smoothly with exactly the same syntax:

0 commit comments

Comments
 (0)