From d2f6682a393f2b99ba558dc409c5b3acb0683652 Mon Sep 17 00:00:00 2001 From: kalmarek Date: Mon, 20 Aug 2018 03:45:50 +0200 Subject: [PATCH] mv logging to solve_SDP function --- src/PropertyT.jl | 16 +++++++--------- src/SDPs.jl | 18 +++++++++++++++++- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/PropertyT.jl b/src/PropertyT.jl index c23982f..0c4ab10 100644 --- a/src/PropertyT.jl +++ b/src/PropertyT.jl @@ -83,17 +83,15 @@ function loadλandP(name::String) 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)) - function f() - Base.Libc.flush_cstdio() - λ, P, w = solve_SDP(SDP, varλ, varP, warmstart=ws) - Base.Libc.flush_cstdio() - return λ, P, w - end + @time λ, P, ws = solve_SDP(SDP_problem, varλ, varP, ws, solverlog=solverlog) - solverlog = open(filename(name, :solverlog),"a+") - λ, P, warmstart = redirect_stdout(f, solverlog) - close(solverlog) + return λ, P, ws +end function saveλandP(name, λ, P, ws) save(filename(name, :λ), "λ", λ) diff --git a/src/SDPs.jl b/src/SDPs.jl index c5d6e36..f436a4e 100644 --- a/src/SDPs.jl +++ b/src/SDPs.jl @@ -55,7 +55,23 @@ function create_SDP_problem(Δ::GroupRingElem, matrix_constraints; upper_bound=I return m, λ, P end -function solve_SDP(m, varλ, varP; warmstart=nothing) +function solve_SDP(model::JuMP.Model, varλ, varP, ws=nothing; solverlog=tempname()*".log") + + function f() + Base.Libc.flush_cstdio() + λ, P, ws = PropertyT.solve(model, varλ, varP, warmstart=ws) + Base.Libc.flush_cstdio() + return λ, P, ws + end + + log = open(solverlog, "a+") + λ, P, ws = redirect_stdout(f, log) + close(log) + + return λ, P, ws +end + +function solve(m::JuMP.Model, varλ, varP; warmstart=nothing) traits = JuMP.ProblemTraits(m, relaxation=false)