Skip to content

Commit

Permalink
yc_fix
Browse files Browse the repository at this point in the history
  • Loading branch information
yonghongchen8 committed Oct 10, 2024
1 parent 4cb605e commit 0d654ac
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 18 deletions.
38 changes: 23 additions & 15 deletions src/algorithms/sequential_algorithm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ end
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 (k, subproblem) in container.subproblems
for field in CONTAINER_FIELDS
subproblem_data_field = getproperty(subproblem, field)
Expand All @@ -42,25 +41,29 @@ function write_results_to_main_container(container::MultiOptimizationContainer)
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
@error "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
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 @@ -86,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 @@ -111,6 +118,7 @@ function solve_impl!(
for (index, subproblem) in container.subproblems
@debug "Solving problem $index"
status = PSI.solve_impl!(subproblem, sys)
println("yc -- solving problem,",index)
if status != ISSIM.RunStatus.SUCCESSFULLY_FINALIZED
return status
end
Expand Down
14 changes: 11 additions & 3 deletions src/models/network_models.jl
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ function _update_parameter_values!(
state = PSI.get_system_states(simulation_state)
current_time = PSI.get_current_time(model)
state_values = PSI.get_dataset_values(state, PSI.get_attribute_key(attributes))

if !isfinite(first(state_values))
@warn "first value not present"
state = PSI.get_decision_states(simulation_state)
Expand All @@ -297,15 +298,19 @@ function _update_parameter_values!(
#t_step = 1
#state_data_index = PSI.find_timestamp_index(state_timestamps, current_time)
sim_timestamps = range(current_time; step=model_resolution, length=time[end])
for state_data_index in [1]

#ychen vertical
#for state_data_index in [1]
for state_data_index in 1:length(axes(parameter_array)[2])
#timestamp_ix = min(max_state_index, state_data_index + t_step)
#@debug "parameter horizon is over the step" max_state_index > state_data_index + 1
#if state_timestamps[timestamp_ix] <= sim_timestamps[t]
# state_data_index = timestamp_ix
#end
#println("******** state_data_index,",state_data_index)
for name_ix in component_names
# Pass indices in this way since JuMP DenseAxisArray don't support view()
state_value = state_values[name_ix, state_data_index]
state_value = state_values[name_ix, state_data_index]
if name_ix == "10313"
@error "update pm" state_value PSI.get_attribute_key(attributes) current_time
end
Expand All @@ -316,7 +321,9 @@ function _update_parameter_values!(
Consider reviewing your models' horizon and interval definitions",
)
end
PSI._set_param_value!(parameter_array, state_value, name_ix, 1)
#ychen vertical
#PSI._set_param_value!(parameter_array, state_value, name_ix, 1)
PSI._set_param_value!(parameter_array, state_value, name_ix, state_data_index)
end
end
return
Expand Down Expand Up @@ -375,6 +382,7 @@ function PSI.update_container_parameter_values!(
# if the keys have strings in the meta fields
parameter_array = PSI.get_parameter_array(optimization_container, key)
parameter_attributes = PSI.get_parameter_attributes(optimization_container, key)
#println("** tmp, disable update")
_update_parameter_values!(
parameter_array,
parameter_attributes,
Expand Down

0 comments on commit 0d654ac

Please sign in to comment.