From 192638446c221a0dd68c80e8442d1874519c4477 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Mon, 22 Jan 2024 15:39:41 -0700 Subject: [PATCH] remove changes related to PTDFNetwork --- src/PowerSimulations.jl | 1 - src/core/formulations.jl | 1 - src/core/optimization_container.jl | 2 +- .../device_constructors/branch_constructor.jl | 8 +-- src/devices_models/devices/HVDCsystems.jl | 2 +- .../devices/common/add_to_expression.jl | 12 ++--- src/network_models/copperplate_model.jl | 2 +- src/network_models/network_constructor.jl | 44 ++++------------- src/network_models/pm_translator.jl | 12 ----- src/network_models/powermodels_interface.jl | 32 +----------- test/test_network_constructors.jl | 49 ------------------- 11 files changed, 24 insertions(+), 141 deletions(-) diff --git a/src/PowerSimulations.jl b/src/PowerSimulations.jl index e640b788a0..d03823aa6b 100644 --- a/src/PowerSimulations.jl +++ b/src/PowerSimulations.jl @@ -20,7 +20,6 @@ export SimulationPartitionResults # Network Relevant Exports export NetworkModel export StandardPTDFModel -export PTDFPowerModel export CopperPlatePowerModel export AreaBalancePowerModel diff --git a/src/core/formulations.jl b/src/core/formulations.jl index 87a6a168c2..64006b2fdb 100644 --- a/src/core/formulations.jl +++ b/src/core/formulations.jl @@ -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 diff --git a/src/core/optimization_container.jl b/src/core/optimization_container.jl index 9686a1d06d..086d98dc5e 100644 --- a/src/core/optimization_container.jl +++ b/src/core/optimization_container.jl @@ -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))) diff --git a/src/devices_models/device_constructors/branch_constructor.jl b/src/devices_models/device_constructors/branch_constructor.jl index 616500cafb..1318e36527 100644 --- a/src/devices_models/device_constructors/branch_constructor.jl +++ b/src/devices_models/device_constructors/branch_constructor.jl @@ -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")) @@ -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 @@ -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")) @@ -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")) diff --git a/src/devices_models/devices/HVDCsystems.jl b/src/devices_models/devices/HVDCsystems.jl index ee20e478f6..540b38b043 100644 --- a/src/devices_models/devices/HVDCsystems.jl +++ b/src/devices_models/devices/HVDCsystems.jl @@ -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) diff --git a/src/devices_models/devices/common/add_to_expression.jl b/src/devices_models/devices/common/add_to_expression.jl index c9c7e1cb68..1a1ea800ec 100644 --- a/src/devices_models/devices/common/add_to_expression.jl +++ b/src/devices_models/devices/common/add_to_expression.jl @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) diff --git a/src/network_models/copperplate_model.jl b/src/network_models/copperplate_model.jl index 3d4c12b01b..a8e8a9d5c2 100644 --- a/src/network_models/copperplate_model.jl +++ b/src/network_models/copperplate_model.jl @@ -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) diff --git a/src/network_models/network_constructor.jl b/src/network_models/network_constructor.jl index 7f53454439..1bd4edb6e7 100644 --- a/src/network_models/network_constructor.jl +++ b/src/network_models/network_constructor.jl @@ -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( @@ -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) @@ -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( @@ -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) @@ -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( @@ -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) @@ -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( @@ -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 = 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) add_pm_variable_refs!(container, T, sys) add_pm_constraint_refs!(container, T, sys) add_constraint_dual!(container, sys, model) diff --git a/src/network_models/pm_translator.jl b/src/network_models/pm_translator.jl index ee86e0544b..e2dc9cdac7 100644 --- a/src/network_models/pm_translator.jl +++ b/src/network_models/pm_translator.jl @@ -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}() diff --git a/src/network_models/powermodels_interface.jl b/src/network_models/powermodels_interface.jl index ea0b6bb991..f0cb0ae5e3 100644 --- a/src/network_models/powermodels_interface.jl +++ b/src/network_models/powermodels_interface.jl @@ -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...) @@ -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]) @@ -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]) @@ -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}}}() @@ -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}, diff --git a/test/test_network_constructors.jl b/test/test_network_constructors.jl index 519b19d28f..945bf06eae 100644 --- a/test/test_network_constructors.jl +++ b/test/test_network_constructors.jl @@ -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 @@ -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")