title : Example Case 3 - Year Planning author : Andrew Rosemberg date : 15th Feb 2019 –-

Introduction

This an example of the HydroPowerModels package for solving a simple stochastic case with the following specifications:

  • 3 Buses

  • 3 Lines

  • 2 Generators

  • 1 Reservoir and Hydrogenerator

  • 3 Scenarios

  • 12 Stages

Case

Importing package and optimizer

using GLPK
using HydroPowerModels

Initialization

  • results = "hidden"

if !@isdefined plot_bool
    plot_bool = true
end
using Random
seed = 1221
1221

Load Case Specifications

Data

alldata = HydroPowerModels.parse_folder(joinpath(WEAVE_ARGS[:testcases_dir], "case3"));

Plot power grid graph

if plot_bool == true
    Random.seed!(seed)
    HydroPowerModels.plot_grid(alldata[1]; node_label=false)
end
ERROR: UndefVarError: `plot_grid` not defined

Parameters

params = create_param(;
    stages=12,
    model_constructor_grid=DCPPowerModel,
    post_method=PowerModels.build_opf,
    optimizer=GLPK.Optimizer,
);

Build Model

  • results = "hidden"

m = hydrothermaloperation(alldata, params);
ERROR: UndefVarError: `MathOptInterface` not defined

Train

  • results = "hidden"

Random.seed!(seed)
start_time = time()
HydroPowerModels.train(
    m;
    iteration_limit=100,
    stopping_rules=[SDDP.Statistical(; num_replications=20, iteration_period=20)],
);
end_time = time() - start_time
ERROR: UndefVarError: `m` not defined

Termination Status and solve time (s)

(SDDP.termination_status(m.policygraph), end_time)
ERROR: UndefVarError: `m` not defined

Bounds

if plot_bool == true
    HydroPowerModels.plot_bound(m)
end
ERROR: UndefVarError: `plot_bound` not defined

Simulation

using Random: Random
Random.seed!(seed)
results = HydroPowerModels.simulate(m, 100);
results
ERROR: UndefVarError: `m` not defined

Testing Results

using Test

Bound

@test SDDP.calculate_bound(m.policygraph) >= 1.1e4
Error During Test at /home/runner/work/HydroPowerModels.jl/HydroPowerModels
.jl/examples/HydroValleys/case3.jl:2
  Test threw exception
  Expression: SDDP.calculate_bound(m.policygraph) >= 11000.0
  UndefVarError: `m` not defined
  Stacktrace:
    [1] top-level scope
      @ /opt/hostedtoolcache/julia/1.9.3/x64/share/julia/stdlib/v1.9/Test/s
rc/Test.jl:478
    [2] eval
      @ ./boot.jl:370 [inlined]
    [3] include_string(mapexpr::typeof(identity), mod::Module, code::String
, filename::String)
      @ Base ./loading.jl:1903
    [4] include_string
      @ ./loading.jl:1913 [inlined]
    [5] (::Weave.var"#32#34"{String, Module, String, Bool, Task, Base.PipeE
ndpoint, Base.PipeEndpoint, Base.PipeEndpoint})()
      @ Weave ~/.julia/packages/Weave/f7Ly3/src/run.jl:218
    [6] task_local_storage(body::Weave.var"#32#34"{String, Module, String, 
Bool, Task, Base.PipeEndpoint, Base.PipeEndpoint, Base.PipeEndpoint}, key::
Symbol, val::String)
      @ Base ./task.jl:296
    [7] capture_output(code::String, mod::Module, path::String, error::Bool
, report::Weave.Report)
      @ Weave ~/.julia/packages/Weave/f7Ly3/src/run.jl:216
    [8] #29
      @ ~/.julia/packages/Weave/f7Ly3/src/run.jl:191 [inlined]
    [9] _broadcast_getindex_evalf
      @ ./broadcast.jl:683 [inlined]
   [10] _broadcast_getindex
      @ ./broadcast.jl:656 [inlined]
   [11] getindex
      @ ./broadcast.jl:610 [inlined]
   [12] macro expansion
      @ ./broadcast.jl:974 [inlined]
   [13] macro expansion
      @ ./simdloop.jl:77 [inlined]
   [14] copyto!
      @ ./broadcast.jl:973 [inlined]
   [15] copyto!
      @ ./broadcast.jl:926 [inlined]
   [16] copy
      @ ./broadcast.jl:898 [inlined]
   [17] materialize(bc::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultAr
rayStyle{1}, Nothing, Weave.var"#29#30"{Weave.Report, Module, Bool, String}
, Tuple{Vector{String}}})
      @ Base.Broadcast ./broadcast.jl:873
   [18] run_code(doc::Weave.WeaveDoc, chunk::Weave.CodeChunk, report::Weave
.Report, mod::Module)
      @ Weave ~/.julia/packages/Weave/f7Ly3/src/run.jl:192
   [19] eval_chunk(doc::Weave.WeaveDoc, chunk::Weave.CodeChunk, report::Wea
ve.Report, mod::Module)
      @ Weave ~/.julia/packages/Weave/f7Ly3/src/run.jl:263
   [20] run_chunk(chunk::Weave.CodeChunk, doc::Weave.WeaveDoc, report::Weav
e.Report, mod::Module)
      @ Weave ~/.julia/packages/Weave/f7Ly3/src/run.jl:133
   [21] run_doc(doc::Weave.WeaveDoc; doctype::String, out_path::String, arg
s::Dict{Symbol, String}, mod::Nothing, fig_path::Nothing, fig_ext::Nothing,
 cache_path::String, cache::Symbol)
      @ Weave ~/.julia/packages/Weave/f7Ly3/src/run.jl:74
   [22] weave(source::String; doctype::String, informat::Nothing, out_path:
:String, args::Dict{Symbol, String}, mod::Nothing, fig_path::Nothing, fig_e
xt::Nothing, cache_path::String, cache::Symbol, template::Nothing, css::Not
hing, highlight_theme::Nothing, pandoc_options::Vector{String}, latex_cmd::
Vector{String}, keep_unicode::Bool)
      @ Weave ~/.julia/packages/Weave/f7Ly3/src/Weave.jl:176
   [23] top-level scope
      @ ~/work/HydroPowerModels.jl/HydroPowerModels.jl/docs/make_examples.j
l:9
   [24] include(fname::String)
      @ Base.MainInclude ./client.jl:478
   [25] top-level scope
      @ ~/work/HydroPowerModels.jl/HydroPowerModels.jl/docs/make.jl:30
   [26] include(fname::String)
      @ Base.MainInclude ./client.jl:478
   [27] top-level scope
      @ none:5
   [28] eval
      @ ./boot.jl:370 [inlined]
   [29] exec_options(opts::Base.JLOptions)
      @ Base ./client.jl:280
   [30] _start()
      @ Base ./client.jl:522
ERROR: Test.FallbackTestSetException("There was an error during testing")

Number of Simulations

@test length(results[:simulations]) == 100
Error During Test at /home/runner/work/HydroPowerModels.jl/HydroPowerModels
.jl/examples/HydroValleys/case3.jl:2
  Test threw exception
  Expression: length(results[:simulations]) == 100
  UndefVarError: `results` not defined
  Stacktrace:
    [1] top-level scope
      @ /opt/hostedtoolcache/julia/1.9.3/x64/share/julia/stdlib/v1.9/Test/s
rc/Test.jl:478
    [2] eval
      @ ./boot.jl:370 [inlined]
    [3] include_string(mapexpr::typeof(identity), mod::Module, code::String
, filename::String)
      @ Base ./loading.jl:1903
    [4] include_string
      @ ./loading.jl:1913 [inlined]
    [5] (::Weave.var"#32#34"{String, Module, String, Bool, Task, Base.PipeE
ndpoint, Base.PipeEndpoint, Base.PipeEndpoint})()
      @ Weave ~/.julia/packages/Weave/f7Ly3/src/run.jl:218
    [6] task_local_storage(body::Weave.var"#32#34"{String, Module, String, 
Bool, Task, Base.PipeEndpoint, Base.PipeEndpoint, Base.PipeEndpoint}, key::
Symbol, val::String)
      @ Base ./task.jl:296
    [7] capture_output(code::String, mod::Module, path::String, error::Bool
, report::Weave.Report)
      @ Weave ~/.julia/packages/Weave/f7Ly3/src/run.jl:216
    [8] #29
      @ ~/.julia/packages/Weave/f7Ly3/src/run.jl:191 [inlined]
    [9] _broadcast_getindex_evalf
      @ ./broadcast.jl:683 [inlined]
   [10] _broadcast_getindex
      @ ./broadcast.jl:656 [inlined]
   [11] getindex
      @ ./broadcast.jl:610 [inlined]
   [12] macro expansion
      @ ./broadcast.jl:974 [inlined]
   [13] macro expansion
      @ ./simdloop.jl:77 [inlined]
   [14] copyto!
      @ ./broadcast.jl:973 [inlined]
   [15] copyto!
      @ ./broadcast.jl:926 [inlined]
   [16] copy
      @ ./broadcast.jl:898 [inlined]
   [17] materialize(bc::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultAr
rayStyle{1}, Nothing, Weave.var"#29#30"{Weave.Report, Module, Bool, String}
, Tuple{Vector{String}}})
      @ Base.Broadcast ./broadcast.jl:873
   [18] run_code(doc::Weave.WeaveDoc, chunk::Weave.CodeChunk, report::Weave
.Report, mod::Module)
      @ Weave ~/.julia/packages/Weave/f7Ly3/src/run.jl:192
   [19] eval_chunk(doc::Weave.WeaveDoc, chunk::Weave.CodeChunk, report::Wea
ve.Report, mod::Module)
      @ Weave ~/.julia/packages/Weave/f7Ly3/src/run.jl:263
   [20] run_chunk(chunk::Weave.CodeChunk, doc::Weave.WeaveDoc, report::Weav
e.Report, mod::Module)
      @ Weave ~/.julia/packages/Weave/f7Ly3/src/run.jl:133
   [21] run_doc(doc::Weave.WeaveDoc; doctype::String, out_path::String, arg
s::Dict{Symbol, String}, mod::Nothing, fig_path::Nothing, fig_ext::Nothing,
 cache_path::String, cache::Symbol)
      @ Weave ~/.julia/packages/Weave/f7Ly3/src/run.jl:74
   [22] weave(source::String; doctype::String, informat::Nothing, out_path:
:String, args::Dict{Symbol, String}, mod::Nothing, fig_path::Nothing, fig_e
xt::Nothing, cache_path::String, cache::Symbol, template::Nothing, css::Not
hing, highlight_theme::Nothing, pandoc_options::Vector{String}, latex_cmd::
Vector{String}, keep_unicode::Bool)
      @ Weave ~/.julia/packages/Weave/f7Ly3/src/Weave.jl:176
   [23] top-level scope
      @ ~/work/HydroPowerModels.jl/HydroPowerModels.jl/docs/make_examples.j
l:9
   [24] include(fname::String)
      @ Base.MainInclude ./client.jl:478
   [25] top-level scope
      @ ~/work/HydroPowerModels.jl/HydroPowerModels.jl/docs/make.jl:30
   [26] include(fname::String)
      @ Base.MainInclude ./client.jl:478
   [27] top-level scope
      @ none:5
   [28] eval
      @ ./boot.jl:370 [inlined]
   [29] exec_options(opts::Base.JLOptions)
      @ Base ./client.jl:280
   [30] _start()
      @ Base ./client.jl:522
ERROR: Test.FallbackTestSetException("There was an error during testing")

Plot Aggregated Results

if plot_bool == true
    HydroPowerModels.plot_aggregated_results(results)
end
ERROR: UndefVarError: `plot_aggregated_results` not defined

Annex 1: Case Summary

if plot_bool == true
    PowerModels.print_summary(alldata[1]["powersystem"])
end
Metadata
  baseMVA: 100
  cost_deficit: 1000
  name: case3
  per_unit: true
  source_type: matpower
  source_version: 2

Table Counts
  bus: 3
  load: 3
  shunt: 0
  gen: 3
  storage: 0
  switch: 0
  branch: 3
  dcline: 0


Table: bus
         bus_i, bus_type
      1:     1,        3
      2:     2,        2
      3:     3,        2

  default values:
    base_kv: 0
    vm: 1
    va: 0
    vmin: 0.900
    vmax: 1.100
    area: 1
    zone: 1


Table: load
         load_bus, pd,    qd
      1:        3,  1,     0
      2:        1,  0, 0.000
      3:        2,  0, 0.000

  default values:
    status: 1


Table: gen
         gen_bus,  pmax, ncost,  cost
      1:       2,     1,     2, [(2)]
      2:       3, 0.500,     2, [(2)]
      3:       1, 0.800,     0, [(0)]

  default values:
    pg: 0
    qg: 0
    vg: 1
    mbase: 100
    pmin: 0
    qmin: -100
    qmax: 100
    gen_status: 1
    model: 2
    startup: 0
    shutdown: 0
    apf: 0
    pc1: 0
    pc2: 0
    qc1max: 0
    qc1min: 0
    qc2max: 0
    qc2min: 0
    ramp_10: 0
    ramp_30: 0
    ramp_agc: 0
    ramp_q: 0


Table: branch
         f_bus, t_bus,  br_r,  br_x,  b_fr,  b_to, rate_a
      1:     1,     3, 0.065,     1, 0.225, 0.225,      1
      2:     3,     2, 0.025, 0.500, 0.350, 0.350,  0.650
      3:     1,     2, 0.042,     1, 0.150, 0.150,  0.250

  default values:
    g_fr: 0
    g_to: 0
    tap: 1
    shift: 0
    br_status: 1
    angmax: 1.047
    angmin: -1.047
    transformer: false

Annex 2: Plot Results

if plot_bool == true
    HydroPowerModels.plotresults(results)
end
ERROR: UndefVarError: `plotresults` not defined