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 20 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
49 changes: 32 additions & 17 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 @@ -28,35 +29,41 @@ function build_main_problem!(
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
data = PSI.jump_value.(src)
catch e
if e isa UndefRefError
#@warn "Skip UndefRefError for" field key
continue
end
rethrow()
end
data = PSI.jump_value.(src)
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])
#ychen fix horizontal passing ACbusinjection issue
if field==:expressions
field1= :parameters
Comment on lines +49 to +51

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
#ychen fix horizontal passing ACbusinjection issue
if field==:expressions
field1= :parameters
#ychen fix horizontal passing ACbusinjection issue
if field == :expressions
field1 = :parameters

subproblem_data_field1 = getproperty(subproblem, field1)
src1=subproblem_data_field1[InfrastructureSystems.Optimization.ParameterKey{PowerSimulationsDecomposition.StateEstimationInjections, PSY.ACBus}("")]
B=parse.(Int,axes(src1.parameter_array)[1])
A=axes(src)[1]
C=filter(x -> !(x in B), A)
columns= C
Comment on lines +53 to +57

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
src1=subproblem_data_field1[InfrastructureSystems.Optimization.ParameterKey{PowerSimulationsDecomposition.StateEstimationInjections, PSY.ACBus}("")]
B=parse.(Int,axes(src1.parameter_array)[1])
A=axes(src)[1]
C=filter(x -> !(x in B), A)
columns= C
src1 =
subproblem_data_field1[InfrastructureSystems.Optimization.ParameterKey{
PowerSimulationsDecomposition.StateEstimationInjections,
PSY.ACBus,
}(
"",
)]
B = parse.(Int, axes(src1.parameter_array)[1])
A = axes(src)[1]
C = filter(x -> !(x in B), A)
columns = C

else
columns = axes(src)[1]
end
#ychen end
len = length(axes(src)[2])
Comment on lines +59 to +62

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
columns = axes(src)[1]
end
#ychen end
len = length(axes(src)[2])
columns = axes(src)[1]
end
#ychen end
len = length(axes(src)[2])

dst[columns, 1:len] = PSI.jump_value.(src[:, :])
#try
# println("======111 dst,k,",dst[203, :],",subproblem,",k)
#catch e end
elseif num_dims == 3
# TODO: untested
axis1 = axes(src)[1]
Expand All @@ -82,9 +89,13 @@ function _write_parameter_results_to_main_container(
src_mult_data = PSI.jump_value.(parameter_container.multiplier_array)
dst_param_data = container.parameters[key].parameter_array
dst_mult_data = container.parameters[key].multiplier_array
#println("*****11,subproblem,",subproblem)
#println("*****12,key,",key)
#println("*****13,num_dims,",num_dims)
if num_dims == 1
dst_param_data[1:length(axes(src_param_data)[1])] = src_param_data
dst_mult_data[1:length(axes(src_mult_data)[1])] = src_mult_data

elseif num_dims == 2
param_columns = axes(src_param_data)[1]
mult_columns = axes(src_mult_data)[1]
Expand All @@ -103,10 +114,14 @@ 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)
println("yc -- solving problem,",index)

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
println("yc -- solving problem,",index)
println("yc -- solving problem,", index)

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