Skip to content

Commit 3e54c2d

Browse files
authored
Add Enzyme testing as a separate CI action (#950)
* Add Enzyme testing as a separate CI action * Move to separate script in test/enzyme * Colour * rename file to main.jl * test/enzyme -> test/integration/enzyme
1 parent a4ad5e2 commit 3e54c2d

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

.github/workflows/Enzyme.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Enzyme on demo models
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
# needed to allow julia-actions/cache to delete old caches that it has created
10+
permissions:
11+
actions: write
12+
contents: read
13+
14+
# Cancel existing tests on the same PR if a new commit is added to a pull request
15+
concurrency:
16+
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
17+
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}
18+
19+
jobs:
20+
enzyme:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- uses: actions/checkout@v4
24+
25+
- uses: julia-actions/setup-julia@v2
26+
with:
27+
version: "1"
28+
29+
- uses: julia-actions/cache@v2
30+
31+
- name: Run AD with Enzyme on demo models
32+
working-directory: test/integration/enzyme
33+
run: |
34+
julia --project=. --color=yes -e 'using Pkg; Pkg.instantiate()'
35+
julia --project=. --color=yes main.jl

test/integration/enzyme/Project.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[deps]
2+
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
3+
DynamicPPL = "366bfd00-2699-11ea-058f-f148b4cae6d8"
4+
Enzyme = "7da242da-08ed-463a-9acd-ee780be4f1d9"
5+
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
6+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
7+
8+
[sources]
9+
DynamicPPL = {path = "../../../"}

test/integration/enzyme/main.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using DynamicPPL.TestUtils: DEMO_MODELS
2+
using DynamicPPL.TestUtils.AD: run_ad
3+
using ADTypes: AutoEnzyme
4+
using Test: @test, @testset
5+
import Enzyme: set_runtime_activity, Forward, Reverse
6+
using ForwardDiff: ForwardDiff # run_ad uses FD for correctness test
7+
8+
ADTYPES = Dict(
9+
"EnzymeForward" => AutoEnzyme(; mode=set_runtime_activity(Forward)),
10+
"EnzymeReverse" => AutoEnzyme(; mode=set_runtime_activity(Reverse)),
11+
)
12+
13+
@testset "$ad_key" for (ad_key, ad_type) in ADTYPES
14+
@testset "$(model.f)" for model in DEMO_MODELS
15+
@test run_ad(model, ad_type) isa Any
16+
end
17+
end

0 commit comments

Comments
 (0)