Skip to content
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

Update backend documentation #215

Merged
merged 2 commits into from
Apr 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 39 additions & 46 deletions DifferentiationInterface/docs/src/backends.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,38 @@ using DifferentiationInterface: backend_string
import Markdown
import Diffractor, Enzyme, FastDifferentiation, FiniteDiff, FiniteDifferences, ForwardDiff, PolyesterForwardDiff, ReverseDiff, Tapir, Tracker, Zygote

function all_backends()
return [
AutoDiffractor(),
AutoEnzyme(; mode=Enzyme.Forward),
AutoEnzyme(; mode=Enzyme.Reverse),
AutoFastDifferentiation(),
AutoFiniteDiff(),
AutoFiniteDifferences(; fdm=FiniteDifferences.central_fdm(3, 1)),
AutoForwardDiff(),
AutoPolyesterForwardDiff(; chunksize=1),
AutoReverseDiff(),
AutoTapir(),
AutoTracker(),
AutoZygote(),
]
const backend_examples = (
"AutoDiffractor()",
"AutoEnzyme(; mode=Enzyme.Forward)",
"AutoEnzyme(; mode=Enzyme.Reverse)",
"AutoFastDifferentiation()",
"AutoFiniteDiff()",
"AutoFiniteDifferences(; fdm=FiniteDifferences.central_fdm(3, 1))",
"AutoForwardDiff()",
"AutoPolyesterForwardDiff(; chunksize=1)",
"AutoReverseDiff()",
"AutoTapir()",
"AutoTracker()",
"AutoZygote()",
)

checkmark(x::Bool) = x ? '✅' : '❌'
unicode_check_available(backend) = checkmark(check_available(backend))
unicode_check_hessian(backend) = checkmark(check_hessian(backend))
unicode_check_twoarg(backend) = checkmark(check_twoarg(backend))

io = IOBuffer()

# Table header
println(io, "| Backend | Availability | Two-argument functions | Hessian support | Example |")
println(io, "|:--------|:------------:|:----------------------:|:---------------:|:--------|")

for example in backend_examples
b = eval(Meta.parse(example)) # backend
join(io, [backend_string(b), unicode_check_available(b), unicode_check_twoarg(b), unicode_check_hessian(b), "`$example`"], '|')
println(io, '|' )
end
backend_table = Markdown.parse(String(take!(io)))
```

# Backends
Expand All @@ -36,44 +52,21 @@ We support all dense backend choices from [ADTypes.jl](https://github.com/SciML/

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

## Availability

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

```@example backends
header = "| backend | available |" # hide
subheader = "|:---|:---:|" # hide
rows = map(all_backends()) do backend # hide
"| `$(backend_string(backend))` | $(check_available(backend) ? '✅' : '❌') |" # hide
end # hide
Markdown.parse(join(vcat(header, subheader, rows...), "\n")) # hide
backend_table #hide
```

## Mutation support
## Availability

You can use [`check_available`](@ref) to verify whether a given backend is loaded.

## Support for two-argument functions

All backends are compatible with one-argument functions `f(x) = y`.
Only some are compatible with two-argument functions `f!(y, x) = nothing`.
You can use [`check_twoarg`](@ref) to check that feature, like we did below:

```@example backends
header = "| backend | mutation |" # hide
subheader = "|:---|:---:|" # hide
rows = map(all_backends()) do backend # hide
"| `$(backend_string(backend))` | $(check_twoarg(backend) ? '✅' : '❌') |" # hide
end # hide
Markdown.parse(join(vcat(header, subheader, rows...), "\n")) # hide
```
You can check this compatibility using [`check_twoarg`](@ref).

## Hessian support

Only some backends are able to compute Hessians.
You can use [`check_hessian`](@ref) to check that feature, like we did below:

```@example backends
header = "| backend | Hessian |" # hide
subheader = "|:---|:---:|" # hide
rows = map(all_backends()) do backend # hide
"| `$(backend_string(backend))` | $(check_hessian(backend) ? '✅' : '❌') |" # hide
end # hide
Markdown.parse(join(vcat(header, subheader, rows...), "\n")) # hide
```
You can use [`check_hessian`](@ref) to check this feature.
Loading