-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
ADTypes.jl
248 lines (185 loc) · 5.54 KB
/
ADTypes.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
"""
ADTypes.jl
[ADTypes.jl](https://github.com/SciML/ADTypes.jl) is a common system for implementing multi-valued logic for choosing which automatic differentiation library to use.
"""
module ADTypes
"""
Base type for AD choices.
"""
abstract type AbstractADType end
abstract type AbstractReverseMode <: AbstractADType end
abstract type AbstractForwardMode <: AbstractADType end
abstract type AbstractFiniteDifferencesMode <: AbstractADType end
abstract type AbstractSymbolicDifferentiationMode <: AbstractADType end
abstract type AbstractSparseReverseMode <: AbstractReverseMode end
abstract type AbstractSparseForwardMode <: AbstractForwardMode end
abstract type AbstractSparseFiniteDifferences <: AbstractFiniteDifferencesMode end
"""
AutoChainRules{RC}
Chooses any AD library based on [ChainRulesCore.jl](https://github.com/JuliaDiff/ChainRulesCore.jl), given an appropriate [`RuleConfig`](https://juliadiff.org/ChainRulesCore.jl/stable/rule_author/superpowers/ruleconfig.html) object.
# Fields
- `ruleconfig::RC`
"""
Base.@kwdef struct AutoChainRules{RC} <: AbstractADType
ruleconfig::RC
end
"""
AutoFiniteDiff{T1,T2,T3}
Chooses [FiniteDiff.jl](https://github.com/JuliaDiff/FiniteDiff.jl).
# Fields
- `fdtype::T1 = Val(:forward)`
- `fdjtype::T2 = fdtype`
- `fdhtype::T3 = Val(:hcentral)`
"""
Base.@kwdef struct AutoFiniteDiff{T1, T2, T3} <: AbstractFiniteDifferencesMode
fdtype::T1 = Val(:forward)
fdjtype::T2 = fdtype
fdhtype::T3 = Val(:hcentral)
end
"""
AutoFiniteDifferences{T}
Chooses [FiniteDifferences.jl](https://github.com/JuliaDiff/FiniteDifferences.jl).
# Fields
- `fdm::T = nothing`
"""
Base.@kwdef struct AutoFiniteDifferences{T} <: AbstractFiniteDifferencesMode
fdm::T = nothing
end
"""
AutoForwardDiff{chunksize,T}
Chooses [ForwardDiff.jl](https://github.com/JuliaDiff/ForwardDiff.jl).
# Fields
- `tag::T`
"""
struct AutoForwardDiff{chunksize, T} <: AbstractForwardMode
tag::T
end
"""
AutoForwardDiff(; chunksize = nothing, tag = nothing)
Constructor.
"""
function AutoForwardDiff(; chunksize = nothing, tag = nothing)
AutoForwardDiff{chunksize, typeof(tag)}(tag)
end
"""
AutoPolyesterForwardDiff{chunksize}
Chooses [PolyesterForwardDiff.jl](https://github.com/JuliaDiff/PolyesterForwardDiff.jl).
"""
struct AutoPolyesterForwardDiff{chunksize} <: AbstractForwardMode
end
"""
AutoPolyesterForwardDiff(; chunksize = nothing)
Constructor.
"""
function AutoPolyesterForwardDiff(; chunksize = nothing)
AutoPolyesterForwardDiff{chunksize}()
end
"""
AutoReverseDiff
Chooses [ReverseDiff.jl](https://github.com/JuliaDiff/ReverseDiff.jl).
# Fields
- `compile::Bool = false`
"""
Base.@kwdef struct AutoReverseDiff <: AbstractReverseMode
compile::Bool = false
end
"""
AutoZygote
Chooses [Zygote.jl](https://github.com/FluxML/Zygote.jl).
"""
struct AutoZygote <: AbstractReverseMode end
"""
AutoSparseZygote
Chooses [Zygote.jl](https://github.com/FluxML/Zygote.jl) while exploiting sparsity.
"""
struct AutoSparseZygote <: AbstractSparseReverseMode end
"""
AutoEnzyme{M}
Chooses [Enzyme.jl](https://github.com/EnzymeAD/Enzyme.jl).
# Fields
- `mode::M = nothing`
"""
Base.@kwdef struct AutoEnzyme{M} <: AbstractADType
mode::M = nothing
end
"""
AutoTracker
Chooses [Tracker.jl](https://github.com/FluxML/Tracker.jl).
"""
struct AutoTracker <: AbstractReverseMode end
"""
AutoModelingToolkit
Chooses [ModelingToolkit.jl](https://github.com/SciML/ModelingToolkit.jl).
# Fields
- `obj_sparse::Bool = false`
- `cons_sparse::Bool = false`
"""
Base.@kwdef struct AutoModelingToolkit <: AbstractSymbolicDifferentiationMode
obj_sparse::Bool = false
cons_sparse::Bool = false
end
"""
AutoSparseFiniteDiff
Chooses [FiniteDiff.jl](https://github.com/JuliaDiff/FiniteDiff.jl) while exploiting sparsity.
"""
struct AutoSparseFiniteDiff <: AbstractSparseFiniteDifferences end
"""
AutoSparseForwardDiff{chunksize,T}
Chooses [ForwardDiff.jl](https://github.com/JuliaDiff/ForwardDiff.jl) while exploiting sparsity.
# Fields
- `tag::T`
"""
struct AutoSparseForwardDiff{chunksize, T} <: AbstractSparseForwardMode
tag::T
end
"""
AutoSparseForwardDiff(; chunksize = nothing, tag = nothing)
Constructor.
"""
function AutoSparseForwardDiff(; chunksize = nothing, tag = nothing)
AutoSparseForwardDiff{chunksize, typeof(tag)}(tag)
end
"""
AutoSparsePolyesterForwardDiff{chunksize}
Chooses [PolyesterForwardDiff.jl](https://github.com/JuliaDiff/PolyesterForwardDiff.jl) while exploiting sparsity.
"""
struct AutoSparsePolyesterForwardDiff{chunksize} <: AbstractSparseForwardMode
end
"""
AutoSparsePolyesterForwardDiff(; chunksize = nothing)
Constructor.
"""
function AutoSparsePolyesterForwardDiff(; chunksize = nothing)
AutoSparsePolyesterForwardDiff{chunksize}()
end
"""
AutoSparseReverseDiff
Chooses [ReverseDiff.jl](https://github.com/JuliaDiff/ReverseDiff.jl) while exploiting sparsity.
# Fields
- `compile::Bool = false`
"""
Base.@kwdef struct AutoSparseReverseDiff <: AbstractSparseReverseMode
compile::Bool = false
end
"""
AutoDiffractor
Chooses [Diffractor.jl](https://github.com/JuliaDiff/Diffractor.jl).
"""
struct AutoDiffractor <: AbstractADType end
export AutoChainRules,
AutoDiffractor,
AutoFiniteDiff,
AutoFiniteDifferences,
AutoForwardDiff,
AutoReverseDiff,
AutoZygote,
AutoEnzyme,
AutoTracker,
AutoModelingToolkit,
AutoSparseFiniteDiff,
AutoSparseForwardDiff,
AutoSparseZygote,
AutoSparseReverseDiff,
AutoPolyesterForwardDiff,
AutoSparsePolyesterForwardDiff
end