Skip to content

Commit

Permalink
Merge pull request #23 from gdalle/docstrings
Browse files Browse the repository at this point in the history
Add docstrings and list of exports
  • Loading branch information
Vaibhavdixit02 authored Mar 8, 2024
2 parents 8684021 + 21f76db commit 0af4052
Show file tree
Hide file tree
Showing 2 changed files with 162 additions and 3 deletions.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,34 @@
ADTypes.jl is a common system for implementing multi-valued logic for choosing which
automatic differentiation library to use.

## Which libraries are supported?

Just run the following code in a Julia REPL to find out:

```julia
julia> using ADTypes

julia> names(ADTypes)
15-element Vector{Symbol}:
:ADTypes
:AutoEnzyme
:AutoFiniteDiff
:AutoFiniteDifferences
:AutoForwardDiff
:AutoModelingToolkit
:AutoPolyesterForwardDiff
:AutoReverseDiff
:AutoSparseFiniteDiff
:AutoSparseForwardDiff
:AutoSparsePolyesterForwardDiff
:AutoSparseReverseDiff
:AutoSparseZygote
:AutoTracker
:AutoZygote
```

Use the help mode of the Julia REPL to find out more about a specific library.

## Why Should Packages Adopt This?

The current standard is to have a keyword argument with `autodiff = true` or `autodiff = false`.
Expand Down
137 changes: 134 additions & 3 deletions src/ADTypes.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
"""
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

"""
Expand All @@ -18,67 +23,193 @@ 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

struct AutoForwardDiff{chunksize,T} <: AbstractForwardMode
"""
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

struct AutoSparseForwardDiff{chunksize,T} <: AbstractSparseForwardMode
"""
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

Base.@kwdef struct AutoSparseReverseDiff <: AbstractSparseReverseMode
"""
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

Expand Down

0 comments on commit 0af4052

Please sign in to comment.