Skip to content

Commit

Permalink
ExaModels ad timing added (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
sshin23 authored Jan 30, 2024
1 parent 863c294 commit bd5ae9c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7"

[compat]
ADNLPModels = "0.7"
ExaModels = "0.4"
ExaModels = "0.5"
Ipopt = "1"
JuMP = "1.15"
NLPModelsIpopt = "0.10"
Expand Down
41 changes: 22 additions & 19 deletions examodels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,14 @@ function solve_opf(file_name)
c13 = ExaModels.constraint!(w, c9, g.bus => -pg[g.i] for g in data.gen)
c14 = ExaModels.constraint!(w, c10, g.bus => -qg[g.i] for g in data.gen)

model = ExaModels.ExaModel(w)
model = ExaModels.TimedNLPModel(
ExaModels.ExaModel(w)
)

model_build_time = time() - time_model_start


time_solve_start = time()

result = NLPModelsIpopt.ipopt(model)

cost = result.objective
Expand All @@ -206,14 +207,14 @@ function solve_opf(file_name)
solve_time = time() - time_solve_start
total_time = time() - time_data_start

# TODO: once a built-in timer is implemented in ExaModels, report callback timing

# total_callback_time =
# nlp_block.evaluator.eval_objective_timer +
# nlp_block.evaluator.eval_objective_gradient_timer +
# nlp_block.evaluator.eval_constraint_timer +
# nlp_block.evaluator.eval_constraint_jacobian_timer +
# nlp_block.evaluator.eval_hessian_lagrangian_timer
total_callback_time =
model.stats.obj_time +
model.stats.grad_time +
model.stats.cons_time +
model.stats.jac_coord_time +
model.stats.hess_coord_time +
model.stats.jac_structure_time +
model.stats.hess_structure_time

println("")
println("\033[1mSummary\033[0m")
Expand All @@ -226,15 +227,15 @@ function solve_opf(file_name)
println(" data time.: $(data_load_time)")
println(" build time: $(model_build_time)")
println(" solve time: $(solve_time)")
# println(" callbacks: $(total_callback_time)")
println(" callbacks: $(total_callback_time)")
println("")
println(" callbacks time:")
println(" * obj.....: $(model.stats.obj_time)")
println(" * grad....: $(model.stats.grad_time)")
println(" * cons....: $(model.stats.cons_time)")
println(" * jac.....: $(model.stats.jac_coord_time + model.stats.jac_structure_time)")
println(" * hesslag.: $(model.stats.hess_coord_time + model.stats.hess_structure_time)")
println("")
# println(" callbacks time:")
# println(" * obj.....: $(nlp_block.evaluator.eval_objective_timer)")
# println(" * grad....: $(nlp_block.evaluator.eval_objective_gradient_timer)")
# println(" * cons....: $(nlp_block.evaluator.eval_constraint_timer)")
# println(" * jac.....: $(nlp_block.evaluator.eval_constraint_jacobian_timer)")
# println(" * hesslag.: $(nlp_block.evaluator.eval_hessian_lagrangian_timer)")
# println("")

va_sol = ExaModels.solution(result, va)
va_dict = Dict("va_$(b.j)" => va_sol[b.i] for (i,b) in enumerate(data.bus))
Expand Down Expand Up @@ -264,7 +265,7 @@ function solve_opf(file_name)
"time_data" => data_load_time,
"time_build" => model_build_time,
"time_solve" => solve_time,
# "time_callbacks" => total_callback_time,
"time_callbacks" => total_callback_time,
"solution" => Dict(
va_dict...,
vm_dict...,
Expand All @@ -280,3 +281,5 @@ write_out_tuple((i,j,k)) = "$(i)_$(j)_$(k)"
if isinteractive() == false
solve_opf("$(@__DIR__)/data/opf_warmup.m")
end


0 comments on commit bd5ae9c

Please sign in to comment.