Skip to content

Commit

Permalink
remove use_twolevel option in AdmmEnv
Browse files Browse the repository at this point in the history
  • Loading branch information
frapac authored and michel2323 committed Jun 1, 2022
1 parent 550ad6f commit 9b4944e
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 124 deletions.
2 changes: 1 addition & 1 deletion src/interface/solve_acopf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function solve_acopf(case::String;
end

env = AdmmEnv{T,TD,TI,TM}(case, rho_pq, rho_va; case_format=case_format,
use_gpu=use_gpu, use_linelimit=use_linelimit, use_twolevel=false,
use_gpu=use_gpu, use_linelimit=use_linelimit,
use_projection=use_projection, tight_factor=tight_factor, gpu_no=gpu_no,
storage_ratio=storage_ratio, storage_charge_max=storage_charge_max,
verbose=verbose)
Expand Down
2 changes: 1 addition & 1 deletion src/interface/solve_acopf_rolling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function solve_acopf_rolling(case::String, load_prefix::String;
end

env = AdmmEnv{T,TD,TI,TM}(case, rho_pq, rho_va; case_format=case_format,
use_gpu=use_gpu, use_linelimit=use_linelimit, use_twolevel=false,
use_gpu=use_gpu, use_linelimit=use_linelimit,
use_projection=use_projection, load_prefix=load_prefix,
tight_factor=tight_factor, gpu_no=gpu_no, verbose=verbose)
mod = ModelAcopf{T,TD,TI,TM}(env; ramp_ratio=ramp_ratio)
Expand Down
2 changes: 1 addition & 1 deletion src/interface/solve_mpacopf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function solve_mpacopf(case::String, load_prefix::String;
end

env = AdmmEnv{T,TD,TI,TM}(case, rho_pq, rho_va; case_format=case_format,
use_gpu=use_gpu, use_linelimit=use_linelimit, use_twolevel=false,
use_gpu=use_gpu, use_linelimit=use_linelimit,
load_prefix=load_prefix, tight_factor=tight_factor, gpu_no=gpu_no, verbose=verbose)
mod = ModelMpacopf{T,TD,TI,TM}(env; start_period=start_period, end_period=end_period, ramp_ratio=ramp_ratio)

Expand Down
2 changes: 1 addition & 1 deletion src/interface/solve_mpec.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function solve_acopf_mpec(case::String;
end

env = AdmmEnv{T,TD,TI,TM}(case, rho_pq, rho_va; case_format=case_format,
use_gpu=use_gpu, use_linelimit=use_linelimit, use_twolevel=false,
use_gpu=use_gpu, use_linelimit=use_linelimit,
use_projection=use_projection, tight_factor=tight_factor,
storage_ratio=storage_ratio, storage_charge_max=storage_charge_max,
gpu_no=gpu_no, verbose=verbose)
Expand Down
2 changes: 1 addition & 1 deletion src/models/acopf/acopf_init_solution_cpu.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function init_solution!(
model::AbstractOPFModel{Float64,Array{Float64,1},Array{Int,1},Array{Float64,2}},
sol::SolutionOneLevel{Float64,Array{Float64,1}},
sol::Solution{Float64,Array{Float64,1}},
rho_pq::Float64, rho_va::Float64
)

Expand Down
2 changes: 1 addition & 1 deletion src/models/acopf/acopf_init_solution_gpu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ end

function init_solution!(
model::AbstractOPFModel{Float64,CuArray{Float64,1},CuArray{Int,1},CuArray{Float64,2}},
sol::SolutionOneLevel{Float64,CuArray{Float64,1}},
sol::Solution{Float64,CuArray{Float64,1}},
rho_pq::Float64, rho_va::Float64
)
fill!(sol, 0.0)
Expand Down
11 changes: 3 additions & 8 deletions src/models/acopf/acopf_model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ mutable struct ModelAcopf{T,TD,TI,TM} <: AbstractOPFModel{T,TD,TI,TM}
model.nvar_padded = model.nvar + 8*(model.nline_padded - model.grid_data.nline)
model.gen_start = 1
model.line_start = 2*model.grid_data.ngen + 1


model.pgmin_curr = TD(undef, model.grid_data.ngen)
model.pgmax_curr = TD(undef, model.grid_data.ngen)
Expand All @@ -77,15 +77,10 @@ mutable struct ModelAcopf{T,TD,TI,TM} <: AbstractOPFModel{T,TD,TI,TM}
model.nvar_u_padded = model.nvar_u + 8*(model.nline_padded - model.grid_data.nline)
model.nvar_v = 2*model.grid_data.ngen + 4*model.grid_data.nline + 2*model.grid_data.nbus
model.bus_start = 2*model.grid_data.ngen + 4*model.grid_data.nline + 1
if env.use_twolevel
model.nvar = model.nvar_u + model.nvar_v
model.nvar_padded = model.nvar_u_padded + model.nvar_v
end

# Memory space is allocated based on the padded size.
model.solution = ifelse(env.use_twolevel,
SolutionTwoLevel{T,TD}(model.nvar_padded, model.nvar_v, model.nline_padded),
SolutionOneLevel{T,TD}(model.nvar_padded))
model.solution =
Solution{T,TD}(model.nvar_padded)
init_solution!(model, model.solution, env.initial_rho_pq, env.initial_rho_va)
model.gen_solution = EmptyGeneratorSolution{T,TD}()

Expand Down
4 changes: 2 additions & 2 deletions src/models/mpec/mpec_init_solution_cpu.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function init_solution!(
model::ComplementarityModel{Float64,Array{Float64,1},Array{Int,1},Array{Float64,2}},
sol::SolutionOneLevel{Float64,Array{Float64,1}},
sol::Solution{Float64,Array{Float64,1}},
rho_pq::Float64, rho_va::Float64
)

Expand Down Expand Up @@ -49,4 +49,4 @@ function init_solution!(
end

return
end
end
4 changes: 2 additions & 2 deletions src/models/mpec/mpec_init_solution_gpu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ end

function init_solution!(
model::ComplementarityModel{Float64,CuArray{Float64,1},CuArray{Int,1},CuArray{Float64,2}},
sol::SolutionOneLevel{Float64,CuArray{Float64,1}},
sol::Solution{Float64,CuArray{Float64,1}},
rho_pq::Float64, rho_va::Float64
)
grid = model.grid
Expand Down Expand Up @@ -85,4 +85,4 @@ function init_solution!(
CUDA.synchronize()

return
end
end
4 changes: 2 additions & 2 deletions src/models/pf/pf_struct.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ mutable struct PowerFlow{T,TD}
F::Vector{Float64}
Jac::SparseMatrixCSC{Float64,Int}

function PowerFlow{T,TD}(case::String; case_format="matpower", start_method="warm", use_scaling=false, use_twolevel=false, verbose=1) where {T,TD<:AbstractArray{T}}
function PowerFlow{T,TD}(case::String; case_format="matpower", start_method="warm", use_scaling=false, verbose=1) where {T,TD<:AbstractArray{T}}
nw = parse_matpower(case; case_format=case_format)
return PowerFlow{T,TD}(nw; start_method=start_method, use_scaling=use_scaling, use_twolevel=use_twolevel, verbose=verbose)
return PowerFlow{T,TD}(nw; start_method=start_method, use_scaling=use_scaling, verbose=verbose)
end

function PowerFlow{T,TD}(nw::Dict{String,Any}; start_method="warm", verbose=1) where {T,TD<:AbstractArray{T}}
Expand Down
111 changes: 7 additions & 104 deletions src/utils/environment.jl
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ mutable struct AdmmEnv{T,TD,TI,TM} <: AbstractAdmmEnv{T,TD,TI,TM}
horizon_length::Int
use_gpu::Bool
use_linelimit::Bool
use_twolevel::Bool
use_mpi::Bool
use_projection::Bool
load_specified::Bool
Expand All @@ -106,7 +105,7 @@ mutable struct AdmmEnv{T,TD,TI,TM} <: AbstractAdmmEnv{T,TD,TI,TM}
function AdmmEnv{T,TD,TI,TM}(
case::String, rho_pq::Float64, rho_va::Float64;
case_format="matpower",
use_gpu=false, use_linelimit=true, use_twolevel=false, use_mpi=false, use_projection=false,
use_gpu=false, use_linelimit=true, use_mpi=false, use_projection=false,
gpu_no::Int=0, verbose::Int=1, tight_factor=1.0, droop=0.04, storage_ratio=0.0, storage_charge_max=1.0,
horizon_length=1, load_prefix::String="", comm::MPI.Comm=MPI.COMM_WORLD
) where {T, TD<:AbstractArray{T}, TI<:AbstractArray{Int}, TM<:AbstractArray{T,2}}
Expand All @@ -126,7 +125,6 @@ mutable struct AdmmEnv{T,TD,TI,TM} <: AbstractAdmmEnv{T,TD,TI,TM}
env.use_mpi = use_mpi
env.use_projection = use_projection
env.gpu_no = gpu_no
env.use_twolevel = use_twolevel
env.load_specified = false
env.comm = comm

Expand Down Expand Up @@ -158,11 +156,11 @@ function Base.copy(ref::EmptyGeneratorSolution{T,TD}) where {T,TD<:AbstractArray
end

"""
SolutionOneLevel{T,TD}
Solution{T,TD}
This contains the solutions of ACOPF model instance, including the ADMM parameter rho.
"""
mutable struct SolutionOneLevel{T,TD} <: AbstractSolution{T,TD}
mutable struct Solution{T,TD} <: AbstractSolution{T,TD}
u_curr::TD
v_curr::TD
l_curr::TD
Expand All @@ -184,7 +182,7 @@ mutable struct SolutionOneLevel{T,TD} <: AbstractSolution{T,TD}
cumul_iters::Int
status::Symbol

function SolutionOneLevel{T,TD}(nvar::Int) where {T, TD<:AbstractArray{T}}
function Solution{T,TD}(nvar::Int) where {T, TD<:AbstractArray{T}}
sol = new{T,TD}(
TD(undef, nvar), # u_curr
TD(undef, nvar), # v_curr
Expand Down Expand Up @@ -214,7 +212,7 @@ mutable struct SolutionOneLevel{T,TD} <: AbstractSolution{T,TD}
end


function Base.fill!(sol::SolutionOneLevel, val)
function Base.fill!(sol::Solution, val)
fill!(sol.u_curr, val)
fill!(sol.v_curr, val)
fill!(sol.l_curr, val)
Expand All @@ -232,9 +230,9 @@ function Base.fill!(sol::SolutionOneLevel, val)
fill!(sol.Ax_plus_By, val)
end

function Base.copy(ref::SolutionOneLevel{T,TD}) where {T,TD<:AbstractArray{T}}
function Base.copy(ref::Solution{T,TD}) where {T,TD<:AbstractArray{T}}
nvar = length(ref.u_curr)
sol = SolutionOneLevel{T,TD}(nvar)
sol = Solution{T,TD}(nvar)

copyto!(sol.u_curr, ref.u_curr)
copyto!(sol.v_curr, ref.v_curr)
Expand All @@ -259,101 +257,6 @@ function Base.copy(ref::SolutionOneLevel{T,TD}) where {T,TD<:AbstractArray{T}}
return sol
end

"""
SolutionTwoLevel{T,TD}
This contains the solutions of ACOPF model instance for two-level ADMM algorithm,
including the ADMM parameter rho.
"""
mutable struct SolutionTwoLevel{T,TD} <: AbstractSolution{T,TD}
x_curr::TD
xbar_curr::TD
z_outer::TD
z_curr::TD
z_prev::TD
l_curr::TD
lz::TD
rho::TD
rp::TD
rd::TD
rp_old::TD
Ax_plus_By::TD
wRIij::TD

function SolutionTwoLevel{T,TD}() where {T, TD<:AbstractArray{T}}
return new{T,TD}()
end

function SolutionTwoLevel{T,TD}(nvar::Int, nvar_v::Int, nline::Int) where {T, TD<:AbstractArray{T}}
sol = new{T,TD}(
TD(undef, nvar), # x_curr
TD(undef, nvar_v), # xbar_curr
TD(undef, nvar), # z_outer
TD(undef, nvar), # z_curr
TD(undef, nvar), # z_prev
TD(undef, nvar), # l_curr
TD(undef, nvar), # lz
TD(undef, nvar), # rho
TD(undef, nvar), # rp
TD(undef, nvar), # rd
TD(undef, nvar), # rp_old
TD(undef, nvar), # Ax_plus_By
TD(undef, 2*nline) # wRIij
)

fill!(sol, 0.0)

return sol
end
end

function Base.fill!(sol::SolutionTwoLevel, val)
fill!(sol.x_curr, val)
fill!(sol.xbar_curr, val)
fill!(sol.z_outer, val)
fill!(sol.z_curr, val)
fill!(sol.z_prev, val)
fill!(sol.l_curr, val)
fill!(sol.lz, val)
fill!(sol.rho, val)
fill!(sol.rp, val)
fill!(sol.rd, val)
fill!(sol.rp_old, val)
fill!(sol.Ax_plus_By, val)
fill!(sol.wRIij, val)
end

function Base.copy(ref::SolutionTwoLevel{T,TD}) where {T, TD<:AbstractArray{T}}
sol = SolutionTwoLevel{T,TD}()
sol.x_curr = TD(undef, length(ref.x_curr))
sol.xbar_curr = TD(undef, length(ref.xbar_curr))
sol.z_outer = TD(undef, length(ref.z_outer))
sol.z_curr = TD(undef, length(ref.z_curr))
sol.z_prev = TD(undef, length(ref.z_prev))
sol.l_curr = TD(undef, length(ref.l_curr))
sol.lz = TD(undef, length(ref.lz))
sol.rho = TD(undef, length(ref.rho))
sol.rp = TD(undef, length(ref.rp))
sol.rd = TD(undef, length(ref.rd))
sol.rp_old = TD(undef, length(ref.rp_old))
sol.Ax_plus_By = TD(undef, length(ref.Ax_plus_By))
sol.wRIij = TD(undef, length(ref.wRIij))

copyto!(sol.x_curr, ref.x_curr)
copyto!(sol.xbar_curr, ref.xbar_curr)
copyto!(sol.z_outer, ref.z_outer)
copyto!(sol.z_curr, ref.z_curr)
copyto!(sol.z_prev, ref.z_prev)
copyto!(sol.l_curr, ref.l_curr)
copyto!(sol.lz, ref.lz)
copyto!(sol.rho, ref.rho)
copyto!(sol.rp, ref.rp)
copyto!(sol.rd, ref.rd)
copyto!(sol.rp_old, ref.rp_old)
copyto!(sol.Ax_plus_By, ref.Ax_plus_By)
copyto!(sol.wRIij, ref.wRIij)
return sol
end

abstract type AbstractUserIterationInformation end

Expand Down

0 comments on commit 9b4944e

Please sign in to comment.