1
0
mirror of https://github.com/kalmarek/PropertyT.jl.git synced 2024-12-24 18:10:29 +01:00

rework the Settings once again

This commit is contained in:
kalmarek 2019-01-11 04:33:56 +01:00
parent ad00c76f68
commit 0ee12f76a5

View File

@ -4,73 +4,66 @@
# #
############################################################################### ###############################################################################
struct Symmetrize end abstract type Settings end
struct Naive end
abstract type PropertyTSettings end struct Naive{El} <: Settings
struct SolverSettings
sdpsolver::AbstractMathProgSolver
upper_bound::Float64
warmstart::Bool
SolverSettings(sol, ub, ws=true) = new(sol, upper_bound, ws)
end
struct Naive <: PropertyTSettings
name::String name::String
G::Group G::Group
S::Vector{GroupElem} S::Vector{El}
radius::Int radius::Int
upper_bound::Float64
solver::SolverSettings solver::AbstractMathProgSolver
warmstart::Bool
end end
struct Symmetrized <: PropertyTSettings struct Symmetrized{El} <: Settings
name::String name::String
G::Group G::Group
S::Vector{GroupElem} S::Vector{El}
autS::Group autS::Group
radius::Int radius::Int
upper_bound::Float64
solver::SolverSettings
solver::AbstractMathProgSolver
warmstart::Bool
end end
function Settings(name::String, function Settings(name::String,
G::Group, S::Vector{GEl}, r::Integer, G::Group, S::Vector{GEl},
sol::Solver, ub, ws=true) where {GEl<:GroupElem, Solver<:AbstractMathProgSolver} radius::Integer, upper_bound::Float64,
sol_sett = SolverSettings(sol, ub, ws) solver::Solver, warmstart=true) where {GEl<:GroupElem, Solver<:AbstractMathProgSolver}
return Naive(name, G, S, r, sol_sett) return Naive(name, G, S, radius, upper_bound, solver, warmstart)
end end
function Settings(name::String, function Settings(name::String,
G::Group, S::Vector{GEl}, autS::Group, r::Integer, G::Group, S::Vector{GEl}, autS::Group,
sol::Solver, ub, ws=true) where {GEl<:GroupElem, Solver<:AbstractMathProgSolver} radius::Integer, upper_bound::Float64,
sol_sett = SolverSettings(sol, ub, ws) solver::Solver, warmstart=true) where {GEl<:GroupElem, Solver<:AbstractMathProgSolver}
return Symmetrized(name, G, S, autS, r, sol_sett) return Symmetrized(name, G, S, autS, radius, upper_bound, solver, warmstart)
end end
prefix(s::Naive) = s.name prefix(s::Naive) = s.name
prefix(s::Symmetrized) = "o"*s.name prefix(s::Symmetrized) = "o"*s.name
suffix(s::PropertyTSettings) = "$(s.upper_bound)" suffix(s::Settings) = "$(s.upper_bound)"
prepath(s::PropertyTSettings) = prefix(s) prepath(s::Settings) = prefix(s)
fullpath(s::PropertyTSettings) = joinpath(prefix(s), suffix(s)) fullpath(s::Settings) = joinpath(prefix(s), suffix(s))
filename(sett::PropertyTSettings, s::Symbol) = filename(sett, Val{s}) filename(sett::Settings, s::Symbol) = filename(sett, Val{s})
filename(sett::PropertyTSettings, ::Type{Val{:fulllog}}) = filename(sett::Settings, ::Type{Val{:fulllog}}) =
joinpath(fullpath(sett), "full_$(string(now())).log") joinpath(fullpath(sett), "full_$(string(now())).log")
filename(sett::PropertyTSettings, ::Type{Val{:solverlog}}) = filename(sett::Settings, ::Type{Val{:solverlog}}) =
joinpath(fullpath(sett), "solver_$(string(now())).log") joinpath(fullpath(sett), "solver_$(string(now())).log")
filename(sett::PropertyTSettings, ::Type{Val{}}) = filename(sett::Settings, ::Type{Val{}}) =
joinpath(prepath(sett), "delta.jld") joinpath(prepath(sett), "delta.jld")
filename(sett::PropertyTSettings, ::Type{Val{:OrbitData}}) = filename(sett::Settings, ::Type{Val{:OrbitData}}) =
joinpath(prepath(sett), "OrbitData.jld") joinpath(prepath(sett), "OrbitData.jld")
filename(sett::PropertyTSettings, ::Type{Val{:warmstart}}) = filename(sett::Settings, ::Type{Val{:warmstart}}) =
joinpath(fullpath(sett), "warmstart.jld") joinpath(fullpath(sett), "warmstart.jld")
filename(sett::PropertyTSettings, ::Type{Val{:solution}}) = filename(sett::Settings, ::Type{Val{:solution}}) =
joinpath(fullpath(sett), "solution.jld") joinpath(fullpath(sett), "solution.jld")
############################################################################### ###############################################################################
@ -79,8 +72,8 @@ filename(sett::PropertyTSettings, ::Type{Val{:solution}}) =
# #
############################################################################### ###############################################################################
function warmstart(sett::PropertyTSettings) function warmstart(sett::Settings)
if sett.solver.warmstart && isfile(filename(sett, :warmstart)) if sett.warmstart && isfile(filename(sett, :warmstart))
ws = load(filename(sett, :warmstart), "warmstart") ws = load(filename(sett, :warmstart), "warmstart")
else else
ws = nothing ws = nothing
@ -92,9 +85,9 @@ function computeλandP(sett::Naive, Δ::GroupRingElem;
solverlog=tempname()*".log") solverlog=tempname()*".log")
info("Creating SDP problem...") info("Creating SDP problem...")
SDP_problem, varλ, varP = SOS_problem(Δ^2, Δ, upper_bound=sett.solver.upper_bound)
JuMP.setsolver(SDP_problem, sett.solver.sdpsolver)
info(Base.repr(SDP_problem)) info(Base.repr(SDP_problem))
SDP_problem, varλ, varP = SOS_problem(Δ^2, Δ, upper_bound=sett.upper_bound)
JuMP.setsolver(SDP_problem, sett.solver)
ws = warmstart(sett) ws = warmstart(sett)
@time status, (λ, P, ws) = PropertyT.solve(solverlog, SDP_problem, varλ, varP, ws) @time status, (λ, P, ws) = PropertyT.solve(solverlog, SDP_problem, varλ, varP, ws)
@ -117,9 +110,9 @@ function computeλandP(sett::Symmetrized, Δ::GroupRingElem;
info("Creating SDP problem...") info("Creating SDP problem...")
SDP_problem, varλ, varP = SOS_problem(Δ^2, Δ, orbit_data, upper_bound=sett.solver.upper_bound)
JuMP.setsolver(SDP_problem, sett.solver.sdpsolver)
info(Base.repr(SDP_problem)) info(Base.repr(SDP_problem))
SDP_problem, varλ, varP = SOS_problem(Δ^2, Δ, orbit_data, upper_bound=sett.upper_bound)
JuMP.setsolver(SDP_problem, sett.solver)
ws = warmstart(sett) ws = warmstart(sett)
@time status, (λ, Ps, ws) = PropertyT.solve(solverlog, SDP_problem, varλ, varP, ws) @time status, (λ, Ps, ws) = PropertyT.solve(solverlog, SDP_problem, varλ, varP, ws)
@ -194,7 +187,7 @@ end
Kazhdan(λ::Number, N::Integer) = sqrt(2*λ/N) Kazhdan(λ::Number, N::Integer) = sqrt(2*λ/N)
function interpret_results(sett::PropertyTSettings, sgap::Number) function interpret_results(sett::Settings, sgap::Number)
if sgap > 0 if sgap > 0
Kazhdan_κ = Kazhdan(sgap, length(sett.S)) Kazhdan_κ = Kazhdan(sgap, length(sett.S))
@ -207,7 +200,7 @@ function interpret_results(sett::PropertyTSettings, sgap::Number)
return false return false
end end
function check_property_T(sett::PropertyTSettings) function check_property_T(sett::Settings)
fp = PropertyT.fullpath(sett) fp = PropertyT.fullpath(sett)
isdir(fp) || mkpath(fp) isdir(fp) || mkpath(fp)
@ -238,8 +231,8 @@ function check_property_T(sett::PropertyTSettings)
info("maximum(P) = $(maximum(P))") info("maximum(P) = $(maximum(P))")
info("minimum(P) = $(minimum(P))") info("minimum(P) = $(minimum(P))")
isapprox(eigvals(P), abs.(eigvals(P)), atol=sett.tol) || isapprox(eigvals(P), abs.(eigvals(P))) ||
warn("The solution matrix doesn't seem to be positive definite!") @warn("The solution matrix doesn't seem to be positive definite!")
@time Q = real(sqrtm((P+P')/2)) @time Q = real(sqrtm((P+P')/2))
sgap = distance_to_positive_cone(Δ, λ, Q, wlen=2*sett.radius) sgap = distance_to_positive_cone(Δ, λ, Q, wlen=2*sett.radius)