1
0
mirror of https://github.com/kalmarek/PropertyT.jl.git synced 2024-11-30 01:55:28 +01:00

sparate logic and IO

IO is moved to the upper level
This commit is contained in:
kalmarek 2018-08-20 03:44:24 +02:00
parent ebe9490465
commit b509f3686d

View File

@ -82,12 +82,6 @@ function loadλandP(name::String)
return λ, P return λ, P
end end
if warmstart && isfile(filename(name, :warm))
ws = load(filename(name, :warm), "warmstart")
else
ws = nothing
end
function computeλandP(Δ::GroupRingElem, upper_bound::AbstractFloat, solver, ws=nothing; solverlog=tempname()*".log") function computeλandP(Δ::GroupRingElem, upper_bound::AbstractFloat, solver, ws=nothing; solverlog=tempname()*".log")
function f() function f()
@ -101,14 +95,10 @@ function computeλandP(Δ::GroupRingElem, upper_bound::AbstractFloat, solver, ws
λ, P, warmstart = redirect_stdout(f, solverlog) λ, P, warmstart = redirect_stdout(f, solverlog)
close(solverlog) close(solverlog)
if λ > 0 function saveλandP(name, λ, P, ws)
save(filename(name, ), "λ", λ) save(filename(name, ), "λ", λ)
save(filename(name, :P), "P", P) save(filename(name, :P), "P", P)
save(filename(name, :warm), "warmstart", warmstart) save(filename(name, :warm), "warmstart", ws)
else
throw(ErrorException("Solver did not produce a valid solution: λ = "))
end
return λ, P
end end
Kazhdan(λ::Number,N::Integer) = sqrt(2*λ/N) Kazhdan(λ::Number,N::Integer) = sqrt(2*λ/N)
@ -135,25 +125,18 @@ function check_property_T(name::String, S, Id, solver, upper_bound, tol, radius,
if !(warm) && files_exist if !(warm) && files_exist
λ, P = loadλandP(fullpath) λ, P = loadλandP(fullpath)
else else
info("Creating SDP problem...") warmfile = filename(fullpath, :warm)
SDP_problem, varλ, varP = create_SDP_problem(Δ, constraints(parent(Δ).pm), upper_bound=upper_bound) if warm && isfile(warmfile)
JuMP.setsolver(SDP_problem, solver) ws = load(warmfile, "warmstart")
info(Base.repr(SDP_problem))
if warm && isfile(filename(name, :warm))
ws = load(filename(name, :warm), "warmstart")
else else
ws = nothing ws = nothing
end end
if λ > 0
save(filename(name, ), "λ", λ)
save(filename(name, :P), "P", P)
save(filename(name, :warm), "warmstart", ws)
else
throw(ErrorException("Solver did not produce a valid solution: λ = "))
λ, P, ws = computeλandP(Δ, upper_bound, solver, ws, λ, P, ws = computeλandP(Δ, upper_bound, solver, ws,
solverlog=filename(fullpath, :solverlog))
saveλandP(fullpath, λ, P, ws)
if λ < 0
warn("Solver did not produce a valid solution!")
end end
end end