Skip to content

Commit

Permalink
Fixing tests files (#15)
Browse files Browse the repository at this point in the history
* Fixinng tests files

* Fixing tests files

* Fixing tests files
  • Loading branch information
arthur-brigatto authored Oct 23, 2023
1 parent 90994a2 commit 4dfad72
Show file tree
Hide file tree
Showing 13 changed files with 175 additions and 284 deletions.
46 changes: 10 additions & 36 deletions examples/HydroValleys/case3.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,23 @@ using HydroPowerModels

#' ## Initialization
#'+ results = "hidden"
if !@isdefined plot_bool
plot_bool = true
end
using Random
seed = 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]; has_nodelabel=false)
end
case = "case3"
current_dir = dirname(dirname(dirname(@__FILE__)))
case_dir = joinpath(current_dir, "testcases")
alldata = HydroPowerModels.parse_folder(joinpath(case_dir, case));

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

#' ## Build Model
Expand All @@ -57,19 +51,14 @@ Random.seed!(seed)
start_time = time()
HydroPowerModels.train(
m;
iteration_limit=100,
stopping_rules=[SDDP.Statistical(; num_replications=20, iteration_period=20)],
iteration_limit = 100,
stopping_rules = [SDDP.Statistical(; num_replications = 20, iteration_period = 20)],
);
end_time = time() - start_time

#' Termination Status and solve time (s)
(SDDP.termination_status(m.forward_graph), end_time)

#' Bounds
if plot_bool == true
HydroPowerModels.plot_bound(m)
end

#' ## Simulation
using Random: Random
Random.seed!(seed)
Expand All @@ -82,18 +71,3 @@ using Test
@test SDDP.calculate_bound(m.forward_graph) >= 1.1e4
#' Number of Simulations
@test length(results[:simulations]) == 100

#' ## Plot Aggregated Results
if plot_bool == true
HydroPowerModels.plot_aggregated_results(results)
end

#' # Annex 1: Case Summary
if plot_bool == true
PowerModels.print_summary(alldata[1]["powersystem"])
end

#' # Annex 2: Plot Results
if plot_bool == true
HydroPowerModels.plotresults(results)
end
54 changes: 10 additions & 44 deletions examples/HydroValleys/case3_5years.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,23 @@ using HydroPowerModels

#' ## Initialization
#+ results = "hidden"
if !@isdefined plot_bool
plot_bool = true
end
using Random
seed = 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]; has_nodelabel=false)
end
case = "case3"
current_dir = dirname(dirname(dirname(@__FILE__)))
case_dir = joinpath(current_dir, "testcases")
alldata = HydroPowerModels.parse_folder(joinpath(case_dir, case));

#' Parameters
params = create_param(;
stages=12 * 5,
model_constructor_grid=DCPPowerModel,
post_method=PowerModels.build_opf,
optimizer=GLPK.Optimizer,
stages = 12 * 5,
model_constructor_grid = DCPPowerModel,
post_method = PowerModels.build_opf,
optimizer = GLPK.Optimizer,
);

#' ## Build Model
Expand All @@ -57,43 +51,15 @@ m = hydro_thermal_operation(alldata, params);
start_time = time()
HydroPowerModels.train(
m;
iteration_limit=100,
stopping_rules=[SDDP.Statistical(; num_replications=200, iteration_period=80)],
iteration_limit = 100,
stopping_rules = [SDDP.Statistical(; num_replications = 200, iteration_period = 80)],
);
end_time = time() - start_time

#' Termination Status and solve time (s)
(SDDP.termination_status(m.forward_graph), end_time)

#' Bounds
if plot_bool == true
HydroPowerModels.plot_bound(m)
end

#' ## Simulation
using Random: Random
Random.seed!(seed)
results = HydroPowerModels.simulate(m, 100);
results

#' ## Testing Results
using Test
#' Bound
@test isapprox(SDDP.calculate_bound(m.forward_graph), 59357.12, atol=10)
#' Number of Simulations
@test length(results[:simulations]) == 100

#' ## Plot Aggregated Results
if plot_bool == true
HydroPowerModels.plot_aggregated_results(results)
end

#' # Annex 1: Case Summary
if plot_bool == true
PowerModels.print_summary(alldata[1]["powersystem"])
end

#' # Annex 2: Plot Results
if plot_bool == true
HydroPowerModels.plotresults(results)
end
46 changes: 10 additions & 36 deletions examples/HydroValleys/case3_ac.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,22 @@ using HydroPowerModels

#' ## Initialization
#+ results = "hidden"
if !@isdefined plot_bool
plot_bool = true
end
using Random
seed = 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]; has_nodelabel=false)
end
case = "case3"
current_dir = dirname(dirname(dirname(@__FILE__)))
case_dir = joinpath(current_dir, "testcases")
alldata = HydroPowerModels.parse_folder(joinpath(case_dir, case));

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

#' ## Build Model
Expand All @@ -57,19 +51,14 @@ m = hydro_thermal_operation(alldata, params);
start_time = time()
HydroPowerModels.train(
m;
iteration_limit=100,
stopping_rules=[SDDP.Statistical(; num_replications=20, iteration_period=20)],
iteration_limit = 100,
stopping_rules = [SDDP.Statistical(; num_replications = 20, iteration_period = 20)],
);
end_time = time() - start_time

#' Termination Status and solve time (s)
(SDDP.termination_status(m.forward_graph), end_time)

#' Bounds
if plot_bool == true
HydroPowerModels.plot_bound(m)
end

#' ## Simulation
#+ results = "hidden"
using Random: Random
Expand All @@ -79,18 +68,3 @@ results = HydroPowerModels.simulate(m, 100);
#' ## Results
#' Objective
results[:simulations][1][1][:objective]

#' ## Plot Aggregated Results
if plot_bool == true
HydroPowerModels.plot_aggregated_results(results)
end

#' # Annex 1: Case Summary
if plot_bool == true
PowerModels.print_summary(alldata[1]["powersystem"])
end

#' # Annex 2: Plot Results
if plot_bool == true
HydroPowerModels.plotresults(results)
end
42 changes: 22 additions & 20 deletions examples/HydroValleys/case3_cmp_formulations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ using Ipopt, GLPK
using HydroPowerModels

#' ## Load Case Specifications
testcases_dir = joinpath(dirname(dirname(dirname(@__FILE__))), "testcases")
data = HydroPowerModels.parse_folder(joinpath(testcases_dir, "case3"))
case = "case3"
current_dir = dirname(dirname(dirname(@__FILE__)))
case_dir = joinpath(current_dir, "testcases")
alldata = HydroPowerModels.parse_folder(joinpath(case_dir, case));

#' ## Results Dict
dcp_stats = Dict()
Expand All @@ -44,17 +46,17 @@ dcp_stats = Dict()
#' ## Parameters

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

#' ## Build Model
m = hydro_thermal_operation(data, params);

#' ## Solve
HydroPowerModels.train(m; iteration_limit=60);
HydroPowerModels.train(m; iteration_limit = 60);

#' ## Simulation
using Random: Random
Expand All @@ -69,17 +71,17 @@ dcp_stats["DC"] = flat_dict(HydroPowerModels.descriptivestatistics_results(resul
#' ## Parameters

params = create_param(;
stages=12,
model_constructor_grid=SOCWRPowerModel,
post_method=PowerModels.build_opf,
optimizer=IpoptSolver(; tol=1e-6),
stages = 12,
model_constructor_grid = SOCWRPowerModel,
post_method = PowerModels.build_opf,
optimizer = IpoptSolver(; tol = 1e-6),
)

#' ## Build Model
m = hydro_thermal_operation(data, params);

#' ## Solve
HydroPowerModels.train(m; iteration_limit=60);
HydroPowerModels.train(m; iteration_limit = 60);

#' ## Simulation
using Random: Random
Expand All @@ -94,17 +96,17 @@ dcp_stats["SOC"] = flat_dict(HydroPowerModels.descriptivestatistics_results(resu
#' ## Parameters

params = create_param(;
stages=12,
model_constructor_grid=ACPPowerModel,
post_method=PowerModels.build_opf,
optimizer=IpoptSolver(; tol=1e-6),
stages = 12,
model_constructor_grid = ACPPowerModel,
post_method = PowerModels.build_opf,
optimizer = IpoptSolver(; tol = 1e-6),
)

#' ## Build Model
m = hydro_thermal_operation(data, params);

#' ## Solve
HydroPowerModels.train(m; iteration_limit=60);
HydroPowerModels.train(m; iteration_limit = 60);

#' ## Simulation
using Random: Random
Expand All @@ -120,13 +122,13 @@ using DataFrames
using Base.Markdown

str_ac = html(
latexify(DataFrame(signif_dict(dcp_stats["AC"], 2)); env=:mdtable, latex=false)
latexify(DataFrame(signif_dict(dcp_stats["AC"], 2)); env = :mdtable, latex = false),
);
str_soc = html(
latexify(DataFrame(signif_dict(dcp_stats["SOC"], 2)); env=:mdtable, latex=false)
latexify(DataFrame(signif_dict(dcp_stats["SOC"], 2)); env = :mdtable, latex = false),
);
str_dc = html(
latexify(DataFrame(signif_dict(dcp_stats["DC"], 2)); env=:mdtable, latex=false)
latexify(DataFrame(signif_dict(dcp_stats["DC"], 2)); env = :mdtable, latex = false),
);

results_str = """
Expand Down
Loading

0 comments on commit 4dfad72

Please sign in to comment.