From bbbfc69dda24d443e3337a6a85a586312ed9e228 Mon Sep 17 00:00:00 2001 From: schillic Date: Wed, 15 Jan 2025 17:32:23 +0100 Subject: [PATCH 1/4] allow Polyhedra v0.8 in tests/docs --- docs/Project.toml | 2 +- test/Project.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/Project.toml b/docs/Project.toml index de6404f13f..b2b4dd95b1 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -31,7 +31,7 @@ LaTeXStrings = "1" MiniQhull = "0.4" Optim = "1" Plots = "1" -Polyhedra = "0.7" +Polyhedra = "0.7 - 0.8" RecipesBase = "1" StaticArrays = "1" SymEngine = "0.7 - 0.12" diff --git a/test/Project.toml b/test/Project.toml index 0121e7a5b7..974f4bc656 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -47,7 +47,7 @@ Makie = "0.9 - 0.21" MiniQhull = "0.1 - 0.4" Optim = "0.15 - 0.22, 1" PkgVersion = "0.3" -Polyhedra = "0.6 - 0.7" +Polyhedra = "0.6 - 0.8" RangeEnclosures = "0.1.1, 0.2" RecipesBase = "0.6 - 0.8, 1" SCS = "1, 2" From 914acd425783b914787ad8c4fdfdcf1355af7961 Mon Sep 17 00:00:00 2001 From: schillic Date: Wed, 15 Jan 2025 23:09:14 +0100 Subject: [PATCH 2/4] allow CDDLib v0.10 in tests/docs --- docs/Project.toml | 2 +- test/Project.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/Project.toml b/docs/Project.toml index b2b4dd95b1..d5ab27f68f 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -21,7 +21,7 @@ TaylorModels = "314ce334-5f6e-57ae-acf6-00b6e903104a" [compat] AbstractTrees = "0.4" BenchmarkTools = "1" -CDDLib = "0.9" +CDDLib = "0.9 - 0.10" Distributions = "0.25" Documenter = "1" ExponentialUtilities = "1" diff --git a/test/Project.toml b/test/Project.toml index 974f4bc656..8192059172 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -32,7 +32,7 @@ WriteVTK = "64499a7a-5c06-52f2-abe2-ccb03c286192" [compat] Aqua = "0.8.9" -CDDLib = "0.6 - 0.9" +CDDLib = "0.6 - 0.10" Distributions = "0.19 - 0.25" Expokit = "0.2" ExponentialUtilities = "1" From 404e9405bf8e14e0e35a98fce0f982828f0ae442 Mon Sep 17 00:00:00 2001 From: schillic Date: Mon, 20 Jan 2025 21:56:19 +0100 Subject: [PATCH 3/4] fix 'triangulate' --- src/Initialization/init_GeometryBasics.jl | 3 +++ src/Initialization/init_Polyhedra.jl | 4 +++- src/Interfaces/LazySet.jl | 12 ++++++++---- src/init.jl | 2 ++ 4 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 src/Initialization/init_GeometryBasics.jl diff --git a/src/Initialization/init_GeometryBasics.jl b/src/Initialization/init_GeometryBasics.jl new file mode 100644 index 0000000000..3da2a19305 --- /dev/null +++ b/src/Initialization/init_GeometryBasics.jl @@ -0,0 +1,3 @@ +# this file is loaded from `init_Polyhedra.jl` + +eval(load_Polyhedra_GeometryBasics_triangulate()) diff --git a/src/Initialization/init_Polyhedra.jl b/src/Initialization/init_Polyhedra.jl index edd6dfeb92..a686aa7277 100644 --- a/src/Initialization/init_Polyhedra.jl +++ b/src/Initialization/init_Polyhedra.jl @@ -38,4 +38,6 @@ function _is_polyhedra_backend(backend::Polyhedra.Library) end eval(load_polyhedra_mesh()) -eval(load_polyhedra_lazyset()) +eval(load_Polyhedra_polyhedron()) + +include("init_GeometryBasics.jl") diff --git a/src/Interfaces/LazySet.jl b/src/Interfaces/LazySet.jl index a5050303ba..7ffbb90441 100644 --- a/src/Interfaces/LazySet.jl +++ b/src/Interfaces/LazySet.jl @@ -1376,7 +1376,7 @@ function chebyshev_center_radius(P::LazySet; return c, r end -function load_polyhedra_lazyset() # function to be loaded by Requires +function load_Polyhedra_polyhedron() return quote # see the interface file init_Polyhedra.jl for the imports @@ -1410,7 +1410,11 @@ function load_polyhedra_lazyset() # function to be loaded by Requires A, b = tosimplehrep(P) return Polyhedra.polyhedron(Polyhedra.hrep(A, b), backend) end + end +end # quote / load_Polyhedra_polyhedron() +function load_Polyhedra_GeometryBasics_triangulate() + return quote """ triangulate(X::LazySet) @@ -1439,8 +1443,8 @@ function load_polyhedra_lazyset() # function to be loaded by Requires P = polyhedron(X) mes = Mesh(P) - coords = Polyhedra.GeometryBasics.coordinates(mes) - connec = Polyhedra.GeometryBasics.faces(mes) + coords = GeometryBasics.coordinates(mes) + connec = GeometryBasics.faces(mes) ntriangles = length(connec) npoints = length(coords) @@ -1456,7 +1460,7 @@ function load_polyhedra_lazyset() # function to be loaded by Requires return points, connec_tup end end -end # quote / load_polyhedra_lazyset() +end # quote / load_Polyhedra_GeometryBasics_triangulate() """ # Extended help diff --git a/src/init.jl b/src/init.jl index c9c6ead7a7..73414a0069 100644 --- a/src/init.jl +++ b/src/init.jl @@ -3,6 +3,8 @@ function __init__() @require Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f" include("Initialization/init_Distributions.jl") @require Expokit = "a1e7a1ef-7a5d-5822-a38c-be74e1bb89f4" include("Initialization/init_Expokit.jl") @require ExponentialUtilities = "d4d017d3-3776-5f7e-afef-a10c40355c18" include("Initialization/init_ExponentialUtilities.jl") + # the includes for `GeometryBasics` are loaded when `Polyhedra` is loaded + @require GeometryBasics = "5c1252a2-5f33-56bf-86c9-59e7332b4326" (nothing,) @require Ipopt = "b6b21f68-93f8-5de0-b562-5493be1d77c9" (nothing,) @require Javis = "78b212ba-a7f9-42d4-b726-60726080707e" include("Initialization/init_Javis.jl") @require Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a" include("Initialization/init_Makie.jl") From 219aad1d3025db4153f3202d579755d82558b12d Mon Sep 17 00:00:00 2001 From: schillic Date: Mon, 20 Jan 2025 22:38:10 +0100 Subject: [PATCH 4/4] adapt to renamed kwarg in 'Polyhedra.removeredundancy' ('ztol' -> 'tol') --- src/ConcreteOperations/intersection.jl | 4 ++-- src/Initialization/init_Polyhedra.jl | 13 +++++++++++++ src/Interfaces/AbstractPolyhedron.jl | 3 ++- src/Sets/HPolytope/HPolytopeModule.jl | 3 ++- src/Sets/HPolytope/vertices_list.jl | 2 +- src/Sets/VPolytope/VPolytopeModule.jl | 3 ++- src/Sets/VPolytope/remove_redundant_vertices.jl | 2 +- 7 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/ConcreteOperations/intersection.jl b/src/ConcreteOperations/intersection.jl index 411d655d82..8733f6565e 100644 --- a/src/ConcreteOperations/intersection.jl +++ b/src/ConcreteOperations/intersection.jl @@ -545,7 +545,7 @@ A `VPolytope`. ### Notes If `prunefunc` is `nothing`, this implementation sets it to -`(X -> removevredundancy!(X; ztol=_ztol(eltype(P1))))`. +`(X -> removevredundancy!(X; tol=_ztol(eltype(P1))))`. """ function intersection(P1::Union{VPolygon,VPolytope}, P2::Union{VPolygon,VPolytope}; @@ -578,7 +578,7 @@ function intersection(P1::Union{VPolygon,VPolytope}, N = promote_type(eltype(P1), eltype(P2)) if isnothing(prunefunc) - prunefunc = (X -> removevredundancy!(X; ztol=_ztol(N))) + prunefunc = (X -> _removevredundancy!(X; N=N)) end prunefunc(Pint) diff --git a/src/Initialization/init_Polyhedra.jl b/src/Initialization/init_Polyhedra.jl index a686aa7277..253ca7a4d8 100644 --- a/src/Initialization/init_Polyhedra.jl +++ b/src/Initialization/init_Polyhedra.jl @@ -37,6 +37,19 @@ function _is_polyhedra_backend(backend::Polyhedra.Library) return true end +# in v0.8.0, `Polyhedra` renamed the kwarg `ztol` to `tol` +@static if hasmethod(Polyhedra.detecthlinearity, (Polyhedra.HRepresentation, Any), (:ztol,)) + function _removevredundancy!(X; N) + return removevredundancy!(X; ztol=_ztol(N)) + end +else + @assert hasmethod(Polyhedra.detecthlinearity, (Polyhedra.HRepresentation, Any), (:tol,)) + + function _removevredundancy!(X; N) + return removevredundancy!(X; tol=_ztol(N)) + end +end + eval(load_polyhedra_mesh()) eval(load_Polyhedra_polyhedron()) diff --git a/src/Interfaces/AbstractPolyhedron.jl b/src/Interfaces/AbstractPolyhedron.jl index 861639bcad..a406b60df1 100644 --- a/src/Interfaces/AbstractPolyhedron.jl +++ b/src/Interfaces/AbstractPolyhedron.jl @@ -77,13 +77,14 @@ function _linear_map_hrep_helper(M::AbstractMatrix, P::LazySet, return HPolyhedron(constraints) end -# internal functions; defined here due to dependency SymEngine and submodules +# internal functions; defined here due to optional dependencies and submodules function isfeasible end function remove_redundant_constraints end function remove_redundant_constraints! end function _ishalfspace end function _ishyperplanar end function _parse_linear_expression end +function _removevredundancy! end # To account for the compilation order, other functions are defined in the file # AbstractPolyhedron_functions.jl diff --git a/src/Sets/HPolytope/HPolytopeModule.jl b/src/Sets/HPolytope/HPolytopeModule.jl index 5187b4d55f..402f9f5df2 100644 --- a/src/Sets/HPolytope/HPolytopeModule.jl +++ b/src/Sets/HPolytope/HPolytopeModule.jl @@ -5,7 +5,8 @@ using Reexport, Requires using ..LazySets: AbstractPolytope, LazySet, AbstractLinearMapAlgorithm, default_polyhedra_backend, vertices_list_1d, _infeasible_constraints_list, _linear_map_hrep, - _minkowski_sum_hrep_preprocess, _normal_Vector + _minkowski_sum_hrep_preprocess, _normal_Vector, + _removevredundancy! using ..HalfSpaceModule: HalfSpace using Random: AbstractRNG, GLOBAL_RNG using ReachabilityBase.Distribution: reseed! diff --git a/src/Sets/HPolytope/vertices_list.jl b/src/Sets/HPolytope/vertices_list.jl index feadd0acdc..30ac55af9f 100644 --- a/src/Sets/HPolytope/vertices_list.jl +++ b/src/Sets/HPolytope/vertices_list.jl @@ -52,7 +52,7 @@ function vertices_list(P::HPolytope; backend=nothing, prune::Bool=true) end Q = Polyhedra.polyhedron(P; backend=backend) if prune - Polyhedra.removevredundancy!(Q; ztol=_ztol(N)) + _removevredundancy!(Q; N=N) end return collect(Polyhedra.points(Q)) end diff --git a/src/Sets/VPolytope/VPolytopeModule.jl b/src/Sets/VPolytope/VPolytopeModule.jl index cc907bc7a5..85ace2dc8b 100644 --- a/src/Sets/VPolytope/VPolytopeModule.jl +++ b/src/Sets/VPolytope/VPolytopeModule.jl @@ -5,7 +5,8 @@ using Reexport, Requires using ..LazySets: AbstractPolytope, LazySet, LinearMapVRep, default_lp_solver, default_lp_solver_polyhedra, default_polyhedra_backend, is_lp_infeasible, is_lp_optimal, linprog, _extrema_vlist, - _high_vlist, _low_vlist, _minkowski_sum_vrep_nd + _high_vlist, _low_vlist, _minkowski_sum_vrep_nd, + _removevredundancy! using LinearAlgebra: dot using Random: AbstractRNG, GLOBAL_RNG using ReachabilityBase.Arrays: projection_matrix diff --git a/src/Sets/VPolytope/remove_redundant_vertices.jl b/src/Sets/VPolytope/remove_redundant_vertices.jl index 30903f68d2..fc894d3730 100644 --- a/src/Sets/VPolytope/remove_redundant_vertices.jl +++ b/src/Sets/VPolytope/remove_redundant_vertices.jl @@ -42,7 +42,7 @@ function remove_redundant_vertices(P::VPolytope; backend=nothing, solver=nothing vQ = Polyhedra.vrep(Q) Polyhedra.setvrep!(Q, Polyhedra.removevredundancy(vQ, solver)) else - Polyhedra.removevredundancy!(Q; ztol=_ztol(N)) + _removevredundancy!(Q; N=N) end return VPolytope(Q) end