Skip to content

Commit 9988f4e

Browse files
Support Enzyme.jl (#314)
* Enzyme WIP * cont. * cont. * Enzyme WIP * Add a sparse Jacobian with Enzyme.jl * Update tests * Update tests * Update nlpmodelstest.jl * Fix Project.toml * Fix the diff * Fix the tests * Fix the tests * Fix the tests * Fix tests * fix tests again * fix tests again * Add SparseEnzymeADHessian * Add SparseEnzymeADHessian * Add SparseEnzymeADHessian * Add SparseEnzymeADHessian * Add SparseEnzymeADHessian * nlp.f(x) -> f(x) * Fix Enzyme in sparse Hessian * Update the sparse Hessian * Fix the backends for Enzyme.jl * Update test/enzyme.jl * Update test/enzyme.jl * Update test/enzyme.jl * Update the function for the lagrangian * Update the function for the lagrangian * Update the function for the lagrangian * comment some tests * Uncomment some tests * Fix cx in Hessian * Fix * Fix the functor * Uncomment some code * fix test/Project.toml * Update the tests for Enzyme and Zygote * Update the documentation * Fix tests * Update nlp/basic.jl * FIx a typo * Fix documentation --------- Co-authored-by: Michel Schanen <[email protected]> Co-authored-by: Michel Schanen <[email protected]>
1 parent 1547be0 commit 9988f4e

21 files changed

+1101
-456
lines changed

docs/src/backend.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ The functions used internally to define the NLPModel API and the possible backen
1010
| Functions | FowardDiff backends | ReverseDiff backends | Zygote backends | Enzyme backend | Sparse backend |
1111
| --------- | ------------------- | -------------------- | --------------- | -------------- | -------------- |
1212
| `gradient` and `gradient!` | `ForwardDiffADGradient`/`GenericForwardDiffADGradient` | `ReverseDiffADGradient`/`GenericReverseDiffADGradient` | `ZygoteADGradient` | `EnzymeADGradient` | -- |
13-
| `jacobian` | `ForwardDiffADJacobian` | `ReverseDiffADJacobian` | `ZygoteADJacobian` | -- | `SparseADJacobian` |
14-
| `hessian` | `ForwardDiffADHessian` | `ReverseDiffADHessian` | `ZygoteADHessian` | -- | `SparseADHessian`/`SparseReverseADHessian` |
15-
| `Jprod` | `ForwardDiffADJprod`/`GenericForwardDiffADJprod` | `ReverseDiffADJprod`/`GenericReverseDiffADJprod` | `ZygoteADJprod` | -- | -- |
16-
| `Jtprod` | `ForwardDiffADJtprod`/`GenericForwardDiffADJtprod` | `ReverseDiffADJtprod`/`GenericReverseDiffADJtprod` | `ZygoteADJtprod` | -- | -- |
17-
| `Hvprod` | `ForwardDiffADHvprod`/`GenericForwardDiffADHvprod` | `ReverseDiffADHvprod`/`GenericReverseDiffADHvprod` | -- | -- | -- |
13+
| `jacobian` | `ForwardDiffADJacobian` | `ReverseDiffADJacobian` | `ZygoteADJacobian` | `EnzymeADJacobian` | `SparseADJacobian` |
14+
| `hessian` | `ForwardDiffADHessian` | `ReverseDiffADHessian` | `ZygoteADHessian` | `EnzymeADHessian` | `SparseADHessian`/`SparseReverseADHessian` |
15+
| `Jprod` | `ForwardDiffADJprod`/`GenericForwardDiffADJprod` | `ReverseDiffADJprod`/`GenericReverseDiffADJprod` | `ZygoteADJprod` | `EnzymeADJprod` | -- |
16+
| `Jtprod` | `ForwardDiffADJtprod`/`GenericForwardDiffADJtprod` | `ReverseDiffADJtprod`/`GenericReverseDiffADJtprod` | `ZygoteADJtprod` | `EnzymeADJtprod` | -- |
17+
| `Hvprod` | `ForwardDiffADHvprod`/`GenericForwardDiffADHvprod` | `ReverseDiffADHvprod`/`GenericReverseDiffADHvprod` | -- | `EnzymeADHvprod` | -- |
1818
| `directional_second_derivative` | `ForwardDiffADGHjvprod` | -- | -- | -- | -- |
1919

2020
The functions `hess_structure!`, `hess_coord!`, `jac_structure!` and `jac_coord!` defined in `ad.jl` are generic to all the backends for now.

docs/src/predefined.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,12 @@ It is possible to use these pre-defined backends using the keyword argument `bac
4646
nlp = ADNLPModel!(f, x0, lvar, uvar, c!, lcon, ucon, backend = :optimized)
4747
get_adbackend(nlp)
4848
```
49+
50+
The backend `:enzyme` focuses on backend based on [Enzyme.jl](https://github.com/EnzymeAD/Enzyme.jl).
51+
52+
```@example ex1
53+
nlp = ADNLPModel!(f, x0, lvar, uvar, c!, lcon, ucon, backend = :enzyme)
54+
get_adbackend(nlp)
55+
```
56+
57+
The backend `:zygote` focuses on backend based on [Zygote.jl](https://github.com/FluxML/Zygote.jl).

docs/src/sparse.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ x = rand(T, 2)
3131
H = hess(nlp, x)
3232
```
3333

34-
The backends available for sparse derivatives (`SparseADJacobian`, `SparseADHessian`, and `SparseReverseADHessian`) allow for customization through keyword arguments such as `detector` and `coloring_algorithm`.
34+
The backends available for sparse derivatives (`SparseADJacobian`, `SparseEnzymeADJacobian`, `SparseADHessian`, `SparseReverseADHessian`, and `SparseEnzymeADHessian`) allow for customization through keyword arguments such as `detector` and `coloring_algorithm`.
3535
These arguments specify the sparsity pattern detector and the coloring algorithm, respectively.
3636

3737
- A **`detector`** must be of type `ADTypes.AbstractSparsityDetector`.
3838
The default detector is `TracerSparsityDetector()` from the package `SparseConnectivityTracer.jl`.
3939
Prior to version 0.8.0, the default was `SymbolicSparsityDetector()` from `Symbolics.jl`.
4040

4141
- A **`coloring_algorithm`** must be of type `SparseMatrixColorings.GreedyColoringAlgorithm`.
42-
The default algorithm is `GreedyColoringAlgorithm{:direct}()` for `SparseADJacobian` and `SparseADHessian`, while it is `GreedyColoringAlgorithm{:substitution}()` for `SparseReverseADHessian`.
42+
The default algorithm is `GreedyColoringAlgorithm{:direct}()` for `SparseADJacobian`, `SparseEnzymeADJacobian` and `SparseADHessian`, while it is `GreedyColoringAlgorithm{:substitution}()` for `SparseReverseADHessian` and `SparseEnzymeADHessian`.
4343
These algorithms are provided by the package `SparseMatrixColorings.jl`.
4444

4545
The `GreedyColoringAlgorithm{:direct}()` performs column coloring for Jacobians and star coloring for Hessians.

0 commit comments

Comments
 (0)