Skip to content

Commit

Permalink
Merge pull request #93 from mariohsouto/improve_print
Browse files Browse the repository at this point in the history
Improving print to use scientific formatting
  • Loading branch information
mariohsouto authored Feb 7, 2023
2 parents a60f3da + 458130a commit e395878
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 15 deletions.
3 changes: 2 additions & 1 deletion docs/src/manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ A quick JuMP example:
using ProxSDP, JuMP

# Create a JuMP model using ProxSDP as the solver
model = Model(with_optimizer(ProxSDP.Optimizer, log_verbose=true))
model = Model(ProxSDP.Optimizer)
set_optimizer_attribute(model, "log_verbose", true)

# Create a Positive Semidefinite variable
@variable(model, X[1:2,1:2], PSD)
Expand Down
5 changes: 4 additions & 1 deletion examples/jump.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ push!(Base.LOAD_PATH, path)
using ProxSDP, JuMP

# Create a JuMP model using ProxSDP as the solver
model = Model(with_optimizer(ProxSDP.Optimizer, log_verbose=true, tol_gap = 1e-4, tol_feasibility = 1e-4))
model = Model(ProxSDP.Optimizer)
set_optimizer_attribute(model, "log_verbose", true)
set_optimizer_attribute(model, "tol_gap", 1e-4)
set_optimizer_attribute(model, "tol_feasibility", 1e-4)

@variable(model, X[1:2,1:2], PSD)

Expand Down
7 changes: 5 additions & 2 deletions examples/sos.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ using DynamicPolynomials
using ProxSDP, SCS

# Using ProxSDP as the SDP solver
model = SOSModel(with_optimizer(ProxSDP.Optimizer, log_verbose=true, max_iter=100000, full_eig_decomp=true))
# model = SOSModel(with_optimizer(SCS.Optimizer, max_iters=100000))
# model = SOSModel(with_optimizer(ProxSDP.Optimizer, log_verbose=true, max_iter=100000, full_eig_decomp=true))
model = SOSModel(ProxSDP.Optimizer)
set_optimizer_attribute(model, "log_verbose", true)
set_optimizer_attribute(model, "max_iter", 100000)
set_optimizer_attribute(model, "full_eig_decomp", true)

@polyvar x z
@variable(model, t)
Expand Down
14 changes: 7 additions & 7 deletions src/printing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,19 @@ function print_progress(residuals::Residuals, p::Params, opt, val = -1.0)
dual_res = residuals.dual_residual[p.iter]
s_k = Printf.@sprintf("%d", p.iter)
s_k *= " |"
s_s = Printf.@sprintf("%.5f", residuals.dual_gap[p.iter])
s_s = Printf.@sprintf("%.2e", residuals.dual_gap[p.iter])
s_s *= " |"
s_o = Printf.@sprintf("%.3f", residuals.prim_obj[p.iter])
s_o = Printf.@sprintf("%.2e", residuals.prim_obj[p.iter])
s_o *= " |"
s_f = Printf.@sprintf("%.5f", residuals.feasibility[p.iter])
s_f = Printf.@sprintf("%.2e", residuals.feasibility[p.iter])
s_f *= " |"
s_p = Printf.@sprintf("%.5f", primal_res)
s_p = Printf.@sprintf("%.2e", primal_res)
s_p *= " |"
s_d = Printf.@sprintf("%.5f", dual_res)
s_d = Printf.@sprintf("%.2e", dual_res)
s_d *= " |"
s_target_rank = Printf.@sprintf("%.0f", sum(p.target_rank))
s_target_rank = Printf.@sprintf("%g", sum(p.target_rank))
s_target_rank *= " |"
s_time = Printf.@sprintf("%.4f", time() - p.time0)
s_time = Printf.@sprintf("%g", time() - p.time0)
s_time *= " |"
a = "|"
a *= " "^max(0, 9 - length(s_k))
Expand Down
2 changes: 1 addition & 1 deletion test/jump_mimo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function jump_mimo(solver, seed, n; verbose = false, test = false)

nvars = ProxSDP.sympackedlen(n + 1)

model = Model(with_optimizer(solver))
model = Model(ProxSDP.Optimizer)
@variable(model, X[1:n+1, 1:n+1], PSD)
for j in 1:(n+1), i in j:(n+1)
@constraint(model, X[i, j] <= 1.0)
Expand Down
2 changes: 1 addition & 1 deletion test/jump_randsdp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ function jump_randsdp(solver, seed, n, m, verbose = false)

A, b, C = randsdp_data(seed, m, n)

model = Model(with_optimizer(solver))
model = Model(ProxSDP.Optimizer)
@variable(model, X[1:n, 1:n], PSD)
@objective(model, Min, sum(C[i, j] * X[i, j] for j in 1:n, i in 1:n))
@constraint(model, ctr[k in 1:m], sum(A[k][i, j] * X[i, j] for j in 1:n, i in 1:n) == b[k])
Expand Down
2 changes: 1 addition & 1 deletion test/jump_sdplib.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function jump_sdplib(solver, path; verbose = false, test = false)
n, m, F, c = sdplib_data(path)

# Build model
model = Model(with_optimizer(solver))
model = Model(ProxSDP.Optimizer)
@variable(model, X[1:n, 1:n], PSD)

# Objective function
Expand Down
2 changes: 1 addition & 1 deletion test/jump_sensorloc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ function jump_sensorloc(solver, seed, n; verbose = false, test = false)

m, x_true, a, d, d_bar = sensorloc_data(seed, n)

model = Model(with_optimizer(solver))
model = Model(ProxSDP.Optimizer)

# Build SDP problem
@variable(model, X[1:n+2, 1:n+2], PSD)
Expand Down

0 comments on commit e395878

Please sign in to comment.