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

DecisionModel Build Failed for network AreaBalancePowerModel with slacks #1208

Open
ymiftah opened this issue Jan 1, 2025 · 0 comments
Open
Labels

Comments

@ymiftah
Copy link
Contributor

ymiftah commented Jan 1, 2025

Describe the bug
Problem build fails when defining a problem with an AreaBalancePowerModel as Network model and requesting slacks

To Reproduce

using PowerSystemCaseBuilder, PowerSystems, PowerSimulations

function get_system()
  sys = build_system(PSITestSystems, "c_sys5_uc")
  
  # Extend the test case with areas
  areas = [Area("Area_1", 0,0,0), Area("Area_2", 0,0,0)]
  add_components!(sys, areas)
  for (i, comp) in enumerate(get_components(ACBus, sys))
      if i < 3
          set_area!(comp, areas[1])
      else
          set_area!(comp, areas[2])
      end
  end
  return sys
end

function define_problem(sys; output_dir=mktempdir())
    template_uc = ProblemTemplate()
    set_device_model!(template_uc, Line, StaticBranch)
    set_device_model!(template_uc, ThermalStandard, ThermalBasicDispatch)
    set_device_model!(template_uc, PowerLoad, StaticPowerLoad)
    set_network_model!(template_uc, NetworkModel(AreaBalancePowerModel, use_slacks=true,))
    solver = optimizer_with_attributes(HiGHS.Optimizer, "mip_rel_gap" => 0.5)
    problem = DecisionModel(
        template_uc,
        sys;
        optimizer=solver,
    )
    build!(problem; output_dir=output_dir)
    return problem
end

sys =  get_system()
problem = define_problem(sys; output_dir="./problem_dir/")

The error stack trace is as follows:

┌ Error: DecisionModel Build Failed
│   exception =
│    InfrastructureSystems.InvalidValue("variable SystemBalanceSlackUp__ACBus is not stored. [:ActivePowerVariable__ThermalStandard, :SystemBalanceSlackUp__Area, :SystemBalanceSlackDown__Area]")
│    Stacktrace:
│      [1] get_variable(container::PowerSimulations.OptimizationContainer, key::InfrastructureSystems.Optimization.VariableKey{SystemBalanceSlackUp, ACBus})
│        @ PowerSimulations ~/.julia/dev/PowerSimulations/src/core/optimization_container.jl:998
│      [2] get_variable (repeats 2 times)
│        @ ~/.julia/dev/PowerSimulations/src/core/optimization_container.jl:1009 [inlined]
│      [3] add_to_expression!(container::PowerSimulations.OptimizationContainer, ::Type{ActivePowerBalance}, ::Type{SystemBalanceSlackUp}, sys::System, ::NetworkModel{AreaBalancePowerModel})
│        @ PowerSimulations ~/.julia/dev/PowerSimulations/src/devices_models/devices/common/add_to_expression.jl:1476
│      [4] construct_network!(container::PowerSimulations.OptimizationContainer, sys::System, model::NetworkModel{AreaBalancePowerModel}, ::ProblemTemplate)
│        @ PowerSimulations ~/.julia/dev/PowerSimulations/src/network_models/network_constructor.jl:36
│      [5] macro expansion
│        @ ~/.julia/dev/PowerSimulations/src/core/optimization_container.jl:715 [inlined]
│      [6] macro expansion
│        @ ~/.julia/packages/TimerOutputs/6KVfH/src/TimerOutput.jl:237 [inlined]
│      [7] build_impl!(container::PowerSimulations.OptimizationContainer, template::ProblemTemplate, sys::System)
│        @ PowerSimulations ~/.julia/dev/PowerSimulations/src/core/optimization_container.jl:712
│      [8] build_model!(model::DecisionModel{GenericOpProblem})
│        @ PowerSimulations ~/.julia/dev/PowerSimulations/src/operation/decision_model.jl:408
│      [9] build_impl!(model::DecisionModel{GenericOpProblem})
│        @ PowerSimulations ~/.julia/dev/PowerSimulations/src/operation/decision_model.jl:344
│     [10] macro expansion
│        @ ~/.julia/dev/PowerSimulations/src/operation/decision_model.jl:386 [inlined]
│     [11] macro expansion
│        @ ~/.julia/packages/TimerOutputs/6KVfH/src/TimerOutput.jl:237 [inlined]
│     [12] (::PowerSimulations.var"#80#81"{DecisionModel{GenericOpProblem}})()
│        @ PowerSimulations ~/.julia/dev/PowerSimulations/src/operation/decision_model.jl:385
│     [13] with_logstate(f::PowerSimulations.var"#80#81"{DecisionModel{GenericOpProblem}}, logstate::Base.CoreLogging.LogState)
│        @ Base.CoreLogging ./logging/logging.jl:522
│     [14] with_logger
│        @ ./logging/logging.jl:632 [inlined]
│     [15] build!(model::DecisionModel{GenericOpProblem}; output_dir::String, recorders::Vector{Any}, console_level::Base.CoreLogging.LogLevel, file_level::Base.CoreLogging.LogLevel, disable_timer_outputs::Bool)
│        @ PowerSimulations ~/.julia/dev/PowerSimulations/src/operation/decision_model.jl:383
│     [16] build!
│        @ ~/.julia/dev/PowerSimulations/src/operation/decision_model.jl:364 [inlined]
│     [17] define_problem(sys::System; output_dir::String)
│        @ Main ~/workspace/experiments/ElectricityMarkets/wip.jl:56
│     [18] top-level scope
│        @ ~/workspace/experiments/ElectricityMarkets/wip.jl:75
│     [19] eval
│        @ ./boot.jl:430 [inlined]
│     [20] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
│        @ Base ./loading.jl:2734
│     [21] invokelatest(::Any, ::Any, ::Vararg{Any}; kwargs::@Kwargs{})
│        @ Base ./essentials.jl:1055
│     [22] invokelatest(::Any, ::Any, ::Vararg{Any})
│        @ Base ./essentials.jl:1052
│     [23] inlineeval(m::Module, code::String, code_line::Int64, code_column::Int64, file::String; softscope::Bool)
│        @ VSCodeServer ~/.vscode-server/extensions/julialang.language-julia-1.127.2/scripts/packages/VSCodeServer/src/eval.jl:271
│     [24] (::VSCodeServer.var"#69#74"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})()
│        @ VSCodeServer ~/.vscode-server/extensions/julialang.language-julia-1.127.2/scripts/packages/VSCodeServer/src/eval.jl:181
│     [25] withpath(f::VSCodeServer.var"#69#74"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams}, path::String)
│        @ VSCodeServer ~/.vscode-server/extensions/julialang.language-julia-1.127.2/scripts/packages/VSCodeServer/src/repl.jl:276
│     [26] (::VSCodeServer.var"#68#73"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})()
│        @ VSCodeServer ~/.vscode-server/extensions/julialang.language-julia-1.127.2/scripts/packages/VSCodeServer/src/eval.jl:179
│     [27] hideprompt(f::VSCodeServer.var"#68#73"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams})
│        @ VSCodeServer ~/.vscode-server/extensions/julialang.language-julia-1.127.2/scripts/packages/VSCodeServer/src/repl.jl:38
│     [28] #67
│        @ ~/.vscode-server/extensions/julialang.language-julia-1.127.2/scripts/packages/VSCodeServer/src/eval.jl:150 [inlined]
│     [29] with_logstate(f::VSCodeServer.var"#67#72"{Bool, Bool, Bool, Module, String, Int64, Int64, String, VSCodeServer.ReplRunCodeRequestParams}, logstate::Base.CoreLogging.LogState)
│        @ Base.CoreLogging ./logging/logging.jl:522
│     [30] with_logger
│        @ ./logging/logging.jl:632 [inlined]
│     [31] (::VSCodeServer.var"#66#71"{VSCodeServer.ReplRunCodeRequestParams})()
│        @ VSCodeServer ~/.vscode-server/extensions/julialang.language-julia-1.127.2/scripts/packages/VSCodeServer/src/eval.jl:263
│     [32] #invokelatest#2
│        @ ./essentials.jl:1055 [inlined]
│     [33] invokelatest(::Any)
│        @ Base ./essentials.jl:1052
│     [34] (::VSCodeServer.var"#64#65")()
│        @ VSCodeServer ~/.vscode-server/extensions/julialang.language-julia-1.127.2/scripts/packages/VSCodeServer/src/eval.jl:34
└ @ PowerSimulations ~/.julia/dev/PowerSimulations/src/operation/decision_model.jl:393

Expected behavior
The problem should build with slacks and should be feasible with slacks inactive

Additional context
The issue seem to be in the add_expression! function for the ActivePowerBalance type. It expects the slack variables to be declared (in a previous step) for ACBus types, but they are actually defined per Area. Replacing the types queried from the system (i.e. ACBus -> Area), fixes the use case above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant