mirror of
https://github.com/kalmarek/PropertyT.jl.git
synced 2024-11-22 16:05:27 +01:00
use ProgressMeter instead of poormans progressbar
This commit is contained in:
parent
fca7733280
commit
ca6a17acca
@ -8,6 +8,7 @@ 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"
|
||||||
|
ProgressMeter = "92933f4c-e287-5a05-a399-4b506db050ca"
|
||||||
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
|
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
|
||||||
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
|
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
|
||||||
SymbolicWedderburn = "858aa9a9-4c7c-4c62-b466-2421203962a2"
|
SymbolicWedderburn = "858aa9a9-4c7c-4c62-b466-2421203962a2"
|
||||||
@ -17,6 +18,7 @@ COSMO = "0.8"
|
|||||||
Groups = "0.7"
|
Groups = "0.7"
|
||||||
IntervalArithmetic = "0.20"
|
IntervalArithmetic = "0.20"
|
||||||
JuMP = "1.3"
|
JuMP = "1.3"
|
||||||
|
ProgressMeter = "1.7"
|
||||||
SCS = "1.1.0"
|
SCS = "1.1.0"
|
||||||
StaticArrays = "1"
|
StaticArrays = "1"
|
||||||
SymbolicWedderburn = "0.3.1"
|
SymbolicWedderburn = "0.3.1"
|
||||||
|
@ -182,13 +182,17 @@ function __fast_recursive_dot!(
|
|||||||
return res
|
return res
|
||||||
end
|
end
|
||||||
|
|
||||||
|
import ProgressMeter
|
||||||
|
__show_itrs(n, total) = () -> [(Symbol("constraint"), "$n/$total")]
|
||||||
|
|
||||||
function sos_problem_primal(
|
function sos_problem_primal(
|
||||||
elt::StarAlgebras.AlgebraElement,
|
elt::StarAlgebras.AlgebraElement,
|
||||||
orderunit::StarAlgebras.AlgebraElement,
|
orderunit::StarAlgebras.AlgebraElement,
|
||||||
wedderburn::WedderburnDecomposition;
|
wedderburn::WedderburnDecomposition;
|
||||||
upper_bound=Inf,
|
upper_bound=Inf,
|
||||||
augmented=iszero(StarAlgebras.aug(elt)) && iszero(StarAlgebras.aug(orderunit)),
|
augmented=iszero(StarAlgebras.aug(elt)) && iszero(StarAlgebras.aug(orderunit)),
|
||||||
check_orthogonality=true
|
check_orthogonality=true,
|
||||||
|
show_progress=false
|
||||||
)
|
)
|
||||||
|
|
||||||
@assert parent(elt) === parent(orderunit)
|
@assert parent(elt) === parent(orderunit)
|
||||||
@ -222,7 +226,7 @@ function sos_problem_primal(
|
|||||||
|
|
||||||
begin # preallocating
|
begin # preallocating
|
||||||
T = eltype(wedderburn)
|
T = eltype(wedderburn)
|
||||||
M = spzeros.(T, size.(P))
|
Ms = spzeros.(T, size.(P))
|
||||||
M_orb = zeros(T, size(parent(elt).mstructure)...)
|
M_orb = zeros(T, size(parent(elt).mstructure)...)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -232,36 +236,40 @@ function sos_problem_primal(
|
|||||||
# 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)
|
||||||
|
|
||||||
@info "Adding $(length(invariant_vectors(wedderburn))) constraints"
|
prog = ProgressMeter.Progress(
|
||||||
|
length(invariant_vectors(wedderburn)),
|
||||||
ds = SymbolicWedderburn.direct_summands(wedderburn)
|
dt=1,
|
||||||
Uπs = SymbolicWedderburn.image_basis.(ds)
|
desc="Adding constraints... ",
|
||||||
T = eltype(first(Uπs))
|
enabled=show_progress,
|
||||||
degrees = SymbolicWedderburn.degree.(ds)
|
barlen=60,
|
||||||
|
showspeed=true
|
||||||
|
)
|
||||||
|
|
||||||
for (i, iv) in enumerate(invariant_vectors(wedderburn))
|
for (i, iv) in enumerate(invariant_vectors(wedderburn))
|
||||||
# @debug i
|
ProgressMeter.next!(prog, showvalues=__show_itrs(i, prog.n))
|
||||||
i % 100 == 0 && print('.')
|
|
||||||
i % 10000 === 0 && print('\n')
|
|
||||||
|
|
||||||
x = dot(X, iv)
|
x = dot(X, iv)
|
||||||
u = dot(U, iv)
|
u = dot(U, iv)
|
||||||
|
|
||||||
M_orb = invariant_constraint!(M_orb, basis(parent(elt)), cnstrs, iv)
|
M_orb = invariant_constraint!(M_orb, basis(parent(elt)), cnstrs, iv)
|
||||||
M = SymbolicWedderburn.diagonalize!(M, M_orb, Uπs, degrees)
|
Ms = SymbolicWedderburn.diagonalize!(Ms, M_orb, wedderburn)
|
||||||
SparseArrays.droptol!.(M, 10 * eps(T) * max(size(M_orb)...))
|
SparseArrays.droptol!.(Ms, 10 * eps(T) * max(size(M_orb)...))
|
||||||
|
|
||||||
# @debug [nnz(m) / length(m) for m in M]
|
# @info [nnz(m) / length(m) for m in Ms]
|
||||||
# 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]
|
|
||||||
|
|
||||||
if feasibility_problem
|
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
|
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
|
||||||
end
|
end
|
||||||
|
ProgressMeter.finish!(prog)
|
||||||
return model, P
|
return model, P
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user