Skip to content

Commit

Permalink
Merge branch 'develop' into configure_multistage_settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Maya Mutic authored and Maya Mutic committed May 22, 2024
2 parents 1a16c37 + 9fa7257 commit c2cb0eb
Show file tree
Hide file tree
Showing 79 changed files with 1,004 additions and 673 deletions.
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# .git-blame-ignore-revs
# Standardize code formatting across project (#673)
ee3f08756584ba16a57bb701492270a7bf129b4d
# Update code formatting
730f91df23447e94177c3a9c3d4e553cb502e2bf
5 changes: 5 additions & 0 deletions .github/workflows/format_suggestions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: julia-actions/julia-format@v2
continue-on-error: true
- name: Check on failures
if: steps.julia-format.outcome != 'success'
run: echo "There are formatting errors. Please check the logs above."
shell: bash
10 changes: 8 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
non-zero in multi-stage GenX (#666)
- Added condition number scaling added to objective function (#667)
- Added versioned doc-pages for v0.3.6 and v0.4.0

- Added a warning message in write_costs_multistage mentioning th approximate value of costs currently.

### Fixed
- Add constraint in mga to compute total capacity in each zone from a given technology type (#681)
- New settings parameter MGAAnnualGeneration to switch between different MGA formulations (#681)
- Add validation for `Can_Retire` column in multi-stage GenX since the current implementation
does not allow a resource to switch from can_retire = 0 to can_retire = 1 between stages. (#683)
- Add tutorials for running GenX (#637 and #685)

### Fixed
- Add writing of multistage stats during optimization with foresight (#687)
- Fix docstring in operational_reserves.jl (#690)
- Fix docstring in energy_share_requirement.jl (#692)
- Set MUST_RUN=1 for RealSystemExample/small_hydro plants (#517).
Previously these plants had no resource flag set, and so they did not contribute to the power balance.
As these plants are now useful, the objective in these cases is slightly lower.
Expand All @@ -70,6 +75,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed outputting capital recovery cost to 0 if the remaining number of years is 0 (#666)
- Updated the docstring for the initialize_cost_to_go function and adjusted the formula for the discount factor to reflect the code implementation (#672).
- Fix write_multi_stage_cost.jl: add discount with OPEX multipliers to cUnmetPolicyPenalty (#679)
- Fix DF calculation in DDP to make it more generic for variable length stages (#680)
- Fix write_power_balance.jl: add additional two columns ("VRE_Storage_Discharge" and "VRE_Storage_Charge") for VRE_STOR

### Changed
Expand Down
7 changes: 7 additions & 0 deletions docs/src/Model_Reference/write_outputs.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,20 @@ GenX.write_vre_stor_discharge
```

## Write Multi-stage files
```@autodocs
Modules = [GenX]
Pages = ["write_multi_stage_outputs.jl"]
```
```@docs
GenX.write_multi_stage_costs
GenX.write_multi_stage_stats
GenX.write_multi_stage_settings
GenX.write_multi_stage_network_expansion
GenX.write_multi_stage_capacities_discharge
GenX.write_multi_stage_capacities_charge
GenX.write_multi_stage_capacities_energy
GenX.create_multi_stage_stats_file
GenX.update_multi_stage_stats_file
```

## Write maintenance files
Expand Down
52 changes: 27 additions & 25 deletions src/additional_tools/method_of_morris.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ function calculate_spread(matrix)
end

function sample_matrices(p_range,
p_steps,
rng;
num_trajectory,
total_num_trajectory,
len_design_mat,
groups)
p_steps,
rng;
num_trajectory,
total_num_trajectory,
len_design_mat,
groups)
matrix_array = []
println(num_trajectory)
println(total_num_trajectory)
Expand All @@ -85,13 +85,13 @@ function sample_matrices(p_range,
end

function my_gsa(f,
p_steps,
num_trajectory,
total_num_trajectory,
p_range::AbstractVector,
len_design_mat,
groups,
random)
p_steps,
num_trajectory,
total_num_trajectory,
p_range::AbstractVector,
len_design_mat,
groups,
random)
rng = Random.default_rng()
if !random
Random.seed!(SEED)
Expand All @@ -113,7 +113,8 @@ function my_gsa(f,
pairs(eachcol(L[!,
((i - 1) * len_design_mat + 1):(i * len_design_mat)]))))))
distinct_trajectories[i] = length(Matrix(DataFrame(unique(last,
pairs(eachcol(L[!, ((i - 1) * len_design_mat + 1):(i * len_design_mat)])))))[1,
pairs(eachcol(L[!, ((i - 1) * len_design_mat + 1):(i * len_design_mat)])))))[
1,
:])
end
end
Expand Down Expand Up @@ -189,12 +190,12 @@ function my_gsa(f,
effects)
end
function morris(EP::Model,
path::AbstractString,
setup::Dict,
inputs::Dict,
outpath::AbstractString,
OPTIMIZER;
random = true)
path::AbstractString,
setup::Dict,
inputs::Dict,
outpath::AbstractString,
OPTIMIZER;
random = true)

# Reading the input parameters
Morris_range = load_dataframe(joinpath(path, "Method_of_morris_range.csv"))
Expand All @@ -215,11 +216,12 @@ function morris(EP::Model,
column_f = isdefined(GenX, col_sym) ? getfield(GenX, col_sym) :
r -> getproperty(r, col_sym)
sigma = [sigma;
[column_f.(gen) .* (1 .+
Morris_range[Morris_range[!, :Parameter] .== column, :Lower_bound] ./ 100) column_f.(gen) .*
(1 .+
Morris_range[Morris_range[!, :Parameter] .== column,
:Upper_bound] ./ 100)]]
[column_f.(gen) .* (1 .+
Morris_range[Morris_range[!, :Parameter] .== column, :Lower_bound] ./
100) column_f.(gen) .*
(1 .+
Morris_range[Morris_range[!, :Parameter] .== column,
:Upper_bound] ./ 100)]]
end
sigma = sigma[2:end, :]

Expand Down
12 changes: 6 additions & 6 deletions src/case_runners/case_runner.jl
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,7 @@ function run_genx_case_multistage!(case::AbstractString, mysetup::Dict, optimize
### Solve model
println("Solving Model")

# Step 3) Run DDP Algorithm
## Solve Model
model_dict, mystats_d, inputs_dict = run_ddp(model_dict, mysetup, inputs_dict)

# Step 4) Write final outputs from each stage

# Prepare folder for results
outpath = get_default_output_folder(case)

if mysetup["OverwriteResults"] == 1
Expand All @@ -188,6 +183,11 @@ function run_genx_case_multistage!(case::AbstractString, mysetup::Dict, optimize
mkdir(outpath)
end

# Step 3) Run DDP Algorithm
## Solve Model
model_dict, mystats_d, inputs_dict = run_ddp(outpath, model_dict, mysetup, inputs_dict)

# Step 4) Write final outputs from each stage
for p in 1:mysetup["MultiStageSettingsDict"]["NumStages"]
outpath_cur = joinpath(outpath, "results_p$p")
write_outputs(model_dict[p], outpath_cur, mysetup, inputs_dict[p])
Expand Down
3 changes: 2 additions & 1 deletion src/configure_settings/configure_settings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ function validate_settings!(settings::Dict{Any, Any})

if haskey(settings, "Reserves")
Base.depwarn("""The Reserves setting has been deprecated. Please use the
OperationalReserves setting instead.""", :validate_settings!, force = true)
OperationalReserves setting instead.""",
:validate_settings!, force = true)
settings["OperationalReserves"] = settings["Reserves"]
delete!(settings, "Reserves")
end
Expand Down
18 changes: 10 additions & 8 deletions src/load_inputs/load_dataframe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ function load_dataframe(dir::AbstractString, basenames::Vector{String})::DataFra
target = look_for_file_with_alternate_case(dir, base)
# admonish
if target != FILENOTFOUND
Base.depwarn("""The filename '$target' is deprecated. '$best_basename' is preferred.""",
Base.depwarn(
"""The filename '$target' is deprecated. '$best_basename' is preferred.""",
:load_dataframe,
force = true)
return load_dataframe_from_file(joinpath(dir, target))
Expand Down Expand Up @@ -132,8 +133,8 @@ function load_dataframe_from_file(path)::DataFrame
end

function find_matrix_columns_in_dataframe(df::DataFrame,
columnprefix::AbstractString;
prefixseparator = '_')::Vector{Int}
columnprefix::AbstractString;
prefixseparator = '_')::Vector{Int}
all_columns = names(df)

# 2 is the length of the '_' connector plus one for indexing
Expand Down Expand Up @@ -167,8 +168,8 @@ ESR_1, other_thing, ESR_3, ESR_2,
```
"""
function extract_matrix_from_dataframe(df::DataFrame,
columnprefix::AbstractString;
prefixseparator = '_')
columnprefix::AbstractString;
prefixseparator = '_')
all_columns = names(df)
columnnumbers = find_matrix_columns_in_dataframe(df,
columnprefix,
Expand All @@ -193,12 +194,13 @@ function extract_matrix_from_dataframe(df::DataFrame,
end

function extract_matrix_from_resources(rs::Vector{T},
columnprefix::AbstractString,
default = 0.0) where {T <: AbstractResource}
columnprefix::AbstractString,
default = 0.0) where {T <: AbstractResource}

# attributes starting with columnprefix with a numeric suffix
attributes_n = [attr
for attr in string.(attributes(rs[1])) if startswith(attr, columnprefix)]
for attr in string.(attributes(rs[1]))
if startswith(attr, columnprefix)]
# sort the attributes by the numeric suffix
sort!(attributes_n, by = x -> parse(Int, split(x, "_")[end]))

Expand Down
5 changes: 3 additions & 2 deletions src/load_inputs/load_demand_data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ function get_demand_dataframe(path)
DEMAND_COLUMN_PREFIX_DEPRECATED()[1:(end - 1)],
prefixseparator = 'z')
old_column_symbols = Symbol.(DEMAND_COLUMN_PREFIX_DEPRECATED() * string(i)
for i in old_columns)
for i in old_columns)
if length(old_column_symbols) > 0
pref_prefix = DEMAND_COLUMN_PREFIX()
dep_prefix = DEMAND_COLUMN_PREFIX_DEPRECATED()
@info "$dep_prefix is deprecated. Use $pref_prefix."
new_column_symbols = Symbol.(DEMAND_COLUMN_PREFIX() * string(i) for i in old_columns)
new_column_symbols = Symbol.(DEMAND_COLUMN_PREFIX() * string(i)
for i in old_columns)
rename!(df, Dict(old_column_symbols .=> new_column_symbols))
end
return df
Expand Down
4 changes: 2 additions & 2 deletions src/load_inputs/load_inputs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ Returns:
- String: The directory path based on the setup parameters.
"""
function get_systemfiles_path(setup::Dict,
TDR_directory::AbstractString,
path::AbstractString)
TDR_directory::AbstractString,
path::AbstractString)
if setup["TimeDomainReduction"] == 1 && time_domain_reduced_files_exist(TDR_directory)
return TDR_directory
else
Expand Down
2 changes: 1 addition & 1 deletion src/load_inputs/load_multistage_data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function scale_multistage_data!(multistage_in::DataFrame, scale_factor::Float64)
:min_retired_cap_charge_dc_mw,
:min_retired_cap_charge_ac_mw,
:min_retired_cap_discharge_dc_mw,
:min_retired_cap_discharge_ac_mw,
:min_retired_cap_discharge_ac_mw
]
scale_columns!(multistage_in, columns_to_scale, scale_factor)
return nothing
Expand Down
3 changes: 2 additions & 1 deletion src/load_inputs/load_operational_reserves.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ function load_operational_reserves!(setup::Dict, path::AbstractString, inputs::D
end
for col in columns
if col in all_columns
Base.depwarn("The column name $col in file $filename is deprecated; prefer $best",
Base.depwarn(
"The column name $col in file $filename is deprecated; prefer $best",
:load_operational_reserves,
force = true)
return float(df[firstrow, col])
Expand Down
Loading

0 comments on commit c2cb0eb

Please sign in to comment.