Skip to content

Commit

Permalink
remove changes related to PTDFNetwork
Browse files Browse the repository at this point in the history
  • Loading branch information
jd-lara committed Jan 22, 2024
1 parent dbe34bd commit 1926384
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 141 deletions.
1 change: 0 additions & 1 deletion src/PowerSimulations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export SimulationPartitionResults
# Network Relevant Exports
export NetworkModel
export StandardPTDFModel
export PTDFPowerModel
export CopperPlatePowerModel
export AreaBalancePowerModel

Expand Down
1 change: 0 additions & 1 deletion src/core/formulations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ struct LossLessLine <: AbstractBranchFormulation end

abstract type AbstractPTDFModel <: PM.AbstractDCPModel end
struct StandardPTDFModel <: AbstractPTDFModel end
struct PTDFPowerModel <: AbstractPTDFModel end

struct CopperPlatePowerModel <: PM.AbstractActivePowerModel end
struct AreaBalancePowerModel <: PM.AbstractActivePowerModel end
Expand Down
2 changes: 1 addition & 1 deletion src/core/optimization_container.jl
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ function _make_system_expressions!(
dc_bus_numbers::Vector{Int},
::Type{T},
bus_reduction_map::Dict{Int64, Set{Int64}},
) where {T <: Union{PTDFPowerModel, StandardPTDFModel}}
) where {T <: StandardPTDFModel}
time_steps = get_time_steps(container)
if isempty(bus_reduction_map)
ac_bus_numbers = collect(Iterators.flatten(values(subnetworks)))
Expand Down
8 changes: 4 additions & 4 deletions src/devices_models/device_constructors/branch_constructor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ function construct_device!(
sys::PSY.System,
::ArgumentConstructStage,
model::DeviceModel{T, HVDCTwoTerminalUnbounded},
network_model::NetworkModel{<:Union{StandardPTDFModel, PTDFPowerModel}},
network_model::NetworkModel{StandardPTDFModel},
) where {T <: TwoTerminalHVDCTypes}
devices =
get_available_components(T, sys, get_attribute(model, "filter_function"))
Expand All @@ -461,7 +461,7 @@ function construct_device!(
sys::PSY.System,
::ModelConstructStage,
model::DeviceModel{<:TwoTerminalHVDCTypes, HVDCTwoTerminalUnbounded},
network_model::NetworkModel{<:Union{StandardPTDFModel, PTDFPowerModel}},
network_model::NetworkModel{StandardPTDFModel},
)
add_constraint_dual!(container, sys, model)
return
Expand Down Expand Up @@ -497,7 +497,7 @@ function construct_device!(
sys::PSY.System,
::ArgumentConstructStage,
model::DeviceModel{T, HVDCTwoTerminalLossless},
network_model::NetworkModel{<:Union{StandardPTDFModel, PTDFPowerModel}},
network_model::NetworkModel{StandardPTDFModel},
) where {T <: TwoTerminalHVDCTypes}
devices =
get_available_components(T, sys, get_attribute(model, "filter_function"))
Expand All @@ -522,7 +522,7 @@ function construct_device!(
network_model::NetworkModel{U},
) where {
T <: TwoTerminalHVDCTypes,
U <: Union{StandardPTDFModel, PTDFPowerModel},
U <: StandardPTDFModel,
}
devices =
get_available_components(T, sys, get_attribute(model, "filter_function"))
Expand Down
2 changes: 1 addition & 1 deletion src/devices_models/devices/HVDCsystems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ function add_to_expression!(
U <: ActivePowerVariable,
V <: PSY.InterconnectingConverter,
W <: AbstractConverterFormulation,
X <: Union{PTDFPowerModel, StandardPTDFModel},
X <: StandardPTDFModel
}
variable = get_variable(container, U(), V)
expression_dc = get_expression(container, T(), PSY.DCBus)
Expand Down
12 changes: 6 additions & 6 deletions src/devices_models/devices/common/add_to_expression.jl
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ function add_to_expression!(
U <: FlowActivePowerToFromVariable,
V <: TwoTerminalHVDCTypes,
W <: AbstractDeviceFormulation,
X <: Union{PTDFPowerModel, StandardPTDFModel},
X <: StandardPTDFModel
}
var = get_variable(container, U(), V)
nodal_expr = get_expression(container, T(), PSY.ACBus)
Expand Down Expand Up @@ -248,7 +248,7 @@ function add_to_expression!(
U <: FlowActivePowerFromToVariable,
V <: TwoTerminalHVDCTypes,
W <: AbstractTwoTerminalDCLineFormulation,
X <: Union{PTDFPowerModel, StandardPTDFModel},
X <: StandardPTDFModel
}
var = get_variable(container, U(), V)
nodal_expr = get_expression(container, T(), PSY.ACBus)
Expand Down Expand Up @@ -579,7 +579,7 @@ function add_to_expression!(
U <: TimeSeriesParameter,
V <: PSY.StaticInjection,
W <: AbstractDeviceFormulation,
X <: Union{PTDFPowerModel, StandardPTDFModel},
X <: StandardPTDFModel
}
param_container = get_parameter(container, U(), V)
multiplier = get_multiplier_array(param_container)
Expand Down Expand Up @@ -613,7 +613,7 @@ function add_to_expression!(
U <: OnStatusParameter,
V <: PSY.ThermalGen,
W <: AbstractDeviceFormulation,
X <: Union{PTDFPowerModel, StandardPTDFModel},
X <: StandardPTDFModel
}
parameter = get_parameter_array(container, U(), V)
sys_expr = get_expression(container, T(), PSY.System)
Expand Down Expand Up @@ -647,7 +647,7 @@ function add_to_expression!(
U <: VariableType,
V <: PSY.StaticInjection,
W <: AbstractDeviceFormulation,
X <: Union{PTDFPowerModel, StandardPTDFModel},
X <: StandardPTDFModel
}
variable = get_variable(container, U(), V)
sys_expr = get_expression(container, T(), PSY.System)
Expand Down Expand Up @@ -686,7 +686,7 @@ function add_to_expression!(
U <: OnVariable,
V <: PSY.ThermalGen,
W <: Union{AbstractCompactUnitCommitment, ThermalCompactDispatch},
X <: Union{PTDFPowerModel, StandardPTDFModel},
X <: StandardPTDFModel
}
variable = get_variable(container, U(), V)
sys_expr = get_expression(container, T(), PSY.System)
Expand Down
2 changes: 1 addition & 1 deletion src/network_models/copperplate_model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function add_constraints!(
) where {
T <: CopperPlateBalanceConstraint,
U <: PSY.System,
V <: Union{CopperPlatePowerModel, StandardPTDFModel, PTDFPowerModel},
V <: Union{CopperPlatePowerModel, StandardPTDFModel},
}
time_steps = get_time_steps(container)
expressions = get_expression(container, ActivePowerBalance(), U)
Expand Down
44 changes: 9 additions & 35 deletions src/network_models/network_constructor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,34 +75,11 @@ function construct_network!(
return
end

function construct_network!(
container::OptimizationContainer,
sys::PSY.System,
model::NetworkModel{T},
template::ProblemTemplate,
) where {T <: PTDFPowerModel}
construct_network!(
container,
sys,
model,
template;
instantiate_model = instantiate_nip_ptdf_expr_model,
)

add_pm_expr_refs!(container, T, sys)

add_constraints!(container, CopperPlateBalanceConstraint, sys, model)
add_constraints!(container, NodalBalanceActiveConstraint, sys, model)
add_constraint_dual!(container, sys, model)
return
end

function construct_network!(
container::OptimizationContainer,
sys::PSY.System,
model::NetworkModel{T},
template::ProblemTemplate;
instantiate_model = instantiate_nip_expr_model,
) where {T <: PM.AbstractActivePowerModel}
if T in UNSUPPORTED_POWERMODELS
throw(
Expand All @@ -126,9 +103,9 @@ function construct_network!(
objective_function!(container, PSY.ACBus, model)
end

@debug "Building the $T network with $instantiate_model method" _group =
@debug "Building the $T network with instantiate_nip_expr_model method" _group =
LOG_GROUP_NETWORK_CONSTRUCTION
powermodels_network!(container, T, sys, template, instantiate_model)
powermodels_network!(container, T, sys, template, instantiate_nip_expr_model)
#Constraints in case the model has DC Buses
add_constraints!(container, NodalBalanceActiveConstraint, sys, model)
add_pm_variable_refs!(container, T, sys)
Expand All @@ -143,7 +120,6 @@ function construct_network!(
sys::PSY.System,
model::NetworkModel{T},
template::ProblemTemplate;
instantiate_model = instantiate_nip_expr_model,
) where {T <: PM.AbstractPowerModel}
if T in UNSUPPORTED_POWERMODELS
throw(
Expand Down Expand Up @@ -174,11 +150,11 @@ function construct_network!(
objective_function!(container, PSY.ACBus, model)
end

@debug "Building the $T network with $instantiate_model method" _group =
@debug "Building the $T network with instantiate_nip_expr_model method" _group =
LOG_GROUP_NETWORK_CONSTRUCTION
#Constraints in case the model has DC Buses
add_constraints!(container, NodalBalanceActiveConstraint, sys, model)
powermodels_network!(container, T, sys, template, instantiate_model)
powermodels_network!(container, T, sys, template, instantiate_nip_expr_model)
add_pm_variable_refs!(container, T, sys)
add_pm_constraint_refs!(container, T, sys)

Expand All @@ -190,8 +166,7 @@ function construct_network!(
container::OptimizationContainer,
sys::PSY.System,
model::NetworkModel{T},
template::ProblemTemplate;
instantiate_model = instantiate_bfp_expr_model,
template::ProblemTemplate
) where {T <: PM.AbstractBFModel}
if T in UNSUPPORTED_POWERMODELS
throw(
Expand Down Expand Up @@ -235,11 +210,11 @@ function construct_network!(
objective_function!(container, PSY.ACBus, model)
end

@debug "Building the $T network with $instantiate_model method" _group =
@debug "Building the $T network with instantiate_bfp_expr_model method" _group =
LOG_GROUP_NETWORK_CONSTRUCTION
#Constraints in case the model has DC Buses
add_constraints!(container, NodalBalanceActiveConstraint, sys, model)
powermodels_network!(container, T, sys, template, instantiate_model)
powermodels_network!(container, T, sys, template, instantiate_bfp_expr_model)
add_pm_variable_refs!(container, T, sys)
add_pm_constraint_refs!(container, T, sys)
add_constraint_dual!(container, sys, model)
Expand All @@ -251,7 +226,6 @@ function construct_network!(
sys::PSY.System,
model::NetworkModel{T},
template::ProblemTemplate;
instantiate_model = instantiate_vip_expr_model,
) where {T <: PM.AbstractIVRModel}
if T in UNSUPPORTED_POWERMODELS
throw(
Expand Down Expand Up @@ -299,11 +273,11 @@ function construct_network!(
objective_function!(container, PSY.ACBus, model)
end

@debug "Building the $T network with $instantiate_model method" _group =
@debug "Building the $T network with instantiate_vip_expr_model method" _group =

Check warning on line 276 in src/network_models/network_constructor.jl

View check run for this annotation

Codecov / codecov/patch

src/network_models/network_constructor.jl#L276

Added line #L276 was not covered by tests
LOG_GROUP_NETWORK_CONSTRUCTION
#Constraints in case the model has DC Buses
add_constraints!(container, NodalBalanceActiveConstraint, sys, model)
powermodels_network!(container, T, sys, template, instantiate_model)
powermodels_network!(container, T, sys, template, instantiate_vip_expr_model)

Check warning on line 280 in src/network_models/network_constructor.jl

View check run for this annotation

Codecov / codecov/patch

src/network_models/network_constructor.jl#L280

Added line #L280 was not covered by tests
add_pm_variable_refs!(container, T, sys)
add_pm_constraint_refs!(container, T, sys)
add_constraint_dual!(container, sys, model)
Expand Down
12 changes: 0 additions & 12 deletions src/network_models/pm_translator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -446,18 +446,6 @@ function get_branches_to_pm(
return PM_branches, PMmap_br
end

function get_branches_to_pm(
::PSY.System,
network_model::NetworkModel{PTDFPowerModel},
::Type{T},
branch_template::BranchModelContainer,
start_idx = 0,
) where {T <: TwoTerminalHVDCTypes}
PM_branches = Dict{String, Any}()
PMmap_br = Dict{PM_MAP_TUPLE, T}()
return PM_branches, PMmap_br
end

function get_buses_to_pm(buses::IS.FlattenIteratorWrapper{PSY.ACBus})
PM_buses = Dict{String, Any}()
PMmap_buses = Dict{Int, PSY.ACBus}()
Expand Down
32 changes: 2 additions & 30 deletions src/network_models/powermodels_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const UNSUPPORTED_POWERMODELS =

const INCOMPATIBLE_WITH_RADIAL_BRANCHES_POWERMODELS = [
PM.SparseSDPWRMPowerModel,
PTDFPowerModel,
]

function instantiate_nip_expr_model(data::Dict{String, Any}, model_constructor; kwargs...)
Expand Down Expand Up @@ -292,7 +291,7 @@ function powermodels_network!(
system_formulation::Type{S},
sys::PSY.System,
template::ProblemTemplate,
instantiate_model = instantiate_nip_expr_model,
instantiate_model,
) where {S <: PM.AbstractPowerModel}
time_steps = get_time_steps(container)
pm_data, PM_map = pass_to_pm(sys, template, time_steps[end])
Expand Down Expand Up @@ -331,7 +330,7 @@ function powermodels_network!(
system_formulation::Type{S},
sys::PSY.System,
template::ProblemTemplate,
instantiate_model = instantiate_nip_expr_model,
instantiate_model,
) where {S <: PM.AbstractActivePowerModel}
time_steps = get_time_steps(container)
pm_data, PM_map = pass_to_pm(sys, template, time_steps[end])
Expand Down Expand Up @@ -395,16 +394,6 @@ function PMvarmap(::Type{S}) where {S <: PM.AbstractActivePowerModel}
return pm_variable_map
end

function PMvarmap(::Type{PTDFPowerModel})
pm_variable_map = Dict{Type, Dict{Symbol, Union{String, NamedTuple}}}()

pm_variable_map[PSY.ACBus] = Dict()
pm_variable_map[PSY.ACBranch] = Dict()
pm_variable_map[TwoTerminalHVDCTypes] = Dict()

return pm_variable_map
end

function PMvarmap(::Type{S}) where {S <: PM.AbstractPowerModel}
pm_variable_map = Dict{Type, Dict{Symbol, Union{VariableType, NamedTuple}}}()

Expand Down Expand Up @@ -459,23 +448,6 @@ function PMexprmap(::Type{S}) where {S <: PM.AbstractPowerModel}
return pm_expr_map
end

function PMexprmap(::Type{PTDFPowerModel})
pm_expr_map = Dict{
Type,
NamedTuple{
(:pm_expr, :psi_con),
Tuple{Dict{Symbol, Union{VariableType, NamedTuple}}, ConstraintType},
},
}()

pm_expr_map[PSY.ACBranch] = (
pm_expr = Dict(:p => (from_to = FlowActivePowerVariable(), to_from = nothing)),
psi_con = NetworkFlowConstraint(),
)

return pm_expr_map
end

function add_pm_variable_refs!(
container::OptimizationContainer,
system_formulation::Type{S},
Expand Down
49 changes: 0 additions & 49 deletions test/test_network_constructors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const NETWORKS_FOR_TESTING = [
#(PM.SOCBFConicPowerModel, fast_ipopt_optimizer), # not implemented
(PM.SDPWRMPowerModel, scs_solver),
(PM.SparseSDPWRMPowerModel, scs_solver),
(PTDFPowerModel, fast_ipopt_optimizer),
]

@testset "All PowerModels models construction" begin
Expand Down Expand Up @@ -206,54 +205,6 @@ end
end
end

@testset "Sparse Network DC-PF with PTDFPowerModel" begin
c_sys5 = PSB.build_system(PSITestSystems, "c_sys5")
c_sys14 = PSB.build_system(PSITestSystems, "c_sys14")
c_sys14_dc = PSB.build_system(PSITestSystems, "c_sys14_dc")
systems = [c_sys5, c_sys14, c_sys14_dc]
objfuncs = [GAEVF, GQEVF, GQEVF]
constraint_keys = [
PSI.ConstraintKey(RateLimitConstraint, PSY.Line, "lb"),
PSI.ConstraintKey(RateLimitConstraint, PSY.Line, "ub"),
PSI.ConstraintKey(CopperPlateBalanceConstraint, PSY.System),
PSI.ConstraintKey(NetworkFlowConstraint, PSY.Line),
]
test_results = IdDict{System, Vector{Int}}(
c_sys5 => [264, 0, 264, 264, 168],
c_sys14 => [600, 0, 600, 600, 504],
c_sys14_dc => [600, 0, 648, 552, 456],
)
test_obj_values = IdDict{System, Float64}(
c_sys5 => 340000.0,
c_sys14 => 142000.0,
c_sys14_dc => 142000.0,
)
for (ix, sys) in enumerate(systems)
template = get_thermal_dispatch_template_network(PTDFPowerModel)
ps_model = DecisionModel(template, sys; optimizer = HiGHS_optimizer)

@test build!(ps_model; output_dir = mktempdir(; cleanup = true)) ==
PSI.BuildStatus.BUILT
psi_constraint_test(ps_model, constraint_keys)
moi_tests(
ps_model,
test_results[sys][1],
test_results[sys][2],
test_results[sys][3],
test_results[sys][4],
test_results[sys][5],
false,
)
psi_checkobjfun_test(ps_model, objfuncs[ix])
psi_checksolve_test(
ps_model,
[MOI.OPTIMAL, MOI.ALMOST_OPTIMAL],
test_obj_values[sys],
10000,
)
end
end

@testset "Network DC lossless -PF network with PowerModels DCPlosslessForm" begin
c_sys5 = PSB.build_system(PSITestSystems, "c_sys5")
c_sys14 = PSB.build_system(PSITestSystems, "c_sys14")
Expand Down

0 comments on commit 1926384

Please sign in to comment.