Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updates to support multiple optimization container #1042

Merged
merged 5 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 33 additions & 33 deletions src/operation/decision_model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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}(
Expand Down
2 changes: 1 addition & 1 deletion src/operation/decision_model_store.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ end

function initialize_storage!(
store::DecisionModelStore,
container::OptimizationContainer,
container::AbstractModelContainer,
params::ModelStoreParams,
)
num_of_executions = get_num_executions(params)
Expand Down
12 changes: 6 additions & 6 deletions src/operation/model_internal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ mutable struct SimulationInfo
sequence_uuid::Base.UUID
end

mutable struct ModelInternal
container::OptimizationContainer
ic_model_container::Union{Nothing, OptimizationContainer}
mutable struct ModelInternal{T <: AbstractModelContainer}
container::T
ic_model_container::Union{Nothing, T}
status::BuildStatus
run_status::RunStatus
base_conversion::Bool
Expand All @@ -31,11 +31,11 @@ mutable struct ModelInternal
end

function ModelInternal(
container::OptimizationContainer;
container::T;
ext = Dict{String, Any}(),
recorders = [],
)
return ModelInternal(
) where {T <: AbstractModelContainer}
return ModelInternal{T}(
container,
nothing,
BuildStatus.EMPTY,
Expand Down
2 changes: 1 addition & 1 deletion src/operation/operation_model_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Loading