diff --git a/.travis.yml b/.travis.yml index b26102ee16..573c12d2c5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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"); diff --git a/README.md b/README.md index f73feef308..01b38a58b6 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,7 @@ on how to install and run Julia in your system. To install the latest release of this package, use the following command inside Julia's REPL: ```julia +using Pkg Pkg.add("LazySets") ``` @@ -33,9 +34,3 @@ If you want to install the latest development version, do: ```julia Pkg.clone("https://github.com/JuliaReach/LazySets.jl.git") ``` - -To update your local copy to the current development version, do: - -```julia -Pkg.checkout("LazySets") -```` diff --git a/REQUIRE b/REQUIRE index 2ec5678fa9..00dbc60616 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,6 +1,5 @@ julia 0.6 Compat 1.0 -Expokit 0.1 GLPKMathProgInterface 0.4 IntervalArithmetic 0.14 MathProgBase 0.7 diff --git a/docs/src/index.md b/docs/src/index.md index ff50e1929a..acdbd49a02 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -91,6 +91,8 @@ The `@time` macro shows that building $\mathcal{Y}$ with `LazySets` is instantaneous. ```jldoctest index_label +julia> using Expokit + julia> Y = CH(SparseMatrixExp(A * δ) * X0 + δ * B * U, X0); ``` diff --git a/docs/src/man/getting_started.md b/docs/src/man/getting_started.md index 12fb538b78..73602a6dbf 100644 --- a/docs/src/man/getting_started.md +++ b/docs/src/man/getting_started.md @@ -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") ``` -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 +[`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 diff --git a/docs/src/man/parallel_approximations.md b/docs/src/man/parallel_approximations.md index b3320bb35e..81df8a51b9 100644 --- a/docs/src/man/parallel_approximations.md +++ b/docs/src/man/parallel_approximations.md @@ -50,7 +50,7 @@ It arises in the discretization of set-based ODEs, and is defined below for an example of a tridiagonal matrix of order `n`, where `n` is a positive integer. ```julia -using LazySets +using LazySets, Expokit using SparseArrays, LinearAlgebra # define an nxn tridiagonal matrix diff --git a/src/ExponentialMap.jl b/src/ExponentialMap.jl index 01982e6d16..108e6f82ee 100644 --- a/src/ExponentialMap.jl +++ b/src/ExponentialMap.jl @@ -1,5 +1,3 @@ -using Expokit - import Base: *, size, ∈, isempty export SparseMatrixExp, @@ -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) @@ -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} @@ -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} @@ -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} @@ -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} @@ -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 --- """ @@ -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} @@ -502,6 +519,8 @@ function σ(d::AbstractVector{N}, return eprojmap.projspmexp.L * daux end +end end # quote / load_expokit_exponentialprojectionmap + """ isbounded(eprojmap::ExponentialProjectionMap)::Bool diff --git a/src/init.jl b/src/init.jl index 5293edeae3..e5756537a9 100644 --- a/src/init.jl +++ b/src/init.jl @@ -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() @@ -9,7 +20,3 @@ function load_polyhedra() eval(load_polyhedra_hpolyhedron()) eval(load_polyhedra_vpolytope()) end - -function load_optim() - eval(load_optim_intersection()) -end diff --git a/test/runtests.jl b/test/runtests.jl index aab5442710..58e854dbda 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,6 +1,6 @@ using LazySets, LazySets.Approximations -import IntervalArithmetic +import IntervalArithmetic, Expokit using IntervalArithmetic: IntervalBox # compatibility between Julia versions