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 33 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
427f209
update code to PSY 4
jd-lara May 28, 2024
11fb21a
update code to PSY 4
jd-lara May 28, 2024
9bef618
Merge branch 'jd/implement_state_estimator' of https://github.com/NRE…
jd-lara May 29, 2024
0010f2f
more PSy4 updates
jd-lara May 29, 2024
85bc349
change log statements to debug
jd-lara May 29, 2024
550b635
add PNM to deps
jd-lara Jun 4, 2024
0574f26
WIP ss
jd-lara Jun 4, 2024
d84d886
add required parameters for ss implementation
jd-lara Jul 9, 2024
ad23fc2
remove prints
jd-lara Jul 10, 2024
b13bd0b
add method for expressions
jd-lara Jul 17, 2024
ffb6750
add auxiliaries
jd-lara Jul 19, 2024
cfe2879
update the network model
jd-lara Jul 19, 2024
4d85f78
some updates to the region problem
jd-lara Jul 19, 2024
6cef2d8
add aux var calculation
jd-lara Jul 19, 2024
6912794
update model getter
jd-lara Jul 30, 2024
de68a83
clean up code
jd-lara Jul 30, 2024
1cf7afb
remove show
jd-lara Jul 30, 2024
275af17
remove debug code
jd-lara Aug 5, 2024
4cb605e
push changes for using state
jd-lara Aug 26, 2024
0d654ac
yc_fix
yonghongchen8 Oct 10, 2024
2b67507
yc_test_scripts
Oct 11, 2024
18035e6
yc_test_scripts
Oct 11, 2024
0075692
yc_test_scripts
Oct 11, 2024
d441db7
yc_test_scripts
yonghongchen8 Dec 30, 2024
823f960
yc_test_scripts
yonghongchen8 Dec 30, 2024
d5e096f
delete scripts
jd-lara Jan 3, 2025
1140b9c
fix parameter update code
jd-lara Jan 3, 2025
db7a67e
fix formatter
jd-lara Jan 3, 2025
0f5fc0a
use get_deterministic_time_series_type
jd-lara Jan 3, 2025
bc8106a
add power simulations version to toml
jd-lara Jan 3, 2025
c5f141b
fix function definition
jd-lara Jan 7, 2025
f2e8802
add different method
jd-lara Jan 7, 2025
0b3cb25
fix key
jd-lara Jan 7, 2025
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
8 changes: 5 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@ 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"
PowerSimulations = "^0.29.1"
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
50 changes: 35 additions & 15 deletions src/algorithms/sequential_algorithm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,35 +28,47 @@ 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]
#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
else
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 +94,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 +119,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)
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