mirror of
https://github.com/kalmarek/PropertyT.jl.git
synced 2024-12-24 02:00:30 +01:00
rework the Settings once again
This commit is contained in:
parent
ad00c76f68
commit
0ee12f76a5
@ -4,73 +4,66 @@
|
||||
#
|
||||
###############################################################################
|
||||
|
||||
struct Symmetrize end
|
||||
struct Naive end
|
||||
abstract type Settings end
|
||||
|
||||
abstract type PropertyTSettings end
|
||||
|
||||
struct SolverSettings
|
||||
sdpsolver::AbstractMathProgSolver
|
||||
upper_bound::Float64
|
||||
warmstart::Bool
|
||||
|
||||
SolverSettings(sol, ub, ws=true) = new(sol, upper_bound, ws)
|
||||
end
|
||||
|
||||
struct Naive <: PropertyTSettings
|
||||
struct Naive{El} <: Settings
|
||||
name::String
|
||||
G::Group
|
||||
S::Vector{GroupElem}
|
||||
S::Vector{El}
|
||||
radius::Int
|
||||
upper_bound::Float64
|
||||
|
||||
solver::SolverSettings
|
||||
solver::AbstractMathProgSolver
|
||||
warmstart::Bool
|
||||
end
|
||||
|
||||
struct Symmetrized <: PropertyTSettings
|
||||
struct Symmetrized{El} <: Settings
|
||||
name::String
|
||||
G::Group
|
||||
S::Vector{GroupElem}
|
||||
S::Vector{El}
|
||||
autS::Group
|
||||
radius::Int
|
||||
|
||||
solver::SolverSettings
|
||||
upper_bound::Float64
|
||||
|
||||
solver::AbstractMathProgSolver
|
||||
warmstart::Bool
|
||||
end
|
||||
|
||||
function Settings(name::String,
|
||||
G::Group, S::Vector{GEl}, r::Integer,
|
||||
sol::Solver, ub, ws=true) where {GEl<:GroupElem, Solver<:AbstractMathProgSolver}
|
||||
sol_sett = SolverSettings(sol, ub, ws)
|
||||
return Naive(name, G, S, r, sol_sett)
|
||||
G::Group, S::Vector{GEl},
|
||||
radius::Integer, upper_bound::Float64,
|
||||
solver::Solver, warmstart=true) where {GEl<:GroupElem, Solver<:AbstractMathProgSolver}
|
||||
return Naive(name, G, S, radius, upper_bound, solver, warmstart)
|
||||
end
|
||||
|
||||
function Settings(name::String,
|
||||
G::Group, S::Vector{GEl}, autS::Group, r::Integer,
|
||||
sol::Solver, ub, ws=true) where {GEl<:GroupElem, Solver<:AbstractMathProgSolver}
|
||||
sol_sett = SolverSettings(sol, ub, ws)
|
||||
return Symmetrized(name, G, S, autS, r, sol_sett)
|
||||
G::Group, S::Vector{GEl}, autS::Group,
|
||||
radius::Integer, upper_bound::Float64,
|
||||
solver::Solver, warmstart=true) where {GEl<:GroupElem, Solver<:AbstractMathProgSolver}
|
||||
return Symmetrized(name, G, S, autS, radius, upper_bound, solver, warmstart)
|
||||
end
|
||||
|
||||
prefix(s::Naive) = s.name
|
||||
prefix(s::Symmetrized) = "o"*s.name
|
||||
suffix(s::PropertyTSettings) = "$(s.upper_bound)"
|
||||
prepath(s::PropertyTSettings) = prefix(s)
|
||||
fullpath(s::PropertyTSettings) = joinpath(prefix(s), suffix(s))
|
||||
suffix(s::Settings) = "$(s.upper_bound)"
|
||||
prepath(s::Settings) = prefix(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")
|
||||
filename(sett::PropertyTSettings, ::Type{Val{:solverlog}}) =
|
||||
filename(sett::Settings, ::Type{Val{:solverlog}}) =
|
||||
joinpath(fullpath(sett), "solver_$(string(now())).log")
|
||||
|
||||
filename(sett::PropertyTSettings, ::Type{Val{:Δ}}) =
|
||||
filename(sett::Settings, ::Type{Val{:Δ}}) =
|
||||
joinpath(prepath(sett), "delta.jld")
|
||||
filename(sett::PropertyTSettings, ::Type{Val{:OrbitData}}) =
|
||||
filename(sett::Settings, ::Type{Val{:OrbitData}}) =
|
||||
joinpath(prepath(sett), "OrbitData.jld")
|
||||
|
||||
filename(sett::PropertyTSettings, ::Type{Val{:warmstart}}) =
|
||||
filename(sett::Settings, ::Type{Val{:warmstart}}) =
|
||||
joinpath(fullpath(sett), "warmstart.jld")
|
||||
filename(sett::PropertyTSettings, ::Type{Val{:solution}}) =
|
||||
filename(sett::Settings, ::Type{Val{:solution}}) =
|
||||
joinpath(fullpath(sett), "solution.jld")
|
||||
|
||||
###############################################################################
|
||||
@ -79,8 +72,8 @@ filename(sett::PropertyTSettings, ::Type{Val{:solution}}) =
|
||||
#
|
||||
###############################################################################
|
||||
|
||||
function warmstart(sett::PropertyTSettings)
|
||||
if sett.solver.warmstart && isfile(filename(sett, :warmstart))
|
||||
function warmstart(sett::Settings)
|
||||
if sett.warmstart && isfile(filename(sett, :warmstart))
|
||||
ws = load(filename(sett, :warmstart), "warmstart")
|
||||
else
|
||||
ws = nothing
|
||||
@ -92,9 +85,9 @@ function computeλandP(sett::Naive, Δ::GroupRingElem;
|
||||
solverlog=tempname()*".log")
|
||||
|
||||
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))
|
||||
SDP_problem, varλ, varP = SOS_problem(Δ^2, Δ, upper_bound=sett.upper_bound)
|
||||
JuMP.setsolver(SDP_problem, sett.solver)
|
||||
|
||||
ws = warmstart(sett)
|
||||
@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...")
|
||||
|
||||
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))
|
||||
SDP_problem, varλ, varP = SOS_problem(Δ^2, Δ, orbit_data, upper_bound=sett.upper_bound)
|
||||
JuMP.setsolver(SDP_problem, sett.solver)
|
||||
|
||||
ws = warmstart(sett)
|
||||
@time status, (λ, Ps, ws) = PropertyT.solve(solverlog, SDP_problem, varλ, varP, ws)
|
||||
@ -194,7 +187,7 @@ end
|
||||
|
||||
Kazhdan(λ::Number, N::Integer) = sqrt(2*λ/N)
|
||||
|
||||
function interpret_results(sett::PropertyTSettings, sgap::Number)
|
||||
function interpret_results(sett::Settings, sgap::Number)
|
||||
|
||||
if sgap > 0
|
||||
Kazhdan_κ = Kazhdan(sgap, length(sett.S))
|
||||
@ -207,7 +200,7 @@ function interpret_results(sett::PropertyTSettings, sgap::Number)
|
||||
return false
|
||||
end
|
||||
|
||||
function check_property_T(sett::PropertyTSettings)
|
||||
function check_property_T(sett::Settings)
|
||||
fp = PropertyT.fullpath(sett)
|
||||
isdir(fp) || mkpath(fp)
|
||||
|
||||
@ -238,8 +231,8 @@ function check_property_T(sett::PropertyTSettings)
|
||||
info("maximum(P) = $(maximum(P))")
|
||||
info("minimum(P) = $(minimum(P))")
|
||||
|
||||
isapprox(eigvals(P), abs.(eigvals(P)), atol=sett.tol) ||
|
||||
warn("The solution matrix doesn't seem to be positive definite!")
|
||||
isapprox(eigvals(P), abs.(eigvals(P))) ||
|
||||
@warn("The solution matrix doesn't seem to be positive definite!")
|
||||
|
||||
@time Q = real(sqrtm((P+P')/2))
|
||||
sgap = distance_to_positive_cone(Δ, λ, Q, wlen=2*sett.radius)
|
||||
|
Loading…
Reference in New Issue
Block a user