From acd5f6e99d0f8b8e4d978d210a6f5048c3bec701 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Mon, 9 Oct 2023 13:36:36 -0600 Subject: [PATCH 1/4] remove FF code --- src/feedforward/feedforwards.jl | 75 --------------------------------- 1 file changed, 75 deletions(-) diff --git a/src/feedforward/feedforwards.jl b/src/feedforward/feedforwards.jl index 82f4220b25..25885c1b2d 100644 --- a/src/feedforward/feedforwards.jl +++ b/src/feedforward/feedforwards.jl @@ -202,42 +202,6 @@ function has_semicontinuous_feedforward( return has_semicontinuous_feedforward(model, ActivePowerVariable) end -""" -Adds a constraint to limit the sum of a variable over the number of periods to the source value -""" -struct EnergyLimitFeedforward <: AbstractAffectFeedforward - optimization_container_key::OptimizationContainerKey - affected_values::Vector{<:OptimizationContainerKey} - number_of_periods::Int - function EnergyLimitFeedforward(; - component_type::Type{<:PSY.Component}, - source::Type{T}, - affected_values::Vector{DataType}, - number_of_periods::Int, - meta = CONTAINER_KEY_EMPTY_META, - ) where {T} - values_vector = Vector{VariableKey}(undef, length(affected_values)) - for (ix, v) in enumerate(affected_values) - if v <: VariableType - values_vector[ix] = - get_optimization_container_key(v(), component_type, meta) - else - error( - "EnergyLimitFeedforward is only compatible with VariableType or ParamterType affected values", - ) - end - end - new( - get_optimization_container_key(T(), component_type, meta), - values_vector, - number_of_periods, - ) - end -end - -get_default_parameter_type(::EnergyLimitFeedforward, _) = EnergyLimitParameter -get_optimization_container_key(ff) = ff.optimization_container_key -get_number_of_periods(ff) = ff.number_of_periods """ Fixes a Variable or Parameter Value in the model. Is the only Feed Forward that can be used @@ -269,42 +233,3 @@ end get_default_parameter_type(::FixValueFeedforward, _) = FixValueParameter get_optimization_container_key(ff::FixValueFeedforward) = ff.optimization_container_key - -""" -Adds a constraint to enforce a minimum energy level target with a slack variable associated witha penalty term. -""" -struct EnergyTargetFeedforward <: AbstractAffectFeedforward - optimization_container_key::OptimizationContainerKey - affected_values::Vector{<:OptimizationContainerKey} - target_period::Int - penalty_cost::Float64 - function EnergyTargetFeedforward(; - component_type::Type{<:PSY.Component}, - source::Type{T}, - affected_values::Vector{DataType}, - target_period::Int, - penalty_cost::Float64, - meta = CONTAINER_KEY_EMPTY_META, - ) where {T} - values_vector = Vector{VariableKey}(undef, length(affected_values)) - for (ix, v) in enumerate(affected_values) - if v <: VariableType - values_vector[ix] = - get_optimization_container_key(v(), component_type, meta) - else - error( - "EnergyTargetFeedforward is only compatible with VariableType or ParamterType affected values", - ) - end - end - new( - get_optimization_container_key(T(), component_type, meta), - values_vector, - target_period, - penalty_cost, - ) - end -end - -get_default_parameter_type(::EnergyTargetFeedforward, _) = EnergyTargetParameter -get_optimization_container_key(ff::EnergyTargetFeedforward) = ff.optimization_container_key From b878bdf9a40f3059833d0062d29aac9becb14fd0 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Mon, 9 Oct 2023 13:37:04 -0600 Subject: [PATCH 2/4] remove constraints code --- src/feedforward/feedforward_constraints.jl | 70 ---------------------- 1 file changed, 70 deletions(-) diff --git a/src/feedforward/feedforward_constraints.jl b/src/feedforward/feedforward_constraints.jl index d29f4c79a3..62e8d704c2 100644 --- a/src/feedforward/feedforward_constraints.jl +++ b/src/feedforward/feedforward_constraints.jl @@ -422,76 +422,6 @@ function add_feedforward_constraints!( return end -@doc raw""" - add_feedforward_constraints(container::OptimizationContainer, - cons_name::Symbol, - param_reference, - var_key::VariableKey) - -Constructs a parameterized integral limit constraint to implement feedforward from other models. -The Parameters are initialized using the upper boundary values of the provided variables. - - -``` sum(variable[var_name, t] for t in 1:affected_periods)/affected_periods <= param_reference[var_name] ``` - -# LaTeX - -`` \sum_{t} x \leq param^{max}`` - -# Arguments -* container::OptimizationContainer : the optimization_container model built in PowerSimulations -* model::DeviceModel : the device model -* devices::IS.FlattenIteratorWrapper{T} : list of devices -* ff::FixValueFeedforward : a instance of the FixValue Feedforward -""" -function add_feedforward_constraints!( - container::OptimizationContainer, - ::DeviceModel, - devices::IS.FlattenIteratorWrapper{T}, - ff::EnergyLimitFeedforward, -) where {T <: PSY.Component} - time_steps = get_time_steps(container) - parameter_type = get_default_parameter_type(ff, T) - param = get_parameter_array(container, parameter_type(), T) - multiplier = get_parameter_multiplier_array(container, parameter_type(), T) - affected_periods = get_number_of_periods(ff) - for var in get_affected_values(ff) - variable = get_variable(container, var) - set_name, set_time = JuMP.axes(variable) - IS.@assert_op set_name == [PSY.get_name(d) for d in devices] - IS.@assert_op set_time == time_steps - - if affected_periods > set_time[end] - error( - "The number of affected periods $affected_periods is larger than the periods available $(set_time[end])", - ) - end - no_trenches = set_time[end] รท affected_periods - var_type = get_entry_type(var) - con_ub = add_constraints_container!( - container, - FeedforwardIntegralLimitConstraint(), - T, - set_name, - 1:no_trenches; - meta = "$(var_type)integral", - ) - - for name in set_name, i in 1:no_trenches - con_ub[name, i] = JuMP.@constraint( - container.JuMPmodel, - sum( - variable[name, t] for - t in (1 + (i - 1) * affected_periods):(i * affected_periods) - ) <= sum( - param[name, t] * multiplier[name, t] for - t in (1 + (i - 1) * affected_periods):(i * affected_periods) - ) - ) - end - end - return -end @doc raw""" add_feedforward_constraints( From edd5080694a853c67f17d3a995917ea77d4fb7c5 Mon Sep 17 00:00:00 2001 From: rodrigomha Date: Tue, 10 Oct 2023 10:57:20 -0700 Subject: [PATCH 3/4] remove additional params --- src/core/parameters.jl | 9 +-------- src/feedforward/feedforward_constraints.jl | 1 - src/feedforward/feedforwards.jl | 1 - 3 files changed, 1 insertion(+), 10 deletions(-) diff --git a/src/core/parameters.jl b/src/core/parameters.jl index ea6baa0fa9..d14c113c26 100644 --- a/src/core/parameters.jl +++ b/src/core/parameters.jl @@ -299,12 +299,8 @@ Parameter to define unit commitment status struct OnStatusParameter <: VariableValueParameter end """ -Parameter to define energy limit +Parameter to FixValueParameter """ -struct EnergyLimitParameter <: VariableValueParameter end -# TODO: Check if EnergyTargetParameter and EnergyLimitParameter should be removed -# This affects feedforwards that can break if not defined -struct EnergyTargetParameter <: VariableValueParameter end struct FixValueParameter <: VariableValueParameter end """ @@ -324,6 +320,3 @@ convert_result_to_natural_units(::Type{ReactivePowerTimeSeriesParameter}) = true convert_result_to_natural_units(::Type{RequirementTimeSeriesParameter}) = true convert_result_to_natural_units(::Type{UpperBoundValueParameter}) = true convert_result_to_natural_units(::Type{LowerBoundValueParameter}) = true -# TODO: Check if EnergyLimitParameter and EnergyTargetParameter should be removed -convert_result_to_natural_units(::Type{EnergyLimitParameter}) = true -convert_result_to_natural_units(::Type{EnergyTargetParameter}) = true diff --git a/src/feedforward/feedforward_constraints.jl b/src/feedforward/feedforward_constraints.jl index 62e8d704c2..7fd5ff8fb3 100644 --- a/src/feedforward/feedforward_constraints.jl +++ b/src/feedforward/feedforward_constraints.jl @@ -422,7 +422,6 @@ function add_feedforward_constraints!( return end - @doc raw""" add_feedforward_constraints( container::OptimizationContainer, diff --git a/src/feedforward/feedforwards.jl b/src/feedforward/feedforwards.jl index 25885c1b2d..5a503a15b0 100644 --- a/src/feedforward/feedforwards.jl +++ b/src/feedforward/feedforwards.jl @@ -202,7 +202,6 @@ function has_semicontinuous_feedforward( return has_semicontinuous_feedforward(model, ActivePowerVariable) end - """ Fixes a Variable or Parameter Value in the model. Is the only Feed Forward that can be used with a Parameter or a Variable as the affected value. From cb179a29bb35faddec634326aee4d8dd3d6b18e0 Mon Sep 17 00:00:00 2001 From: rodrigomha Date: Tue, 10 Oct 2023 11:01:44 -0700 Subject: [PATCH 4/4] remove upd parameter limit FF --- src/parameters/update_parameters.jl | 82 ----------------------------- 1 file changed, 82 deletions(-) diff --git a/src/parameters/update_parameters.jl b/src/parameters/update_parameters.jl index 671c1b59d7..ac021131bb 100644 --- a/src/parameters/update_parameters.jl +++ b/src/parameters/update_parameters.jl @@ -428,88 +428,6 @@ function update_parameter_values!( return end -function update_parameter_values!( - model::OperationModel, - key::ParameterKey{T, U}, - input::DatasetContainer{InMemoryDataset}, -) where {T <: EnergyLimitParameter, U <: PSY.Generator} - # Enable again for detailed debugging - # TimerOutputs.@timeit RUN_SIMULATION_TIMER "$T $U Parameter Update" begin - optimization_container = get_optimization_container(model) - # Note: Do not instantite a new key here because it might not match the param keys in the container - # if the keys have strings in the meta fields - parameter_array = get_parameter_array(optimization_container, key) - parameter_attributes = get_parameter_attributes(optimization_container, key) - internal = get_internal(model) - execution_count = internal.execution_count - current_time = get_current_time(model) - state_values = get_dataset_values(input, get_attribute_key(parameter_attributes)) - component_names, time = axes(parameter_array) - resolution = get_resolution(model) - interval_time_steps = Int(get_interval(model.internal.store_parameters) / resolution) - state_data = get_dataset(input, get_attribute_key(parameter_attributes)) - state_timestamps = state_data.timestamps - max_state_index = get_num_rows(state_data) - - state_data_index = find_timestamp_index(state_timestamps, current_time) - sim_timestamps = range(current_time; step = resolution, length = time[end]) - old_parameter_values = jump_value.(parameter_array) - # The current method uses older parameter values because when passing the energy output from one stage - # to the next, the aux variable values gets over-written by the lower level model after its solve. - # This approach is a temporary hack and will be replaced in future versions. - for t in time - timestamp_ix = min(max_state_index, state_data_index + 1) - @debug "parameter horizon is over the step" max_state_index > state_data_index + 1 - if state_timestamps[timestamp_ix] <= sim_timestamps[t] - state_data_index = timestamp_ix - end - for name in component_names - # the if statement checks if its the first solve of the model and uses the values stored in the state - # and for subsequent solves uses the state data to update the parameter values for the last set of time periods - # that are equal to the length of the interval i.e. the time periods that dont overlap between each solves. - if execution_count == 0 || t > time[end] - interval_time_steps - # Pass indices in this way since JuMP DenseAxisArray don't support view() - state_value = state_values[name, state_data_index] - if !isfinite(state_value) - error( - "The value for the system state used in $(encode_key_as_string(key)) is not a finite value $(state_value) \ - This is commonly caused by referencing a state value at a time when such decision hasn't been made. \ - Consider reviewing your models' horizon and interval definitions", - ) - end - _set_param_value!(parameter_array, state_value, name, t) - else - # Currently the update method relies on using older parameter values of the EnergyLimitParameter - # to update the parameter for overlapping periods between solves i.e. we ingoring the parameter values - # in the model interval time periods. - state_value = state_values[name, state_data_index] - if !isfinite(state_value) - error( - "The value for the system state used in $(encode_key_as_string(key)) is not a finite value $(state_value) \ - This is commonly caused by referencing a state value at a time when such decision hasn't been made. \ - Consider reviewing your models' horizon and interval definitions", - ) - end - _set_param_value!( - parameter_array, - old_parameter_values[name, t + interval_time_steps], - name, - t, - ) - end - end - end - - IS.@record :execution ParameterUpdateEvent( - T, - U, - parameter_attributes, - get_current_timestamp(model), - get_name(model), - ) - return -end - """ Update parameter function an OperationModel """