Skip to content

Commit

Permalink
Examodels AD Timing (#63)
Browse files Browse the repository at this point in the history
* ExaModels ad timing added (#62)

---------

Co-authored-by: Sungho Shin <[email protected]>
  • Loading branch information
ccoffrin and sshin23 authored Jan 30, 2024
1 parent 863c294 commit bdfc24d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 24 deletions.
12 changes: 8 additions & 4 deletions Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

julia_version = "1.10.0"
manifest_format = "2.0"
project_hash = "00bfc230370ab2d06ed7ae6128542d1a85a5a113"
project_hash = "2b196f4165a07d56342f51102f8b4a3a616731b5"

[[deps.ADNLPModels]]
deps = ["ColPack", "ForwardDiff", "LinearAlgebra", "NLPModels", "Requires", "ReverseDiff", "SparseArrays"]
Expand Down Expand Up @@ -444,22 +444,26 @@ uuid = "90fa49ef-747e-5e6f-a989-263ba693cf1a"
version = "0.5.2"

[[deps.ExaModels]]
deps = ["NLPModels", "SolverCore"]
git-tree-sha1 = "054b99d8f8d19a81a1fbbad74223af16f8012f2a"
deps = ["NLPModels", "Printf", "SolverCore"]
git-tree-sha1 = "606d0f6c1bcdda9ec7841a4892337b00814e2334"
uuid = "1037b233-b668-4ce9-9b63-f9f681f55dd2"
version = "0.4.2"
version = "0.5.0"

[deps.ExaModels.extensions]
ExaModelsAMDGPU = "AMDGPU"
ExaModelsCUDA = "CUDA"
ExaModelsJuMP = "JuMP"
ExaModelsKernelAbstractions = "KernelAbstractions"
ExaModelsMOI = "MathOptInterface"
ExaModelsOneAPI = "oneAPI"
ExaModelsSpecialFunctions = "SpecialFunctions"

[deps.ExaModels.weakdeps]
AMDGPU = "21141c5a-9bdb-4563-92ae-f87d6854732e"
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
KernelAbstractions = "63c18a36-062a-441e-b654-da1e3ab1ce7c"
MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
oneAPI = "8f75cd03-7ff8-4ecb-9b8f-daf728133b1b"

Expand Down
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 bdfc24d

Please sign in to comment.