|
| 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