Skip to content

Commit 3090b3f

Browse files
authored
Merge pull request #1 from blegat/bl/ReverseAD
Copy source code of ReverseAD
2 parents d09cd71 + 0d72312 commit 3090b3f

18 files changed

+4353
-2
lines changed

.JuliaFormatter.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Configuration file for JuliaFormatter.jl
2+
# For more information, see: https://domluna.github.io/JuliaFormatter.jl/stable/config/
3+
4+
always_for_in = true
5+
always_use_return = true
6+
margin = 80
7+
remove_extra_newlines = true
8+
short_to_long_function_def = true

.github/workflows/TagBot.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: TagBot
2+
on:
3+
issue_comment:
4+
types:
5+
- created
6+
workflow_dispatch:
7+
jobs:
8+
TagBot:
9+
if: github.event_name == 'workflow_dispatch' || github.actor == 'JuliaTagBot'
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: JuliaRegistries/TagBot@v1
13+
with:
14+
token: ${{ secrets.GITHUB_TOKEN }}
15+
ssh: ${{ secrets.DOCUMENTER_KEY }}

.github/workflows/ci.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: CI
2+
on:
3+
push:
4+
branches: [main]
5+
pull_request:
6+
types: [opened, synchronize, reopened]
7+
jobs:
8+
test:
9+
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
10+
runs-on: ${{ matrix.os }}
11+
strategy:
12+
fail-fast: false
13+
matrix:
14+
include:
15+
- version: '1.10'
16+
os: ubuntu-latest
17+
arch: x64
18+
- version: '1'
19+
os: ubuntu-latest
20+
arch: x64
21+
steps:
22+
- uses: actions/checkout@v4
23+
- uses: julia-actions/setup-julia@v2
24+
with:
25+
version: ${{ matrix.version }}
26+
arch: ${{ matrix.arch }}
27+
- uses: julia-actions/cache@v1
28+
- uses: julia-actions/julia-buildpkg@v1
29+
- uses: julia-actions/julia-runtest@v1
30+
with:
31+
depwarn: error
32+
- uses: julia-actions/julia-processcoverage@v1
33+
- uses: codecov/codecov-action@v4
34+
with:
35+
file: lcov.info
36+
token: ${{ secrets.CODECOV_TOKEN }}

.github/workflows/format_check.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: format-check
2+
on:
3+
push:
4+
branches:
5+
- maain
6+
- release-*
7+
pull_request:
8+
types: [opened, synchronize, reopened]
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: julia-actions/setup-julia@latest
14+
with:
15+
version: '1'
16+
- uses: actions/checkout@v4
17+
- name: Format check
18+
shell: julia --color=yes {0}
19+
run: |
20+
using Pkg
21+
Pkg.add(PackageSpec(name="JuliaFormatter", version="2"))
22+
using JuliaFormatter
23+
format(".", verbose=true)
24+
out = String(read(Cmd(`git diff`)))
25+
if isempty(out)
26+
exit(0)
27+
end
28+
@error "Some files have not been formatted !!!"
29+
write(stdout, out)
30+
exit(1)

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Manifest.toml

Project.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,18 @@ name = "ArrayAD"
22
uuid = "c45fa1ca-6901-44ac-ae5b-5513a4852d50"
33
authors = ["Benoît Legat <benoit.legat@gmail.com>"]
44
version = "0.1.0"
5+
6+
[deps]
7+
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
8+
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
9+
MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"
10+
NaNMath = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3"
11+
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
12+
13+
[compat]
14+
DataStructures = "0.18"
15+
ForwardDiff = "1"
16+
MathOptInterface = "1.40"
17+
NaNMath = "1"
18+
SparseArrays = "1.10"
19+
julia = "1.10"

src/ArrayAD.jl

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,60 @@
1+
# Copyright (c) 2017: Miles Lubin and contributors
2+
# Copyright (c) 2017: Google Inc.
3+
#
4+
# Use of this source code is governed by an MIT-style license that can be found
5+
# in the LICENSE.md file or at https://opensource.org/licenses/MIT.
6+
17
module ArrayAD
28

3-
greet() = print("Hello World!")
9+
import ForwardDiff
10+
import MathOptInterface as MOI
11+
const Nonlinear = MOI.Nonlinear
12+
import SparseArrays
13+
14+
"""
15+
Mode() <: AbstractAutomaticDifferentiation
16+
17+
Fork of `MOI.Nonlinear.SparseReverseMode` to add array support.
18+
"""
19+
struct Mode <: MOI.Nonlinear.AbstractAutomaticDifferentiation end
20+
21+
function MOI.Nonlinear.Evaluator(
22+
model::MOI.Nonlinear.Model,
23+
::Mode,
24+
ordered_variables::Vector{MOI.VariableIndex},
25+
)
26+
return MOI.Nonlinear.Evaluator(
27+
model,
28+
NLPEvaluator(model, ordered_variables),
29+
)
30+
end
31+
32+
# Override basic math functions to return NaN instead of throwing errors.
33+
# This is what NLP solvers expect, and sometimes the results aren't needed
34+
# anyway, because the code may compute derivatives wrt constants.
35+
import NaNMath:
36+
sin,
37+
cos,
38+
tan,
39+
asin,
40+
acos,
41+
acosh,
42+
atanh,
43+
log,
44+
log2,
45+
log10,
46+
lgamma,
47+
log1p,
48+
pow,
49+
sqrt
50+
51+
include("Coloring/Coloring.jl")
52+
include("graph_tools.jl")
53+
include("types.jl")
54+
include("utils.jl")
55+
56+
include("reverse_mode.jl")
57+
include("forward_over_reverse.jl")
58+
include("mathoptinterface_api.jl")
459

5-
end # module ArrayAD
60+
end # module

0 commit comments

Comments
 (0)