Skip to content

Commit 8ad8221

Browse files
committed
Add new backends with DifferentiationInterface.jl
1 parent ffbaba9 commit 8ad8221

28 files changed

+856
-326
lines changed

.buildkite/pipeline.yml

Lines changed: 221 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,225 @@ steps:
88
cuda: "*"
99
command: |
1010
julia --color=yes --project -e 'using Pkg; Pkg.add("CUDA"); Pkg.add("NLPModels"); Pkg.add("NLPModelsTest"); Pkg.instantiate()'
11-
julia --color=yes --project -e 'include("test/gpu.jl")'
11+
julia --color=yes --project -e 'include("test/gpu/nvidia.jl")'
1212
timeout_in_minutes: 30
13+
14+
- label: "CPUs -- ForwardDiff.jl"
15+
plugins:
16+
- JuliaCI/julia#v1:
17+
version: "1.10"
18+
agents:
19+
queue: "juliaecosystem"
20+
os: "linux"
21+
arch: "x86_64"
22+
command: |
23+
julia --color=yes --project -e '
24+
using Pkg
25+
Pkg.add("OptimizationProblems")
26+
Pkg.add("ForwardDiff")
27+
Pkg.instantiate()
28+
include("test/backend/ForwardDiff.jl")'
29+
timeout_in_minutes: 30
30+
31+
- label: "CPUs -- ReverseDiff.jl"
32+
plugins:
33+
- JuliaCI/julia#v1:
34+
version: "1.10"
35+
agents:
36+
queue: "juliaecosystem"
37+
os: "linux"
38+
arch: "x86_64"
39+
command: |
40+
julia --color=yes --project -e '
41+
using Pkg
42+
Pkg.add("OptimizationProblems")
43+
Pkg.add("ReverseDiff")
44+
Pkg.instantiate()
45+
include("test/backend/ReverseDiff.jl")'
46+
timeout_in_minutes: 30
47+
48+
- label: "CPUs -- Enzyme.jl"
49+
plugins:
50+
- JuliaCI/julia#v1:
51+
version: "1.10"
52+
agents:
53+
queue: "juliaecosystem"
54+
os: "linux"
55+
arch: "x86_64"
56+
command: |
57+
julia --color=yes --project -e '
58+
using Pkg
59+
Pkg.add("OptimizationProblems")
60+
Pkg.add("Enzyme")
61+
Pkg.instantiate()
62+
include("test/backend/Enzyme.jl")'
63+
timeout_in_minutes: 30
64+
65+
- label: "CPUs -- Zygote.jl"
66+
plugins:
67+
- JuliaCI/julia#v1:
68+
version: "1.10"
69+
agents:
70+
queue: "juliaecosystem"
71+
os: "linux"
72+
arch: "x86_64"
73+
command: |
74+
julia --color=yes --project -e '
75+
using Pkg
76+
Pkg.add("OptimizationProblems")
77+
Pkg.add("Zygote")
78+
Pkg.instantiate()
79+
include("test/backend/Zygote.jl")'
80+
timeout_in_minutes: 30
81+
82+
- label: "CPUs -- Mooncake.jl"
83+
plugins:
84+
- JuliaCI/julia#v1:
85+
version: "1.10"
86+
agents:
87+
queue: "juliaecosystem"
88+
os: "linux"
89+
arch: "x86_64"
90+
command: |
91+
julia --color=yes --project -e '
92+
using Pkg
93+
Pkg.add("OptimizationProblems")
94+
Pkg.add("Mooncake")
95+
Pkg.instantiate()
96+
include("test/backend/Mooncake.jl")'
97+
timeout_in_minutes: 30
98+
99+
- label: "CPUs -- Diffractor.jl"
100+
plugins:
101+
- JuliaCI/julia#v1:
102+
version: "1.10"
103+
agents:
104+
queue: "juliaecosystem"
105+
os: "linux"
106+
arch: "x86_64"
107+
command: |
108+
julia --color=yes --project -e '
109+
using Pkg
110+
Pkg.add("OptimizationProblems")
111+
Pkg.add("Diffractor")
112+
Pkg.instantiate()
113+
include("test/backend/Diffractor.jl")'
114+
timeout_in_minutes: 30
115+
116+
- label: "CPUs -- Tracker.jl"
117+
plugins:
118+
- JuliaCI/julia#v1:
119+
version: "1.10"
120+
agents:
121+
queue: "juliaecosystem"
122+
os: "linux"
123+
arch: "x86_64"
124+
command: |
125+
julia --color=yes --project -e '
126+
using Pkg
127+
Pkg.add("OptimizationProblems")
128+
Pkg.add("Tracker")
129+
Pkg.instantiate()
130+
include("test/backend/Tracker.jl")'
131+
timeout_in_minutes: 30
132+
133+
- label: "CPUs -- Symbolics.jl"
134+
plugins:
135+
- JuliaCI/julia#v1:
136+
version: "1.10"
137+
agents:
138+
queue: "juliaecosystem"
139+
os: "linux"
140+
arch: "x86_64"
141+
command: |
142+
julia --color=yes --project -e '
143+
using Pkg
144+
Pkg.add("OptimizationProblems")
145+
Pkg.add("Symbolics")
146+
Pkg.instantiate()
147+
include("test/backend/Symbolics.jl")'
148+
timeout_in_minutes: 30
149+
150+
- label: "CPUs -- ChainRules.jl"
151+
plugins:
152+
- JuliaCI/julia#v1:
153+
version: "1.10"
154+
agents:
155+
queue: "juliaecosystem"
156+
os: "linux"
157+
arch: "x86_64"
158+
command: |
159+
julia --color=yes --project -e '
160+
using Pkg
161+
Pkg.add("OptimizationProblems")
162+
Pkg.add("ChainRules")
163+
Pkg.instantiate()
164+
include("test/backend/ChainRules.jl")'
165+
timeout_in_minutes: 30
166+
167+
- label: "CPUs -- FastDifferentiation.jl"
168+
plugins:
169+
- JuliaCI/julia#v1:
170+
version: "1.10"
171+
agents:
172+
queue: "juliaecosystem"
173+
os: "linux"
174+
arch: "x86_64"
175+
command: |
176+
julia --color=yes --project -e '
177+
using Pkg
178+
Pkg.add("OptimizationProblems")
179+
Pkg.add("FastDifferentiation")
180+
Pkg.instantiate()
181+
include("test/backend/FastDifferentiation.jl")'
182+
timeout_in_minutes: 30
183+
184+
- label: "CPUs -- FiniteDiff.jl"
185+
plugins:
186+
- JuliaCI/julia#v1:
187+
version: "1.10"
188+
agents:
189+
queue: "juliaecosystem"
190+
os: "linux"
191+
arch: "x86_64"
192+
command: |
193+
julia --color=yes --project -e '
194+
using Pkg
195+
Pkg.add("OptimizationProblems")
196+
Pkg.add("FiniteDiff")
197+
Pkg.instantiate()
198+
include("test/backend/FiniteDiff.jl")'
199+
timeout_in_minutes: 30
200+
201+
- label: "CPUs -- FiniteDifferences.jl"
202+
plugins:
203+
- JuliaCI/julia#v1:
204+
version: "1.10"
205+
agents:
206+
queue: "juliaecosystem"
207+
os: "linux"
208+
arch: "x86_64"
209+
command: |
210+
julia --color=yes --project -e '
211+
using Pkg
212+
Pkg.add("OptimizationProblems")
213+
Pkg.add("FiniteDifferences")
214+
Pkg.instantiate()
215+
include("test/backend/FiniteDifferences.jl")'
216+
timeout_in_minutes: 30
217+
218+
- label: "CPUs -- PolyesterForwardDiff.jl"
219+
plugins:
220+
- JuliaCI/julia#v1:
221+
version: "1.10"
222+
agents:
223+
queue: "juliaecosystem"
224+
os: "linux"
225+
arch: "x86_64"
226+
command: |
227+
julia --color=yes --project -e '
228+
using Pkg
229+
Pkg.add("OptimizationProblems")
230+
Pkg.add("PolyesterForwardDiff")
231+
Pkg.instantiate()
232+
include("test/backend/PolyesterForwardDiff.jl")'

.github/workflows/CI.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
with:
2929
version: ${{ matrix.version }}
3030
arch: ${{ matrix.arch }}
31-
- uses: actions/cache@v1
31+
- uses: actions/cache@v4
3232
env:
3333
cache-name: cache-artifacts
3434
with:

Project.toml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@ version = "0.8.7"
44

55
[deps]
66
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
7+
DifferentiationInterface = "a0c0ee7d-e4b9-4e03-894e-1c5f64a51d63"
78
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
89
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
910
NLPModels = "a4795742-8479-5a88-8948-cc11e1c8c1a6"
10-
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
1111
ReverseDiff = "37e2e3b7-166d-5795-8a7a-e32c996b4267"
1212
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
1313
SparseConnectivityTracer = "9f842d2f-2579-4b1d-911e-f412cf18a3f5"
1414
SparseMatrixColorings = "0a514795-09f3-496d-8182-132a7b665d35"
1515

1616
[compat]
17-
ADTypes = "1.2.1"
18-
ForwardDiff = "0.9.0, 0.10.0"
19-
NLPModels = "0.18, 0.19, 0.20, 0.21"
20-
Requires = "1"
21-
ReverseDiff = "1"
17+
ADTypes = "1.9.0"
18+
DifferentiationInterface = "0.6.1"
19+
ForwardDiff = "0.10.36"
20+
NLPModels = "0.21.3"
21+
ReverseDiff = "1.15.3"
2222
SparseConnectivityTracer = "0.6.1"
2323
SparseMatrixColorings = "0.4.0"
24-
julia = "^1.6"
24+
julia = "1.6"

docs/Project.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"
1616
DataFrames = "1"
1717
Documenter = "1.0"
1818
ManualNLPModels = "0.1"
19-
NLPModels = "0.21"
20-
NLPModelsJuMP = "0.13"
21-
OptimizationProblems = "0.8"
19+
NLPModels = "0.21.3"
20+
NLPModelsJuMP = "0.13.2"
21+
OptimizationProblems = "0.9"
2222
Percival = "0.7"
2323
Plots = "1"
2424
SolverBenchmark = "0.6"
25-
Zygote = "0.6.62"
25+
Zygote = "0.6.70"

docs/src/backend.md

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
# How to switch backend in ADNLPModels
22

33
`ADNLPModels` allows the use of different backends to compute the derivatives required within NLPModel API.
4-
It uses `ForwardDiff.jl`, `ReverseDiff.jl`, and more via optional depencies.
4+
It uses `ForwardDiff.jl`, `ReverseDiff.jl`, and more via optional dependencies.
55

66
The backend information is in a structure [`ADNLPModels.ADModelBackend`](@ref) in the attribute `adbackend` of a `ADNLPModel`, it can also be accessed with [`get_adbackend`](@ref).
77

88
The functions used internally to define the NLPModel API and the possible backends are defined in the following table:
99

10-
| Functions | FowardDiff backends | ReverseDiff backends | Zygote backends | Enzyme backend | Sparse backend |
11-
| --------- | ------------------- | -------------------- | --------------- | -------------- | -------------- |
12-
| `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` | -- | -- | -- |
18-
| `directional_second_derivative` | `ForwardDiffADGHjvprod` | -- | -- | -- | -- |
19-
20-
The functions `hess_structure!`, `hess_coord!`, `jac_structure!` and `jac_coord!` defined in `ad.jl` are generic to all the backends for now.
10+
| package | ForwardDiff.jl | ReverseDiff.jl | Enzyme.jl | Zygote.jl | Mooncake.jl | Diffractor.jl | Tracker.jl | Symbolics.jl | ChainRules.jl | FastDifferentiation.jl | FiniteDiff.jl | FiniteDifferences.jl | PolyesterForwardDiff.jl |
11+
|--------|----------------|----------------|-----------|-----------|-------------|---------------|------------|--------------|----------------------|------------------------|---------------|----------------------|-------------------------|
12+
| $\nabla f(x)$ | `ForwardDiffADGradient` | `ReverseDiffADGradient` | `EnzymeADGradient` | `ZygoteADGradient` | `MooncakeADGradient` | `DiffractorADGradient` | `TrackerADGradient` | `SymbolicsADGradient` | `ChainRulesADGradient` | `FastDifferentiationADGradient` | `FiniteDiffADGradient` | `FiniteDifferencesADGradient` | `PolyesterForwardDiffADGradient` |
13+
| $J_c(x)*v$ | `ForwardDiffADJprod` | `ReverseDiffADJprod` | `EnzymeADJprod` | `ZygoteADJprod` | `MooncakeADJprod` | `DiffractorADJprod` | `TrackerADJprod` | `SymbolicsADJprod` | `ChainRulesADJprod` | `FastDifferentiationADJprod` | `FiniteDiffADJprod` | `FiniteDifferencesADJprod` | `PolyesterForwardDiffADJprod` |
14+
| $J^T_c(x)*v$ | `ForwardDiffADJtprod` | `ReverseDiffADJtprod` | `EnzymeADJtprod` | `ZygoteADJtprod` | `MooncakeADJtprod` | `DiffractorADJtprod` | `TrackerADJtprod` | `SymbolicsADJtprod` | `ChainRulesADJtprod` | `FastDifferentiationADJtprod` | `FiniteDiffADJtprod` | `FiniteDifferencesADJtprod` | `PolyesterForwardDiffADJtprod` |
15+
| $J_c(x)$ | `ForwardDiffADJacobian` | `ReverseDiffADJacobian` | `EnzymeADJacobian` | `ZygoteADJacobian` | `MooncakeADJacobian` | `DiffractorADJacobian` | `TrackerADJacobian` | `SymbolicsADJacobian` | `ChainRulesADJacobian` | `FastDifferentiationADJacobian` | `FiniteDiffADJacobian` | `FiniteDifferencesADJacobian` | `PolyesterForwardDiffADJacobian` |
16+
| $\nabla^2 \mathcal{L}(x)*v$ | `ForwardDiffADHvprod` | `ReverseDiffADHvprod` | `EnzymeADHvprod` | `ZygoteADHvprod` | `MooncakeADHvprod` | `DiffractorADHvprod` | `TrackerADHvprod` | `SymbolicsADHvprod` | `ChainRulesADHvprod` | `FastDifferentiationADHvprod` | `FiniteDiffADHvprod` | `FiniteDifferencesADHvprod` | `PolyesterForwardDiffADHvprod` |
17+
| $\nabla^2 \mathcal{L}(x)$ | `ForwardDiffADHessian` | `ReverseDiffADHessian` | `EnzymeADHessian` | `ZygoteADHessian` | `MooncakeADHessian` | `DiffractorADHessian` | `TrackerADHessian` | `SymbolicsADHessian` | `ChainRulesADHessian` | `FastDifferentiationADHessian` | `FiniteDiffADHessian` | `FiniteDifferencesADHessian` | `PolyesterForwardDiffADHessian` |
18+
19+
$\mathcal{L}(x)$ denotes the Lagrangian $f(x) + \lambda^T c(x)$.
20+
Except for the backends based on `ForwardDiff.jl` and `ReverseDiff.jl`, all other backends require the associated AD package to be manually installed by the user to work.
21+
Note that the Jacobians and Hessians computed by the backends above are dense.
22+
The backends `SparseADJacobian`, `SparseADHessian`, and `SparseReverseADHessian` should be used instead if sparse Jacobians and Hessians are required.
2123

2224
```@example ex1
2325
using ADNLPModels

src/ADNLPModels.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@ module ADNLPModels
44
using LinearAlgebra, SparseArrays
55

66
# external
7-
using ADTypes: ADTypes, AbstractColoringAlgorithm, AbstractSparsityDetector
7+
import DifferentiationInterface
8+
using ADTypes: ADTypes, AbstractADType, AbstractColoringAlgorithm, AbstractSparsityDetector, AutoEnzyme, AutoZygote
9+
using ADTypes: AutoForwardDiff, AutoReverseDiff, AutoMooncake, AutoDiffractor, AutoTracker, AutoSymbolics
10+
using ADTypes: AutoChainRules, AutoFastDifferentiation, AutoFiniteDiff, AutoFiniteDifferences, AutoPolyesterForwardDiff
811
using SparseConnectivityTracer: TracerSparsityDetector
912
using SparseMatrixColorings
1013
using ForwardDiff, ReverseDiff
1114

1215
# JSO
1316
using NLPModels
14-
using Requires
1517

1618
abstract type AbstractADNLPModel{T, S} <: AbstractNLPModel{T, S} end
1719
abstract type AbstractADNLSModel{T, S} <: AbstractNLSModel{T, S} end
@@ -27,8 +29,7 @@ include("sparse_hessian.jl")
2729

2830
include("forward.jl")
2931
include("reverse.jl")
30-
include("enzyme.jl")
31-
include("zygote.jl")
32+
include("di.jl")
3233
include("predefined_backend.jl")
3334
include("nlp.jl")
3435

0 commit comments

Comments
 (0)