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

Make Expokit an optional requirement #1290

Merged
merged 6 commits into from
Apr 27, 2019
Merged
Show file tree
Hide file tree
Changes from 5 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
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ after_success:
Pkg.add("GR");
Pkg.add("Polyhedra");
Pkg.add("CDDLib");
Pkg.add("Expokit");
Pkg.add("Optim");
Pkg.add("StaticArrays");
Pkg.add("BenchmarkTools");
Expand Down
1 change: 0 additions & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
julia 0.6
Compat 1.0
Expokit 0.1
GLPKMathProgInterface 0.4
IntervalArithmetic 0.14
MathProgBase 0.7
Expand Down
29 changes: 23 additions & 6 deletions docs/src/man/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,30 @@ that it builds correctly.
To install `LazySets`, use the following command inside Julia's REPL:

```julia
Pkg.clone("https://github.com/JuliaReach/LazySets.jl")
Pkg.add("LazySets")
schillic marked this conversation as resolved.
Show resolved Hide resolved
```
The dependencies of `LazySets`, such as
[Expokit.jl](https://github.com/acroy/Expokit.jl)
-- which provides lazy matrix exponentiation routines -- are automatically
installed through Julia's package manager.
The full list of dependencies is specified in the `REQUIRE` file.
or replace `add` by `clone` if you want to develop the code.
The full list of dependencies (which are automatically installed) is specified
in the `REQUIRE` file.


### Building the package

Use the following command from Julia's REPL:
```
julia> using LazySets
```
This should precompile the package and make it available afterward.


## Optional dependencies

Some optional dependencies, such as
schillic marked this conversation as resolved.
Show resolved Hide resolved
[`Expokit.jl`](https://github.com/acroy/Expokit.jl) (a package that provides
lazy matrix exponentiation routines), are not installed by default.
When loading the corresponding packages in addition, new functionality in
`LazySets` is added automatically (a feature that is possible through the
[`Requires`](https://github.com/MikeInnes/Requires.jl) package).


## Workflow tips
Expand Down
91 changes: 55 additions & 36 deletions src/ExponentialMap.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using Expokit

import Base: *, size, ∈, isempty

export SparseMatrixExp,
Expand Down Expand Up @@ -74,6 +72,11 @@ function size(spmexp::SparseMatrixExp, ax::Int)::Int
return size(spmexp.M, ax)
end

function load_expokit_sparsematrixexp()
return quote

using Expokit: expmv

function get_column(spmexp::SparseMatrixExp{N}, j::Int)::Vector{N} where {N}
n = size(spmexp, 1)
aux = zeros(N, n)
Expand Down Expand Up @@ -144,6 +147,8 @@ function get_rows(spmexp::SparseMatrixExp{N},
return ans
end

end end # quote / load_expokit_sparsematrixexp

"""
ExponentialMap{N<:Real, S<:LazySet{N}} <: LazySet{N}

Expand Down Expand Up @@ -219,6 +224,11 @@ function dim(em::ExponentialMap)::Int
return size(em.spmexp.M, 1)
end

function load_expokit_exponentialmap()
return quote

using Expokit: expmv

"""
σ(d::AbstractVector{N}, em::ExponentialMap{N}) where {N<:Real}

Expand Down Expand Up @@ -276,23 +286,6 @@ function ρ(d::AbstractVector{N}, em::ExponentialMap{N}) where {N<:Real}
return ρ(v, em.X)
end

"""
isbounded(em::ExponentialMap)::Bool

Determine whether an exponential map is bounded.

### Input

- `em` -- exponential map

### Output

`true` iff the exponential map is bounded.
"""
function isbounded(em::ExponentialMap)::Bool
return isbounded(em.X)
end

"""
∈(x::AbstractVector{N}, em::ExponentialMap{N})::Bool where {N<:Real}

Expand Down Expand Up @@ -331,23 +324,6 @@ function ∈(x::AbstractVector{N}, em::ExponentialMap{N})::Bool where {N<:Real}
return ∈(expmv(-one(N), em.spmexp.M, x), em.X)
end

"""
isempty(em::ExponentialMap)::Bool

Return if an exponential map is empty or not.

### Input

- `em` -- exponential map

### Output

`true` iff the wrapped set is empty.
"""
function isempty(em::ExponentialMap)::Bool
return isempty(em.X)
end

"""
vertices_list(em::ExponentialMap{N})::Vector{Vector{N}} where {N<:Real}

Expand Down Expand Up @@ -380,6 +356,42 @@ function vertices_list(em::ExponentialMap{N})::Vector{Vector{N}} where {N<:Real}
return vlist
end

end end # quote / load_expokit_exponentialmap

"""
isbounded(em::ExponentialMap)::Bool

Determine whether an exponential map is bounded.

### Input

- `em` -- exponential map

### Output

`true` iff the exponential map is bounded.
"""
function isbounded(em::ExponentialMap)::Bool
return isbounded(em.X)
end

"""
isempty(em::ExponentialMap)::Bool

Return if an exponential map is empty or not.

### Input

- `em` -- exponential map

### Output

`true` iff the wrapped set is empty.
"""
function isempty(em::ExponentialMap)::Bool
return isempty(em.X)
end

# --- ProjectionSparseMatrixExp & ExponentialProjectionMap ---

"""
Expand Down Expand Up @@ -464,6 +476,11 @@ function dim(eprojmap::ExponentialProjectionMap)::Int
return size(eprojmap.projspmexp.L, 1)
end

function load_expokit_exponentialprojectionmap()
return quote

using Expokit: expmv

"""
σ(d::AbstractVector{N},
eprojmap::ExponentialProjectionMap{N}) where {N<:Real}
Expand Down Expand Up @@ -502,6 +519,8 @@ function σ(d::AbstractVector{N},
return eprojmap.projspmexp.L * daux
end

end end # quote / load_expokit_exponentialprojectionmap

"""
isbounded(eprojmap::ExponentialProjectionMap)::Bool

Expand Down
17 changes: 12 additions & 5 deletions src/init.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
function __init__()
@require Polyhedra = "67491407-f73d-577b-9b50-8179a7c68029" load_polyhedra()
@require Expokit = "a1e7a1ef-7a5d-5822-a38c-be74e1bb89f4" load_expokit()
@require Optim = "429524aa-4258-5aef-a3af-852621145aeb" load_optim()
@require Polyhedra = "67491407-f73d-577b-9b50-8179a7c68029" load_polyhedra()
end

function load_expokit()
eval(load_expokit_sparsematrixexp())
eval(load_expokit_exponentialmap())
eval(load_expokit_exponentialprojectionmap())
end

function load_optim()
eval(load_optim_intersection())
end

function load_polyhedra()
Expand All @@ -9,7 +20,3 @@ function load_polyhedra()
eval(load_polyhedra_hpolyhedron())
eval(load_polyhedra_vpolytope())
end

function load_optim()
eval(load_optim_intersection())
end
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using LazySets, LazySets.Approximations

import IntervalArithmetic
import IntervalArithmetic, Expokit
using IntervalArithmetic: IntervalBox

# compatibility between Julia versions
Expand Down