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

Jd/implement state estimator #5

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 19 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
7 changes: 4 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@ InfrastructureSystems = "2cd47ed4-ca9b-11e9-27f2-ab636a7671f1"
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
MPI = "da04e1cc-30fd-572f-bb4f-1f8673147195"
MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"
PowerNetworkMatrices = "bed98974-b02a-5e2f-9fe0-a103f5c450dd"
PowerSimulations = "e690365d-45e2-57bb-ac84-44ba829e73c4"
PowerSystems = "bcd98974-b02a-5e2f-9ee0-a103f5c450dd"

[compat]
Dates = "1"
DataStructures = "^0.18"
Dates = "1"
DocStringExtensions = "~0.8, ~0.9"
InfrastructureSystems = "^1.21"
InfrastructureSystems = "2"
JuMP = "1"
MPI = "^0.20"
MathOptInterface = "1"
PowerSystems = "^3"
PowerSystems = "4"
julia = "^1.6"
16 changes: 14 additions & 2 deletions src/PowerSimulationsDecomposition.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ module PowerSimulationsDecomposition
export MultiRegionProblem
export MultiProblemTemplate

export SplitAreaPTDFPowerModel

import PowerSimulations
import PowerNetworkMatrices
import PowerSystems
import InfrastructureSystems
import InfrastructureSystems: @assert_op
Expand All @@ -15,7 +18,10 @@ import DataStructures: OrderedDict, SortedDict

const PSI = PowerSimulations
const PSY = PowerSystems
const PNM = PowerNetworkMatrices
const IS = InfrastructureSystems
const ISOPT = InfrastructureSystems.Optimization
const ISSIM = InfrastructureSystems.Simulation
const PM = PSI.PM
const MOI = MathOptInterface

Expand All @@ -25,13 +31,19 @@ using DocStringExtensions
$(DOCSTRING)
"""

include("definitions.jl")
include("core.jl")
include("core/algorithms.jl")
include("core/definitions.jl")
include("core/formulations.jl")
include("core/mpi_info.jl")
include("core/parameters.jl")
include("core/auxiliary_variables.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("models/network_models.jl")
include("print.jl")

end
19 changes: 13 additions & 6 deletions src/algorithms/sequential_algorithm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ function build_main_problem!(
container::MultiOptimizationContainer{SequentialAlgorithm},
template::MultiProblemTemplate,
sys::PSY.System,
) end
)
end
Comment on lines +22 to +23

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
)
end
) 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
Expand All @@ -29,23 +30,26 @@ 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 (k, subproblem) in 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
@debug "Skip SparseAxisArray" field key
continue
end
num_dims = ndims(src)
num_dims > 2 && error("ndims = $(num_dims) is not supported yet")
data = nothing
try
if key == ISOPT.ExpressionKey{PSI.ActivePowerBalance, PSY.ACBus}("")
@error "mt exp $k" data = PSI.jump_value.(src)[10313, :]
end
data = PSI.jump_value.(src)
catch e
if e isa UndefRefError
#@warn "Skip UndefRefError for" field key
@error "Skip UndefRefError for" field key
continue
end
rethrow()
Expand Down Expand Up @@ -103,10 +107,13 @@ function solve_impl!(
sys::PSY.System,
)
# Solve main problem
status = PSI.RunStatus.SUCCESSFUL
status = ISSIM.RunStatus.RUNNING
for (index, subproblem) in container.subproblems
@info "Solving problem $index"
@debug "Solving problem $index"
status = PSI.solve_impl!(subproblem, sys)
if status != ISSIM.RunStatus.SUCCESSFULLY_FINALIZED
return status
end
end
write_results_to_main_container(container)
return status
Expand Down
4 changes: 4 additions & 0 deletions src/core/algorithms.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
abstract type DecompositionAlgorithm end

struct SequentialAlgorithm <: DecompositionAlgorithm end
struct MPIParallelAlgorithm <: DecompositionAlgorithm end
1 change: 1 addition & 0 deletions src/core/auxiliary_variables.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

File renamed without changes.
3 changes: 3 additions & 0 deletions src/core/formulations.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Formulations

struct SplitAreaPTDFPowerModel <: PSI.AbstractPTDFModel end
5 changes: 0 additions & 5 deletions src/core.jl → src/core/mpi_info.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
abstract type DecompositionAlgorithm end

struct SequentialAlgorithm <: DecompositionAlgorithm end
struct MPIParallelAlgorithm <: DecompositionAlgorithm end

# Taken from https://github.com/ANL-CEEESA/UnitCommitment.jl/blob/dev/src/solution/methods/ProgressiveHedging/structs.jl
struct MpiInfo
comm::Any
Expand Down
1 change: 1 addition & 0 deletions src/core/parameters.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
struct StateEstimationInjections <: PSI.VariableValueParameter end
Loading
Loading