From a3af6b36751d258125e310e700a2a1db27f72247 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Wed, 10 Jan 2024 11:02:12 -0700 Subject: [PATCH 1/5] change internal --- src/operation/model_internal.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/operation/model_internal.jl b/src/operation/model_internal.jl index f00b690259..4f881eca88 100644 --- a/src/operation/model_internal.jl +++ b/src/operation/model_internal.jl @@ -12,9 +12,9 @@ mutable struct SimulationInfo sequence_uuid::Base.UUID end -mutable struct ModelInternal +mutable struct ModelInternal{T <: AbstractModelContainer} container::OptimizationContainer - ic_model_container::Union{Nothing, OptimizationContainer} + ic_model_container::Union{Nothing, T} status::BuildStatus run_status::RunStatus base_conversion::Bool @@ -31,7 +31,7 @@ mutable struct ModelInternal end function ModelInternal( - container::OptimizationContainer; + container::AbstractModelContainer; ext = Dict{String, Any}(), recorders = [], ) From b8cac7fcd0f56fb7cafd700719685c4f86e6c9b4 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Wed, 10 Jan 2024 11:26:10 -0700 Subject: [PATCH 2/5] parametrize internal --- src/operation/model_internal.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/operation/model_internal.jl b/src/operation/model_internal.jl index 4f881eca88..4753e6f648 100644 --- a/src/operation/model_internal.jl +++ b/src/operation/model_internal.jl @@ -13,7 +13,7 @@ mutable struct SimulationInfo end mutable struct ModelInternal{T <: AbstractModelContainer} - container::OptimizationContainer + container::T ic_model_container::Union{Nothing, T} status::BuildStatus run_status::RunStatus @@ -31,11 +31,11 @@ mutable struct ModelInternal{T <: AbstractModelContainer} end function ModelInternal( - container::AbstractModelContainer; + container::T; ext = Dict{String, Any}(), recorders = [], -) - return ModelInternal( +) where {T <: AbstractModelContainer} + return ModelInternal{T}( container, nothing, BuildStatus.EMPTY, From 6976b148f5e3d7b6a823ff055df385d298095ed3 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Wed, 10 Jan 2024 11:26:19 -0700 Subject: [PATCH 3/5] separate outer constructor --- src/operation/decision_model.jl | 66 ++++++++++++++++----------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/src/operation/decision_model.jl b/src/operation/decision_model.jl index 8287346b53..a0cde57e3d 100644 --- a/src/operation/decision_model.jl +++ b/src/operation/decision_model.jl @@ -9,6 +9,15 @@ Generic PowerSimulations Operation Problem Type for unspecified models """ struct GenericOpProblem <: DefaultDecisionProblem end +mutable struct DecisionModel{M <: DecisionProblem} <: OperationModel + name::Symbol + template::ProblemTemplate + sys::PSY.System + internal::Union{Nothing, ModelInternal} + store::DecisionModelStore + ext::Dict{String, Any} +end + """ DecisionModel{M}( template::ProblemTemplate, @@ -51,40 +60,31 @@ template = ProblemTemplate(CopperPlatePowerModel, devices, branches, services) OpModel = DecisionModel(MockOperationProblem, template, system) ``` """ -mutable struct DecisionModel{M <: DecisionProblem} <: OperationModel - name::Symbol - template::ProblemTemplate - sys::PSY.System - internal::Union{Nothing, ModelInternal} - store::DecisionModelStore - ext::Dict{String, Any} - - function DecisionModel{M}( - template::ProblemTemplate, - sys::PSY.System, - settings::Settings, - jump_model::Union{Nothing, JuMP.Model} = nothing; - name = nothing, - ) where {M <: DecisionProblem} - if name === nothing - name = nameof(M) - elseif name isa String - name = Symbol(name) - end - internal = ModelInternal( - OptimizationContainer(sys, settings, jump_model, PSY.Deterministic), - ) - template_ = deepcopy(template) - finalize_template!(template_, sys) - return new{M}( - name, - template_, - sys, - internal, - DecisionModelStore(), - Dict{String, Any}(), - ) +function DecisionModel{M}( + template::ProblemTemplate, + sys::PSY.System, + settings::Settings, + jump_model::Union{Nothing, JuMP.Model} = nothing; + name = nothing, +) where {M <: DecisionProblem} + if name === nothing + name = nameof(M) + elseif name isa String + name = Symbol(name) end + internal = ModelInternal( + OptimizationContainer(sys, settings, jump_model, PSY.Deterministic), + ) + template_ = deepcopy(template) + finalize_template!(template_, sys) + return DecisionModel{M}( + name, + template_, + sys, + internal, + DecisionModelStore(), + Dict{String, Any}(), + ) end function DecisionModel{M}( From 32c7e033c9aca90edd18f11a5e72fd1e659963b3 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Wed, 10 Jan 2024 12:12:23 -0700 Subject: [PATCH 4/5] abstract container --- src/operation/decision_model_store.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/operation/decision_model_store.jl b/src/operation/decision_model_store.jl index b8c2591164..686a5b9586 100644 --- a/src/operation/decision_model_store.jl +++ b/src/operation/decision_model_store.jl @@ -27,7 +27,7 @@ end function initialize_storage!( store::DecisionModelStore, - container::OptimizationContainer, + container::AbstractModelContainer, params::ModelStoreParams, ) num_of_executions = get_num_executions(params) From 8ac313fc3e1924b1b9c09fe6cdfe05cdb503ede4 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Wed, 10 Jan 2024 12:47:57 -0700 Subject: [PATCH 5/5] use getter function --- src/operation/operation_model_interface.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/operation/operation_model_interface.jl b/src/operation/operation_model_interface.jl index 688f6013f7..9a1e01c0c0 100644 --- a/src/operation/operation_model_interface.jl +++ b/src/operation/operation_model_interface.jl @@ -10,7 +10,7 @@ get_execution_count(model::OperationModel) = get_internal(model).execution_count get_executions(model::OperationModel) = get_internal(model).executions get_initial_time(model::OperationModel) = get_initial_time(get_settings(model)) get_internal(model::OperationModel) = model.internal -get_jump_model(model::OperationModel) = get_internal(model).container.JuMPmodel +get_jump_model(model::OperationModel) = get_jump_model(get_internal(model).container) get_name(model::OperationModel) = model.name get_store(model::OperationModel) = model.store is_synchronized(model::OperationModel) = is_synchronized(get_optimization_container(model))