Skip to content

Commit

Permalink
Match formatting to simplify diff
Browse files Browse the repository at this point in the history
  • Loading branch information
odow committed Mar 22, 2022
1 parent 11de0f1 commit 813327b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 18 deletions.
16 changes: 4 additions & 12 deletions galacticoptim.jl
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
time_start = time()

import PowerModels
using GalacticOptim
using ForwardDiff
using GalacticOptim, ForwardDiff
using Ipopt

pkg_load_time = time() - time_start


time_start = time()



file_name = "data/pglib_opf_case5_pjm.m"
#file_name = "data/pglib_opf_case118_ieee.m"

Expand Down Expand Up @@ -74,7 +71,6 @@ for (i,branch) in ref[:branch]
br_b_to[i] = branch["b_to"]
end


var_lookup = Dict{String,Int}()

var_init = Float64[]
Expand Down Expand Up @@ -128,8 +124,7 @@ end

@assert var_idx == length(var_init)+1


function opf_objective(x,param)
function opf_objective(x, param)
cost = 0.0
for (i,gen) in ref[:gen]
pg = x[var_lookup["pg_$(i)"]]
Expand All @@ -138,7 +133,7 @@ function opf_objective(x,param)
return cost
end

function opf_constraints(x,param)
function opf_constraints(x, param)

va = Dict(i => x[var_lookup["va_$(i)"]] for (i,bus) in ref[:bus])
vm = Dict(i => x[var_lookup["vm_$(i)"]] for (i,bus) in ref[:bus])
Expand Down Expand Up @@ -208,7 +203,7 @@ function opf_constraints(x,param)
power_flow_q_from_con = [
-(br_b[l]+br_b_fr[l])/br_tm[l]*vm_fr[l]^2 -
(-br_b[l]*br_tr[l]-br_g[l]*br_ti[l])/br_tm[l]*(vm_fr[l]*vm_to[l]*cos(va_fr[l]-va_to[l])) +
(-br_g[l]*br_tr[l]+br_b[l]*br_ti[l])/br_tm[l]*(vm_fr[l]*vm_to[l]*sin(va_fr[l]-va_to[l])) -
(-br_g[l]*br_tr[l]+br_b[l]*br_ti[l])/br_tm[l]*(vm_fr[l]*vm_to[l]*sin(va_fr[l]-va_to[l])) -
q[(l,i,j)]
for (l,i,j) in ref[:arcs_from]
]
Expand Down Expand Up @@ -255,7 +250,6 @@ function opf_constraints(x,param)
]
end


con_lbs = Float64[]
con_ubs = Float64[]

Expand All @@ -277,7 +271,6 @@ for (i,bus) in ref[:bus]
push!(con_ubs, 0.0)
end


#power_flow_p_from_con
for (l,i,j) in ref[:arcs_from]
push!(con_lbs, 0.0)
Expand Down Expand Up @@ -323,7 +316,6 @@ for (l,i,j) in ref[:arcs_to]
push!(con_ubs, branch["rate_a"]^2)
end


println("variables: $(length(var_init)), $(length(var_lb)), $(length(var_ub))")
println("constraints: $(length(opf_constraints(var_init, ref))), $(length(con_lbs)), $(length(con_ubs))")

Expand Down
8 changes: 2 additions & 6 deletions nlpmodels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ end

function opf_constraints(x::Vector)

### Note this example beaks ForwardDiff ###
### Note this example beaks ForwardDiff ###
# con_vals = Float64[]

# for (i,bus) in ref[:ref_buses]
Expand Down Expand Up @@ -214,7 +214,7 @@ function opf_constraints(x::Vector)
power_flow_q_from_con = [
-(br_b[l]+br_b_fr[l])/br_tm[l]*vm_fr[l]^2 -
(-br_b[l]*br_tr[l]-br_g[l]*br_ti[l])/br_tm[l]*(vm_fr[l]*vm_to[l]*cos(va_fr[l]-va_to[l])) +
(-br_g[l]*br_tr[l]+br_b[l]*br_ti[l])/br_tm[l]*(vm_fr[l]*vm_to[l]*sin(va_fr[l]-va_to[l])) -
(-br_g[l]*br_tr[l]+br_b[l]*br_ti[l])/br_tm[l]*(vm_fr[l]*vm_to[l]*sin(va_fr[l]-va_to[l])) -
q[(l,i,j)]
for (l,i,j) in ref[:arcs_from]
]
Expand Down Expand Up @@ -270,7 +270,6 @@ for (i,bus) in ref[:ref_buses]
push!(con_ubs, 0.0)
end


#power_balance_p_con
for (i,bus) in ref[:bus]
push!(con_lbs, 0.0)
Expand All @@ -283,7 +282,6 @@ for (i,bus) in ref[:bus]
push!(con_ubs, 0.0)
end


#power_flow_p_from_con
for (l,i,j) in ref[:arcs_from]
push!(con_lbs, 0.0)
Expand Down Expand Up @@ -329,7 +327,6 @@ for (l,i,j) in ref[:arcs_to]
push!(con_ubs, branch["rate_a"]^2)
end


#println("variables: $(length(var_init)), $(length(var_lb)), $(length(var_ub))")
#println("constraints: $(length(opf_constraints(var_init))), $(length(con_lbs)), $(length(con_ubs))")

Expand All @@ -339,7 +336,6 @@ nlp = ADNLPModel(opf_objective, var_init, var_lb, var_ub, opf_constraints, con_l
# objective-only solve
#nlp = ADNLPModel(opf_objective, var_init, var_lb, var_ub)


model_build_time = time() - time_start


Expand Down

4 comments on commit 813327b

@odow
Copy link
Collaborator Author

@odow odow commented on 813327b Mar 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ccoffrin if you run with SciML/Optimization.jl#218 then I get:

julia> include("galacticoptim.jl")

[info | PowerModels]: extending matpower format with data: areas 1x3
[info | PowerModels]: removing 1 cost terms from generator 4: [4000.0, 0.0]
[info | PowerModels]: removing 1 cost terms from generator 1: [1400.0, 0.0]
[info | PowerModels]: removing 1 cost terms from generator 5: [1000.0, 0.0]
[info | PowerModels]: removing 1 cost terms from generator 2: [1500.0, 0.0]
[info | PowerModels]: removing 1 cost terms from generator 3: [3000.0, 0.0]
[info | PowerModels]: updated generator 4 cost function with order 2 to a function of order 3: [0.0, 4000.0, 0.0]
[info | PowerModels]: updated generator 1 cost function with order 2 to a function of order 3: [0.0, 1400.0, 0.0]
[info | PowerModels]: updated generator 5 cost function with order 2 to a function of order 3: [0.0, 1000.0, 0.0]
[info | PowerModels]: updated generator 2 cost function with order 2 to a function of order 3: [0.0, 1500.0, 0.0]
[info | PowerModels]: updated generator 3 cost function with order 2 to a function of order 3: [0.0, 3000.0, 0.0]
variables: 44, 44, 44
constraints: 53, 53, 53
This is Ipopt version 3.14.4, running with linear solver MUMPS 5.4.1.

Number of nonzeros in equality constraint Jacobian...:     1540
Number of nonzeros in inequality constraint Jacobian.:      792
Number of nonzeros in Lagrangian Hessian.............:      990

Total number of variables............................:       44
                     variables with only lower bounds:        0
                variables with lower and upper bounds:       39
                     variables with only upper bounds:        0
Total number of equality constraints.................:       35
Total number of inequality constraints...............:       18
        inequality constraints with only lower bounds:        0
   inequality constraints with lower and upper bounds:        6
        inequality constraints with only upper bounds:       12

iter    objective    inf_pr   inf_du lg(mu)  ||d||  lg(rg) alpha_du alpha_pr  ls
   0  1.0059989e+02 3.99e+00 2.88e+01  -1.0 0.00e+00    -  0.00e+00 0.00e+00   0
   1  8.3066346e+03 2.47e+00 1.01e+02  -1.0 2.78e+00    -  4.11e-03 3.82e-01h  1
   2  6.7182484e+03 2.36e+00 9.62e+01  -1.0 1.60e+01    -  7.37e-02 4.44e-02f  1
   3  6.6691211e+03 2.30e+00 9.34e+01  -1.0 1.30e+01    -  4.95e-01 2.40e-02f  1
   4  6.5744238e+03 2.04e+00 8.25e+01  -1.0 1.29e+01    -  3.67e-01 1.12e-01f  2
   5  6.8265929e+03 1.80e+00 7.10e+01  -1.0 1.23e+01    -  8.72e-01 1.20e-01h  2
   6  8.8541540e+03 1.08e+00 4.20e+01  -1.0 9.14e+00    -  5.92e-01 4.00e-01h  1
   7  1.0572759e+04 8.62e-01 3.58e+01  -1.0 2.94e+00    -  4.94e-01 2.00e-01h  1
   8  1.7308372e+04 3.63e-02 1.47e+01  -1.0 2.41e+00    -  7.66e-01 9.58e-01h  1
   9  1.7572883e+04 1.33e-02 1.10e+00  -1.0 2.11e+00    -  1.00e+00 1.00e+00h  1
iter    objective    inf_pr   inf_du lg(mu)  ||d||  lg(rg) alpha_du alpha_pr  ls
  10  1.7590632e+04 1.69e-03 1.61e-01  -1.0 5.03e-01    -  1.00e+00 1.00e+00h  1
  11  1.7558725e+04 5.24e-03 5.03e-01  -2.5 6.03e-01    -  8.35e-01 9.36e-01f  1
  12  1.7553111e+04 3.34e-03 4.11e+00  -2.5 2.84e-01    -  1.00e+00 8.20e-01h  1
  13  1.7552956e+04 3.24e-05 1.26e-02  -2.5 6.35e-02    -  1.00e+00 1.00e+00h  1
  14  1.7551990e+04 1.35e-05 1.09e+00  -3.8 2.53e-02    -  1.00e+00 9.25e-01h  1
  15  1.7551938e+04 4.46e-08 1.23e-02  -3.8 7.00e-03    -  1.00e+00 1.00e+00f  1
  16  1.7551940e+04 2.35e-10 2.06e-04  -3.8 3.84e-04    -  1.00e+00 1.00e+00h  1
  17  1.7551892e+04 1.75e-07 2.11e-01  -5.7 2.49e-03    -  1.00e+00 9.68e-01f  1
  18  1.7551891e+04 6.82e-11 3.10e-05  -5.7 2.38e-04    -  1.00e+00 1.00e+00f  1
  19  1.7551891e+04 1.62e-14 6.53e-10  -5.7 5.20e-07    -  1.00e+00 1.00e+00h  1
iter    objective    inf_pr   inf_du lg(mu)  ||d||  lg(rg) alpha_du alpha_pr  ls
  20  1.7551891e+04 6.34e-12 3.03e-07  -8.6 3.52e-05    -  1.00e+00 1.00e+00f  1
  21  1.7551891e+04 2.86e-14 1.86e-12  -8.6 3.34e-08    -  1.00e+00 1.00e+00h  1

Number of Iterations....: 21

                                   (scaled)                 (unscaled)
Objective...............:   4.3879727096486914e+02    1.7551890838594765e+04
Dual infeasibility......:   1.8607602096326991e-12    7.4430408385307965e-11
Constraint violation....:   1.8515322608436690e-14    2.8643754035329039e-14
Variable bound violation:   2.9463905093507492e-08    2.9463905093507492e-08
Complementarity.........:   2.5059076302148607e-09    1.0023630520859442e-07
Overall NLP error.......:   2.5059076302148607e-09    1.0023630520859442e-07


Number of objective function evaluations             = 28
Number of objective gradient evaluations             = 22
Number of equality constraint evaluations            = 28
Number of inequality constraint evaluations          = 28
Number of equality constraint Jacobian evaluations   = 22
Number of inequality constraint Jacobian evaluations = 22
Number of Lagrangian Hessian evaluations             = 21
Total seconds in IPOPT                               = 22.625

EXIT: Optimal Solution Found.

Summary
   case......: data/pglib_opf_case5_pjm.m
   cost......: 17552
   pkg time..: 0.001653909683227539
   data time.: 0.012835025787353516
   build time: 3.8377931118011475
   solve time: 22.768468856811523

@ccoffrin
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That log looks spot on to me.

I tried with this setup,

Status `~/Documents/dev/rosetta-opf/Project.toml`
  [54578032] ADNLPModels v0.3.1
  [25c3070e] ComplexOptInterface v0.0.3
  [f6369f11] ForwardDiff v0.10.25
  [a75be94c] GalacticOptim v2.4.0 `git@github.com:odow/GalacticOptim.jl.git#master`
  [b6b21f68] Ipopt v0.9.1
  [4076af6c] JuMP v0.22.3 ⚲
  [f4238b75] NLPModelsIpopt v0.9.1
  [792afdf1] NLPModelsJuMP v0.9.1
  [01bcebdf] Nonconvex v1.0.2
  [bf347577] NonconvexIpopt v0.1.4
  [429524aa] Optim v1.6.2
  [c36e90e8] PowerModels v0.19.4

I also tried with JuMP v0.23 with similar results.

I am getting this error,

ERROR: LoadError: UndefVarError: SingleVariable not defined
Stacktrace:
 [1] __solve(prob::OptimizationProblem{true, OptimizationFunction{true, GalacticOptim.AutoForwardDiff{nothing}, typeof(opf_objective), Nothing, Nothing, Nothing, typeof(opf_constraints), Nothing, Nothing}, Vector{Float64}, Dict{Symbol, Any}, Vector{Float64}, Vector{Float64}, Vector{Float64}, Nothing, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}}, opt::Ipopt.Optimizer; maxiters::Nothing, maxtime::Nothing, abstol::Nothing, reltol::Nothing, kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
   @ GalacticOptim ~/.julia/packages/GalacticOptim/mlA5m/src/solve/moi.jl:145
 [2] __solve
   @ ~/.julia/packages/GalacticOptim/mlA5m/src/solve/moi.jl:135 [inlined]
 [3] #solve#480
   @ ~/.julia/packages/SciMLBase/BoNUy/src/solve.jl:3 [inlined]
 [4] solve(::OptimizationProblem{true, OptimizationFunction{true, GalacticOptim.AutoForwardDiff{nothing}, typeof(opf_objective), Nothing, Nothing, Nothing, typeof(opf_constraints), Nothing, Nothing}, Vector{Float64}, Dict{Symbol, Any}, Vector{Float64}, Vector{Float64}, Vector{Float64}, Nothing, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}}, ::Ipopt.Optimizer)
   @ SciMLBase ~/.julia/packages/SciMLBase/BoNUy/src/solve.jl:3
 [5] top-level scope
   @ ~/Documents/dev/rosetta-opf/galacticoptim.jl:335
 [6] include(fname::String)
   @ Base.MainInclude ./client.jl:451
 [7] top-level scope
   @ REPL[16]:1
in expression starting at /Users/cjc/Documents/dev/rosetta-opf/galacticoptim.jl:335

@odow
Copy link
Collaborator Author

@odow odow commented on 813327b Mar 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[a75be94c] GalacticOptim v2.4.0 git@github.com:odow/GalacticOptim.jl.git#master

Should be #od/moi1

@ccoffrin
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oppps, working now. Thanks!

Please sign in to comment.