Skip to content

Commit 5d2196c

Browse files
authored
Add OPF benchmark (#2739)
1 parent d060acd commit 5d2196c

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

perf/opf/Project.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[deps]
2+
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
3+
Ipopt = "b6b21f68-93f8-5de0-b562-5493be1d77c9"
4+
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
5+
MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"
6+
PGLib = "07a8691f-3d11-4330-951b-3c50f98338be"
7+
PowerModels = "c36e90e8-916a-50a6-bd94-075b64ef4655"
8+
9+
[compat]
10+
PGLib = "0.2"
11+
PowerModels = "0.21"

perf/opf/opf.jl

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Copyright (c) 2017: Miles Lubin and contributors
2+
# Copyright (c) 2017: Google Inc.
3+
#
4+
# Use of this source code is governed by an MIT-style license that can be found
5+
# in the LICENSE.md file or at https://opensource.org/licenses/MIT.
6+
7+
import Ipopt
8+
import JuMP
9+
import MathOptInterface as MOI
10+
import PGLib
11+
import PowerModels
12+
13+
model = JuMP.direct_model(Ipopt.Optimizer())
14+
pm = PowerModels.instantiate_model(
15+
PGLib.pglib("pglib_opf_case10000_goc"),
16+
PowerModels.ACPPowerModel,
17+
PowerModels.build_opf;
18+
jump_model = model,
19+
);
20+
21+
ipopt = JuMP.backend(model)
22+
x = MOI.get(ipopt, MOI.ListOfVariableIndices())
23+
m, n = length(ipopt.nlp_model.constraints), length(x)
24+
25+
evaluator = MOI.Nonlinear.Evaluator(
26+
ipopt.nlp_model,
27+
MOI.Nonlinear.SparseReverseMode(),
28+
x,
29+
)
30+
MOI.initialize(evaluator, [:Grad, :Jac, :Hess])
31+
32+
H_struct = MOI.hessian_lagrangian_structure(evaluator)
33+
H = zeros(length(H_struct))
34+
μ = rand(m)
35+
σ = 0.0
36+
v = rand(n)
37+
@time MOI.eval_hessian_lagrangian(evaluator, H, v, σ, μ)
38+
39+
using BenchmarkTools
40+
@benchmark MOI.eval_hessian_lagrangian($evaluator, $H, $v, $σ, $μ) seconds = 100

0 commit comments

Comments
 (0)