1
0
mirror of https://github.com/kalmarek/PropertyT.jl.git synced 2024-12-26 02:30:29 +01:00

move compute lambdaandP to its own section

This commit is contained in:
kalmarek 2018-09-05 09:09:22 +02:00
parent 504647223b
commit 613c12e157
3 changed files with 67 additions and 40 deletions

View File

@ -56,3 +56,70 @@ function loadLaplacian(name::String, G::Group)
return Δ return Δ
end end
###############################################################################
#
# λandP
#
###############################################################################
function computeλandP(::Type{Naive}, Δ::GroupRingElem, sett::Settings, ws=nothing; solverlog=tempname()*".log")
info("Creating SDP problem...")
SDP_problem, varλ, varP = SOS_problem(Δ^2, Δ, upper_bound=sett.upper_bound)
JuMP.setsolver(SDP_problem, sett.solver)
info(Base.repr(SDP_problem))
@time λ, P, ws = solve_logged(SDP_problem, varλ, varP, ws, solverlog=solverlog)
return λ, P, ws
end
function computeλandP(::Type{Symmetrize}, Δ::GroupRingElem, sett::Settings, ws=nothing; solverlog=tempname()*".log")
pdir = prepath(sett)
files_exist = exists(filename(pdir,:Uπs)) && exists(filename(pdir,:orbits)) && exists(filename(pdir,:preps))
if files_exist
orbit_data = load_OrbitData(sett)
else
isdefined(parent(Δ), :basis) || throw("You need to define basis of Group Ring to compute orbit decomposition!")
orbit_data = compute_OrbitData(parent(Δ), sett.autS)
save_OrbitData(sett, orbit_data)
end
orbit_data = decimate(orbit_data)
info("Creating SDP problem...")
SDP_problem, varλ, varP = SOS_problem(Δ^2, Δ, orbit_data, upper_bound=sett.upper_bound)
JuMP.setsolver(SDP_problem, sett.solver)
info(Base.repr(SDP_problem))
@time λ, P, ws = solve_logged(SDP_problem, varλ, varP, ws, solverlog=solverlog)
fname = filename(fullpath(sett), :P)
save(joinpath(dirname(fname), "orig_"*basename(fname)), "origP", P)
info("Reconstructing P...")
@time recP = reconstruct(P, orbit_data)
return λ, recP, ws
end
function saveλandP(name, λ, P, ws)
save(filename(name, ), "λ", λ)
save(filename(name, :P), "P", P)
save(filename(name, :warm), "warmstart", ws)
end
function loadλandP(name::String)
λ_fname = filename(name, )
P_fname = filename(name, :P)
if exists(λ_fname) && exists(P_fname)
info("Loading precomputed λ, P...")
λ = load(λ_fname, "λ")
P = load(P_fname, "P")
else
throw("You need to precompute $λ_fname and $P_fname to load it!")
end
return λ, P
end

View File

@ -117,24 +117,10 @@ function SOS_problem(X::GroupRingElem, orderunit::GroupRingElem, data::OrbitData
return m, λ, P return m, λ, P
end end
function computeλandP(Δ::GroupRingElem, sett::Settings, ws=nothing; solverlog=tempname()*".log")
@time orbit_data = OrbitData(sett);
info("Creating SDP problem...")
SDP_problem, varλ, varP = SOS_problem(Δ^2, Δ, orbit_data, upper_bound=sett.upper_bound)
JuMP.setsolver(SDP_problem, sett.solver)
info(Base.repr(SDP_problem))
@time λ, P, ws = solve_SDP(SDP_problem, varλ, varP, ws, solverlog=solverlog)
fname = filename(fullpath(sett), :P)
save(joinpath(dirname(fname), "orig_"*basename(fname)), "origP", P)
info("Reconstructing P...")
preps = load_preps(filename(prepath(sett), :preps), sett.autS) preps = load_preps(filename(prepath(sett), :preps), sett.autS)
@time recP = reconstruct_sol(preps, orbit_data.Uπs, P, orbit_data.dims)
return λ, recP, ws
end end
function load_preps(fname::String, G::Group) function load_preps(fname::String, G::Group)

View File

@ -34,48 +34,22 @@ mutable struct Settings{Gr<:Group, GEl<:GroupElem, Sol<:AbstractMathProgSolver}
autS::Group autS::Group
function loadλandP(name::String)
λ_fname = filename(name, )
P_fname = filename(name, :P)
function Settings(name, G::Gr, S::Vector{GEl}, r::Int, function Settings(name, G::Gr, S::Vector{GEl}, r::Int,
sol::Sol, ub, tol, ws) where {Gr, GEl, Sol} sol::Sol, ub, tol, ws) where {Gr, GEl, Sol}
return new{Gr, GEl, Sol}(name, G, S, r, sol, ub, tol, ws) return new{Gr, GEl, Sol}(name, G, S, r, sol, ub, tol, ws)
end end
if exists(λ_fname) && exists(P_fname)
info("Loading precomputed λ, P...")
λ = load(λ_fname, "λ")
P = load(P_fname, "P")
else
throw("You need to precompute $λ_fname and $P_fname to load it!")
function Settings(name, G::Gr, S::Vector{GEl}, r::Int, function Settings(name, G::Gr, S::Vector{GEl}, r::Int,
sol::Sol, ub, tol, ws, autS) where {Gr, GEl, Sol} sol::Sol, ub, tol, ws, autS) where {Gr, GEl, Sol}
return new{Gr, GEl, Sol}(name, G, S, r, sol, ub, tol, ws, autS) return new{Gr, GEl, Sol}(name, G, S, r, sol, ub, tol, ws, autS)
end end
return λ, P
end end
function computeλandP(Δ::GroupRingElem, upper_bound::AbstractFloat, solver, ws=nothing; solverlog=tempname()*".log")
info("Creating SDP problem...")
SDP_problem, varλ, varP = SOS_problem(Δ^2, Δ, upper_bound=upper_bound)
JuMP.setsolver(SDP_problem, solver)
info(Base.repr(SDP_problem))
@time λ, P, ws = solve_SDP(SDP_problem, varλ, varP, ws, solverlog=solverlog)
return λ, P, ws
end
prefix(s::Settings) = s.name prefix(s::Settings) = s.name
suffix(s::Settings) = "$(s.upper_bound)" suffix(s::Settings) = "$(s.upper_bound)"
prepath(s::Settings) = prefix(s) prepath(s::Settings) = prefix(s)
fullpath(s::Settings) = joinpath(prefix(s), suffix(s)) fullpath(s::Settings) = joinpath(prefix(s), suffix(s))
function saveλandP(name, λ, P, ws)
save(filename(name, ), "λ", λ)
save(filename(name, :P), "P", P)
save(filename(name, :warm), "warmstart", ws)
end
exists(fname::String) = isfile(fname) || islink(fname) exists(fname::String) = isfile(fname) || islink(fname)
filename(prefix, s::Symbol) = filename(prefix, Val{s}) filename(prefix, s::Symbol) = filename(prefix, Val{s})