Skip to content

Commit

Permalink
Merge pull request #1 from NREL-Sienna/jd/subsystems_implementation
Browse files Browse the repository at this point in the history
Jd/subsystems implementation
  • Loading branch information
jd-lara authored Mar 15, 2024
2 parents 9f416e6 + 811494e commit 2754405
Show file tree
Hide file tree
Showing 15 changed files with 323 additions and 292 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/format-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Format Check
on:
push:
branches:
- 'master'
- 'main'
- 'release-'
tags: '*'
pull_request:
Expand Down
4 changes: 3 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ authors = ["Jose Daniel Lara"]
version = "0.1.0"

[deps]
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
InfrastructureSystems = "2cd47ed4-ca9b-11e9-27f2-ab636a7671f1"
Expand All @@ -15,10 +16,11 @@ PowerSystems = "bcd98974-b02a-5e2f-9ee0-a103f5c450dd"

[compat]
Dates = "1"
DataStructures = "^0.18"
DocStringExtensions = "~0.8, ~0.9"
InfrastructureSystems = "^1.21"
JuMP = "1"
MathOptInterface = "1"
MPI = "^0.20"
MathOptInterface = "1"
PowerSystems = "^3"
julia = "^1.6"
3 changes: 2 additions & 1 deletion docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ CurrentModule = PowerSimulationsDecomposition

`PowerSimulationsDecomposition .jl` is a [`Julia`](http://www.julialang.org) package that provides blah blah

------------
* * *

PowerSimulationsDecomposition has been developed as part of the Scalable Integrated Infrastructure Planning
(SIIP) initiative at the U.S. Department of Energy's National Renewable Energy
Laboratory ([NREL](https://www.nrel.gov/)).
3 changes: 3 additions & 0 deletions src/PowerSimulationsDecomposition.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import JuMP
import Dates
import MPI
import MathOptInterface
import DataStructures: SortedDict

const PSI = PowerSimulations
const PSY = PowerSystems
Expand All @@ -23,11 +24,13 @@ using DocStringExtensions
$(DOCSTRING)
"""

include("definitions.jl")
include("core.jl")
include("multiproblem_template.jl")
include("multi_optimization_container.jl")
include("algorithms/sequential_algorithm.jl")
include("algorithms/mpi_parallel_algorithm.jl")
include("problems/multi_region_problem.jl")
include("print.jl")

end
61 changes: 53 additions & 8 deletions src/algorithms/sequential_algorithm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ function build_impl!(
template::MultiProblemTemplate,
sys::PSY.System,
)
sub_templates = get_subtemplates(template)
for (index, sub_problem) in container.subproblems
@debug "Building Subproblem $index" _group = PSI.LOG_GROUP_OPTIMIZATION_CONTAINER
_system_modification!(sys, index)
PSI.build_impl!(sub_problem, sub_templates[index], sys)
for (index, sub_template) in get_sub_templates(template)
@info "Building Subproblem $index" _group = PSI.LOG_GROUP_OPTIMIZATION_CONTAINER
PSI.build_impl!(get_subproblem(container, index), sub_template, sys)
end

build_main_problem!(container, template, sys)
Expand All @@ -23,7 +21,54 @@ function build_main_problem!(
sys::PSY.System,
) end

# The drawback of this approach is that it will loop over the results twice
# once to write into the main container and a second time when writing into the
# store. The upside of this approach is that doesn't require overloading write_model_XXX_results!
# methods from PowerSimulations.
function write_results_to_main_container(container::MultiOptimizationContainer)
# TODO: This process needs to work in parallel almost right away
# TODO: This doesn't handle the case where subproblems have an overlap in axis names.

for subproblem in values(container.subproblems)
for field in CONTAINER_FIELDS
subproblem_data_field = getproperty(subproblem, field)
main_container_data_field = getproperty(container, field)
for (key, src) in subproblem_data_field
if src isa JuMP.Containers.SparseAxisArray
@warn "Skip SparseAxisArray" field key
continue
end
num_dims = ndims(src)
num_dims > 2 && error("ndims = $(num_dims) is not supported yet")
data = nothing
try
data = PSI.jump_value.(src)
catch e
if e isa UndefRefError
@warn "Skip UndefRefError for" field key
continue
end
rethrow()
end
dst = main_container_data_field[key]
if num_dims == 1
dst[1:length(axes(src)[1])] = data
elseif num_dims == 2
columns = axes(src)[1]
len = length(axes(src)[2])
dst[columns, 1:len] = PSI.jump_value.(src[:, :])
elseif num_dims == 3
# TODO: untested
axis1 = axes(src)[1]
axis2 = axes(src)[2]
len = length(axes(src)[3])
dst[axis1, axis2, 1:len] = PSI.jump_value.(src[:, :, :])
end
end
end
end
# Parameters need a separate approach due to the way the containers work
return
end

function solve_impl!(
Expand All @@ -32,10 +77,10 @@ function solve_impl!(
)
# Solve main problem
status = PSI.RunStatus.SUCCESSFUL
for (index, sub_problem) in container.subproblems
for (index, subproblem) in container.subproblems
@info "Solving problem $index"
status = PSI.solve_impl!(sub_problem, sys)
status = PSI.solve_impl!(subproblem, sys)
end
#write_results_to_main_container()
write_results_to_main_container(container)
return status
end
1 change: 1 addition & 0 deletions src/definitions.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const CONTAINER_FIELDS = [:variables, :aux_variables, :constraints, :expressions, :duals]
2 changes: 1 addition & 1 deletion src/multi_decision_model.jl
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# ! needs the definition of decision problem that can get type MultiProblemTemplate
# ! needs the definition of decision problem that can get type MultiProblemTemplate
Loading

0 comments on commit 2754405

Please sign in to comment.