mirror of
https://github.com/kalmarek/PropertyT.jl.git
synced 2024-12-26 02:30:29 +01:00
fix Memento deprecations; make clear when logger is global
This commit is contained in:
parent
ce34633df7
commit
fc54803b58
@ -51,10 +51,10 @@ function distance_to_cone{T<:Interval}(elt::GroupRingElem, Q::AbstractArray{T,2}
|
||||
SOS_diff = elt - SOS
|
||||
|
||||
ɛ_dist = GroupRings.augmentation(SOS_diff)
|
||||
info(logger, "ɛ(∑ξᵢ*ξᵢ) ∈ $(ɛ_dist)")
|
||||
info(LOGGER, "ɛ(∑ξᵢ*ξᵢ) ∈ $(ɛ_dist)")
|
||||
|
||||
eoi_SOS_L1_dist = norm(SOS_diff,1)
|
||||
info(logger, "‖Δ² - λΔ - ∑ξᵢ*ξᵢ‖₁ ∈ $(eoi_SOS_L1_dist)")
|
||||
info(LOGGER, "‖Δ² - λΔ - ∑ξᵢ*ξᵢ‖₁ ∈ $(eoi_SOS_L1_dist)")
|
||||
|
||||
dist = 2^(wlen-1)*eoi_SOS_L1_dist
|
||||
return dist
|
||||
@ -65,10 +65,10 @@ function distance_to_cone{T}(elt::GroupRingElem, Q::AbstractArray{T,2}, wlen::In
|
||||
SOS_diff = elt - SOS
|
||||
|
||||
ɛ_dist = GroupRings.augmentation(SOS_diff)
|
||||
info(logger, "ɛ(Δ² - λΔ - ∑ξᵢ*ξᵢ) ≈ $(@sprintf("%.10f", ɛ_dist))")
|
||||
info(LOGGER, "ɛ(Δ² - λΔ - ∑ξᵢ*ξᵢ) ≈ $(@sprintf("%.10f", ɛ_dist))")
|
||||
|
||||
eoi_SOS_L1_dist = norm(SOS_diff,1)
|
||||
info(logger, "‖Δ² - λΔ - ∑ξᵢ*ξᵢ‖₁ ≈ $(@sprintf("%.10f", eoi_SOS_L1_dist))")
|
||||
info(LOGGER, "‖Δ² - λΔ - ∑ξᵢ*ξᵢ‖₁ ≈ $(@sprintf("%.10f", eoi_SOS_L1_dist))")
|
||||
|
||||
dist = 2^(wlen-1)*eoi_SOS_L1_dist
|
||||
return dist
|
||||
@ -99,7 +99,7 @@ function augIdproj{T}(Q::AbstractArray{T,2}, logger)
|
||||
return Q
|
||||
end
|
||||
|
||||
function distance_to_positive_cone(Δ::GroupRingElem, λ, Q, wlen::Int)
|
||||
function distance_to_positive_cone(Δ::GroupRingElem, λ, Q, wlen::Int, logger)
|
||||
info(logger, "------------------------------------------------------------")
|
||||
info(logger, "λ = $λ")
|
||||
info(logger, "Checking in floating-point arithmetic...")
|
||||
|
@ -79,7 +79,7 @@ function sparsify!{Tv,Ti}(M::SparseMatrixCSC{Tv,Ti}, eps=eps(Tv); verbose=false)
|
||||
m = nnz(M)
|
||||
|
||||
if verbose
|
||||
info(logger, "Sparsified density:", rpad(densM, 20), " → ", rpad(dens(M), 20))
|
||||
info(LOGGER, "Sparsified density:", rpad(densM, 20), " → ", rpad(dens(M), 20))
|
||||
end
|
||||
|
||||
return M
|
||||
@ -91,11 +91,11 @@ function sparsify!{T}(M::AbstractArray{T}, eps=eps(T); check=false, verbose=fals
|
||||
M[abs.(M) .< eps] .= zero(T)
|
||||
|
||||
if check && rankM != rank(M)
|
||||
warn(logger, "Sparsification decreased the rank!")
|
||||
warn(LOGGER, "Sparsification decreased the rank!")
|
||||
end
|
||||
|
||||
if verbose
|
||||
info(logger, "Sparsified density:", rpad(densM, 20), " → ", rpad(dens(M),20))
|
||||
info(LOGGER, "Sparsified density:", rpad(densM, 20), " → ", rpad(dens(M),20))
|
||||
end
|
||||
|
||||
return sparse(M)
|
||||
@ -178,8 +178,8 @@ function init_model(n, sizes)
|
||||
end
|
||||
|
||||
function create_SDP_problem(sett::Settings)
|
||||
info(logger, "Loading orbit data....")
|
||||
@logtime logger SDP_problem, orb_data = OrbitData(sett);
|
||||
info(LOGGER, "Loading orbit data....")
|
||||
@logtime LOGGER SDP_problem, orb_data = OrbitData(sett);
|
||||
|
||||
if sett.upper_bound < Inf
|
||||
λ = JuMP.getvariable(SDP_problem, :λ)
|
||||
@ -187,8 +187,8 @@ function create_SDP_problem(sett::Settings)
|
||||
end
|
||||
|
||||
t = length(orb_data.laplacian)
|
||||
info(logger, "Adding $t constraints ... ")
|
||||
@logtime logger addconstraints!(SDP_problem, orb_data)
|
||||
info(LOGGER, "Adding $t constraints ... ")
|
||||
@logtime LOGGER addconstraints!(SDP_problem, orb_data)
|
||||
|
||||
return SDP_problem, orb_data
|
||||
end
|
||||
@ -201,14 +201,14 @@ function λandP(m::JuMP.Model, data::OrbitData, warmstart=true)
|
||||
end
|
||||
|
||||
function λandP(m::JuMP.Model, data::OrbitData, sett::Settings)
|
||||
info(logger, "Solving SDP problem...")
|
||||
info(LOGGER, "Solving SDP problem...")
|
||||
λ, Ps = λandP(m, data, sett.warmstart)
|
||||
|
||||
info(logger, "Reconstructing P...")
|
||||
info(LOGGER, "Reconstructing P...")
|
||||
|
||||
preps = load_preps(joinpath(prepath(sett), "preps.jld"), sett.autS)
|
||||
|
||||
@logtime logger recP = reconstruct_sol(preps, data.Us, Ps, data.dims)
|
||||
@logtime LOGGER recP = reconstruct_sol(preps, data.Us, Ps, data.dims)
|
||||
|
||||
fname = PropertyT.λSDPfilenames(fullpath(sett))[2]
|
||||
save(fname, "origP", Ps, "P", recP)
|
||||
@ -229,22 +229,22 @@ end
|
||||
|
||||
function check_property_T(sett::Settings)
|
||||
|
||||
init_orbit_data(logger, sett, radius=sett.radius)
|
||||
init_orbit_data(LOGGER, sett, radius=sett.radius)
|
||||
|
||||
if !sett.warmstart && all(isfile.(λSDPfilenames(fullpath(sett))))
|
||||
λ, P = PropertyT.λandP(fullpath(sett))
|
||||
else
|
||||
info(logger, "Creating SDP problem...")
|
||||
info(LOGGER, "Creating SDP problem...")
|
||||
SDP_problem, orb_data = create_SDP_problem(sett)
|
||||
JuMP.setsolver(SDP_problem, sett.solver)
|
||||
|
||||
λ, P = λandP(SDP_problem, orb_data, sett)
|
||||
end
|
||||
|
||||
info(logger, "λ = $λ")
|
||||
info(logger, "sum(P) = $(sum(P))")
|
||||
info(logger, "maximum(P) = $(maximum(P))")
|
||||
info(logger, "minimum(P) = $(minimum(P))")
|
||||
info(LOGGER, "λ = $λ")
|
||||
info(LOGGER, "sum(P) = $(sum(P))")
|
||||
info(LOGGER, "maximum(P) = $(maximum(P))")
|
||||
info(LOGGER, "minimum(P) = $(minimum(P))")
|
||||
|
||||
if λ > 0
|
||||
pm_fname, Δ_fname = pmΔfilenames(prepath(sett))
|
||||
@ -254,24 +254,24 @@ function check_property_T(sett::Settings)
|
||||
isapprox(eigvals(P), abs.(eigvals(P)), atol=sett.tol) ||
|
||||
warn("The solution matrix doesn't seem to be positive definite!")
|
||||
# @assert P == Symmetric(P)
|
||||
@logtime logger Q = real(sqrtm(Symmetric(P)))
|
||||
@logtime LOGGER Q = real(sqrtm(Symmetric(P)))
|
||||
|
||||
sgap = distance_to_positive_cone(Δ, λ, Q, 2*sett.radius)
|
||||
sgap = distance_to_positive_cone(Δ, λ, Q, 2*sett.radius, LOGGER)
|
||||
if isa(sgap, Interval)
|
||||
sgap = sgap.lo
|
||||
end
|
||||
if sgap > 0
|
||||
info(logger, "λ ≥ $(Float64(trunc(sgap,12)))")
|
||||
info(LOGGER, "λ ≥ $(Float64(trunc(sgap,12)))")
|
||||
Kazhdan_κ = PropertyT.Kazhdan_from_sgap(sgap, length(sett.S))
|
||||
Kazhdan_κ = Float64(trunc(Kazhdan_κ, 12))
|
||||
info(logger, "κ($(sett.name), S) ≥ $Kazhdan_κ: Group HAS property (T)!")
|
||||
info(LOGGER, "κ($(sett.name), S) ≥ $Kazhdan_κ: Group HAS property (T)!")
|
||||
return true
|
||||
else
|
||||
sgap = Float64(trunc(sgap, 12))
|
||||
info(logger, "λ($(sett.name), S) ≥ $sgap: Group may NOT HAVE property (T)!")
|
||||
info(LOGGER, "λ($(sett.name), S) ≥ $sgap: Group may NOT HAVE property (T)!")
|
||||
return false
|
||||
end
|
||||
end
|
||||
info(logger, "κ($(sett.name), S) ≥ $λ < 0: Tells us nothing about property (T)")
|
||||
info(LOGGER, "κ($(sett.name), S) ≥ $λ < 0: Tells us nothing about property (T)")
|
||||
return false
|
||||
end
|
||||
|
@ -12,15 +12,17 @@ using MathProgBase
|
||||
|
||||
using Memento
|
||||
|
||||
const logger = Memento.config("info", fmt="{msg}")
|
||||
const solver_logger = Memento.config("info", fmt="{msg}")
|
||||
const LOGGER = Memento.config("info", fmt="{msg}")
|
||||
const LOGGER_SOLVER = Memento.config("info", fmt="{msg}")
|
||||
|
||||
function setup_logging(name::String)
|
||||
isdir(name) || mkdir(name)
|
||||
|
||||
Memento.add_handler(logger,
|
||||
Memento.DefaultHandler(joinpath(name,"full_$(string((now()))).log"),
|
||||
Memento.DefaultFormatter("{date}| {msg}")), "full_log")
|
||||
handler = Memento.DefaultHandler(
|
||||
joinpath(name,"full_$(string((now()))).log"), Memento.DefaultFormatter("{date}| {msg}")
|
||||
)
|
||||
handler.levels.x = LOGGER.levels
|
||||
LOGGER.handlers["full_log"] = handler
|
||||
|
||||
e = redirect_stderr(logger.handlers["full_log"].io)
|
||||
|
||||
@ -85,7 +87,7 @@ function λSDPfilenames(prefix::String)
|
||||
end
|
||||
|
||||
function ΔandSDPconstraints(prefix::String, G::Group)
|
||||
info(logger, "Loading precomputed pm, Δ, sdp_constraints...")
|
||||
info(LOGGER, "Loading precomputed pm, Δ, sdp_constraints...")
|
||||
pm_fname, Δ_fname = pmΔfilenames(prefix)
|
||||
|
||||
product_matrix = load(pm_fname, "pm")
|
||||
@ -98,7 +100,7 @@ function ΔandSDPconstraints(prefix::String, G::Group)
|
||||
end
|
||||
|
||||
function ΔandSDPconstraints{T<:GroupElem}(name::String, S::Vector{T}, Id::T; radius::Int=2)
|
||||
info(logger, "Computing pm, Δ, sdp_constraints...")
|
||||
info(LOGGER, "Computing pm, Δ, sdp_constraints...")
|
||||
Δ, sdp_constraints = ΔandSDPconstraints(S, Id, radius=radius)
|
||||
pm_fname, Δ_fname = pmΔfilenames(name)
|
||||
save(pm_fname, "pm", parent(Δ).pm)
|
||||
@ -107,14 +109,14 @@ function ΔandSDPconstraints{T<:GroupElem}(name::String, S::Vector{T}, Id::T; ra
|
||||
end
|
||||
|
||||
function ΔandSDPconstraints{T<:GroupElem}(S::Vector{T}, Id::T; radius::Int=2)
|
||||
info(logger, "Generating balls of sizes $sizes")
|
||||
@logtime logger E_R, sizes = Groups.generate_balls(S, Id, radius=2*radius)
|
||||
info(LOGGER, "Generating balls of sizes $sizes")
|
||||
@logtime LOGGER E_R, sizes = Groups.generate_balls(S, Id, radius=2*radius)
|
||||
|
||||
info(logger, "Creating product matrix...")
|
||||
@logtime logger pm = GroupRings.create_pm(E_R, GroupRings.reverse_dict(E_R), sizes[radius]; twisted=true)
|
||||
info(LOGGER, "Creating product matrix...")
|
||||
@logtime LOGGER pm = GroupRings.create_pm(E_R, GroupRings.reverse_dict(E_R), sizes[radius]; twisted=true)
|
||||
|
||||
info(logger, "Creating sdp_constratints...")
|
||||
@logtime logger sdp_constraints = PropertyT.constraints(pm)
|
||||
info(LOGGER, "Creating sdp_constratints...")
|
||||
@logtime LOGGER sdp_constraints = PropertyT.constraints(pm)
|
||||
|
||||
RG = GroupRing(parent(Id), E_R, pm)
|
||||
|
||||
@ -128,7 +130,7 @@ function λandP(name::String)
|
||||
f₂ = exists(SDP_fname)
|
||||
|
||||
if f₁ && f₂
|
||||
info(logger, "Loading precomputed λ, P...")
|
||||
info(LOGGER, "Loading precomputed λ, P...")
|
||||
λ = load(λ_fname, "λ")
|
||||
P = load(SDP_fname, "P")
|
||||
else
|
||||
@ -138,10 +140,14 @@ function λandP(name::String)
|
||||
end
|
||||
|
||||
function λandP(name::String, SDP_problem::JuMP.Model, varλ, varP, warmstart=false)
|
||||
add_handler(solver_logger,
|
||||
DefaultHandler(joinpath(name, "solver_$(string(now())).log"),
|
||||
DefaultFormatter("{date}| {msg}")),
|
||||
"solver_log")
|
||||
|
||||
handler = DefaultHandler(
|
||||
joinpath(name, "solver_$(string(now())).log"),
|
||||
DefaultFormatter("{date}| {msg}")
|
||||
)
|
||||
handler.levels.x = LOGGER_SOLVER.levels
|
||||
LOGGER_SOLVER.handlers["solver_log"] = handler
|
||||
|
||||
if warmstart && isfile(joinpath(name, "warmstart.jld"))
|
||||
ws = load(joinpath(name, "warmstart.jld"), "warmstart")
|
||||
else
|
||||
@ -150,7 +156,7 @@ function λandP(name::String, SDP_problem::JuMP.Model, varλ, varP, warmstart=fa
|
||||
|
||||
λ, P, warmstart = compute_λandP(SDP_problem, varλ, varP, warmstart=ws)
|
||||
|
||||
remove_handler(solver_logger, "solver_log")
|
||||
delete!(LOGGER_SOLVER.handlers, "solver_log")
|
||||
|
||||
λ_fname, P_fname = λSDPfilenames(name)
|
||||
|
||||
@ -276,7 +282,7 @@ function compute_λandP(m, varλ, varP; warmstart=nothing)
|
||||
solve_SDP(m)
|
||||
λ = MathProgBase.getobjval(m.internalModel)
|
||||
catch y
|
||||
warn(solver_logger, y)
|
||||
warn(LOGGER_SOLVER, y)
|
||||
end
|
||||
end
|
||||
|
||||
@ -308,7 +314,7 @@ function check_property_T(name::String, S, Id, solver, upper_bound, tol, radius)
|
||||
if all(exists.(λSDPfilenames(name)))
|
||||
λ, P = λandP(name)
|
||||
else
|
||||
info(logger, "Creating SDP problem...")
|
||||
info(LOGGER, "Creating SDP problem...")
|
||||
SDP_problem, λ, P = create_SDP_problem(Δ, sdp_constraints, upper_bound=upper_bound)
|
||||
JuMP.setsolver(SDP_problem, solver)
|
||||
|
||||
@ -316,10 +322,10 @@ function check_property_T(name::String, S, Id, solver, upper_bound, tol, radius)
|
||||
λ, P = λandP(name, SDP_problem, λ, P)
|
||||
end
|
||||
|
||||
info(logger, "λ = $λ")
|
||||
info(logger, "sum(P) = $(sum(P))")
|
||||
info(logger, "maximum(P) = $(maximum(P))")
|
||||
info(logger, "minimum(P) = $(minimum(P))")
|
||||
info(LOGGER, "λ = $λ")
|
||||
info(LOGGER, "sum(P) = $(sum(P))")
|
||||
info(LOGGER, "maximum(P) = $(maximum(P))")
|
||||
info(LOGGER, "minimum(P) = $(minimum(P))")
|
||||
|
||||
if λ > 0
|
||||
pm_fname, Δ_fname = pmΔfilenames(name)
|
||||
@ -329,25 +335,25 @@ function check_property_T(name::String, S, Id, solver, upper_bound, tol, radius)
|
||||
isapprox(eigvals(P), abs(eigvals(P)), atol=tol) ||
|
||||
warn("The solution matrix doesn't seem to be positive definite!")
|
||||
# @assert P == Symmetric(P)
|
||||
@logtime logger Q = real(sqrtm(Symmetric(P)))
|
||||
@logtime LOGGER Q = real(sqrtm(Symmetric(P)))
|
||||
|
||||
sgap = distance_to_positive_cone(Δ, λ, Q, 2*radius)
|
||||
sgap = distance_to_positive_cone(Δ, λ, Q, 2*radius, LOGGER)
|
||||
if isa(sgap, Interval)
|
||||
sgap = sgap.lo
|
||||
end
|
||||
if sgap > 0
|
||||
info(logger, "λ ≥ $(Float64(trunc(sgap,12)))")
|
||||
info(LOGGER, "λ ≥ $(Float64(trunc(sgap,12)))")
|
||||
Kazhdan_κ = Kazhdan_from_sgap(sgap, length(S))
|
||||
Kazhdan_κ = Float64(trunc(Kazhdan_κ, 12))
|
||||
info(logger, "κ($name, S) ≥ $Kazhdan_κ: Group HAS property (T)!")
|
||||
info(LOGGER, "κ($name, S) ≥ $Kazhdan_κ: Group HAS property (T)!")
|
||||
return true
|
||||
else
|
||||
sgap = Float64(trunc(sgap, 12))
|
||||
info(logger, "λ($name, S) ≥ $sgap: Group may NOT HAVE property (T)!")
|
||||
info(LOGGER, "λ($name, S) ≥ $sgap: Group may NOT HAVE property (T)!")
|
||||
return false
|
||||
end
|
||||
end
|
||||
info(logger, "κ($name, S) ≥ $λ < 0: Tells us nothing about property (T)")
|
||||
info(LOGGER, "κ($name, S) ≥ $λ < 0: Tells us nothing about property (T)")
|
||||
return false
|
||||
end
|
||||
|
||||
|
10
src/SDPs.jl
10
src/SDPs.jl
@ -56,20 +56,20 @@ function create_SDP_problem(Δ::GroupRingElem, matrix_constraints; upper_bound=I
|
||||
end
|
||||
|
||||
function solve_SDP(SDP_problem)
|
||||
info(logger, Base.repr(SDP_problem))
|
||||
info(LOGGER, Base.repr(SDP_problem))
|
||||
|
||||
o = redirect_stdout(solver_logger.handlers["solver_log"].io)
|
||||
o = redirect_stdout(LOGGER_SOLVER.handlers["solver_log"].io)
|
||||
Base.Libc.flush_cstdio()
|
||||
|
||||
@logtime logger solution_status = MathProgBase.optimize!(SDP_problem.internalModel)
|
||||
@logtime LOGGER solution_status = MathProgBase.optimize!(SDP_problem.internalModel)
|
||||
Base.Libc.flush_cstdio()
|
||||
|
||||
redirect_stdout(o)
|
||||
|
||||
if solution_status != :Optimal
|
||||
warn(logger, "The solver did not solve the problem successfully!")
|
||||
warn(LOGGER, "The solver did not solve the problem successfully!")
|
||||
end
|
||||
info(logger, solution_status)
|
||||
info(LOGGER, solution_status)
|
||||
|
||||
return 0
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user