1
0
mirror of https://github.com/kalmarek/PropertyT.jl.git synced 2024-12-24 02:00:30 +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"
[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Groups = "5d8bd718-bd84-11e8-3b40-ad14f4a32557"
IntervalArithmetic = "d1acc4aa-44c8-5952-acd4-ba5d80a2a253"
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
SCS = "c946c3f1-0d1f-5ce8-9dea-7daa1f7e2d13"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
SymbolicWedderburn = "858aa9a9-4c7c-4c62-b466-2421203962a2"
[compat]
IntervalArithmetic = "^0.16.0"
JuMP = "^0.20.0"
SCS = "^0.7.0"
julia = "^1.3.0"
COSMO = "0.8"
Groups = "0.7"
IntervalArithmetic = "0.20"
JuMP = "1.3"
SCS = "1.1.0"
StaticArrays = "1"
SymbolicWedderburn = "0.3.1"
julia = "1.6"
[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"
Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
[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 SparseArrays
using Dates
using IntervalArithmetic
using JuMP
using Groups
using StarAlgebras
import Groups.GroupsCore
using SymbolicWedderburn
import SymbolicWedderburn.StarAlgebras
import SymbolicWedderburn.PermutationGroups
include("constraint_matrix.jl")
include("sos_sdps.jl")

View File

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

View File

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

View File

@ -34,7 +34,7 @@ function _fma_SOS_thr!(
return result
end
function _cnstr_sos!(res::AlgebraElement, Q::AbstractMatrix, cnstrs)
function _cnstr_sos!(res::StarAlgebras.AlgebraElement, Q::AbstractMatrix, cnstrs)
StarAlgebras.zero!(res)
= Q' * Q
for (g, A_g) in cnstrs
@ -43,7 +43,7 @@ function _cnstr_sos!(res::AlgebraElement, Q::AbstractMatrix, cnstrs)
return res
end
function _augmented_sos!(res::AlgebraElement, Q::AbstractMatrix)
function _augmented_sos!(res::StarAlgebras.AlgebraElement, Q::AbstractMatrix)
A = parent(res)
StarAlgebras.zero!(res)
= Q' * Q
@ -64,10 +64,10 @@ function _augmented_sos!(res::AlgebraElement, Q::AbstractMatrix)
return res
end
function compute_sos(A::StarAlgebra, Q::AbstractMatrix; augmented::Bool)
function compute_sos(A::StarAlgebras.StarAlgebra, Q::AbstractMatrix; augmented::Bool)
if augmented
z = zeros(eltype(Q), length(basis(A)))
res = AlgebraElement(z, A)
res = StarAlgebras.AlgebraElement(z, A)
return _augmented_sos!(res, Q)
cnstrs = constraints(basis(A), A.mstructure; augmented=true)
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)
return AlgebraElement(z, A)
return StarAlgebras.AlgebraElement(z, A)
end
end
function sufficient_λ(residual::AlgebraElement, λ; halfradius)
function sufficient_λ(residual::StarAlgebras.AlgebraElement, λ; halfradius)
L1_norm = norm(residual, 1)
suff_λ = λ - 2.0^(2ceil(log2(halfradius))) * L1_norm
@ -97,7 +97,7 @@ function sufficient_λ(residual::AlgebraElement, λ; halfradius)
info_strs = [
"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)",
" λ $eq_sign $suff_λ",
]
@ -107,10 +107,10 @@ function sufficient_λ(residual::AlgebraElement, λ; halfradius)
end
function sufficient_λ(
elt::AlgebraElement,
order_unit::AlgebraElement,
elt::StarAlgebras.AlgebraElement,
order_unit::StarAlgebras.AlgebraElement,
λ,
sos::AlgebraElement;
sos::StarAlgebras.AlgebraElement;
halfradius
)
@ -121,15 +121,15 @@ function sufficient_λ(
end
function certify_solution(
elt::AlgebraElement,
orderunit::AlgebraElement,
elt::StarAlgebras.AlgebraElement,
orderunit::StarAlgebras.AlgebraElement,
λ,
Q::AbstractMatrix{<:AbstractFloat};
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
@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
end
function laplacians(RG::StarAlgebra, S, grading)
function laplacians(RG::StarAlgebras.StarAlgebra, S, grading)
d = _groupby(grading, S)
Δs = Dict(α => RG(length(Sα)) - sum(RG(s) for s in Sα) for (α, Sα) in d)
return Δs
@ -61,7 +61,7 @@ function Adj(rootsystem::AbstractDict, subtype::Symbol)
+,
(
Δα * Δβ for (α, Δα) in rootsystem for (β, Δβ) in rootsystem if
PropertyT_new.Roots.classify_sub_root_system(
Roots.classify_sub_root_system(
roots,
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).
"""
function sos_problem_dual(
elt::AlgebraElement,
order_unit::AlgebraElement=zero(elt);
elt::StarAlgebras.AlgebraElement,
order_unit::StarAlgebras.AlgebraElement=zero(elt);
lower_bound=-Inf
)
@assert parent(elt) == parent(order_unit)
@ -70,7 +70,7 @@ function constraints(
a, b = basis[i], basis[j]
push!(cnstrs[basis[one(a)]], k)
push!(cnstrs[basis[star(a)]], -k)
push!(cnstrs[basis[StarAlgebras.star(a)]], -k)
push!(cnstrs[basis[b]], -k)
end
end
@ -80,7 +80,7 @@ function constraints(
)
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
A.mstructure
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.
"""
function sos_problem_primal(
elt::AlgebraElement,
order_unit::AlgebraElement=zero(elt);
elt::StarAlgebras.AlgebraElement,
order_unit::StarAlgebras.AlgebraElement=zero(elt);
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)
@ -168,22 +168,25 @@ function isorth_projection(ds::SymbolicWedderburn.DirectSummand)
end
sos_problem_primal(
elt::AlgebraElement,
elt::StarAlgebras.AlgebraElement,
wedderburn::WedderburnDecomposition;
kwargs...
) = sos_problem_primal(elt, zero(elt), wedderburn; kwargs...)
function sos_problem_primal(
elt::AlgebraElement,
orderunit::AlgebraElement,
elt::StarAlgebras.AlgebraElement,
orderunit::StarAlgebras.AlgebraElement,
wedderburn::WedderburnDecomposition;
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)
if any(!isorth_projection, direct_summands(wedderburn))
error("Wedderburn decomposition contains a non-orthogonal projection")
if check_orthogonality
if any(!isorth_projection, direct_summands(wedderburn))
error("Wedderburn decomposition contains a non-orthogonal projection")
end
end
feasibility_problem = iszero(orderunit)
@ -215,8 +218,8 @@ function sos_problem_primal(
tmps = SymbolicWedderburn._tmps(wedderburn)
end
X = convert(Vector{T}, coeffs(elt))
U = convert(Vector{T}, coeffs(orderunit))
X = convert(Vector{T}, StarAlgebras.coeffs(elt))
U = convert(Vector{T}, StarAlgebras.coeffs(orderunit))
# defining constraints based on the multiplicative structure
cnstrs = constraints(parent(elt), augmented=augmented, twisted=true)
@ -278,7 +281,7 @@ function reconstruct!(
if eltype(res) <: AbstractFloat
SymbolicWedderburn.zerotol!(tmp2, atol=1e-12)
end
tmp2 .*= degree(ds)
tmp2 .*= SymbolicWedderburn.degree(ds)
@assert size(tmp2) == size(res)
@ -291,7 +294,7 @@ function reconstruct!(
end
end
end
res ./= order(Int, G)
res ./= Groups.order(Int, G)
return res
end

View File

@ -1,4 +1,4 @@
import PermutationGroups.AbstractPerm
import SymbolicWedderburn.PermutationGroups.AbstractPerm
# move to Groups
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 τ
function _ncycle(start, length, n=start + length - 1)
p = Perm(Int8(n))
p = PermutationGroups.Perm(Int8(n))
@assert n start + length - 1
for k in start:start+length-2
p[k] = k + 1
@ -24,7 +24,7 @@ function _ncycle(start, length, n=start + length - 1)
return p
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)
A = alphabet(G)
@ -46,13 +46,13 @@ function small_gens(G::Groups.AutomorphismGroup{<:FreeGroup})
return union!(S, inv.(S))
end
function small_laplacian(RG::StarAlgebra)
function small_laplacian(RG::StarAlgebras.StarAlgebra)
G = StarAlgebras.object(RG)
S₂ = small_gens(G)
return length(S₂) * one(RG) - sum(RG(s) for s in S₂)
end
function SqAdjOp(A::StarAlgebra, n::Integer, Δ₂=small_laplacian(A))
function SqAdjOp(A::StarAlgebras.StarAlgebra, n::Integer, Δ₂=small_laplacian(A))
@assert parent(Δ₂) === A
alt_n = alternating_group(n)