mirror of
https://github.com/kalmarek/PropertyT.jl.git
synced 2024-11-14 14:15:28 +01:00
move compute lambdaandP to its own section
This commit is contained in:
parent
504647223b
commit
613c12e157
@ -56,3 +56,70 @@ function loadLaplacian(name::String, G::Group)
|
||||
return Δ
|
||||
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
|
||||
|
@ -117,24 +117,10 @@ function SOS_problem(X::GroupRingElem, orderunit::GroupRingElem, data::OrbitData
|
||||
return m, λ, P
|
||||
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)
|
||||
@time recP = reconstruct_sol(preps, orbit_data.Uπs, P, orbit_data.dims)
|
||||
|
||||
return λ, recP, ws
|
||||
end
|
||||
|
||||
function load_preps(fname::String, G::Group)
|
||||
|
@ -34,48 +34,22 @@ mutable struct Settings{Gr<:Group, GEl<:GroupElem, Sol<:AbstractMathProgSolver}
|
||||
|
||||
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,
|
||||
sol::Sol, ub, tol, ws) where {Gr, GEl, Sol}
|
||||
return new{Gr, GEl, Sol}(name, G, S, r, sol, ub, tol, ws)
|
||||
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,
|
||||
sol::Sol, ub, tol, ws, autS) where {Gr, GEl, Sol}
|
||||
return new{Gr, GEl, Sol}(name, G, S, r, sol, ub, tol, ws, autS)
|
||||
end
|
||||
return λ, P
|
||||
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
|
||||
suffix(s::Settings) = "$(s.upper_bound)"
|
||||
prepath(s::Settings) = prefix(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)
|
||||
|
||||
filename(prefix, s::Symbol) = filename(prefix, Val{s})
|
||||
|
Loading…
Reference in New Issue
Block a user