diff --git a/Project.toml b/Project.toml index ade1715..cad256d 100644 --- a/Project.toml +++ b/Project.toml @@ -8,6 +8,7 @@ Groups = "5d8bd718-bd84-11e8-3b40-ad14f4a32557" IntervalArithmetic = "d1acc4aa-44c8-5952-acd4-ba5d80a2a253" JuMP = "4076af6c-e467-56ae-b986-b466b2749572" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" +ProgressMeter = "92933f4c-e287-5a05-a399-4b506db050ca" SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" SymbolicWedderburn = "858aa9a9-4c7c-4c62-b466-2421203962a2" @@ -17,6 +18,7 @@ COSMO = "0.8" Groups = "0.7" IntervalArithmetic = "0.20" JuMP = "1.3" +ProgressMeter = "1.7" SCS = "1.1.0" StaticArrays = "1" SymbolicWedderburn = "0.3.1" diff --git a/src/sos_sdps.jl b/src/sos_sdps.jl index bbcba67..96c71c3 100644 --- a/src/sos_sdps.jl +++ b/src/sos_sdps.jl @@ -182,13 +182,17 @@ function __fast_recursive_dot!( return res end +import ProgressMeter +__show_itrs(n, total) = () -> [(Symbol("constraint"), "$n/$total")] + function sos_problem_primal( elt::StarAlgebras.AlgebraElement, orderunit::StarAlgebras.AlgebraElement, wedderburn::WedderburnDecomposition; upper_bound=Inf, augmented=iszero(StarAlgebras.aug(elt)) && iszero(StarAlgebras.aug(orderunit)), - check_orthogonality=true + check_orthogonality=true, + show_progress=false ) @assert parent(elt) === parent(orderunit) @@ -222,7 +226,7 @@ function sos_problem_primal( begin # preallocating T = eltype(wedderburn) - M = spzeros.(T, size.(P)) + Ms = spzeros.(T, size.(P)) M_orb = zeros(T, size(parent(elt).mstructure)...) end @@ -232,36 +236,40 @@ function sos_problem_primal( # defining constraints based on the multiplicative structure cnstrs = constraints(parent(elt), augmented=augmented, twisted=true) - @info "Adding $(length(invariant_vectors(wedderburn))) constraints" - - ds = SymbolicWedderburn.direct_summands(wedderburn) - Uπs = SymbolicWedderburn.image_basis.(ds) - T = eltype(first(Uπs)) - degrees = SymbolicWedderburn.degree.(ds) + prog = ProgressMeter.Progress( + length(invariant_vectors(wedderburn)), + dt=1, + desc="Adding constraints... ", + enabled=show_progress, + barlen=60, + showspeed=true + ) for (i, iv) in enumerate(invariant_vectors(wedderburn)) - # @debug i - i % 100 == 0 && print('.') - i % 10000 === 0 && print('\n') + ProgressMeter.next!(prog, showvalues=__show_itrs(i, prog.n)) x = dot(X, iv) u = dot(U, iv) M_orb = invariant_constraint!(M_orb, basis(parent(elt)), cnstrs, iv) - M = SymbolicWedderburn.diagonalize!(M, M_orb, Uπs, degrees) - SparseArrays.droptol!.(M, 10 * eps(T) * max(size(M_orb)...)) + Ms = SymbolicWedderburn.diagonalize!(Ms, M_orb, wedderburn) + SparseArrays.droptol!.(Ms, 10 * eps(T) * max(size(M_orb)...)) - # @debug [nnz(m) / length(m) for m in M] - # spM = sparse.(M) - # @time M_dot_P = sum(dot(spM[π], P[π]) for π in eachindex(spM) if !iszero(spM[π])) - # @info density = [count(!iszero, m) / sum(length, m) for m in M] + # @info [nnz(m) / length(m) for m in Ms] if feasibility_problem - JuMP.@constraint(model, x == __fast_recursive_dot!(JuMP.AffExpr(), P, M)) + JuMP.@constraint( + model, + x == __fast_recursive_dot!(JuMP.AffExpr(), P, Ms) + ) else - JuMP.@constraint(model, x - λ * u == __fast_recursive_dot!(JuMP.AffExpr(), P, M)) + JuMP.@constraint( + model, + x - λ * u == __fast_recursive_dot!(JuMP.AffExpr(), P, Ms) + ) end end + ProgressMeter.finish!(prog) return model, P end