From 4a0eb76646586c438f1f25d6db3cdb016801092e Mon Sep 17 00:00:00 2001 From: schillic Date: Sat, 6 Apr 2024 10:18:57 +0200 Subject: [PATCH 1/2] fix piracies with MathematicalSystems --- src/write.jl | 78 ++++++++++++++++++++++------------------------------ 1 file changed, 33 insertions(+), 45 deletions(-) diff --git a/src/write.jl b/src/write.jl index cce7261..2487d16 100644 --- a/src/write.jl +++ b/src/write.jl @@ -1,31 +1,3 @@ -# ============== -# API extensions -# ============== - -function MathematicalSystems.statedim(H::HybridSystem) - ns = [statedim(H, i) for i in 1:nmodes(H)] - if !all(==(ns[1]), ns) - @warn("the number of state dimensions differs across locations") - end - return maximum(ns) -end - -function MathematicalSystems.inputdim(H::HybridSystem) - ms = [inputdim(H, i) for i in 1:nmodes(H)] - if !all(==(ms[1]), ms) - @warn("the number of input dimensions differs across locations") - end - return maximum(ms) -end - -function MathematicalSystems.isconstrained(X::LazySet) - return !isuniversal(X) -end - -function MathematicalSystems.isconstrained(v::AbstractVector{<:LazySet}) - return !all(isuniversal, v) -end - # =========== # Indentation # =========== @@ -153,19 +125,37 @@ function _write_invariant(io, system, dictionary, indentation) return # nothing to write end - _write_indented(io, "", indentation) - indent!(indentation) + wrote_prefix = false X = stateset(system) - if !isnothing(X) + if !isnothing(X) && !isuniversal(X) + if !wrote_prefix + _write_invariant_prefix(io, indentation) + wrote_prefix = true + end _write_state_constraints_specific(io, system, X, dictionary, indentation) end U = inputset(system) - if !isnothing(U) + if !isnothing(U) && !isuniversal(U) + if !wrote_prefix + _write_invariant_prefix(io, indentation) + wrote_prefix = true + end _write_input_constraints_specific(io, system, U, dictionary, indentation) end + if wrote_prefix + _write_invariant_suffix(io, indentation) + end +end + +function _write_invariant_prefix(io, indentation) + _write_indented(io, "", indentation) + return indent!(indentation) +end + +function _write_invariant_suffix(io, indentation) dedent!(indentation) return write(io, "\n") end @@ -176,11 +166,6 @@ function _write_state_constraints_specific(::IO, ::AbstractSystem, X, ::Dict, "not supported and will be ignored") end -function _write_state_constraints_specific(::IO, ::AbstractSystem, ::Universe, ::Dict, - ::Indentation) - # nothing to write -end - function _write_state_constraints_specific(io::IO, ::AbstractSystem, X::AbstractHyperrectangle, dictionary::Dict, ::Indentation) for i in 1:dim(X) @@ -237,7 +222,7 @@ function _write_state_constraints_specific(io::IO, ::AbstractSystem, return write(io, " $operator $b") end -function _write_state_constraints_specific(io::IO, system::Dict, X::AbstractVector{<:LazySet}, +function _write_state_constraints_specific(io::IO, system::Dict, X::Intersection, dictionary::Dict, indentation::Indentation) first = true for Xi in X @@ -255,11 +240,6 @@ function _write_input_constraints_specific(::IO, system, U, dictionary, indentat "not supported and will be ignored") end -function _write_input_constraints_specific(::IO, system, U::Universe, dictionary, - indentation) - # nothing to write -end - function _write_input_constraints_specific(io::IO, ::AbstractSystem, U::AbstractHyperrectangle, dictionary, ::Indentation) for i in 1:dim(U) @@ -404,7 +384,7 @@ end function _write_guard(io, H, transition, dictionary, indentation) G = guard(H, transition) - if !isconstrained(G) + if isuniversal(G) return # nothing to write end _write_indented(io, "", indentation) @@ -418,7 +398,7 @@ function _write_assignment(io, H, transition, dictionary, indentation) return # nothing to write end - n = statedim(H) + n = _statedim(H) if asgn isa AbstractMap if (asgn isa IdentityMap) || (asgn isa ConstrainedIdentityMap) return # nothing to write @@ -502,3 +482,11 @@ function _write_assignment(io, H, transition, dictionary, indentation) end return write(io, "\n") end + +function _statedim(H::HybridSystem) + ns = [statedim(H, i) for i in 1:nmodes(H)] + if !all(==(ns[1]), ns) + @warn("the number of state dimensions differs across locations") + end + return maximum(ns) +end From df5de70d5e2c68d20db98c4b198927c03ceb545e Mon Sep 17 00:00:00 2001 From: schillic Date: Fri, 28 Jun 2024 20:40:08 +0200 Subject: [PATCH 2/2] activate piracy check in Aqua --- test/Aqua.jl | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/Aqua.jl b/test/Aqua.jl index 6c0778c..e20464c 100644 --- a/test/Aqua.jl +++ b/test/Aqua.jl @@ -2,9 +2,7 @@ using SpaceExParser, Test import Aqua @testset "Aqua tests" begin - Aqua.test_all(SpaceExParser; ambiguities=false, - # the piracies should be resolved in the future - piracies=(broken=true,)) + Aqua.test_all(SpaceExParser; ambiguities=false) # do not warn about ambiguities in dependencies Aqua.test_ambiguities(SpaceExParser)