1
0
mirror of https://github.com/kalmarek/PropertyT.jl.git synced 2024-11-19 07:20:28 +01:00

cleanup Project.toml and fix imports

This commit is contained in:
Marek Kaluba 2022-11-07 17:01:06 +01:00
parent f00bfb7ca9
commit 633f065488
No known key found for this signature in database
GPG Key ID: 8BF1A3855328FC15
8 changed files with 68 additions and 53 deletions

View File

@ -4,23 +4,32 @@ authors = ["Marek Kaluba <kalmar@amu.edu.pl>"]
version = "0.3.2" version = "0.3.2"
[deps] [deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" Groups = "5d8bd718-bd84-11e8-3b40-ad14f4a32557"
IntervalArithmetic = "d1acc4aa-44c8-5952-acd4-ba5d80a2a253" IntervalArithmetic = "d1acc4aa-44c8-5952-acd4-ba5d80a2a253"
JuMP = "4076af6c-e467-56ae-b986-b466b2749572" JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
SCS = "c946c3f1-0d1f-5ce8-9dea-7daa1f7e2d13"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
SymbolicWedderburn = "858aa9a9-4c7c-4c62-b466-2421203962a2" SymbolicWedderburn = "858aa9a9-4c7c-4c62-b466-2421203962a2"
[compat] [compat]
IntervalArithmetic = "^0.16.0" COSMO = "0.8"
JuMP = "^0.20.0" Groups = "0.7"
SCS = "^0.7.0" IntervalArithmetic = "0.20"
julia = "^1.3.0" JuMP = "1.3"
SCS = "1.1.0"
StaticArrays = "1"
SymbolicWedderburn = "0.3.1"
julia = "1.6"
[extras] [extras]
COSMO = "1e616198-aa4e-51ec-90a2-23f7fbd31d8d"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
SCS = "c946c3f1-0d1f-5ce8-9dea-7daa1f7e2d13" SCS = "c946c3f1-0d1f-5ce8-9dea-7daa1f7e2d13"
Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
[targets] [targets]
test = ["Test", "SCS"] scripts = ["Dates", "Logging", "Serialization", "SCS", "COSMO"]
test = ["Test", "SCS", "COSMO"]

View File

@ -3,14 +3,15 @@ module PropertyT
using LinearAlgebra using LinearAlgebra
using SparseArrays using SparseArrays
using Dates
using IntervalArithmetic using IntervalArithmetic
using JuMP using JuMP
using Groups using Groups
using StarAlgebras import Groups.GroupsCore
using SymbolicWedderburn using SymbolicWedderburn
import SymbolicWedderburn.StarAlgebras
import SymbolicWedderburn.PermutationGroups
include("constraint_matrix.jl") include("constraint_matrix.jl")
include("sos_sdps.jl") include("sos_sdps.jl")

View File

@ -1,5 +1,5 @@
import SymbolicWedderburn.action import SymbolicWedderburn.action
StarAlgebras.star(g::GroupElement) = inv(g) StarAlgebras.star(g::Groups.GroupElement) = inv(g)
include("alphabet_permutation.jl") include("alphabet_permutation.jl")

View File

@ -1,7 +1,9 @@
## action induced from permuting letters of an alphabet ## action induced from permuting letters of an alphabet
import Groups: Constructions
struct AlphabetPermutation{GEl,I} <: SymbolicWedderburn.ByPermutations struct AlphabetPermutation{GEl,I} <: SymbolicWedderburn.ByPermutations
perms::Dict{GEl,Perm{I}} perms::Dict{GEl,PermutationGroups.Perm{I}}
end end
function AlphabetPermutation( function AlphabetPermutation(
@ -10,14 +12,14 @@ function AlphabetPermutation(
op, op,
) )
return AlphabetPermutation( return AlphabetPermutation(
Dict(γ => inv(Perm([A[op(l, γ)] for l in A])) for γ in Γ), Dict(γ => inv(PermutationGroups.Perm([A[op(l, γ)] for l in A])) for γ in Γ),
) )
end end
function AlphabetPermutation(A::Alphabet, W::Constructions.WreathProduct, op) function AlphabetPermutation(A::Alphabet, W::Constructions.WreathProduct, op)
return AlphabetPermutation( return AlphabetPermutation(
Dict( Dict(
w => inv(Perm([A[op(op(l, w.p), w.n)] for l in A])) for w => inv(PermutationGroups.Perm([A[op(op(l, w.p), w.n)] for l in A])) for
w in W w in W
), ),
) )
@ -25,7 +27,7 @@ end
function SymbolicWedderburn.action( function SymbolicWedderburn.action(
act::AlphabetPermutation, act::AlphabetPermutation,
γ::GroupElement, γ::Groups.GroupElement,
w::Groups.AbstractWord, w::Groups.AbstractWord,
) )
return w^(act.perms[γ]) return w^(act.perms[γ])
@ -33,7 +35,7 @@ end
function SymbolicWedderburn.action( function SymbolicWedderburn.action(
act::AlphabetPermutation, act::AlphabetPermutation,
γ::GroupElement, γ::Groups.GroupElement,
g::Groups.AbstractFPGroupElement, g::Groups.AbstractFPGroupElement,
) )
G = parent(g) G = parent(g)

View File

@ -34,7 +34,7 @@ function _fma_SOS_thr!(
return result return result
end end
function _cnstr_sos!(res::AlgebraElement, Q::AbstractMatrix, cnstrs) function _cnstr_sos!(res::StarAlgebras.AlgebraElement, Q::AbstractMatrix, cnstrs)
StarAlgebras.zero!(res) StarAlgebras.zero!(res)
= Q' * Q = Q' * Q
for (g, A_g) in cnstrs for (g, A_g) in cnstrs
@ -43,7 +43,7 @@ function _cnstr_sos!(res::AlgebraElement, Q::AbstractMatrix, cnstrs)
return res return res
end end
function _augmented_sos!(res::AlgebraElement, Q::AbstractMatrix) function _augmented_sos!(res::StarAlgebras.AlgebraElement, Q::AbstractMatrix)
A = parent(res) A = parent(res)
StarAlgebras.zero!(res) StarAlgebras.zero!(res)
= Q' * Q = Q' * Q
@ -64,10 +64,10 @@ function _augmented_sos!(res::AlgebraElement, Q::AbstractMatrix)
return res return res
end end
function compute_sos(A::StarAlgebra, Q::AbstractMatrix; augmented::Bool) function compute_sos(A::StarAlgebras.StarAlgebra, Q::AbstractMatrix; augmented::Bool)
if augmented if augmented
z = zeros(eltype(Q), length(basis(A))) z = zeros(eltype(Q), length(basis(A)))
res = AlgebraElement(z, A) res = StarAlgebras.AlgebraElement(z, A)
return _augmented_sos!(res, Q) return _augmented_sos!(res, Q)
cnstrs = constraints(basis(A), A.mstructure; augmented=true) cnstrs = constraints(basis(A), A.mstructure; augmented=true)
return _cnstr_sos!(res, Q, cnstrs) return _cnstr_sos!(res, Q, cnstrs)
@ -77,11 +77,11 @@ function compute_sos(A::StarAlgebra, Q::AbstractMatrix; augmented::Bool)
_fma_SOS_thr!(z, A.mstructure, Q) _fma_SOS_thr!(z, A.mstructure, Q)
return AlgebraElement(z, A) return StarAlgebras.AlgebraElement(z, A)
end end
end end
function sufficient_λ(residual::AlgebraElement, λ; halfradius) function sufficient_λ(residual::StarAlgebras.AlgebraElement, λ; halfradius)
L1_norm = norm(residual, 1) L1_norm = norm(residual, 1)
suff_λ = λ - 2.0^(2ceil(log2(halfradius))) * L1_norm suff_λ = λ - 2.0^(2ceil(log2(halfradius))) * L1_norm
@ -97,7 +97,7 @@ function sufficient_λ(residual::AlgebraElement, λ; halfradius)
info_strs = [ info_strs = [
"Numerical metrics of the obtained SOS:", "Numerical metrics of the obtained SOS:",
"ɛ(elt - λu - ∑ξᵢ*ξᵢ) $eq_sign $(aug(residual))", "ɛ(elt - λu - ∑ξᵢ*ξᵢ) $eq_sign $(StarAlgebras.aug(residual))",
"‖elt - λu - ∑ξᵢ*ξᵢ‖₁ $eq_sign $(L1_norm)", "‖elt - λu - ∑ξᵢ*ξᵢ‖₁ $eq_sign $(L1_norm)",
" λ $eq_sign $suff_λ", " λ $eq_sign $suff_λ",
] ]
@ -107,10 +107,10 @@ function sufficient_λ(residual::AlgebraElement, λ; halfradius)
end end
function sufficient_λ( function sufficient_λ(
elt::AlgebraElement, elt::StarAlgebras.AlgebraElement,
order_unit::AlgebraElement, order_unit::StarAlgebras.AlgebraElement,
λ, λ,
sos::AlgebraElement; sos::StarAlgebras.AlgebraElement;
halfradius halfradius
) )
@ -121,15 +121,15 @@ function sufficient_λ(
end end
function certify_solution( function certify_solution(
elt::AlgebraElement, elt::StarAlgebras.AlgebraElement,
orderunit::AlgebraElement, orderunit::StarAlgebras.AlgebraElement,
λ, λ,
Q::AbstractMatrix{<:AbstractFloat}; Q::AbstractMatrix{<:AbstractFloat};
halfradius, halfradius,
augmented=iszero(aug(elt)) && iszero(aug(orderunit)) augmented=iszero(StarAlgebras.aug(elt)) && iszero(StarAlgebras.aug(orderunit))
) )
should_we_augment = !augmented && aug(elt) == aug(orderunit) == 0 should_we_augment = !augmented && StarAlgebras.aug(elt) == StarAlgebras.aug(orderunit) == 0
Q = should_we_augment ? augment_columns!(Q) : Q Q = should_we_augment ? augment_columns!(Q) : Q
@time sos = compute_sos(parent(elt), Q, augmented=augmented) @time sos = compute_sos(parent(elt), Q, augmented=augmented)

View File

@ -46,7 +46,7 @@ function _groupby(keys::AbstractVector{K}, vals::AbstractVector{V}) where {K,V}
return d return d
end end
function laplacians(RG::StarAlgebra, S, grading) function laplacians(RG::StarAlgebras.StarAlgebra, S, grading)
d = _groupby(grading, S) d = _groupby(grading, S)
Δs = Dict(α => RG(length(Sα)) - sum(RG(s) for s in Sα) for (α, Sα) in d) Δs = Dict(α => RG(length(Sα)) - sum(RG(s) for s in Sα) for (α, Sα) in d)
return Δs return Δs
@ -61,7 +61,7 @@ function Adj(rootsystem::AbstractDict, subtype::Symbol)
+, +,
( (
Δα * Δβ for (α, Δα) in rootsystem for (β, Δβ) in rootsystem if Δα * Δβ for (α, Δα) in rootsystem for (β, Δβ) in rootsystem if
PropertyT_new.Roots.classify_sub_root_system( Roots.classify_sub_root_system(
roots, roots,
first(α), first(α),
first(β), first(β),

View File

@ -5,8 +5,8 @@ Formulate the dual to the sum of squares decomposition problem for `X - λ·u`.
See also [sos_problem_primal](@ref). See also [sos_problem_primal](@ref).
""" """
function sos_problem_dual( function sos_problem_dual(
elt::AlgebraElement, elt::StarAlgebras.AlgebraElement,
order_unit::AlgebraElement=zero(elt); order_unit::StarAlgebras.AlgebraElement=zero(elt);
lower_bound=-Inf lower_bound=-Inf
) )
@assert parent(elt) == parent(order_unit) @assert parent(elt) == parent(order_unit)
@ -70,7 +70,7 @@ function constraints(
a, b = basis[i], basis[j] a, b = basis[i], basis[j]
push!(cnstrs[basis[one(a)]], k) push!(cnstrs[basis[one(a)]], k)
push!(cnstrs[basis[star(a)]], -k) push!(cnstrs[basis[StarAlgebras.star(a)]], -k)
push!(cnstrs[basis[b]], -k) push!(cnstrs[basis[b]], -k)
end end
end end
@ -80,7 +80,7 @@ function constraints(
) )
end end
function constraints(A::StarAlgebra; augmented::Bool, twisted::Bool) function constraints(A::StarAlgebras.StarAlgebra; augmented::Bool, twisted::Bool)
mstructure = if StarAlgebras._istwisted(A.mstructure) == twisted mstructure = if StarAlgebras._istwisted(A.mstructure) == twisted
A.mstructure A.mstructure
else else
@ -108,10 +108,10 @@ be added to the model. This may improve the accuracy of the solution if
The default `u = zero(X)` formulates a simple feasibility problem. The default `u = zero(X)` formulates a simple feasibility problem.
""" """
function sos_problem_primal( function sos_problem_primal(
elt::AlgebraElement, elt::StarAlgebras.AlgebraElement,
order_unit::AlgebraElement=zero(elt); order_unit::StarAlgebras.AlgebraElement=zero(elt);
upper_bound=Inf, upper_bound=Inf,
augmented::Bool=iszero(aug(elt)) && iszero(aug(order_unit)) augmented::Bool=iszero(StarAlgebras.aug(elt)) && iszero(StarAlgebras.aug(order_unit))
) )
@assert parent(elt) === parent(order_unit) @assert parent(elt) === parent(order_unit)
@ -168,23 +168,26 @@ function isorth_projection(ds::SymbolicWedderburn.DirectSummand)
end end
sos_problem_primal( sos_problem_primal(
elt::AlgebraElement, elt::StarAlgebras.AlgebraElement,
wedderburn::WedderburnDecomposition; wedderburn::WedderburnDecomposition;
kwargs... kwargs...
) = sos_problem_primal(elt, zero(elt), wedderburn; kwargs...) ) = sos_problem_primal(elt, zero(elt), wedderburn; kwargs...)
function sos_problem_primal( function sos_problem_primal(
elt::AlgebraElement, elt::StarAlgebras.AlgebraElement,
orderunit::AlgebraElement, orderunit::StarAlgebras.AlgebraElement,
wedderburn::WedderburnDecomposition; wedderburn::WedderburnDecomposition;
upper_bound=Inf, upper_bound=Inf,
augmented=iszero(aug(elt)) && iszero(aug(orderunit)) augmented=iszero(StarAlgebras.aug(elt)) && iszero(StarAlgebras.aug(orderunit)),
check_orthogonality=true
) )
@assert parent(elt) === parent(orderunit) @assert parent(elt) === parent(orderunit)
if check_orthogonality
if any(!isorth_projection, direct_summands(wedderburn)) if any(!isorth_projection, direct_summands(wedderburn))
error("Wedderburn decomposition contains a non-orthogonal projection") error("Wedderburn decomposition contains a non-orthogonal projection")
end end
end
feasibility_problem = iszero(orderunit) feasibility_problem = iszero(orderunit)
@ -215,8 +218,8 @@ function sos_problem_primal(
tmps = SymbolicWedderburn._tmps(wedderburn) tmps = SymbolicWedderburn._tmps(wedderburn)
end end
X = convert(Vector{T}, coeffs(elt)) X = convert(Vector{T}, StarAlgebras.coeffs(elt))
U = convert(Vector{T}, coeffs(orderunit)) U = convert(Vector{T}, StarAlgebras.coeffs(orderunit))
# defining constraints based on the multiplicative structure # defining constraints based on the multiplicative structure
cnstrs = constraints(parent(elt), augmented=augmented, twisted=true) cnstrs = constraints(parent(elt), augmented=augmented, twisted=true)
@ -278,7 +281,7 @@ function reconstruct!(
if eltype(res) <: AbstractFloat if eltype(res) <: AbstractFloat
SymbolicWedderburn.zerotol!(tmp2, atol=1e-12) SymbolicWedderburn.zerotol!(tmp2, atol=1e-12)
end end
tmp2 .*= degree(ds) tmp2 .*= SymbolicWedderburn.degree(ds)
@assert size(tmp2) == size(res) @assert size(tmp2) == size(res)
@ -291,7 +294,7 @@ function reconstruct!(
end end
end end
end end
res ./= order(Int, G) res ./= Groups.order(Int, G)
return res return res
end end

View File

@ -1,4 +1,4 @@
import PermutationGroups.AbstractPerm import SymbolicWedderburn.PermutationGroups.AbstractPerm
# move to Groups # move to Groups
Base.keys(a::Alphabet) = keys(1:length(a)) Base.keys(a::Alphabet) = keys(1:length(a))
@ -15,7 +15,7 @@ isadjacent(σ::AbstractPerm, τ::AbstractPerm, i=1, j=2) =
(j^σ == i^τ && i^σ j^τ) # second σ equal to first τ (j^σ == i^τ && i^σ j^τ) # second σ equal to first τ
function _ncycle(start, length, n=start + length - 1) function _ncycle(start, length, n=start + length - 1)
p = Perm(Int8(n)) p = PermutationGroups.Perm(Int8(n))
@assert n start + length - 1 @assert n start + length - 1
for k in start:start+length-2 for k in start:start+length-2
p[k] = k + 1 p[k] = k + 1
@ -24,7 +24,7 @@ function _ncycle(start, length, n=start + length - 1)
return p return p
end end
alternating_group(n::Integer) = PermGroup([_ncycle(i, 3) for i in 1:n-2]) alternating_group(n::Integer) = PermutationGroups.PermGroup([_ncycle(i, 3) for i in 1:n-2])
function small_gens(G::MatrixGroups.SpecialLinearGroup) function small_gens(G::MatrixGroups.SpecialLinearGroup)
A = alphabet(G) A = alphabet(G)
@ -46,13 +46,13 @@ function small_gens(G::Groups.AutomorphismGroup{<:FreeGroup})
return union!(S, inv.(S)) return union!(S, inv.(S))
end end
function small_laplacian(RG::StarAlgebra) function small_laplacian(RG::StarAlgebras.StarAlgebra)
G = StarAlgebras.object(RG) G = StarAlgebras.object(RG)
S₂ = small_gens(G) S₂ = small_gens(G)
return length(S₂) * one(RG) - sum(RG(s) for s in S₂) return length(S₂) * one(RG) - sum(RG(s) for s in S₂)
end end
function SqAdjOp(A::StarAlgebra, n::Integer, Δ₂=small_laplacian(A)) function SqAdjOp(A::StarAlgebras.StarAlgebra, n::Integer, Δ₂=small_laplacian(A))
@assert parent(Δ₂) === A @assert parent(Δ₂) === A
alt_n = alternating_group(n) alt_n = alternating_group(n)