Skip to content

Commit

Permalink
update code in main to new IS code
Browse files Browse the repository at this point in the history
  • Loading branch information
jd-lara committed Apr 25, 2024
1 parent 1414436 commit 479e4e6
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 42 deletions.
16 changes: 8 additions & 8 deletions src/core/initial_conditions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,16 @@ function has_initial_condition_value(
end

######################### Initial Conditions Definitions#####################################
struct DevicePower <: IS.InitialConditionType end
struct DeviceAboveMinPower <: IS.InitialConditionType end
struct DeviceStatus <: IS.InitialConditionType end
struct InitialTimeDurationOn <: IS.InitialConditionType end
struct InitialTimeDurationOff <: IS.InitialConditionType end
struct InitialEnergyLevel <: IS.InitialConditionType end
struct AreaControlError <: IS.InitialConditionType end
struct DevicePower <: InitialConditionType end
struct DeviceAboveMinPower <: InitialConditionType end
struct DeviceStatus <: InitialConditionType end
struct InitialTimeDurationOn <: InitialConditionType end
struct InitialTimeDurationOff <: InitialConditionType end
struct InitialEnergyLevel <: InitialConditionType end
struct AreaControlError <: InitialConditionType end

# Decide whether to run the initial conditions reconciliation algorithm based on the presence of any of these
requires_reconciliation(::Type{<:IS.InitialConditionType}) = false
requires_reconciliation(::Type{<:InitialConditionType}) = false

requires_reconciliation(::Type{InitialTimeDurationOn}) = true
requires_reconciliation(::Type{InitialTimeDurationOff}) = true
Expand Down
4 changes: 2 additions & 2 deletions src/core/variables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ struct SystemBalanceSlackDown <: VariableType end

struct ReserveRequirementSlack <: VariableType end

struct FlowActivePowerSlackUpperBound <: IS.VariableType end
struct FlowActivePowerSlackUpperBound <: VariableType end

struct FlowActivePowerSlackLowerBound <: IS.VariableType end
struct FlowActivePowerSlackLowerBound <: VariableType end

"""
Struct to dispatch the creation of Voltage Magnitude Variables for AC formulations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ end
function construct_device!(
container::OptimizationContainer,
sys::PSY.System,
::IS.ModelConstructStage,
::ModelConstructStage,
device_model::DeviceModel{<:TwoTerminalHVDCTypes, HVDCTwoTerminalUnbounded},
::NetworkModel{<:PM.AbstractPowerModel},
)
Expand Down
21 changes: 2 additions & 19 deletions src/parameters/update_parameters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,6 @@ function update_container_parameter_values!(
) where {T <: ParameterType, U <: PSY.Component}
# 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)
Expand Down Expand Up @@ -374,7 +373,7 @@ end
function update_container_parameter_values!(
optimization_container::OptimizationContainer,
model::OperationModel,
key::IS.ParameterKey{FixValueParameter, U},
key::ParameterKey{FixValueParameter, U},
input::DatasetContainer{InMemoryDataset},
) where {U <: PSY.Component}
# Note: Do not instantite a new key here because it might not match the param keys in the container
Expand All @@ -386,22 +385,6 @@ function update_container_parameter_values!(
return
end

function update_container_parameter_values!(
optimization_container::OptimizationContainer,
model::OperationModel,
key::ParameterKey{T, U},
input::DatasetContainer{InMemoryDataset},
) where {T <: ParameterType, U <: PSY.Service}
# 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)
service = PSY.get_component(U, get_system(model), key.meta)
@assert service !== nothing
_update_parameter_values!(parameter_array, parameter_attributes, service, model, input)
return
end

function update_container_parameter_values!(
optimization_container::OptimizationContainer,
model::OperationModel,
Expand All @@ -425,7 +408,7 @@ function update_parameter_values!(
model::OperationModel,
key::ParameterKey{T, U},
input::DatasetContainer{InMemoryDataset},
) where {T <: IS.ParameterType, U <: PSY.Component}
) where {T <: ParameterType, U <: PSY.Component}
# Enable again for detailed debugging
# TimerOutputs.@timeit RUN_SIMULATION_TIMER "$T $U Parameter Update" begin
optimization_container = get_optimization_container(model)
Expand Down
2 changes: 1 addition & 1 deletion src/simulation/decision_model_simulation_results.jl
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ function _read_results(
cols::Union{Colon, Vector{String}} = (:),
)
vals = _read_results(res, result_keys, timestamps, store)
converted_vals = Dict{IS.OptimizationContainerKey, ResultsByTime{Matrix{Float64}}}()
converted_vals = Dict{OptimizationContainerKey, ResultsByTime{Matrix{Float64}}}()
for (result_key, result_data) in vals
inner_converted = SortedDict(
(date_key, Matrix{Float64}(permutedims(inner_data[cols, :].data)))
Expand Down
22 changes: 11 additions & 11 deletions src/simulation/simulation_problem_results.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,27 +79,27 @@ function set_results_timestamps!(
result.results_timestamps = results_timestamps
end

list_result_keys(res::SimulationProblemResults, ::IS.AuxVarKey) = list_aux_variable_keys(res)
list_result_keys(res::SimulationProblemResults, ::IS.ConstraintKey) = list_dual_keys(res)
list_result_keys(res::SimulationProblemResults, ::IS.ExpressionKey) =
list_result_keys(res::SimulationProblemResults, ::AuxVarKey) = list_aux_variable_keys(res)
list_result_keys(res::SimulationProblemResults, ::ConstraintKey) = list_dual_keys(res)
list_result_keys(res::SimulationProblemResults, ::ExpressionKey) =
list_expression_keys(res)
list_result_keys(res::SimulationProblemResults, ::IS.ParameterKey) =
list_result_keys(res::SimulationProblemResults, ::ParameterKey) =
list_parameter_keys(res)
list_result_keys(res::SimulationProblemResults, ::IS.VariableKey) = list_variable_keys(res)
list_result_keys(res::SimulationProblemResults, ::VariableKey) = list_variable_keys(res)

get_cached_results(res::SimulationProblemResults, ::Type{<:IS.AuxVarKey}) =
get_cached_results(res::SimulationProblemResults, ::Type{<:AuxVarKey}) =
get_cached_aux_variables(res)
get_cached_results(res::SimulationProblemResults, ::Type{<:IS.ConstraintKey}) =
get_cached_results(res::SimulationProblemResults, ::Type{<:ConstraintKey}) =
get_cached_duals(res)
get_cached_results(res::SimulationProblemResults, ::Type{<:IS.ExpressionKey}) =
get_cached_results(res::SimulationProblemResults, ::Type{<:ExpressionKey}) =
get_cached_expressions(res)
get_cached_results(res::SimulationProblemResults, ::Type{<:IS.ParameterKey}) =
get_cached_results(res::SimulationProblemResults, ::Type{<:ParameterKey}) =
get_cached_parameters(res)
get_cached_results(res::SimulationProblemResults, ::Type{<:IS.VariableKey}) =
get_cached_results(res::SimulationProblemResults, ::Type{<:VariableKey}) =
get_cached_variables(res)
get_cached_results(
res::SimulationProblemResults,
::Type{<:IS.OptimizationContainerKey} = OptimizationContainerKey,
::Type{<:OptimizationContainerKey} = OptimizationContainerKey,
) =
merge( # PERF: could be done lazily
get_cached_aux_variables(res),
Expand Down

0 comments on commit 479e4e6

Please sign in to comment.