Skip to content

Commit 9ceeb97

Browse files
committed
Add tests
1 parent 52a91fe commit 9ceeb97

2 files changed

Lines changed: 71 additions & 0 deletions

File tree

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using DifferentiationInterface
2+
using Enzyme: Enzyme
3+
using Test
4+
5+
@testset "MutabilityError" begin
6+
f = let
7+
cache = [0.0]
8+
x -> sum(copyto!(cache, x))
9+
end
10+
11+
msg = try
12+
gradient(f, AutoEnzyme(), [1.0])
13+
catch e
14+
buf = IOBuffer()
15+
showerror(buf, e)
16+
String(take!(buf))
17+
end
18+
@test occursin("AutoEnzyme", msg)
19+
@test occursin("function_annotation", msg)
20+
@test occursin("ADTypes", msg)
21+
@test occursin("DifferentiationInterface", msg)
22+
end
23+
24+
@testset "RuntimeActivityError" begin
25+
function g(active_var, constant_var, cond)
26+
if cond
27+
return active_var
28+
else
29+
return constant_var
30+
end
31+
end
32+
33+
function h(active_var, constant_var, cond)
34+
return [g(active_var, constant_var, cond), g(active_var, constant_var, cond)]
35+
end
36+
37+
msg = try
38+
pushforward(
39+
h,
40+
AutoEnzyme(; mode=Enzyme.Forward),
41+
[1.0],
42+
([1.0],),
43+
Constant([1.0]),
44+
Constant(true),
45+
)
46+
catch e
47+
buf = IOBuffer()
48+
showerror(buf, e)
49+
String(take!(buf))
50+
end
51+
@test occursin("AutoEnzyme", msg)
52+
@test occursin("mode", msg)
53+
@test occursin("set_runtime_activity", msg)
54+
@test occursin("ADTypes", msg)
55+
@test occursin("DifferentiationInterface", msg)
56+
end
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using ADTypes
2+
using DifferentiationInterface
3+
import DifferentiationInterface as DI
4+
using Test
5+
6+
@testset "Missing backend" begin
7+
msg = try
8+
gradient(sum, AutoZygote(), [1.0])
9+
catch e
10+
buf = IOBuffer()
11+
showerror(buf, e)
12+
String(take!(buf))
13+
end
14+
@test occursin("import Zygote", msg)
15+
end

0 commit comments

Comments
 (0)