martinbiel / StochasticPrograms.jl

Julia package for formulating and analyzing stochastic recourse models.
MIT License
75 stars 25 forks source link

Asynchronous Progressive Hedging Solution fetch issue #44

Open kaarthiksundar opened 1 year ago

kaarthiksundar commented 1 year ago

There seems to be an issue with accessing the solution of a 2-stage stochastic programming model after using PG with Asynchronous option to solve the same. The error occurs when we use JuMP.value(model[2, :x], 25) for say a 25 scenario problem. The issue arises when I try to access the solution of the decision variables in the last scenario. This error is erratic, some times it throws an error with a certain number of scenarios and it does not with others. The error does not occur when we do the same solve in the Serial mode.

Here is the stack trace:

ERROR: LoadError: On worker 10:
BoundsError: attempt to access 3-element Vector{Model} at index [4]
Stacktrace:
 [1] getindex
   @ ./array.jl:861
 [2] #298
   @ ~/.julia/packages/StochasticPrograms/pIScW/src/types/decomposition/scenarioproblems.jl:404
 [3] #110
   @ ~/Applications/Julia-1.7.app/Contents/Resources/julia/share/julia/stdlib/v1.7/Distributed/src/process_messages.jl:278
 [4] run_work_thunk
   @ ~/Applications/Julia-1.7.app/Contents/Resources/julia/share/julia/stdlib/v1.7/Distributed/src/process_messages.jl:63
 [5] macro expansion
   @ ~/Applications/Julia-1.7.app/Contents/Resources/julia/share/julia/stdlib/v1.7/Distributed/src/process_messages.jl:278 [inlined]
 [6] #109
   @ ./task.jl:429
Stacktrace:
  [1] remotecall_fetch(::Function, ::Distributed.Worker, ::RemoteChannel{Channel{StochasticPrograms.ScenarioProblems{AbstractScenario}}}, ::Vararg{Any}; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ Distributed ~/Applications/Julia-1.7.app/Contents/Resources/julia/share/julia/stdlib/v1.7/Distributed/src/remotecall.jl:469
  [2] remotecall_fetch(::Function, ::Distributed.Worker, ::RemoteChannel{Channel{StochasticPrograms.ScenarioProblems{AbstractScenario}}}, ::Vararg{Any})
    @ Distributed ~/Applications/Julia-1.7.app/Contents/Resources/julia/share/julia/stdlib/v1.7/Distributed/src/remotecall.jl:461
  [3] remotecall_fetch(::Function, ::Int64, ::RemoteChannel{Channel{StochasticPrograms.ScenarioProblems{AbstractScenario}}}, ::Vararg{Any}; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ Distributed ~/Applications/Julia-1.7.app/Contents/Resources/julia/share/julia/stdlib/v1.7/Distributed/src/remotecall.jl:496
  [4] remotecall_fetch(::Function, ::Int64, ::RemoteChannel{Channel{StochasticPrograms.ScenarioProblems{AbstractScenario}}}, ::Vararg{Any})
    @ Distributed ~/Applications/Julia-1.7.app/Contents/Resources/julia/share/julia/stdlib/v1.7/Distributed/src/remotecall.jl:496
  [5] get_from_scenarioproblem(::Function, ::StochasticPrograms.DistributedScenarioProblems{AbstractScenario}, ::Int64, ::Function, ::Vararg{Any})
    @ StochasticPrograms ~/.julia/packages/StochasticPrograms/pIScW/src/types/decomposition/scenarioproblems.jl:102
  [6] scenario_decision_dispatch(::Function, ::StochasticPrograms.DistributedScenarioProblems{AbstractScenario}, ::MathOptInterface.VariableIndex, ::Int64)
    @ StochasticPrograms ~/.julia/packages/StochasticPrograms/pIScW/src/types/decomposition/scenarioproblems.jl:403
  [7] scenario_decision_dispatch(::Function, ::ScenarioDecompositionStructure{2, 1, Tuple{StochasticPrograms.DistributedScenarioProblems{AbstractScenario}}}, ::MathOptInterface.VariableIndex, ::Int64, ::Int64)
    @ StochasticPrograms ~/.julia/packages/StochasticPrograms/pIScW/src/types/decomposition/scenario_decomposition.jl:392
  [8] decision(dvar::DecisionVariable, scenario_index::Int64)
    @ StochasticPrograms ~/.julia/packages/StochasticPrograms/pIScW/src/types/decision_variable.jl:57
  [9] value(dvar::DecisionVariable, scenario_index::Int64; result::Int64)
    @ StochasticPrograms ~/.julia/packages/StochasticPrograms/pIScW/src/types/decision_variable.jl:427
 [10] value
    @ ~/.julia/packages/StochasticPrograms/pIScW/src/types/decision_variable.jl:426 [inlined]
 [11] _broadcast_getindex_evalf
    @ ./broadcast.jl:670 [inlined]
 [12] _broadcast_getindex
    @ ./broadcast.jl:643 [inlined]
 [13] getindex
    @ ./broadcast.jl:597 [inlined]
 [14] macro expansion
    @ ./broadcast.jl:961 [inlined]
 [15] macro expansion
    @ ./simdloop.jl:77 [inlined]
 [16] copyto!
    @ ./broadcast.jl:960 [inlined]
 [17] copyto!
    @ ./broadcast.jl:913 [inlined]
 [18] copy
    @ ./broadcast.jl:885 [inlined]
 [19] materialize
    @ ./broadcast.jl:860 [inlined]
 [20] broadcast(::typeof(value), ::Vector{DecisionVariable}, ::Int64)
    @ Base.Broadcast ./broadcast.jl:798
 [21] broadcasted(::Base.Broadcast.ArrayStyle{JuMP.Containers.DenseAxisArray}, ::Function, ::JuMP.Containers.DenseAxisArray{DecisionVariable, 1, Tuple{Vector{Int64}}, Tuple{JuMP.Containers._AxisLookup{Dict{Int64, Int64}}}}, ::Int64)
    @ JuMP.Containers ~/.julia/packages/JuMP/60Bnj/src/Containers/DenseAxisArray.jl:437
 [22] broadcasted(::Function, ::JuMP.Containers.DenseAxisArray{DecisionVariable, 1, Tuple{Vector{Int64}}, Tuple{JuMP.Containers._AxisLookup{Dict{Int64, Int64}}}}, ::Int64)
    @ Base.Broadcast ./broadcast.jl:1303
 [23] (::var"#167#187"{StochasticProgram{2, Tuple{StochasticPrograms.Stage{Nothing}, StochasticPrograms.Stage{Nothing}}, ScenarioDecompositionStructure{2, 1, Tuple{StochasticPrograms.DistributedScenarioProblems{AbstractScenario}}}}})(i::Int64)
    @ Main ./none:0
 [24] iterate
    @ ./generator.jl:47 [inlined]
 [25] Dict{String, Any}(kv::Base.Generator{UnitRange{Int64}, var"#167#187"{StochasticProgram{2, Tuple{StochasticPrograms.Stage{Nothing}, StochasticPrograms.Stage{Nothing}}, ScenarioDecompositionStructure{2, 1, Tuple{StochasticPrograms.DistributedScenarioProblems{AbstractScenario}}}}}})
    @ Base ./dict.jl:104
 [26] save_preventive_control_model_results(ref::Dict{Symbol, Any}, cli_args::Dict{String, Any}, preventive_model::NamedTuple{(:model, :scenarios, :var, :extra), Tuple{StochasticProgram{2, Tuple{StochasticPrograms.Stage{Nothing}, StochasticPrograms.Stage{Nothing}}, ScenarioDecompositionStructure{2, 1, Tuple{StochasticPrograms.DistributedScenarioProblems{AbstractScenario}}}}, Vector{AbstractScenario}, Dict{Symbol, Any}, Dict{Symbol, Any}}}, off_branches::Vector{Any}, file::String)
    @ Main ~/Documents/codes/wildfire-bes/src/preventive.jl:266
 [27] run_preventive_control_model(ref::Dict{Symbol, Any}, input_cli_args::Dict{String, Any})
    @ Main ~/Documents/codes/wildfire-bes/src/main.jl:95
 [28] top-level scope
    @ ~/Documents/codes/wildfire-bes/src/main.jl:119