mirror of
https://github.com/kalmarek/PropertyT.jl.git
synced 2024-12-26 10:35:29 +01:00
rework filename logic
This commit is contained in:
parent
f48e8ba8d7
commit
d5a4f4957a
@ -210,7 +210,7 @@ function λandP(m::JuMP.Model, data::OrbitData, sett::Settings)
|
|||||||
|
|
||||||
@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]
|
fname = filename(fullpath(sett), :P)
|
||||||
save(fname, "origP", Ps, "P", recP)
|
save(fname, "origP", Ps, "P", recP)
|
||||||
return λ, recP
|
return λ, recP
|
||||||
end
|
end
|
||||||
@ -231,7 +231,10 @@ 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))))
|
cond1 = exists(filename(fullpath(sett), :λ))
|
||||||
|
cond2 = exists(filename(fullpath(sett), :P))
|
||||||
|
|
||||||
|
if !sett.warmstart && cond1 && cond2
|
||||||
λ, P = PropertyT.λandP(fullpath(sett))
|
λ, P = PropertyT.λandP(fullpath(sett))
|
||||||
else
|
else
|
||||||
info(LOGGER, "Creating SDP problem...")
|
info(LOGGER, "Creating SDP problem...")
|
||||||
@ -247,7 +250,8 @@ function check_property_T(sett::Settings)
|
|||||||
info(LOGGER, "minimum(P) = $(minimum(P))")
|
info(LOGGER, "minimum(P) = $(minimum(P))")
|
||||||
|
|
||||||
if λ > 0
|
if λ > 0
|
||||||
pm_fname, Δ_fname = pmΔfilenames(prepath(sett))
|
pm_fname = filename(prepath(sett), :pm)
|
||||||
|
Δ_fname = filename(prepath(sett), :Δ)
|
||||||
RG = GroupRing(sett.G, load(pm_fname, "pm"))
|
RG = GroupRing(sett.G, load(pm_fname, "pm"))
|
||||||
Δ = GroupRingElem(load(Δ_fname, "Δ")[:, 1], RG)
|
Δ = GroupRingElem(load(Δ_fname, "Δ")[:, 1], RG)
|
||||||
|
|
||||||
|
@ -70,19 +70,15 @@ end
|
|||||||
|
|
||||||
exists(fname::String) = isfile(fname) || islink(fname)
|
exists(fname::String) = isfile(fname) || islink(fname)
|
||||||
|
|
||||||
function pmΔfilenames(prefix::String)
|
function filename(prefix, s::Symbol)
|
||||||
isdir(prefix) || mkdir(prefix)
|
isdir(prefix) || mkdir(prefix)
|
||||||
pm_filename = joinpath(prefix, "pm.jld")
|
return filename(prefix, Val{s})
|
||||||
Δ_coeff_filename = joinpath(prefix, "delta.jld")
|
|
||||||
return pm_filename, Δ_coeff_filename
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function λSDPfilenames(prefix::String)
|
filename(prefix::String, ::Type{Val{:pm}}) = joinpath(prefix, "pm.jld")
|
||||||
isdir(prefix) || mkdir(prefix)
|
filename(prefix::String, ::Type{Val{:Δ}}) = joinpath(prefix, "delta.jld")
|
||||||
λ_filename = joinpath(prefix, "lambda.jld")
|
filename(prefix::String, ::Type{Val{:λ}}) = joinpath(prefix, "lambda.jld")
|
||||||
SDP_filename = joinpath(prefix, "SDPmatrix.jld")
|
filename(prefix::String, ::Type{Val{:P}}) = joinpath(prefix, "SDPmatrix.jld")
|
||||||
return λ_filename, SDP_filename
|
|
||||||
end
|
|
||||||
|
|
||||||
function ΔandSDPconstraints(prefix::String, G::Group)
|
function ΔandSDPconstraints(prefix::String, G::Group)
|
||||||
info(LOGGER, "Loading precomputed pm, Δ, sdp_constraints...")
|
info(LOGGER, "Loading precomputed pm, Δ, sdp_constraints...")
|
||||||
@ -123,16 +119,14 @@ function ΔandSDPconstraints{T<:GroupElem}(S::Vector{T}, Id::T; radius::Int=2)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function λandP(name::String)
|
function λandP(name::String)
|
||||||
λ_fname, SDP_fname = λSDPfilenames(name)
|
λ_fname = filename(name, :λ)
|
||||||
f₁ = exists(λ_fname)
|
P_fname = filename(name, :P)
|
||||||
f₂ = exists(SDP_fname)
|
|
||||||
|
|
||||||
if f₁ && f₂
|
if exists(λ_fname) && exists(P_fname)
|
||||||
info(LOGGER, "Loading precomputed λ, P...")
|
|
||||||
λ = load(λ_fname, "λ")
|
λ = load(λ_fname, "λ")
|
||||||
P = load(SDP_fname, "P")
|
P = load(P_fname, "P")
|
||||||
else
|
else
|
||||||
throw(ArgumentError("You need to precompute λ and SDP matrix P to load it!"))
|
throw("You need to precompute $λ_fname and $P_fname to load it!")
|
||||||
end
|
end
|
||||||
return λ, P
|
return λ, P
|
||||||
end
|
end
|
||||||
@ -156,14 +150,12 @@ function λandP(name::String, SDP_problem::JuMP.Model, varλ, varP, warmstart=fa
|
|||||||
|
|
||||||
delete!(LOGGER_SOLVER.handlers, "solver_log")
|
delete!(LOGGER_SOLVER.handlers, "solver_log")
|
||||||
|
|
||||||
λ_fname, P_fname = λSDPfilenames(name)
|
|
||||||
|
|
||||||
if λ > 0
|
if λ > 0
|
||||||
save(λ_fname, "λ", λ)
|
save(filename(name, :λ), "λ", λ)
|
||||||
save(P_fname, "P", P)
|
save(filename(name, :P), "P", P)
|
||||||
save(joinpath(name, "warmstart.jld"), "warmstart", warmstart)
|
save(joinpath(name, "warmstart.jld"), "warmstart", warmstart)
|
||||||
else
|
else
|
||||||
throw(ErrorException("Solver did not produce a valid solution!: λ = $λ"))
|
throw(ErrorException("Solver did not produce a valid solution: λ = $λ"))
|
||||||
end
|
end
|
||||||
return λ, P
|
return λ, P
|
||||||
end
|
end
|
||||||
@ -300,7 +292,7 @@ function check_property_T(name::String, S, Id, solver, upper_bound, tol, radius)
|
|||||||
|
|
||||||
isdir(name) || mkdir(name)
|
isdir(name) || mkdir(name)
|
||||||
|
|
||||||
if all(exists.(pmΔfilenames(name)))
|
if exists(filename(name, :pm)) && exists(filename(name, :Δ))
|
||||||
# cached
|
# cached
|
||||||
Δ, sdp_constraints = ΔandSDPconstraints(name, parent(S[1]))
|
Δ, sdp_constraints = ΔandSDPconstraints(name, parent(S[1]))
|
||||||
else
|
else
|
||||||
@ -308,7 +300,8 @@ function check_property_T(name::String, S, Id, solver, upper_bound, tol, radius)
|
|||||||
Δ, sdp_constraints = ΔandSDPconstraints(name, S, Id, radius=radius)
|
Δ, sdp_constraints = ΔandSDPconstraints(name, S, Id, radius=radius)
|
||||||
end
|
end
|
||||||
|
|
||||||
if all(exists.(λSDPfilenames(name)))
|
if exists(filename(name, :λ)) && exists(filename(name, :P))
|
||||||
|
info(LOGGER, "Loading precomputed λ, P...")
|
||||||
λ, P = λandP(name)
|
λ, P = λandP(name)
|
||||||
else
|
else
|
||||||
info(LOGGER, "Creating SDP problem...")
|
info(LOGGER, "Creating SDP problem...")
|
||||||
@ -324,9 +317,9 @@ function check_property_T(name::String, S, Id, solver, upper_bound, tol, radius)
|
|||||||
info(LOGGER, "minimum(P) = $(minimum(P))")
|
info(LOGGER, "minimum(P) = $(minimum(P))")
|
||||||
|
|
||||||
if λ > 0
|
if λ > 0
|
||||||
pm_fname, Δ_fname = pmΔfilenames(name)
|
|
||||||
RG = GroupRing(parent(first(S)), load(pm_fname, "pm"))
|
RG = GroupRing(parent(first(S)), load(filename(name, :pm), "pm"))
|
||||||
Δ = GroupRingElem(load(Δ_fname, "Δ")[:, 1], RG)
|
Δ = GroupRingElem(load(filename(name, :Δ), "Δ")[:, 1], RG)
|
||||||
|
|
||||||
isapprox(eigvals(P), abs(eigvals(P)), atol=tol) ||
|
isapprox(eigvals(P), abs(eigvals(P)), atol=tol) ||
|
||||||
warn("The solution matrix doesn't seem to be positive definite!")
|
warn("The solution matrix doesn't seem to be positive definite!")
|
||||||
|
Loading…
Reference in New Issue
Block a user