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/decomposition support #1123

Merged
merged 4 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions src/core/expressions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ struct PTDFBranchFlow <: ExpressionType end
should_write_resulting_value(::Type{<:CostExpressions}) = true
should_write_resulting_value(::Type{InterfaceTotalFlow}) = true
should_write_resulting_value(::Type{RawACE}) = true
should_write_resulting_value(::Type{ActivePowerBalance}) = true
should_write_resulting_value(::Type{ReactivePowerBalance}) = true

convert_result_to_natural_units(::Type{InterfaceTotalFlow}) = true
73 changes: 35 additions & 38 deletions src/core/optimization_container.jl
Original file line number Diff line number Diff line change
Expand Up @@ -410,11 +410,14 @@
container.expressions = Dict(
ExpressionKey(ActivePowerBalance, PSY.ACBus) =>
_make_container_array(ac_bus_numbers, time_steps),
ExpressionKey(ActivePowerBalance, PSY.DCBus) =>
_make_container_array(dc_bus_numbers, time_steps),
ExpressionKey(ReactivePowerBalance, PSY.ACBus) =>
_make_container_array(ac_bus_numbers, time_steps),
)

if !isempty(dc_bus_numbers)
container.expressions[ExpressionKey(ActivePowerBalance, PSY.DCBus)] =

Check warning on line 418 in src/core/optimization_container.jl

View check run for this annotation

Codecov / codecov/patch

src/core/optimization_container.jl#L418

Added line #L418 was not covered by tests
_make_container_array(dc_bus_numbers, time_steps)
end
return
end

Expand All @@ -434,9 +437,11 @@
container.expressions = Dict(
ExpressionKey(ActivePowerBalance, PSY.ACBus) =>
_make_container_array(ac_bus_numbers, time_steps),
ExpressionKey(ActivePowerBalance, PSY.DCBus) =>
_make_container_array(dc_bus_numbers, time_steps),
)
if !isempty(dc_bus_numbers)
container.expressions[ExpressionKey(ActivePowerBalance, PSY.DCBus)] =
_make_container_array(dc_bus_numbers, time_steps)
end
return
end

Expand Down Expand Up @@ -473,13 +478,16 @@
container.expressions = Dict(
ExpressionKey(ActivePowerBalance, PSY.System) =>
_make_container_array(subnetworks, time_steps),
ExpressionKey(ActivePowerBalance, PSY.DCBus) =>
_make_container_array(dc_bus_numbers, time_steps),
ExpressionKey(ActivePowerBalance, PSY.ACBus) =>
# Bus numbers are sorted to guarantee consistency in the order between the
# containers
_make_container_array(sort!(ac_bus_numbers), time_steps),
)

if !isempty(dc_bus_numbers)
container.expressions[ExpressionKey(ActivePowerBalance, PSY.DCBus)] =
_make_container_array(dc_bus_numbers, time_steps)
end
return
end

Expand Down Expand Up @@ -518,41 +526,29 @@
else
ac_bus_numbers = collect(keys(bus_reduction_map))
end
container.expressions = Dict(
# Enforces the balance by Area
ExpressionKey(ActivePowerBalance, PSY.Area) =>
_make_container_array(PSY.get_name.(areas), time_steps),
# Keeps track of the Injections by bus.
ExpressionKey(ActivePowerBalance, PSY.ACBus) =>
# Bus numbers are sorted to guarantee consistency in the order between the
# containers
_make_container_array(sort!(ac_bus_numbers), time_steps),
)

if length(subnetworks) > 1
@warn "The system contains $(length(subnetworks)) synchronous regions. \
When combined with AreaPTDFPowerModel, the model can be infeasible if the data doesn't \
have a well defined topology"
subnetworks_ref_buses = collect(keys(subnetworks))
container.expressions = Dict(
# Enforces the balance by Area
ExpressionKey(ActivePowerBalance, PSY.Area) =>
_make_container_array(PSY.get_name.(areas), time_steps),
# Enforces the balance by Synchronous System
ExpressionKey(ActivePowerBalance, PSY.System) =>
_make_container_array(subnetworks_ref_buses, time_steps),
# Enforces the balance by DC Buses
ExpressionKey(ActivePowerBalance, PSY.DCBus) =>
_make_container_array(dc_bus_numbers, time_steps),
# Keeps track of the Injections by bus.
ExpressionKey(ActivePowerBalance, PSY.ACBus) =>
# Bus numbers are sorted to guarantee consistency in the order between the
# containers
_make_container_array(sort!(ac_bus_numbers), time_steps),
)
else
container.expressions = Dict(
# Enforces the balance by Area
ExpressionKey(ActivePowerBalance, PSY.Area) =>
_make_container_array(PSY.get_name.(areas), time_steps),
# Enforces the balance by DC Buses
ExpressionKey(ActivePowerBalance, PSY.DCBus) =>
_make_container_array(dc_bus_numbers, time_steps),
# Keeps track of the Injections by bus.
ExpressionKey(ActivePowerBalance, PSY.ACBus) =>
# Bus numbers are sorted to guarantee consistency in the order between the
# containers
_make_container_array(sort!(ac_bus_numbers), time_steps),
)
container.expressions[ExpressionKey(ActivePowerBalance, PSY.System)] =

Check warning on line 545 in src/core/optimization_container.jl

View check run for this annotation

Codecov / codecov/patch

src/core/optimization_container.jl#L545

Added line #L545 was not covered by tests
_make_container_array(subnetworks_ref_buses, time_steps)
end

if !isempty(dc_bus_numbers)
container.expressions[ExpressionKey(ActivePowerBalance, PSY.DCBus)] =

Check warning on line 550 in src/core/optimization_container.jl

View check run for this annotation

Codecov / codecov/patch

src/core/optimization_container.jl#L550

Added line #L550 was not covered by tests
_make_container_array(dc_bus_numbers, time_steps)
end

return
Expand Down Expand Up @@ -799,8 +795,6 @@
end
end

status = RunStatus.SUCCESSFULLY_FINALIZED

_, optimizer_stats.timed_calculate_aux_variables =
@timed calculate_aux_variables!(container, system)

Expand All @@ -809,6 +803,9 @@

_, optimizer_stats.timed_calculate_dual_variables =
@timed calculate_dual_variables!(container, system, is_milp(container))

status = RunStatus.SUCCESSFULLY_FINALIZED

return status
end

Expand Down
4 changes: 2 additions & 2 deletions test/test_model_decision.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ end
@test length(read_variables(res)) == 4
@test length(read_parameters(res)) == 1
@test length(read_duals(res)) == 0
@test length(read_expressions(res)) == 1
@test length(read_expressions(res)) == 2
@test read_variables(res, ["StartVariable__ThermalStandard"])["StartVariable__ThermalStandard"] ==
read_variable(res, "StartVariable__ThermalStandard")
@test read_variables(res, [(StartVariable, ThermalStandard)])["StartVariable__ThermalStandard"] ==
Expand Down Expand Up @@ -347,7 +347,7 @@ end
# Manually Multiply by the base power var1_a has natural units and export writes directly from the solver
@test var1_a[:, propertynames(var1_a) .!= :DateTime] == var4 .* 100.0

@test length(readdir(IS.Optimization.export_realized_results(results1))) === 6
@test length(readdir(IS.Optimization.export_realized_results(results1))) === 7
end

@testset "Test Numerical Stability of Constraints" begin
Expand Down
2 changes: 1 addition & 1 deletion test/test_simulation_partitions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ end
skip && continue
r_sum = 0
p_sum = 0
atol = occursin("ProductionCostExpression", key) ? 11000 : 0
atol = occursin("ProductionCostExpression", key) ? 11000 : 1e-6
for i in 2:ncol(rdf)
r_sum += sum(rdf[!, i])
p_sum += sum(pdf[!, i])
Expand Down
4 changes: 2 additions & 2 deletions test/test_simulation_results.jl
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ function test_simulation_results(
@test isempty(results)

verify_export_results(results, export_path)
@test length(readdir(export_realized_results(results_ed))) === 17
@test length(readdir(export_realized_results(results_ed))) === 18

# Test that you can't read a failed simulation.
PSI.set_simulation_status!(sim, PSI.RunStatus.FAILED)
Expand Down Expand Up @@ -738,7 +738,7 @@ function test_emulation_problem_results(results::SimulationResults, in_memory)
end

expressions_keys = collect(keys(read_realized_expressions(results_em)))
@test length(expressions_keys) == 3
@test length(expressions_keys) == 4
expressions_inputs = (
[
"ProductionCostExpression__HydroEnergyReservoir",
Expand Down
Loading