Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

snoop precompile and package load times #122

Merged
merged 9 commits into from
Apr 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,24 @@ version = "0.4.1"

[deps]
AMD = "14f7f29c-3bd6-536c-9a0b-7339e30b5a3e"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
PrettyTables = "08abe8d2-0d0c-5749-adfa-8a2ac140af0d"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
QDLDL = "bfc457fd-c171-5ab7-bd9e-d5dbfc242d63"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
SnoopPrecompile = "66db9d55-30c0-4569-8b51-7e840670fc0c"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
SuiteSparse = "4607b0f0-06f3-5cda-b6b1-a6196a1729e9"
TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76"
TimerOutputs = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f"

[compat]
AMD = "0.4, 0.5"
DataFrames = "1"
MathOptInterface = "1.2"
PrettyTables = "1, 2"
QDLDL = "0.4"
Requires = "1"
SnoopPrecompile = "1"
StaticArrays = "1"
TimerOutputs = "0.5"
julia = "1.2"
Expand Down
13 changes: 12 additions & 1 deletion src/Clarabel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,16 @@ module Clarabel
end
const Optimizer{T} = Clarabel.MOImodule.Optimizer{T}

end

#precompile minimal MOI / native examples
using SnoopPrecompile
include("./precompile.jl")
redirect_stdout(devnull) do;
SnoopPrecompile.@precompile_all_calls begin
__precompile_native()
__precompile_moi()
end
end
__precompile_printfcns()

end #end module
10 changes: 7 additions & 3 deletions src/MOI_wrapper/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,14 @@ function MOI.empty!(optimizer::Optimizer{T}) where {T}
optimizer.rowranges = Dict{Int, UnitRange{Int}}()
end

MOI.is_empty(optimizer::Optimizer) = isnothing(optimizer.solver)
MOI.is_empty(optimizer::Optimizer{T}) where {T} = isnothing(optimizer.solver)

function MOI.optimize!(optimizer::Optimizer)
solution = optimizer.solver_module.solve!(optimizer.solver)
function MOI.optimize!(optimizer::Optimizer{T}) where {T}
if(optimizer.solver_module === Clarabel)
solution = Clarabel.solve!(optimizer.solver)
else
solution = optimizer.solver_module.solve!(optimizer.solver)
end
optimizer.solver_solution = solution
optimizer.solver_info = optimizer.solver_module.get_info(optimizer.solver)
nothing
Expand Down
2 changes: 0 additions & 2 deletions src/cones/coneops_defaults.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import Statistics: mean

## -------------------------------------------
# Default implementations for cone operations
# --------------------------------------------
Expand Down
1 change: 0 additions & 1 deletion src/equilibration.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import LinearAlgebra
import Statistics: mean

#Ruiz Equilibration procedure, using same method as in COSMO.jl

Expand Down
156 changes: 84 additions & 72 deletions src/info_print.jl
Original file line number Diff line number Diff line change
@@ -1,174 +1,186 @@

function print_banner(verbose::Bool)
function print_banner(io::IO, verbose::Bool)

if !verbose return; end
println("-------------------------------------------------------------")
@printf(" Clarabel.jl v%s - Clever Acronym \n", version())
println(" (c) Paul Goulart ")
println(" University of Oxford, 2022 ")
println("-------------------------------------------------------------")
println(io, "-------------------------------------------------------------")
@printf(io, " Clarabel.jl v%s - Clever Acronym \n", version())
println(io, " (c) Paul Goulart ")
println(io, " University of Oxford, 2022 ")
println(io, "-------------------------------------------------------------")
end
print_banner(verbose) = print_banner(stdout,verbose)


function info_print_configuration(
io::IO,
info::DefaultInfo{T},
settings::Settings,
settings::Settings{T},
data::DefaultProblemData{T},
cones::CompositeCone{T}
) where {T}

if(settings.verbose == false) return end

if(is_reduced(data.presolver))
@printf("\npresolve: removed %i constraints\n", count_reduced(data.presolver))
@printf(io, "\npresolve: removed %i constraints\n", count_reduced(data.presolver))
end

@printf("\nproblem:\n")
@printf(" variables = %i\n", data.n)
@printf(" constraints = %i\n", data.m)
@printf(" nnz(P) = %i\n", nnz(data.P))
@printf(" nnz(A) = %i\n", nnz(data.A))
@printf(" cones (total) = %i\n", length(cones))
print_conedims_by_type(cones, ZeroCone)
print_conedims_by_type(cones, NonnegativeCone)
print_conedims_by_type(cones, SecondOrderCone)
print_conedims_by_type(cones, PSDTriangleCone)
print_conedims_by_type(cones, PowerCone)
print_conedims_by_type(cones, ExponentialCone)
print_settings(settings, T)
@printf("\n")
@printf(io, "\nproblem:\n")
@printf(io, " variables = %i\n", data.n)
@printf(io, " constraints = %i\n", data.m)
@printf(io, " nnz(P) = %i\n", nnz(data.P))
@printf(io, " nnz(A) = %i\n", nnz(data.A))
@printf(io, " cones (total) = %i\n", length(cones))
print_conedims_by_type(io, cones, ZeroCone)
print_conedims_by_type(io, cones, NonnegativeCone)
print_conedims_by_type(io, cones, SecondOrderCone)
print_conedims_by_type(io, cones, PSDTriangleCone)
print_conedims_by_type(io, cones, PowerCone)
print_conedims_by_type(io, cones, ExponentialCone)
print_settings(io, settings)
@printf(io, "\n")

return nothing
end
info_print_configuration(info,settings,data,cones) = info_print_configuration(stdout,info,settings,data,cones)


function info_print_status_header(
io::IO,
info::DefaultInfo{T},
settings::Settings,
settings::Settings{T},
) where {T}

if(settings.verbose == false) return end

#print a subheader for the iterations info
@printf("%s", "iter ")
@printf("%s", "pcost ")
@printf("%s", "dcost ")
@printf("%s", "gap ")
@printf("%s", "pres ")
@printf("%s", "dres ")
@printf("%s", "k/t ")
@printf("%s", " μ ")
@printf("%s", "step ")
@printf("\n")
println("---------------------------------------------------------------------------------------------")
@printf(io, "%s", "iter ")
@printf(io, "%s", "pcost ")
@printf(io, "%s", "dcost ")
@printf(io, "%s", "gap ")
@printf(io, "%s", "pres ")
@printf(io, "%s", "dres ")
@printf(io, "%s", "k/t ")
@printf(io, "%s", " μ ")
@printf(io, "%s", "step ")
@printf(io, "\n")
println(io, "---------------------------------------------------------------------------------------------")

return nothing
end
info_print_status_header(info, settings) = info_print_status_header(stdout,info,settings)

function info_print_status(
io::IO,
info::DefaultInfo{T},
settings::Settings
) where {T}

if(settings.verbose == false) return end

@printf("%3d ", info.iterations)
@printf("% .4e ", info.cost_primal)
@printf("% .4e ", info.cost_dual)
@printf("%.2e ", min(info.gap_abs,info.gap_rel))
@printf("%.2e ", info.res_primal)
@printf("%.2e ", info.res_dual)
@printf("%.2e ", info.ktratio)
@printf("%.2e ", info.μ)
@printf(io, "%3d ", info.iterations)
@printf(io, "% .4e ", info.cost_primal)
@printf(io, "% .4e ", info.cost_dual)
@printf(io, "%.2e ", min(info.gap_abs,info.gap_rel))
@printf(io, "%.2e ", info.res_primal)
@printf(io, "%.2e ", info.res_dual)
@printf(io, "%.2e ", info.ktratio)
@printf(io, "%.2e ", info.μ)
if(info.iterations > 0)
@printf("%.2e ", info.step_length)
@printf(io, "%.2e ", info.step_length)
else
@printf(" ------ ") #info.step_length
@printf(io, " ------ ") #info.step_length
end

@printf("\n")
@printf(io, "\n")

return nothing
end
info_print_status(info,settings) = info_print_status(stdout,info,settings)


function info_print_footer(
io::IO,
info::DefaultInfo{T},
settings::Settings
) where {T}

if(settings.verbose == false) return end

println("---------------------------------------------------------------------------------------------")
@printf("Terminated with status = %s\n",SolverStatusDict[info.status])
@printf("solve time = %s\n",TimerOutputs.prettytime(info.solve_time*1e9))
println(io, "---------------------------------------------------------------------------------------------")
@printf(io, "Terminated with status = %s\n",SolverStatusDict[info.status])
@printf(io, "solve time = %s\n",TimerOutputs.prettytime(info.solve_time*1e9))

return nothing
end
info_print_footer(info,settings) = info_print_footer(stdout,info,settings)


function bool_on_off(v::Bool)
return v ? "on" : "off"
end



function print_settings(settings::Settings, T::DataType)
function print_settings(io::IO, settings::Settings{T}) where {T}

set = settings
@printf("\nsettings:\n")
@printf(io, "\nsettings:\n")

if(set.direct_kkt_solver)
@printf(" linear algebra: direct / %s, precision: %s\n", set.direct_solve_method, get_precision_string(T))
@printf(io, " linear algebra: direct / %s, precision: %s\n", set.direct_solve_method, get_precision_string(T))
end

@printf(" max iter = %i, time limit = %f, max step = %.3f\n",
@printf(io, " max iter = %i, time limit = %f, max step = %.3f\n",
set.max_iter,
set.time_limit,
set.max_step_fraction,
)
#
@printf(" tol_feas = %0.1e, tol_gap_abs = %0.1e, tol_gap_rel = %0.1e,\n",
@printf(io, " tol_feas = %0.1e, tol_gap_abs = %0.1e, tol_gap_rel = %0.1e,\n",
set.tol_feas,
set.tol_gap_abs,
set.tol_gap_rel
)

@printf(" static reg : %s, ϵ1 = %0.1e, ϵ2 = %0.1e\n",
@printf(io, " static reg : %s, ϵ1 = %0.1e, ϵ2 = %0.1e\n",
bool_on_off(set.static_regularization_enable),
set.static_regularization_constant,
set.static_regularization_proportional,

)
#
@printf(" dynamic reg: %s, ϵ = %0.1e, δ = %0.1e\n",
@printf(io, " dynamic reg: %s, ϵ = %0.1e, δ = %0.1e\n",
bool_on_off(set.dynamic_regularization_enable),
set.dynamic_regularization_eps,
set.dynamic_regularization_delta
)
@printf(" iter refine: %s, reltol = %0.1e, abstol = %0.1e, \n",
@printf(io, " iter refine: %s, reltol = %0.1e, abstol = %0.1e, \n",
bool_on_off(set.iterative_refinement_enable),
set.iterative_refinement_reltol,
set.iterative_refinement_abstol
)
@printf(" max iter = %d, stop ratio = %.1f\n",
@printf(io, " max iter = %d, stop ratio = %.1f\n",
set.iterative_refinement_max_iter,
set.iterative_refinement_stop_ratio
)
@printf(" equilibrate: %s, min_scale = %0.1e, max_scale = %0.1e\n",
@printf(io, " equilibrate: %s, min_scale = %0.1e, max_scale = %0.1e\n",
bool_on_off(set.equilibrate_enable),
set.equilibrate_min_scaling,
set.equilibrate_max_scaling
)
@printf(" max iter = %d\n",
@printf(io, " max iter = %d\n",
set.equilibrate_max_iter,
)

return nothing
end


get_precision_string(T::Type{<:Real}) = string(T)
get_precision_string(T::Type{<:BigFloat}) = string(T," (", precision(T), " bit)")


function print_conedims_by_type(cones::CompositeCone{T}, type) where {T}
function print_conedims_by_type(io::IO, cones::CompositeCone{T}, type::Type) where {T}

maxlistlen = 5

Expand All @@ -180,27 +192,27 @@ function print_conedims_by_type(cones::CompositeCone{T}, type) where {T}
return #don't report if none
end

nvars = map(K->Clarabel.numel(K), cones[isa.(cones,type)])
nvars = Int64[Clarabel.numel(K) for K in cones[isa.(cones,type)]]
name = rpad(string(nameof(type))[1:end-4],11) #drops "Cone" part
@printf(" : %s = %i, ", name, count)
@printf(io, " : %s = %i, ", name, count)

if count == 1
@printf(" numel = %i",nvars[1])
@printf(io, " numel = %i",nvars[1])

elseif count <= maxlistlen
#print them all
@printf(" numel = (")
foreach(x->@printf("%i,",x),nvars[1:end-1])
@printf("%i)",nvars[end])
@printf(io, " numel = (")
foreach(x->@printf(io, "%i,",x),nvars[1:end-1])
@printf(io, "%i)",nvars[end])

else
#print first (maxlistlen-1) and the final one
@printf(" numel = (")
foreach(x->@printf("%i,",x),nvars[1:(maxlistlen-1)])
@printf("...,%i)",nvars[end])
@printf(io, " numel = (")
foreach(x->@printf(io, "%i,",x),nvars[1:(maxlistlen-1)])
@printf(io, "...,%i)",nvars[end])
end

@printf("\n")

@printf(io, "\n")

end

2 changes: 1 addition & 1 deletion src/kktsolvers/direct-ldl/directldl_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ struct LDLDataMap
SOC_v = Vector{Vector{Int}}(undef,nsoc)

count = 1
for (i,cone) in enumerate(cones)
for cone in cones
if isa(cone,Clarabel.SecondOrderCone)
SOC_u[count] = Vector{Int}(undef,numel(cone))
SOC_v[count] = Vector{Int}(undef,numel(cone))
Expand Down
Loading