Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option for shorter tests and use in PkgEval #33

Merged
merged 1 commit into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions test/ForwardAlgorithms/forward.jl
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ end
@test forward(x, N, DefaultForward()) == [47.0, 94]

# exact algorithms (in this case)
for algo in (ConcreteForward(), LazyForward(), BoxForward(),
BoxForward(LazyForward()), DeepZ(), Verisig())
for algo in @tv [ConcreteForward(), LazyForward(), BoxForward(),
BoxForward(LazyForward()), DeepZ()] [Verisig()]
@test isequivalent(concretize(forward(X, N, algo)), Y)
end
# approximate algorithms
Expand Down Expand Up @@ -316,12 +316,12 @@ end
end

# algorithms not supporting ReLU activation
for algo in (DefaultForward(), Verisig())
@ts for algo in (DefaultForward(), Verisig())
@test_throws ArgumentError forward(X, N, algo)
end
end

@testset "AI² ReLU example" begin
@ts @testset "AI² ReLU example" begin
N = example_network_AI2()
W = N.layers[1].weights
b = N.layers[1].bias
Expand Down Expand Up @@ -371,7 +371,7 @@ end
end

# algorithms not supporting ReLU activation
for algo in (DefaultForward(), Verisig())
@ts for algo in (DefaultForward(), Verisig())
@test_throws ArgumentError forward(X, N, algo)
end

Expand All @@ -397,14 +397,16 @@ end
end

# Verisig result has a special type
Y = forward(X, N, Verisig())
if act == Sigmoid()
@test Y_exact ⊆ overapproximate(Y, Zonotope)
elseif act == Tanh()
# this is a known case where the algorithm is unsound
@test_broken Y_exact ⊆ overapproximate(Y, Zonotope)
else
error("unexpected case")
@ts begin
Y = forward(X, N, Verisig())
if act == Sigmoid()
@test Y_exact ⊆ overapproximate(Y, Zonotope)
elseif act == Tanh()
# this is a known case where the algorithm is unsound
@test_broken Y_exact ⊆ overapproximate(Y, Zonotope)
else
error("unexpected case")
end
end

# algorithms not supporting sigmoid activation
Expand Down
26 changes: 24 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,36 @@
using Test, NeuralNetworkReachability
using ControllerFormats, LazySets

# auxiliary code to skip expensive tests
begin
__test_short = haskey(ENV, "JULIA_PKGEVAL")

macro ts(arg)
if !__test_short
quote
$(esc(arg))
end
end
end

macro tv(v1, v2)
if __test_short
return v1
else
return @eval vcat($v1, $v2)
end
end
end

include("example_networks.jl")

@testset "Optional dependencies (not loaded)" begin
include("optional_dependencies_not_loaded.jl")
end

# load optional dependencies
import IntervalConstraintProgramming, ReachabilityAnalysis, Polyhedra, CDDLib, Optim
import Polyhedra, CDDLib, Optim
@ts import IntervalConstraintProgramming, ReachabilityAnalysis

@testset "Util" begin
include("Util/Util.jl")
Expand Down Expand Up @@ -43,4 +65,4 @@ end
end
end

include("Aqua.jl")
@ts include("Aqua.jl")