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

#1699 - Add benchmark mode #1732

Merged
merged 3 commits into from
Sep 26, 2019
Merged

#1699 - Add benchmark mode #1732

merged 3 commits into from
Sep 26, 2019

Conversation

schillic
Copy link
Member

@schillic schillic commented Sep 25, 2019

First part of #1699.

julia> using LazySets

julia> @time Hyperplane(ones(2), 1.)  # warm-up
  0.036591 seconds (47.90 k allocations: 2.362 MiB, 15.39% gc time)
Hyperplane{Float64}([1.0, 1.0], 1.0)

julia> @time Hyperplane(ones(2), 1.)  # normal runtime
  0.000013 seconds (6 allocations: 288 bytes)
Hyperplane{Float64}([1.0, 1.0], 1.0)

julia> @time Hyperplane(zeros(2), 1.)  # illegal argument, triggers assertion
ERROR: AssertionError: a hyperplane needs a non-zero normal vector
Stacktrace:
 [1] macro expansion at .julia/dev/LazySets/src/Utils/assertions.jl:22 [inlined]
 [2] Hyperplane{Float64}(::Array{Float64,1}, ::Float64) at .julia/dev/LazySets/src/Sets/Hyperplane.jl:32
 [3] Hyperplane(::Array{Float64,1}, ::Float64) at .julia/dev/LazySets/src/Sets/Hyperplane.jl:38
 [4] top-level scope at util.jl:156

julia> deactivate_assertions()

julia> @time Hyperplane(zeros(2), 1.)  # warm-up
  0.012239 seconds (4.71 k allocations: 277.524 KiB)
Hyperplane{Float64}([0.0, 0.0], 1.0)

julia> @time Hyperplane(zeros(2), 1.)  # illegal argument, but assertions are ignored
  0.000007 seconds (6 allocations: 288 bytes)
Hyperplane{Float64}([0.0, 0.0], 1.0)

julia> activate_assertions()

julia> @time Hyperplane(zeros(2), 1.)  # illegal argument, assertions are active again
ERROR: AssertionError: a hyperplane needs a non-zero normal vector
Stacktrace:
 [1] macro expansion at .julia/dev/LazySets/src/Utils/assertions.jl:22 [inlined]
 [2] Hyperplane{Float64}(::Array{Float64,1}, ::Float64) at .julia/dev/LazySets/src/Sets/Hyperplane.jl:32
 [3] Hyperplane(::Array{Float64,1}, ::Float64) at .julia/dev/LazySets/src/Sets/Hyperplane.jl:38
 [4] top-level scope at util.jl:156

I also checked that deactivating the assertions really avoids evaluating the code inside @assert completely.

This implements the proposal here, which is however more general because now this feature only works for LazySets and not for its submodules or other packages like Reachability. Enumerating all submodules of LazySets would not be a problem but I do not know whether we always want to copy-paste this code to all packages. Maybe we should create a helper package?

@mforets
Copy link
Member

mforets commented Sep 25, 2019

Maybe we should create a helper package?

Sounds good, maybe after a first round of testing in Reachability + LazySets, to validate if it is worth the effort to create the package.

src/Utils/assertions.jl Outdated Show resolved Hide resolved
@schillic
Copy link
Member Author

I managed to synchronize the setting for all submodules. I think this is better.

julia> Hyperplane([0.], 1.)
ERROR: AssertionError: a hyperplane needs a non-zero normal vector
Stacktrace:
 [1] macro expansion at .julia/dev/LazySets/src/Assertions/Assertions.jl:27 [inlined]
 [2] Hyperplane{Float64}(::Array{Float64,1}, ::Float64) at .julia/dev/LazySets/src/Sets/Hyperplane.jl:32
 [3] Hyperplane(::Array{Float64,1}, ::Float64) at .julia/dev/LazySets/src/Sets/Hyperplane.jl:38
 [4] top-level scope at REPL[2]:1

julia> underapproximate(rand(Interval), BoxDirections(2))
ERROR: AssertionError: $(Expr(:escape, :(LazySets.dim(X) == LazySets.dim(dirs))))
Stacktrace:
 [1] macro expansion at .julia/dev/LazySets/src/Assertions/Assertions.jl:27 [inlined]
 [2] #underapproximate#17(::Bool, ::typeof(underapproximate), ::Interval{Float64,IntervalArithmetic.Interval{Float64}}, ::BoxDirections{Float64}) at .julia/dev/LazySets/src/Approximations/underapproximate.jl:20
 [3] underapproximate(::Interval{Float64,IntervalArithmetic.Interval{Float64}}, ::BoxDirections{Float64}) at .julia/dev/LazySets/src/Approximations/underapproximate.jl:20
 [4] top-level scope at REPL[3]:1

julia> deactivate_assertions()

julia> Hyperplane([0.], 1.)
Hyperplane{Float64}([0.0], 1.0)

julia> underapproximate(rand(Interval), BoxDirections(2))
VPolytope{Float64}(Array{Float64,1}[[0.5987999558851578], [-1.1883260639396718], [-1.1883260639396718], [-1.1883260639396718]])

julia> activate_assertions()

julia> Hyperplane([0.], 1.)
ERROR: AssertionError: a hyperplane needs a non-zero normal vector
Stacktrace:
 [1] macro expansion at .julia/dev/LazySets/src/Assertions/Assertions.jl:27 [inlined]
 [2] Hyperplane{Float64}(::Array{Float64,1}, ::Float64) at .julia/dev/LazySets/src/Sets/Hyperplane.jl:32
 [3] Hyperplane(::Array{Float64,1}, ::Float64) at .julia/dev/LazySets/src/Sets/Hyperplane.jl:38
 [4] top-level scope at REPL[8]:1

julia> underapproximate(rand(Interval), BoxDirections(2))
ERROR: AssertionError: $(Expr(:escape, :(LazySets.dim(X) == LazySets.dim(dirs))))
Stacktrace:
 [1] macro expansion at .julia/dev/LazySets/src/Assertions/Assertions.jl:27 [inlined]
 [2] #underapproximate#17(::Bool, ::typeof(underapproximate), ::Interval{Float64,IntervalArithmetic.Interval{Float64}}, ::BoxDirections{Float64}) at .julia/dev/LazySets/src/Approximations/underapproximate.jl:20
 [3] underapproximate(::Interval{Float64,IntervalArithmetic.Interval{Float64}}, ::BoxDirections{Float64}) at .julia/dev/LazySets/src/Approximations/underapproximate.jl:20
 [4] top-level scope at REPL[9]:1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants