Skip to content

Commit 170a729

Browse files
authored
Revamp documentation (#276)
* Revamp documentation * Don't remove detector * Sparsity tutorial * Rename advanced * Add docstrings * Alignment * Link * No need for current module * Examples instead of REPL in DIT * Warning on AutoSparse and other operators * Link
1 parent dc317b0 commit 170a729

File tree

21 files changed

+642
-448
lines changed

21 files changed

+642
-448
lines changed

DifferentiationInterface/Project.toml

Lines changed: 1 addition & 1 deletion
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.4.1"
4+
version = "0.4.2"
55

66
[deps]
77
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"

DifferentiationInterface/docs/make.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ makedocs(;
3434
format=Documenter.HTML(; assets=["assets/favicon.ico"]),
3535
pages=[
3636
"Home" => "index.md",
37-
"Start here" => ["tutorial.md", "overview.md", "backends.md"],
38-
"API reference" => "api.md",
39-
"Advanced" => ["design.md", "overloads.md"],
37+
"Tutorials" => ["tutorial1.md", "tutorial2.md"],
38+
"Reference" => ["operators.md", "backends.md", "api.md"],
39+
"Advanced" => ["preparation.md", "overloads.md"],
4040
],
4141
checkdocs=:exports,
4242
plugins=[links],

DifferentiationInterface/docs/src/api.md

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,38 @@
1+
# API
2+
13
```@meta
2-
CurrentModule = Main
34
CollapsedDocStrings = true
45
```
56

6-
# API reference
7-
87
```@docs
98
DifferentiationInterface
109
```
1110

12-
## Derivative
11+
## First order
12+
13+
### Pushforward
14+
15+
```@docs
16+
prepare_pushforward
17+
prepare_pushforward_same_point
18+
pushforward
19+
pushforward!
20+
value_and_pushforward
21+
value_and_pushforward!
22+
```
23+
24+
### Pullback
25+
26+
```@docs
27+
prepare_pullback
28+
prepare_pullback_same_point
29+
pullback
30+
pullback!
31+
value_and_pullback
32+
value_and_pullback!
33+
```
34+
35+
### Derivative
1336

1437
```@docs
1538
prepare_derivative
@@ -19,7 +42,7 @@ value_and_derivative
1942
value_and_derivative!
2043
```
2144

22-
## Gradient
45+
### Gradient
2346

2447
```@docs
2548
prepare_gradient
@@ -29,7 +52,7 @@ value_and_gradient
2952
value_and_gradient!
3053
```
3154

32-
## Jacobian
55+
### Jacobian
3356

3457
```@docs
3558
prepare_jacobian
@@ -45,62 +68,50 @@ value_and_jacobian!
4568
SecondOrder
4669
```
4770

71+
### Second derivative
72+
4873
```@docs
4974
prepare_second_derivative
5075
second_derivative
5176
second_derivative!
5277
```
5378

79+
### Hessian-vector product
80+
5481
```@docs
5582
prepare_hvp
5683
prepare_hvp_same_point
5784
hvp
5885
hvp!
5986
```
6087

88+
### Hessian
89+
6190
```@docs
6291
prepare_hessian
6392
hessian
6493
hessian!
6594
```
6695

67-
## Primitives
68-
69-
```@docs
70-
prepare_pushforward
71-
prepare_pushforward_same_point
72-
pushforward
73-
pushforward!
74-
value_and_pushforward
75-
value_and_pushforward!
76-
```
77-
78-
```@docs
79-
prepare_pullback
80-
prepare_pullback_same_point
81-
pullback
82-
pullback!
83-
value_and_pullback
84-
value_and_pullback!
85-
```
96+
## Utilities
8697

87-
## Backend queries
98+
### Backend queries
8899

89100
```@docs
90101
check_available
91102
check_twoarg
92103
check_hessian
93104
```
94105

95-
## Miscellaneous
106+
### Backend switch
96107

97108
```@docs
98109
DifferentiateWith
99110
```
100111

101112
## Internals
102113

103-
This is not part of the public API.
114+
The following is not part of the public API.
104115

105116
```@autodocs
106117
Modules = [DifferentiationInterface]

DifferentiationInterface/docs/src/backends.md

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
```@meta
2-
CurrentModule = Main
3-
CollapsedDocStrings = true
4-
```
1+
# Backends
2+
3+
DifferentiationInterface.jl is based on two concepts: **operators** and **backends**.
4+
This page is about the latter, check out [that page](@ref "Operators") to learn about the former.
5+
6+
## List of backends
7+
8+
We support all dense backend choices from [ADTypes.jl](https://github.com/SciML/ADTypes.jl), as well as their sparse wrapper [`AutoSparse`](@extref ADTypes.AutoSparse).
59

610
```@setup backends
711
using DifferentiationInterface
@@ -32,7 +36,7 @@ const backend_examples = (
3236
"AutoPolyesterForwardDiff(; chunksize=1)",
3337
"AutoReverseDiff()",
3438
"AutoSymbolics()",
35-
"AutoTapir()",
39+
"AutoTapir(; safe_mode=false)",
3640
"AutoTracker()",
3741
"AutoZygote()",
3842
)
@@ -56,14 +60,6 @@ end
5660
backend_table = Markdown.parse(String(take!(io)))
5761
```
5862

59-
# Backends
60-
61-
## Types
62-
63-
We support all dense backend choices from [ADTypes.jl](https://github.com/SciML/ADTypes.jl), as well as their sparse wrapper [`AutoSparse`](@ref).
64-
65-
For sparse backends, only the Jacobian and Hessian operators are implemented differently, the other operators behave the same as for the corresponding dense backend.
66-
6763
```@example backends
6864
backend_table #hide
6965
```
@@ -88,9 +84,30 @@ You can use [`check_available`](@ref) to verify whether a given backend is loade
8884

8985
All backends are compatible with one-argument functions `f(x) = y`.
9086
Only some are compatible with two-argument functions `f!(y, x) = nothing`.
91-
You can check this compatibility using [`check_twoarg`](@ref).
87+
You can use [`check_twoarg`](@ref) to verify this compatibility.
9288

9389
### Support for Hessian
9490

9591
Only some backends are able to compute Hessians.
96-
You can use [`check_hessian`](@ref) to check this feature (beware that it will try to compute a small Hessian, so it is not instantaneous).
92+
You can use [`check_hessian`](@ref) to verify this feature (beware that it will try to compute a small Hessian, so it is not instantaneous like the other checks).
93+
94+
## Backend switch
95+
96+
The wrapper [`DifferentiateWith`](@ref) allows you to switch between backends.
97+
It takes a function `f` and specifies that `f` should be differentiated with the backend of your choice, instead of whatever other backend the code is trying to use.
98+
In other words, when someone tries to differentiate `dw = DifferentiateWith(f, backend1)` with `backend2`, then `backend1` steps in and `backend2` does nothing.
99+
At the moment, `DifferentiateWith` only works when `backend2` supports [ChainRules.jl](https://github.com/JuliaDiff/ChainRules.jl).
100+
101+
## Defining your own
102+
103+
To work with DifferentiationInterface.jl, a new AD system would need to create an object subtyping [`ADTypes.AbstractADType`](@extref ADTypes).
104+
In addition, some low-level operators would need to be defined at the very least:
105+
106+
| backend subtype | pushforward necessary | pullback necessary |
107+
| :---------------------------------------- | :-------------------- | :----------------- |
108+
| [`ADTypes.ForwardMode`](@extref ADTypes) | yes | no |
109+
| [`ADTypes.ReverseMode`](@extref ADTypes) | no | yes |
110+
| [`ADTypes.SymbolicMode`](@extref ADTypes) | yes | yes |
111+
112+
Every backend we support corresponds to a package extension of DifferentiationInterface.jl (located in the `ext` subfolder).
113+
If you need to implement your own backend, take a look in there for inspiration, or reach out to us in the GitHub issues.

DifferentiationInterface/docs/src/design.md

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)