From 8dd0f795060b2c3ab8c381719727fbfce2b1a69b Mon Sep 17 00:00:00 2001 From: rodrigomha Date: Mon, 9 Dec 2024 11:26:15 -0800 Subject: [PATCH] formatter --- .../common/objective_function/market_bid.jl | 222 ++++++------ test/run_market_bid_cost.jl | 20 +- ..._device_thermal_generation_constructors.jl | 328 +++++++++--------- 3 files changed, 287 insertions(+), 283 deletions(-) diff --git a/src/devices_models/devices/common/objective_function/market_bid.jl b/src/devices_models/devices/common/objective_function/market_bid.jl index c64472ad4..d20d16528 100644 --- a/src/devices_models/devices/common/objective_function/market_bid.jl +++ b/src/devices_models/devices/common/objective_function/market_bid.jl @@ -4,18 +4,20 @@ # For Market Bid function _add_pwl_variables!(container::OptimizationContainer, - ::Type{T}, - component_name::String, - time_period::Int, - cost_data::PSY.PiecewiseStepData) where {T<:PSY.Component} + ::Type{T}, + component_name::String, + time_period::Int, + cost_data::PSY.PiecewiseStepData) where {T <: PSY.Component} var_container = lazy_container_addition!(container, PieceWiseLinearBlockOffer(), T) # length(PiecewiseStepData) gets number of segments, here we want number of points break_points = PSY.get_x_coords(cost_data) pwlvars = Array{JuMP.VariableRef}(undef, length(break_points)) for i in 1:(length(break_points) - 1) - pwlvars[i] = var_container[(component_name, i, time_period)] = JuMP.@variable(get_jump_model(container), - base_name = "PieceWiseLinearBlockOffer_$(component_name)_{pwl_$(i), $time_period}", - lower_bound = 0.0,) + pwlvars[i] = + var_container[(component_name, i, time_period)] = + JuMP.@variable(get_jump_model(container), + base_name = "PieceWiseLinearBlockOffer_$(component_name)_{pwl_$(i), $time_period}", + lower_bound = 0.0,) end return pwlvars end @@ -33,23 +35,23 @@ Implement the constraints for PWL Block Offer variables. That is: ``` """ function _add_pwl_constraint!(container::OptimizationContainer, - component::T, - ::U, - break_points::Vector{Float64}, - period::Int) where {T<:PSY.Component,U<:VariableType} + component::T, + ::U, + break_points::Vector{Float64}, + period::Int) where {T <: PSY.Component, U <: VariableType} variables = get_variable(container, U(), T) const_container = lazy_container_addition!(container, - PieceWiseLinearBlockOfferConstraint(), - T, - axes(variables)...) + PieceWiseLinearBlockOfferConstraint(), + T, + axes(variables)...) len_cost_data = length(break_points) - 1 jump_model = get_jump_model(container) pwl_vars = get_variable(container, PieceWiseLinearBlockOffer(), T) name = PSY.get_name(component) const_container[name, period] = JuMP.@constraint(jump_model, - variables[name, period] == - sum(pwl_vars[name, ix, period] - for ix in 1:len_cost_data)) + variables[name, period] == + sum(pwl_vars[name, ix, period] + for ix in 1:len_cost_data)) #= const_upperbound_container = lazy_container_addition!( @@ -63,8 +65,8 @@ function _add_pwl_constraint!(container::OptimizationContainer, # TODO: Parameter for this for ix in 1:len_cost_data JuMP.@constraint(jump_model, - pwl_vars[name, ix, period] <= - break_points[ix + 1] - break_points[ix]) + pwl_vars[name, ix, period] <= + break_points[ix + 1] - break_points[ix]) end return end @@ -78,31 +80,31 @@ Implement the constraints for PWL Block Offer variables for ORDC. That is: ``` """ function _add_pwl_constraint!(container::OptimizationContainer, - component::T, - ::U, - break_points::Vector{Float64}, - sos_status::SOSStatusVariable, - period::Int) where {T<:PSY.ReserveDemandCurve, - U<:ServiceRequirementVariable} + component::T, + ::U, + break_points::Vector{Float64}, + sos_status::SOSStatusVariable, + period::Int) where {T <: PSY.ReserveDemandCurve, + U <: ServiceRequirementVariable} name = PSY.get_name(component) variables = get_variable(container, U(), T, name) const_container = lazy_container_addition!(container, - PieceWiseLinearBlockOfferConstraint(), - T, - axes(variables)...; - meta=name,) + PieceWiseLinearBlockOfferConstraint(), + T, + axes(variables)...; + meta = name) len_cost_data = length(break_points) - 1 jump_model = get_jump_model(container) pwl_vars = get_variable(container, PieceWiseLinearBlockOffer(), T) const_container[name, period] = JuMP.@constraint(jump_model, - variables[name, period] == - sum(pwl_vars[name, ix, period] - for ix in 1:len_cost_data)) + variables[name, period] == + sum(pwl_vars[name, ix, period] + for ix in 1:len_cost_data)) for ix in 1:len_cost_data JuMP.@constraint(jump_model, - pwl_vars[name, ix, period] <= - break_points[ix + 1] - break_points[ix]) + pwl_vars[name, ix, period] <= + break_points[ix + 1] - break_points[ix]) end return end @@ -112,30 +114,30 @@ end ################################################## function _get_pwl_cost_expression(container::OptimizationContainer, - component::T, - time_period::Int, - cost_data::PSY.PiecewiseStepData, - multiplier::Float64) where {T<:PSY.Component} + component::T, + time_period::Int, + cost_data::PSY.PiecewiseStepData, + multiplier::Float64) where {T <: PSY.Component} name = PSY.get_name(component) pwl_var_container = get_variable(container, PieceWiseLinearBlockOffer(), T) gen_cost = JuMP.AffExpr(0.0) cost_data = PSY.get_y_coords(cost_data) for (i, cost) in enumerate(cost_data) JuMP.add_to_expression!(gen_cost, - cost * multiplier * - pwl_var_container[(name, i, time_period)]) + cost * multiplier * + pwl_var_container[(name, i, time_period)]) end return gen_cost end function _get_pwl_cost_expression(container::OptimizationContainer, - component::T, - time_period::Int, - cost_function::PSY.MarketBidCost, - ::PSY.PiecewiseStepData, - ::U, - ::V) where {T<:PSY.Component,U<:VariableType, - V<:AbstractDeviceFormulation} + component::T, + time_period::Int, + cost_function::PSY.MarketBidCost, + ::PSY.PiecewiseStepData, + ::U, + ::V) where {T <: PSY.Component, U <: VariableType, + V <: AbstractDeviceFormulation} incremental_curve = PSY.get_incremental_offer_curves(cost_function) value_curve = PSY.get_value_curve(incremental_curve) power_units = PSY.get_power_units(incremental_curve) @@ -143,34 +145,34 @@ function _get_pwl_cost_expression(container::OptimizationContainer, base_power = get_base_power(container) device_base_power = PSY.get_base_power(component) cost_data_normalized = get_piecewise_incrementalcurve_per_system_unit(cost_component, - power_units, - base_power, - device_base_power) + power_units, + base_power, + device_base_power) resolution = get_resolution(container) dt = Dates.value(resolution) / MILLISECONDS_IN_HOUR return _get_pwl_cost_expression(container, - component, - time_period, - cost_data_normalized, - dt) + component, + time_period, + cost_data_normalized, + dt) end """ Get cost expression for StepwiseCostReserve """ function _get_pwl_cost_expression(container::OptimizationContainer, - component::T, - time_period::Int, - cost_data::PSY.PiecewiseStepData, - multiplier::Float64) where {T<:PSY.ReserveDemandCurve} + component::T, + time_period::Int, + cost_data::PSY.PiecewiseStepData, + multiplier::Float64) where {T <: PSY.ReserveDemandCurve} name = PSY.get_name(component) pwl_var_container = get_variable(container, PieceWiseLinearBlockOffer(), T) slopes = PSY.get_y_coords(cost_data) ordc_cost = JuMP.AffExpr(0.0) for i in 1:length(slopes) JuMP.add_to_expression!(ordc_cost, - slopes[i] * multiplier * - pwl_var_container[(name, i, time_period)]) + slopes[i] * multiplier * + pwl_var_container[(name, i, time_period)]) end return ordc_cost end @@ -253,12 +255,12 @@ Add PWL cost terms for data coming from the MarketBidCost with a fixed incremental offer curve """ function _add_pwl_term!(container::OptimizationContainer, - component::T, - cost_function::PSY.MarketBidCost, - ::PSY.CostCurve{PSY.PiecewiseIncrementalCurve}, - ::U, - ::V) where {T<:PSY.Component,U<:VariableType, - V<:AbstractDeviceFormulation} + component::T, + cost_function::PSY.MarketBidCost, + ::PSY.CostCurve{PSY.PiecewiseIncrementalCurve}, + ::U, + ::V) where {T <: PSY.Component, U <: VariableType, + V <: AbstractDeviceFormulation} name = PSY.get_name(component) incremental_offer_curve = PSY.get_incremental_offer_curves(cost_function) value_curve = PSY.get_value_curve(incremental_offer_curve) @@ -268,9 +270,9 @@ function _add_pwl_term!(container::OptimizationContainer, power_units = PSY.get_power_units(incremental_offer_curve) data = get_piecewise_incrementalcurve_per_system_unit(cost_component, - power_units, - base_power, - device_base_power) + power_units, + base_power, + device_base_power) cost_is_convex = PSY.is_convex(data) if !cost_is_convex @@ -284,7 +286,7 @@ function _add_pwl_term!(container::OptimizationContainer, _add_pwl_variables!(container, T, name, t, data) _add_pwl_constraint!(container, component, U(), break_points, t) pwl_cost = _get_pwl_cost_expression(container, component, t, cost_function, data, - U(), V()) + U(), V()) pwl_cost_expressions[t] = pwl_cost end return pwl_cost_expressions @@ -295,11 +297,11 @@ end ################################################## function _add_pwl_term!(container::OptimizationContainer, - component::T, - cost_data::PSY.CostCurve{PSY.PiecewiseIncrementalCurve}, - ::U, - ::V) where {T<:PSY.Component,U<:VariableType, - V<:AbstractServiceFormulation} + component::T, + cost_data::PSY.CostCurve{PSY.PiecewiseIncrementalCurve}, + ::U, + ::V) where {T <: PSY.Component, U <: VariableType, + V <: AbstractServiceFormulation} multiplier = objective_function_multiplier(U(), V()) resolution = get_resolution(container) dt = Dates.value(Dates.Second(resolution)) / SECONDS_IN_HOUR @@ -309,9 +311,9 @@ function _add_pwl_term!(container::OptimizationContainer, cost_component = PSY.get_function_data(value_curve) device_base_power = PSY.get_base_power(component) data = get_piecewise_incrementalcurve_per_system_unit(cost_component, - power_units, - base_power, - device_base_power) + power_units, + base_power, + device_base_power) name = PSY.get_name(component) time_steps = get_time_steps(container) pwl_cost_expressions = Vector{JuMP.AffExpr}(undef, time_steps[end]) @@ -431,11 +433,11 @@ Decremental offers are not accepted for most components, except Storage systems - cost_function::MarketBidCost : container for market bid cost """ function _add_variable_cost_to_objective!(container::OptimizationContainer, - ::T, - component::PSY.Component, - cost_function::PSY.MarketBidCost, - ::U) where {T<:VariableType, - U<:AbstractDeviceFormulation} + ::T, + component::PSY.Component, + cost_function::PSY.MarketBidCost, + ::U) where {T <: VariableType, + U <: AbstractDeviceFormulation} component_name = PSY.get_name(component) @debug "Market Bid" _group = LOG_GROUP_COST_FUNCTIONS component_name time_steps = get_time_steps(container) @@ -463,11 +465,11 @@ function _add_variable_cost_to_objective!(container::OptimizationContainer, ) =# pwl_cost_expressions = _add_pwl_term!(container, - component, - cost_function, - incremental_cost_curves, - T(), - U()) + component, + cost_function, + incremental_cost_curves, + T(), + U()) jump_model = get_jump_model(container) for t in time_steps #= @@ -488,10 +490,10 @@ function _add_variable_cost_to_objective!(container::OptimizationContainer, ) =# add_to_expression!(container, - ProductionCostExpression, - pwl_cost_expressions[t], - component, - t) + ProductionCostExpression, + pwl_cost_expressions[t], + component, + t) add_to_objective_variant_expression!(container, pwl_cost_expressions[t]) end @@ -506,16 +508,16 @@ function _add_variable_cost_to_objective!(container::OptimizationContainer, end function _add_service_bid_cost!(container::OptimizationContainer, - component::PSY.Component, - service::T) where {T<:PSY.Reserve{<:PSY.ReserveDirection}} + component::PSY.Component, + service::T) where {T <: PSY.Reserve{<:PSY.ReserveDirection}} time_steps = get_time_steps(container) initial_time = get_initial_time(container) base_power = get_base_power(container) forecast_data = PSY.get_services_bid(component, - PSY.get_operation_cost(component), - service; - start_time=initial_time, - len=length(time_steps),) + PSY.get_operation_cost(component), + service; + start_time = initial_time, + len = length(time_steps)) forecast_data_values = PSY.get_cost.(TimeSeries.values(forecast_data)) # Single Price Bid if eltype(forecast_data_values) == Float64 @@ -528,12 +530,12 @@ function _add_service_bid_cost!(container::OptimizationContainer, end reserve_variable = get_variable(container, ActivePowerReserveVariable(), T, - PSY.get_name(service)) + PSY.get_name(service)) component_name = PSY.get_name(component) for t in time_steps add_to_objective_invariant_expression!(container, - data_values[t] * base_power * - reserve_variable[component_name, t]) + data_values[t] * base_power * + reserve_variable[component_name, t]) end return end @@ -541,11 +543,11 @@ end function _add_service_bid_cost!(::OptimizationContainer, ::PSY.Component, ::PSY.Service) end function _add_vom_cost_to_objective!(container::OptimizationContainer, - ::T, - component::PSY.Component, - op_cost::PSY.MarketBidCost, - ::U) where {T<:VariableType, - U<:AbstractDeviceFormulation} + ::T, + component::PSY.Component, + op_cost::PSY.MarketBidCost, + ::U) where {T <: VariableType, + U <: AbstractDeviceFormulation} incremental_cost_curves = PSY.get_incremental_offer_curves(op_cost) decremental_cost_curves = PSY.get_decremental_offer_curves(op_cost) power_units = PSY.get_power_units(incremental_cost_curves) @@ -556,12 +558,12 @@ function _add_vom_cost_to_objective!(container::OptimizationContainer, base_power = get_base_power(container) device_base_power = PSY.get_base_power(component) cost_term_normalized = get_proportional_cost_per_system_unit(cost_term, - power_units, - base_power, - device_base_power) + power_units, + base_power, + device_base_power) for t in get_time_steps(container) exp = _add_proportional_term!(container, T(), d, cost_term_normalized * multiplier, - t) + t) add_to_expression!(container, ProductionCostExpression, exp, d, t) end return diff --git a/test/run_market_bid_cost.jl b/test/run_market_bid_cost.jl index e166781d6..990d592f8 100644 --- a/test/run_market_bid_cost.jl +++ b/test/run_market_bid_cost.jl @@ -41,19 +41,19 @@ get_bus(th_solitude) #### Add MarketBidCost proposed_offer_curve = make_market_bid_curve( - [0.0, 100.0, 200.0, 300.0, 400.0, 500.0, 600.0], - [25.0, 25.5, 26.0, 27.0, 28.0, 30.0], - 10.0 + [0.0, 100.0, 200.0, 300.0, 400.0, 500.0, 600.0], + [25.0, 25.5, 26.0, 27.0, 28.0, 30.0], + 10.0, ) set_operation_cost!( - th_solitude, + th_solitude, MarketBidCost(; - no_load_cost=0.0, - start_up = (hot=3.0, warm=0.0, cold=0.0), - shut_down = 1.5, - incremental_offer_curves = proposed_offer_curve - ) + no_load_cost = 0.0, + start_up = (hot = 3.0, warm = 0.0, cold = 0.0), + shut_down = 1.5, + incremental_offer_curves = proposed_offer_curve, + ), ) #### PowerSimulations Stuff ### @@ -104,4 +104,4 @@ param_re = read_parameter(res, "ActivePowerTimeSeriesParameter__RenewableDispatc p_re = read_variable(res, "ActivePowerVariable__RenewableDispatch") # $/(per-unit MW) = $/(100 MW) = 0.01 $/MW -price = read_dual(res, "CopperPlateBalanceConstraint__System") \ No newline at end of file +price = read_dual(res, "CopperPlateBalanceConstraint__System") diff --git a/test/test_device_thermal_generation_constructors.jl b/test/test_device_thermal_generation_constructors.jl index 785e75d93..69f98e144 100644 --- a/test/test_device_thermal_generation_constructors.jl +++ b/test/test_device_thermal_generation_constructors.jl @@ -2,14 +2,14 @@ test_path = mktempdir() @testset "Test Thermal Generation Cost Functions " begin test_cases = [("linear_cost_test", 4664.88, ThermalBasicUnitCommitment), - ("linear_fuel_test", 4664.88, ThermalBasicUnitCommitment), - ("quadratic_cost_test", 3301.81, ThermalDispatchNoMin), - ("quadratic_fuel_test", 3331.12, ThermalDispatchNoMin), - ("pwl_io_cost_test", 3421.64, ThermalBasicUnitCommitment), - ("pwl_io_fuel_test", 3421.64, ThermalBasicUnitCommitment), - ("pwl_incremental_cost_test", 3424.43, ThermalBasicUnitCommitment), - ("pwl_incremental_fuel_test", 3424.43, ThermalBasicUnitCommitment), - ("non_convex_io_pwl_cost_test", 3047.14, ThermalBasicUnitCommitment)] + ("linear_fuel_test", 4664.88, ThermalBasicUnitCommitment), + ("quadratic_cost_test", 3301.81, ThermalDispatchNoMin), + ("quadratic_fuel_test", 3331.12, ThermalDispatchNoMin), + ("pwl_io_cost_test", 3421.64, ThermalBasicUnitCommitment), + ("pwl_io_fuel_test", 3421.64, ThermalBasicUnitCommitment), + ("pwl_incremental_cost_test", 3424.43, ThermalBasicUnitCommitment), + ("pwl_incremental_fuel_test", 3424.43, ThermalBasicUnitCommitment), + ("non_convex_io_pwl_cost_test", 3047.14, ThermalBasicUnitCommitment)] for (i, cost_reference, thermal_formulation) in test_cases @testset "$i" begin sys = build_system(PSITestSystems, "c_$(i)") @@ -17,17 +17,17 @@ test_path = mktempdir() set_device_model!(template, ThermalStandard, thermal_formulation) set_device_model!(template, PowerLoad, StaticPowerLoad) model = DecisionModel(template, - sys; - name="UC_$(i)", - optimizer=HiGHS_optimizer, - system_to_file=false, - optimizer_solve_log_print=true,) - @test build!(model; output_dir=test_path) == PSI.ModelBuildStatus.BUILT + sys; + name = "UC_$(i)", + optimizer = HiGHS_optimizer, + system_to_file = false, + optimizer_solve_log_print = true) + @test build!(model; output_dir = test_path) == PSI.ModelBuildStatus.BUILT @test solve!(model) == PSI.RunStatus.SUCCESSFULLY_FINALIZED results = OptimizationProblemResults(model) expr = read_expression(results, "ProductionCostExpression__ThermalStandard") var_unit_cost = sum(expr[!, "Test Unit"]) - @test isapprox(var_unit_cost, cost_reference; atol=1) + @test isapprox(var_unit_cost, cost_reference; atol = 1) @test expr[!, "Test Unit"][end] == 0.0 end end @@ -67,8 +67,8 @@ end #TODO: timeseries market_bid_cost @testset "Test Thermal Generation MarketBidCost models" begin test_cases = [("fixed_market_bid_cost", 20772.76) - #"market_bid_cost", - ] + #"market_bid_cost", + ] for (i, cost_reference) in test_cases @testset "$i" begin sys = build_system(PSITestSystems, "c_$(i)") @@ -76,17 +76,17 @@ end set_device_model!(template, ThermalStandard, ThermalBasicUnitCommitment) set_device_model!(template, PowerLoad, StaticPowerLoad) model = DecisionModel(template, - sys; - name="UC_$(i)", - optimizer=HiGHS_optimizer, - system_to_file=false, - optimizer_solve_log_print=true,) - @test build!(model; output_dir=test_path) == PSI.ModelBuildStatus.BUILT + sys; + name = "UC_$(i)", + optimizer = HiGHS_optimizer, + system_to_file = false, + optimizer_solve_log_print = true) + @test build!(model; output_dir = test_path) == PSI.ModelBuildStatus.BUILT @test solve!(model) == PSI.RunStatus.SUCCESSFULLY_FINALIZED results = OptimizationProblemResults(model) expr = read_expression(results, "ProductionCostExpression__ThermalStandard") var_unit_cost = sum(expr[!, "Test Unit1"]) - @test isapprox(var_unit_cost, cost_reference; atol=1) + @test isapprox(var_unit_cost, cost_reference; atol = 1) @test expr[!, "Test Unit2"][end] == 50.0 end end @@ -95,16 +95,16 @@ end ################################### Unit Commitment tests ################################## @testset "Thermal UC With DC - PF" begin bin_variable_keys = [PSI.VariableKey(OnVariable, PSY.ThermalStandard), - PSI.VariableKey(StartVariable, PSY.ThermalStandard), - PSI.VariableKey(StopVariable, PSY.ThermalStandard)] + PSI.VariableKey(StartVariable, PSY.ThermalStandard), + PSI.VariableKey(StopVariable, PSY.ThermalStandard)] uc_constraint_keys = [PSI.ConstraintKey(RampConstraint, PSY.ThermalStandard, "up"), - PSI.ConstraintKey(RampConstraint, PSY.ThermalStandard, "dn"), - PSI.ConstraintKey(DurationConstraint, PSY.ThermalStandard, "up"), - PSI.ConstraintKey(DurationConstraint, PSY.ThermalStandard, "dn")] + PSI.ConstraintKey(RampConstraint, PSY.ThermalStandard, "dn"), + PSI.ConstraintKey(DurationConstraint, PSY.ThermalStandard, "up"), + PSI.ConstraintKey(DurationConstraint, PSY.ThermalStandard, "dn")] aux_variables_keys = [PSI.AuxVarKey(PSI.TimeDurationOff, ThermalStandard), - PSI.AuxVarKey(PSI.TimeDurationOn, ThermalStandard)] + PSI.AuxVarKey(PSI.TimeDurationOn, ThermalStandard)] device_model = DeviceModel(ThermalStandard, ThermalStandardUnitCommitment) c_sys5_uc = PSB.build_system(PSITestSystems, "c_sys5_uc") @@ -126,15 +126,15 @@ end @testset "Thermal UC With AC - PF" begin bin_variable_keys = [PSI.VariableKey(OnVariable, PSY.ThermalStandard), - PSI.VariableKey(StartVariable, PSY.ThermalStandard), - PSI.VariableKey(StopVariable, PSY.ThermalStandard)] + PSI.VariableKey(StartVariable, PSY.ThermalStandard), + PSI.VariableKey(StopVariable, PSY.ThermalStandard)] uc_constraint_keys = [PSI.ConstraintKey(RampConstraint, PSY.ThermalStandard, "up"), - PSI.ConstraintKey(RampConstraint, PSY.ThermalStandard, "dn"), - PSI.ConstraintKey(DurationConstraint, PSY.ThermalStandard, "up"), - PSI.ConstraintKey(DurationConstraint, PSY.ThermalStandard, "dn")] + PSI.ConstraintKey(RampConstraint, PSY.ThermalStandard, "dn"), + PSI.ConstraintKey(DurationConstraint, PSY.ThermalStandard, "up"), + PSI.ConstraintKey(DurationConstraint, PSY.ThermalStandard, "dn")] aux_variables_keys = [PSI.AuxVarKey(PSI.TimeDurationOff, ThermalStandard), - PSI.AuxVarKey(PSI.TimeDurationOn, ThermalStandard)] + PSI.AuxVarKey(PSI.TimeDurationOn, ThermalStandard)] device_model = DeviceModel(ThermalStandard, ThermalStandardUnitCommitment) @@ -157,14 +157,14 @@ end @testset "Thermal MultiStart UC With DC - PF" begin bin_variable_keys = [PSI.VariableKey(OnVariable, PSY.ThermalMultiStart), - PSI.VariableKey(StartVariable, PSY.ThermalMultiStart), - PSI.VariableKey(StopVariable, PSY.ThermalMultiStart)] + PSI.VariableKey(StartVariable, PSY.ThermalMultiStart), + PSI.VariableKey(StopVariable, PSY.ThermalMultiStart)] uc_constraint_keys = [PSI.ConstraintKey(RampConstraint, PSY.ThermalMultiStart, "up"), - PSI.ConstraintKey(RampConstraint, PSY.ThermalMultiStart, "dn"), - PSI.ConstraintKey(DurationConstraint, PSY.ThermalMultiStart, - "up"), - PSI.ConstraintKey(DurationConstraint, PSY.ThermalMultiStart, - "dn")] + PSI.ConstraintKey(RampConstraint, PSY.ThermalMultiStart, "dn"), + PSI.ConstraintKey(DurationConstraint, PSY.ThermalMultiStart, + "up"), + PSI.ConstraintKey(DurationConstraint, PSY.ThermalMultiStart, + "dn")] device_model = DeviceModel(ThermalMultiStart, ThermalStandardUnitCommitment) c_sys5_uc = PSB.build_system(PSITestSystems, "c_sys5_pglib") @@ -178,14 +178,14 @@ end @testset "Thermal MultiStart UC With AC - PF" begin bin_variable_keys = [PSI.VariableKey(OnVariable, PSY.ThermalMultiStart), - PSI.VariableKey(StartVariable, PSY.ThermalMultiStart), - PSI.VariableKey(StopVariable, PSY.ThermalMultiStart)] + PSI.VariableKey(StartVariable, PSY.ThermalMultiStart), + PSI.VariableKey(StopVariable, PSY.ThermalMultiStart)] uc_constraint_keys = [PSI.ConstraintKey(RampConstraint, PSY.ThermalMultiStart, "up"), - PSI.ConstraintKey(RampConstraint, PSY.ThermalMultiStart, "dn"), - PSI.ConstraintKey(DurationConstraint, PSY.ThermalMultiStart, - "up"), - PSI.ConstraintKey(DurationConstraint, PSY.ThermalMultiStart, - "dn")] + PSI.ConstraintKey(RampConstraint, PSY.ThermalMultiStart, "dn"), + PSI.ConstraintKey(DurationConstraint, PSY.ThermalMultiStart, + "up"), + PSI.ConstraintKey(DurationConstraint, PSY.ThermalMultiStart, + "dn")] device_model = DeviceModel(ThermalMultiStart, ThermalStandardUnitCommitment) c_sys5_uc = PSB.build_system(PSITestSystems, "c_sys5_pglib") @@ -200,8 +200,8 @@ end ################################### Basic Unit Commitment tests ############################ @testset "Thermal Basic UC With DC - PF" begin bin_variable_keys = [PSI.VariableKey(OnVariable, PSY.ThermalStandard), - PSI.VariableKey(StartVariable, PSY.ThermalStandard), - PSI.VariableKey(StopVariable, PSY.ThermalStandard)] + PSI.VariableKey(StartVariable, PSY.ThermalStandard), + PSI.VariableKey(StopVariable, PSY.ThermalStandard)] device_model = DeviceModel(ThermalStandard, ThermalBasicUnitCommitment) c_sys5_uc = PSB.build_system(PSITestSystems, "c_sys5_uc") @@ -221,8 +221,8 @@ end @testset "Thermal Basic UC With AC - PF" begin bin_variable_keys = [PSI.VariableKey(OnVariable, PSY.ThermalStandard), - PSI.VariableKey(StartVariable, PSY.ThermalStandard), - PSI.VariableKey(StopVariable, PSY.ThermalStandard)] + PSI.VariableKey(StartVariable, PSY.ThermalStandard), + PSI.VariableKey(StopVariable, PSY.ThermalStandard)] device_model = DeviceModel(ThermalStandard, ThermalBasicUnitCommitment) c_sys5_uc = PSB.build_system(PSITestSystems, "c_sys5_uc") @@ -242,8 +242,8 @@ end @testset "Thermal MultiStart Basic UC With DC - PF" begin bin_variable_keys = [PSI.VariableKey(OnVariable, PSY.ThermalMultiStart), - PSI.VariableKey(StartVariable, PSY.ThermalMultiStart), - PSI.VariableKey(StopVariable, PSY.ThermalMultiStart)] + PSI.VariableKey(StartVariable, PSY.ThermalMultiStart), + PSI.VariableKey(StopVariable, PSY.ThermalMultiStart)] device_model = DeviceModel(ThermalMultiStart, ThermalBasicUnitCommitment) c_sys5_uc = PSB.build_system(PSITestSystems, "c_sys5_pglib") @@ -256,8 +256,8 @@ end @testset "Thermal MultiStart Basic UC With AC - PF" begin bin_variable_keys = [PSI.VariableKey(OnVariable, PSY.ThermalMultiStart), - PSI.VariableKey(StartVariable, PSY.ThermalMultiStart), - PSI.VariableKey(StopVariable, PSY.ThermalMultiStart)] + PSI.VariableKey(StartVariable, PSY.ThermalMultiStart), + PSI.VariableKey(StopVariable, PSY.ThermalMultiStart)] device_model = DeviceModel(ThermalMultiStart, ThermalBasicUnitCommitment) c_sys5_uc = PSB.build_system(PSITestSystems, "c_sys5_pglib") @@ -379,19 +379,19 @@ end template = get_thermal_dispatch_template_network() set_device_model!(template, DeviceModel(ThermalStandard, ThermalDispatchNoMin)) model = DecisionModel(MockOperationProblem, - CopperPlatePowerModel, - c_sys5_pwl_ed_nonconvex; - export_pwl_vars=true, - initialize_model=false,) + CopperPlatePowerModel, + c_sys5_pwl_ed_nonconvex; + export_pwl_vars = true, + initialize_model = false) @test_throws IS.InvalidValue mock_construct_device!(model, - DeviceModel(ThermalStandard, - ThermalDispatchNoMin)) + DeviceModel(ThermalStandard, + ThermalDispatchNoMin)) end ################################## Ramp Limited Testing ################################## @testset "ThermalStandard with ThermalStandardDispatch With DC - PF" begin constraint_keys = [PSI.ConstraintKey(RampConstraint, PSY.ThermalStandard, "up"), - PSI.ConstraintKey(RampConstraint, PSY.ThermalStandard, "dn")] + PSI.ConstraintKey(RampConstraint, PSY.ThermalStandard, "dn")] device_model = DeviceModel(ThermalStandard, ThermalStandardDispatch) c_sys5_uc = PSB.build_system(PSITestSystems, "c_sys5_uc") model = DecisionModel(MockOperationProblem, DCPPowerModel, c_sys5_uc;) @@ -409,7 +409,7 @@ end @testset "ThermalStandard with ThermalStandardDispatch With AC - PF" begin constraint_keys = [PSI.ConstraintKey(RampConstraint, PSY.ThermalStandard, "up"), - PSI.ConstraintKey(RampConstraint, PSY.ThermalStandard, "dn")] + PSI.ConstraintKey(RampConstraint, PSY.ThermalStandard, "dn")] device_model = DeviceModel(ThermalStandard, ThermalStandardDispatch) c_sys5_uc = PSB.build_system(PSITestSystems, "c_sys5_uc") model = DecisionModel(MockOperationProblem, ACPPowerModel, c_sys5_uc;) @@ -427,7 +427,7 @@ end @testset "ThermalMultiStart with ThermalStandardDispatch With DC - PF" begin constraint_keys = [PSI.ConstraintKey(RampConstraint, PSY.ThermalMultiStart, "up"), - PSI.ConstraintKey(RampConstraint, PSY.ThermalMultiStart, "dn")] + PSI.ConstraintKey(RampConstraint, PSY.ThermalMultiStart, "dn")] device_model = DeviceModel(ThermalMultiStart, ThermalStandardDispatch) c_sys5_uc = PSB.build_system(PSITestSystems, "c_sys5_pglib") model = DecisionModel(MockOperationProblem, DCPPowerModel, c_sys5_uc;) @@ -439,7 +439,7 @@ end @testset "ThermalMultiStart with ThermalStandardDispatch With AC - PF" begin constraint_keys = [PSI.ConstraintKey(RampConstraint, PSY.ThermalMultiStart, "up"), - PSI.ConstraintKey(RampConstraint, PSY.ThermalMultiStart, "dn")] + PSI.ConstraintKey(RampConstraint, PSY.ThermalMultiStart, "dn")] device_model = DeviceModel(ThermalMultiStart, ThermalStandardDispatch) c_sys5_uc = PSB.build_system(PSITestSystems, "c_sys5_pglib") model = DecisionModel(MockOperationProblem, ACPPowerModel, c_sys5_uc;) @@ -453,19 +453,19 @@ end @testset "Thermal MultiStart with MultiStart UC and DC - PF" begin constraint_keys = [PSI.ConstraintKey(ActiveRangeICConstraint, PSY.ThermalMultiStart), - PSI.ConstraintKey(StartTypeConstraint, PSY.ThermalMultiStart), - PSI.ConstraintKey(StartupTimeLimitTemperatureConstraint, - PSY.ThermalMultiStart, - "warm"), - PSI.ConstraintKey(StartupTimeLimitTemperatureConstraint, - PSY.ThermalMultiStart, - "hot"), - PSI.ConstraintKey(StartupInitialConditionConstraint, - PSY.ThermalMultiStart, - "lb"), - PSI.ConstraintKey(StartupInitialConditionConstraint, - PSY.ThermalMultiStart, - "ub")] + PSI.ConstraintKey(StartTypeConstraint, PSY.ThermalMultiStart), + PSI.ConstraintKey(StartupTimeLimitTemperatureConstraint, + PSY.ThermalMultiStart, + "warm"), + PSI.ConstraintKey(StartupTimeLimitTemperatureConstraint, + PSY.ThermalMultiStart, + "hot"), + PSI.ConstraintKey(StartupInitialConditionConstraint, + PSY.ThermalMultiStart, + "lb"), + PSI.ConstraintKey(StartupInitialConditionConstraint, + PSY.ThermalMultiStart, + "ub")] device_model = DeviceModel(PSY.ThermalMultiStart, PSI.ThermalMultiStartUnitCommitment) no_less_than = Dict(true => 334, false => 282) c_sys5_pglib = PSB.build_system(PSITestSystems, "c_sys5_pglib") @@ -478,19 +478,19 @@ end @testset "Thermal MultiStart with MultiStart UC and AC - PF" begin constraint_keys = [PSI.ConstraintKey(ActiveRangeICConstraint, PSY.ThermalMultiStart), - PSI.ConstraintKey(StartTypeConstraint, PSY.ThermalMultiStart), - PSI.ConstraintKey(StartupTimeLimitTemperatureConstraint, - PSY.ThermalMultiStart, - "warm"), - PSI.ConstraintKey(StartupTimeLimitTemperatureConstraint, - PSY.ThermalMultiStart, - "hot"), - PSI.ConstraintKey(StartupInitialConditionConstraint, - PSY.ThermalMultiStart, - "lb"), - PSI.ConstraintKey(StartupInitialConditionConstraint, - PSY.ThermalMultiStart, - "ub")] + PSI.ConstraintKey(StartTypeConstraint, PSY.ThermalMultiStart), + PSI.ConstraintKey(StartupTimeLimitTemperatureConstraint, + PSY.ThermalMultiStart, + "warm"), + PSI.ConstraintKey(StartupTimeLimitTemperatureConstraint, + PSY.ThermalMultiStart, + "hot"), + PSI.ConstraintKey(StartupInitialConditionConstraint, + PSY.ThermalMultiStart, + "lb"), + PSI.ConstraintKey(StartupInitialConditionConstraint, + PSY.ThermalMultiStart, + "ub")] device_model = DeviceModel(PSY.ThermalMultiStart, PSI.ThermalMultiStartUnitCommitment) no_less_than = Dict(true => 382, false => 330) c_sys5_pglib = PSB.build_system(PSITestSystems, "c_sys5_pglib") @@ -580,7 +580,7 @@ end device_model = DeviceModel(PSY.ThermalStandard, PSI.ThermalCompactDispatch) c_sys5 = PSB.build_system(PSITestSystems, "c_sys5") model = DecisionModel(MockOperationProblem, DCPPowerModel, c_sys5) - mock_construct_device!(model, device_model; built_for_recurrent_solves=true) + mock_construct_device!(model, device_model; built_for_recurrent_solves = true) moi_tests(model, 245, 0, 144, 144, 0, false) psi_checkobjfun_test(model, GAEVF) end @@ -589,7 +589,7 @@ end device_model = DeviceModel(PSY.ThermalMultiStart, PSI.ThermalCompactDispatch) c_sys5_pglib = PSB.build_system(PSITestSystems, "c_sys5_pglib") model = DecisionModel(MockOperationProblem, DCPPowerModel, c_sys5_pglib) - mock_construct_device!(model, device_model; built_for_recurrent_solves=true) + mock_construct_device!(model, device_model; built_for_recurrent_solves = true) moi_tests(model, 290, 0, 96, 96, 96, false) psi_checkobjfun_test(model, GAEVF) end @@ -598,7 +598,7 @@ end device_model = DeviceModel(PSY.ThermalStandard, PSI.ThermalCompactDispatch) c_sys5 = PSB.build_system(PSITestSystems, "c_sys5") model = DecisionModel(MockOperationProblem, ACPPowerModel, c_sys5) - mock_construct_device!(model, device_model; built_for_recurrent_solves=true) + mock_construct_device!(model, device_model; built_for_recurrent_solves = true) moi_tests(model, 365, 0, 264, 264, 0, false) psi_checkobjfun_test(model, GAEVF) end @@ -607,7 +607,7 @@ end device_model = DeviceModel(PSY.ThermalMultiStart, PSI.ThermalCompactDispatch) c_sys5_pglib = PSB.build_system(PSITestSystems, "c_sys5_pglib") model = DecisionModel(MockOperationProblem, ACPPowerModel, c_sys5_pglib) - mock_construct_device!(model, device_model; built_for_recurrent_solves=true) + mock_construct_device!(model, device_model; built_for_recurrent_solves = true) moi_tests(model, 338, 0, 144, 144, 96, false) psi_checkobjfun_test(model, GAEVF) end @@ -619,11 +619,11 @@ end set_device_model!(template, ThermalStandard, ThermalStandardDispatch) set_device_model!(template, PowerLoad, StaticPowerLoad) ED = DecisionModel(EconomicDispatchProblem, - template, - ramp_test_sys; - optimizer=HiGHS_optimizer, - initialize_model=false,) - @test build!(ED; output_dir=mktempdir(; cleanup=true)) == PSI.ModelBuildStatus.BUILT + template, + ramp_test_sys; + optimizer = HiGHS_optimizer, + initialize_model = false) + @test build!(ED; output_dir = mktempdir(; cleanup = true)) == PSI.ModelBuildStatus.BUILT moi_tests(ED, 10, 0, 15, 15, 5, false) psi_checksolve_test(ED, [MOI.OPTIMAL], 11191.00) end @@ -632,13 +632,13 @@ end @testset "Solving UC with CopperPlate for testing Duration Constraints" begin template = get_thermal_standard_uc_template() UC = DecisionModel(UnitCommitmentProblem, - template, - PSB.build_system(PSITestSystems, "c_duration_test"); - optimizer=HiGHS_optimizer, - initialize_model=false, - store_variable_names=true,) - build!(UC; output_dir=mktempdir(; cleanup=true)) - @test build!(UC; output_dir=mktempdir(; cleanup=true)) == PSI.ModelBuildStatus.BUILT + template, + PSB.build_system(PSITestSystems, "c_duration_test"); + optimizer = HiGHS_optimizer, + initialize_model = false, + store_variable_names = true) + build!(UC; output_dir = mktempdir(; cleanup = true)) + @test build!(UC; output_dir = mktempdir(; cleanup = true)) == PSI.ModelBuildStatus.BUILT moi_tests(UC, 56, 0, 56, 14, 21, true) psi_checksolve_test(UC, [MOI.OPTIMAL], 8223.50) end @@ -673,8 +673,8 @@ end for net in networks, sys in systems, model in commitment_models template = get_thermal_dispatch_template_network(NetworkModel(net)) set_device_model!(template, ThermalStandard, model) - UC = DecisionModel(template, sys; optimizer=HiGHS_optimizer) - @test build!(UC; output_dir=mktempdir(; cleanup=true)) == + UC = DecisionModel(template, sys; optimizer = HiGHS_optimizer) + @test build!(UC; output_dir = mktempdir(; cleanup = true)) == PSI.ModelBuildStatus.BUILT psi_checksolve_test(UC, [MOI.OPTIMAL, MOI.LOCALLY_SOLVED], 340000, 100000) end @@ -683,120 +683,120 @@ end @testset "Test Feedforwards to ThermalStandard with ThermalStandardDispatch" begin device_model = DeviceModel(ThermalStandard, ThermalStandardDispatch) ff_sc = SemiContinuousFeedforward(; - component_type=ThermalStandard, - source=OnVariable, - affected_values=[ActivePowerVariable],) + component_type = ThermalStandard, + source = OnVariable, + affected_values = [ActivePowerVariable]) ff_ub = UpperBoundFeedforward(; - component_type=ThermalStandard, - source=ActivePowerVariable, - affected_values=[ActivePowerVariable],) + component_type = ThermalStandard, + source = ActivePowerVariable, + affected_values = [ActivePowerVariable]) PSI.attach_feedforward!(device_model, ff_sc) PSI.attach_feedforward!(device_model, ff_ub) c_sys5 = PSB.build_system(PSITestSystems, "c_sys5") model = DecisionModel(MockOperationProblem, DCPPowerModel, c_sys5) - mock_construct_device!(model, device_model; built_for_recurrent_solves=true) + mock_construct_device!(model, device_model; built_for_recurrent_solves = true) moi_tests(model, 365, 0, 264, 144, 0, false) end @testset "Test Feedforwards to ThermalStandard with ThermalBasicDispatch" begin device_model = DeviceModel(ThermalStandard, ThermalBasicDispatch) ff_sc = SemiContinuousFeedforward(; - component_type=ThermalStandard, - source=OnVariable, - affected_values=[ActivePowerVariable],) + component_type = ThermalStandard, + source = OnVariable, + affected_values = [ActivePowerVariable]) ff_ub = UpperBoundFeedforward(; - component_type=ThermalStandard, - source=ActivePowerVariable, - affected_values=[ActivePowerVariable],) + component_type = ThermalStandard, + source = ActivePowerVariable, + affected_values = [ActivePowerVariable]) PSI.attach_feedforward!(device_model, ff_sc) PSI.attach_feedforward!(device_model, ff_ub) c_sys5 = PSB.build_system(PSITestSystems, "c_sys5") model = DecisionModel(MockOperationProblem, DCPPowerModel, c_sys5) - mock_construct_device!(model, device_model; built_for_recurrent_solves=true) + mock_construct_device!(model, device_model; built_for_recurrent_solves = true) moi_tests(model, 360, 0, 240, 120, 0, false) end @testset "Test Feedforwards to ThermalStandard with ThermalCompactDispatch" begin device_model = DeviceModel(PSY.ThermalStandard, PSI.ThermalCompactDispatch) ff_sc = SemiContinuousFeedforward(; - component_type=ThermalStandard, - source=OnVariable, - affected_values=[PowerAboveMinimumVariable],) + component_type = ThermalStandard, + source = OnVariable, + affected_values = [PowerAboveMinimumVariable]) ff_ub = UpperBoundFeedforward(; - component_type=ThermalStandard, - source=PSI.PowerAboveMinimumVariable, - affected_values=[PSI.PowerAboveMinimumVariable],) + component_type = ThermalStandard, + source = PSI.PowerAboveMinimumVariable, + affected_values = [PSI.PowerAboveMinimumVariable]) PSI.attach_feedforward!(device_model, ff_sc) PSI.attach_feedforward!(device_model, ff_ub) c_sys5 = PSB.build_system(PSITestSystems, "c_sys5") model = DecisionModel(MockOperationProblem, DCPPowerModel, c_sys5) - mock_construct_device!(model, device_model; built_for_recurrent_solves=true) + mock_construct_device!(model, device_model; built_for_recurrent_solves = true) moi_tests(model, 365, 0, 264, 144, 0, false) end @testset "Test Feedforwards to ThermalMultiStart with ThermalStandardDispatch" begin device_model = DeviceModel(ThermalMultiStart, ThermalStandardDispatch) ff_sc = SemiContinuousFeedforward(; - component_type=ThermalMultiStart, - source=OnVariable, - affected_values=[ActivePowerVariable],) + component_type = ThermalMultiStart, + source = OnVariable, + affected_values = [ActivePowerVariable]) ff_ub = UpperBoundFeedforward(; - component_type=ThermalMultiStart, - source=ActivePowerVariable, - affected_values=[ActivePowerVariable],) + component_type = ThermalMultiStart, + source = ActivePowerVariable, + affected_values = [ActivePowerVariable]) PSI.attach_feedforward!(device_model, ff_sc) PSI.attach_feedforward!(device_model, ff_ub) c_sys5 = PSB.build_system(PSITestSystems, "c_sys5_pglib") model = DecisionModel(MockOperationProblem, DCPPowerModel, c_sys5) - mock_construct_device!(model, device_model; built_for_recurrent_solves=true) + mock_construct_device!(model, device_model; built_for_recurrent_solves = true) moi_tests(model, 338, 0, 144, 96, 96, false) end @testset "Test Feedforwards to ThermalMultiStart with ThermalBasicDispatch" begin device_model = DeviceModel(ThermalMultiStart, ThermalBasicDispatch) ff_sc = SemiContinuousFeedforward(; - component_type=ThermalMultiStart, - source=OnVariable, - affected_values=[ActivePowerVariable],) + component_type = ThermalMultiStart, + source = OnVariable, + affected_values = [ActivePowerVariable]) ff_ub = UpperBoundFeedforward(; - component_type=ThermalMultiStart, - source=ActivePowerVariable, - affected_values=[ActivePowerVariable],) + component_type = ThermalMultiStart, + source = ActivePowerVariable, + affected_values = [ActivePowerVariable]) PSI.attach_feedforward!(device_model, ff_sc) PSI.attach_feedforward!(device_model, ff_ub) c_sys5 = PSB.build_system(PSITestSystems, "c_sys5_pglib") model = DecisionModel(MockOperationProblem, DCPPowerModel, c_sys5) - mock_construct_device!(model, device_model; built_for_recurrent_solves=true) + mock_construct_device!(model, device_model; built_for_recurrent_solves = true) moi_tests(model, 336, 0, 96, 48, 96, false) end @testset "Test Feedforwards to ThermalMultiStart with ThermalCompactDispatch" begin device_model = DeviceModel(PSY.ThermalMultiStart, PSI.ThermalCompactDispatch) ff_sc = SemiContinuousFeedforward(; - component_type=ThermalMultiStart, - source=OnVariable, - affected_values=[PSI.PowerAboveMinimumVariable],) + component_type = ThermalMultiStart, + source = OnVariable, + affected_values = [PSI.PowerAboveMinimumVariable]) ff_ub = UpperBoundFeedforward(; - component_type=ThermalMultiStart, - source=PSI.PowerAboveMinimumVariable, - affected_values=[PSI.PowerAboveMinimumVariable],) + component_type = ThermalMultiStart, + source = PSI.PowerAboveMinimumVariable, + affected_values = [PSI.PowerAboveMinimumVariable]) PSI.attach_feedforward!(device_model, ff_sc) PSI.attach_feedforward!(device_model, ff_ub) c_sys5 = PSB.build_system(PSITestSystems, "c_sys5_pglib") model = DecisionModel(MockOperationProblem, DCPPowerModel, c_sys5) - mock_construct_device!(model, device_model; built_for_recurrent_solves=true) + mock_construct_device!(model, device_model; built_for_recurrent_solves = true) moi_tests(model, 338, 0, 144, 96, 96, false) end @@ -813,17 +813,19 @@ end set_must_run!(sundance, true) for rebuild in [true, false] model = DecisionModel(template_uc, - sys_5; - name="UC", - optimizer=HiGHS_optimizer, - system_to_file=false, - store_variable_names=true, - rebuild_model=rebuild,) - - solve!(model; output_dir=mktempdir()) + sys_5; + name = "UC", + optimizer = HiGHS_optimizer, + system_to_file = false, + store_variable_names = true, + rebuild_model = rebuild) + + solve!(model; output_dir = mktempdir()) ptdf_vars = get_variable_values(OptimizationProblemResults(model)) power = ptdf_vars[PowerSimulations.VariableKey{ActivePowerVariable, - ThermalStandard}("")] + ThermalStandard}( + "", + )] on = ptdf_vars[PowerSimulations.VariableKey{OnVariable, ThermalStandard}("")] start = ptdf_vars[PowerSimulations.VariableKey{StartVariable, ThermalStandard}("")] stop = ptdf_vars[PowerSimulations.VariableKey{StopVariable, ThermalStandard}("")]