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

Add MacroEnergySystemsScaling.jl #792

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ HiGHS = "87dc4568-4c63-4d18-b0c0-bb2238e4078b"
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
MacroEnergySystemsScaling = "e07ba8b4-499e-4f54-a885-af58260c741f"
MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Expand Down
1 change: 0 additions & 1 deletion docs/src/Tutorials/Tutorial_1_configuring_settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ genx_settings_SNE = YAML.load(open("example_systems/1_three_zones/settings/genx_
Dict{Any, Any} with 19 entries:
"NetworkExpansion" => 1
"ModelingToGenerateAlternativeIterations" => 3
"ParameterScale" => 1
"EnergyShareRequirement" => 0
"PrintModel" => 0
"TimeDomainReduction" => 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ genx_settings_TZ = YAML.load(open((joinpath(case,"settings/genx_settings.yml")))
Dict{Any, Any} with 19 entries:
"NetworkExpansion" => 1
"ModelingToGenerateAlternativeIterations" => 3
"ParameterScale" => 1
"EnergyShareRequirement" => 0
"PrintModel" => 0
"TimeDomainReduction" => 1
Expand Down Expand Up @@ -129,7 +128,6 @@ genx_settings_TZ ## Output settings
```
Dict{Any, Any} with 13 entries:
"NetworkExpansion" => 1
"ParameterScale" => 1
"EnergyShareRequirement" => 0
"TimeDomainReduction" => 0
"Trans_Loss_Segments" => 1
Expand Down
1 change: 0 additions & 1 deletion docs/src/Tutorials/Tutorial_4_model_generation.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ setup = GenX.configure_settings(genx_settings,writeoutput_settings) # Combines g
"CO2Cap" => 2
"WriteShadowPrices" => 1
"ModelingToGenerateAlternativeIterations" => 3
"ParameterScale" => 1
"EnergyShareRequirement" => 1
"PrintModel" => 0
"TimeDomainReduction" => 1
Expand Down
1 change: 0 additions & 1 deletion docs/src/Tutorials/Tutorial_7_setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ setup = GenX.configure_settings(genx_settings,writeoutput_settings)
"CO2Cap" => 2
"WriteShadowPrices" => 1
"OperationalReserves" => 0
"ParameterScale" => 1
"EnergyShareRequirement" => 0
"PrintModel" => 0
"TimeDomainReduction" => 1
Expand Down
2 changes: 1 addition & 1 deletion docs/src/User_Guide/model_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ The following tables summarize the model settings parameters and their default/p

|**Parameter** | **Description**|
| :------------ | :-----------|
|ParameterScale | Flag to turn on parameter scaling wherein demand, capacity and power variables defined in GW rather than MW. This flag aides in improving the computational performance of the model. |
|AutoScaling | Flag to turn on constraint scaling wherein demand. This feature usually aides in improving the computational performance of the model. It does not affect the units of the inputs or results. The scaling can be adjusted by using the additional settings detailed [here](https://macroenergy.github.io/MacroEnergySystemsScaling.jl/stable/scaling_settings/)|
||1 = Scaling is activated. |
||0 = Scaling is not activated. |
|ObjScale| Parameter value to scale the objective function during optimization.|
Expand Down
4 changes: 2 additions & 2 deletions example_systems/1_three_zones/settings/genx_settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ CO2Cap: 2 # CO2 emissions cap; 0 = not active (no CO2 emission limit); 1 = mass-
StorageLosses: 1 # Energy Share Requirement and CO2 constraints account for energy lost; 0 = not active (DO NOT account for energy lost); 1 = active systemwide (DO account for energy lost)
MinCapReq: 1 # Activate minimum technology carveout constraints; 0 = not active; 1 = active
MaxCapReq: 0 # Activate maximum technology carveout constraints; 0 = not active; 1 = active
ParameterScale: 1 # Turn on parameter scaling wherein demand, capacity and power variables are defined in GW rather than MW. 0 = not active; 1 = active systemwide
WriteShadowPrices: 1 # Write shadow prices of LP or relaxed MILP; 0 = not active; 1 = active
UCommit: 2 # Unit committment of thermal power plants; 0 = not active; 1 = active using integer clestering; 2 = active using linearized clustering
TimeDomainReduction: 1 # Time domain reduce (i.e. cluster) inputs based on Demand_data.csv, Generators_variability.csv, and Fuels_data.csv; 0 = not active (use input data as provided); 0 = active (cluster input data, or use data that has already been clustered)
OutputFullTimeSeries: 1
OutputFullTimeSeries: 1
AutoScaling : 1
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ Trans_Loss_Segments: 1 # Number of segments used in piecewise linear approximati
UCommit: 2 # Unit committment of thermal power plants; 0 = not active; 1 = active using integer clestering; 2 = active using linearized clustering
StorageLosses: 1 # Energy Share Requirement and CO2 constraints account for energy lost; 0 = not active (DO NOT account for energy lost); 1 = active systemwide (DO account for energy lost)
HydrogenHourlyMatching: 1 # Hydrogen electrolyzer contribution to hourly supply matching required
ParameterScale: 1 # Turn on parameter scaling wherein demand, capacity and power variables are defined in GW rather than MW. 0 = not active; 1 = active systemwide
TimeDomainReduction: 1 # Time domain reduce (i.e. cluster) inputs based on Demand_data.csv, Generators_variability.csv, and Fuels_data.csv; 0 = not active (use input data as provided); 0 = active (cluster input data, or use data that has already been clustered)
WriteShadowPrices: 1 # Write shadow prices of LP or relaxed MILP; 0 = not active; 1 = active
HydrogenMinimumProduction: 1 # Hydrogen production requirement; 0 = not active; 1 = active, meet regional level H2 production requirements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ CO2Cap: 2 # CO2 emissions cap; 0 = not active (no CO2 emission limit); 1 = mass-
StorageLosses: 1 # Energy Share Requirement and CO2 constraints account for energy lost; 0 = not active (DO NOT account for energy lost); 1 = active systemwide (DO account for energy lost)
MinCapReq: 1 # Activate minimum technology carveout constraints; 0 = not active; 1 = active
MaxCapReq: 0 # Activate maximum technology carveout constraints; 0 = not active; 1 = active
ParameterScale: 1 # Turn on parameter scaling wherein demand, capacity and power variables are defined in GW rather than MW. 0 = not active; 1 = active systemwide
WriteShadowPrices: 1 # Write shadow prices of LP or relaxed MILP; 0 = not active; 1 = active
UCommit: 2 # Unit committment of thermal power plants; 0 = not active; 1 = active using integer clestering; 2 = active using linearized clustering
TimeDomainReduction: 1 # Time domain reduce (i.e. cluster) inputs based on Demand_data.csv, Generators_variability.csv, and Fuels_data.csv; 0 = not active (use input data as provided); 0 = active (cluster input data, or use data that has already been clustered)
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ CO2Cap: 2 # CO2 emissions cap; 0 = not active (no CO2 emission limit); 1 = mass-
StorageLosses: 1 # Energy Share Requirement and CO2 constraints account for energy lost; 0 = not active (DO NOT account for energy lost); 1 = active systemwide (DO account for energy lost)
MinCapReq: 1 # Activate minimum technology carveout constraints; 0 = not active; 1 = active
MaxCapReq: 1 # Activate maximum technology carveout constraints; 0 = not active; 1 = active
ParameterScale: 1 # Turn on parameter scaling wherein demand, capacity and power variables are defined in GW rather than MW. 0 = not active; 1 = active systemwide
WriteShadowPrices: 1 # Write shadow prices of LP or relaxed MILP; 0 = not active; 1 = active
UCommit: 2 # Unit committment of thermal power plants; 0 = not active; 1 = active using integer clestering; 2 = active using linearized clustering
TimeDomainReduction: 1 # Time domain reduce (i.e. cluster) inputs based on Demand_data.csv, Generators_variability.csv, and Fuels_data.csv; 0 = not active (use input data as provided); 0 = active (cluster input data, or use data that has already been clustered)
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ CO2Cap: 2 # CO2 emissions cap; 0 = not active (no CO2 emission limit); 1 = mass-
StorageLosses: 1 # Energy Share Requirement and CO2 constraints account for energy lost; 0 = not active (DO NOT account for energy lost); 1 = active systemwide (DO account for energy lost)
MinCapReq: 1 # Activate minimum technology carveout constraints; 0 = not active; 1 = active
MaxCapReq: 0 # Activate maximum technology carveout constraints; 0 = not active; 1 = active
ParameterScale: 1 # Turn on parameter scaling wherein demand, capacity and power variables are defined in GW rather than MW. 0 = not active; 1 = active systemwide
WriteShadowPrices: 1 # Write shadow prices of LP or relaxed MILP; 0 = not active; 1 = active
UCommit: 2 # Unit committment of thermal power plants; 0 = not active; 1 = active using integer clestering; 2 = active using linearized clustering
TimeDomainReduction: 1 # Time domain reduce (i.e. cluster) inputs based on Demand_data.csv, Generators_variability.csv, and Fuels_data.csv; 0 = not active (use input data as provided); 0 = active (cluster input data, or use data that has already been clustered)
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ CO2Cap: 2 # CO2 emissions cap; 0 = not active (no CO2 emission limit); 1 = mass-
StorageLosses: 1 # Energy Share Requirement and CO2 constraints account for energy lost; 0 = not active (DO NOT account for energy lost); 1 = active systemwide (DO account for energy lost)
MinCapReq: 0 # Activate minimum technology carveout constraints; 0 = not active; 1 = active
MaxCapReq: 0 # Activate maximum technology carveout constraints; 0 = not active; 1 = active
ParameterScale: 1 # Turn on parameter scaling wherein demand, capacity and power variables are defined in GW rather than MW. 0 = not active; 1 = active systemwide
UCommit: 2 # Unit committment of thermal power plants; 0 = not active; 1 = active using integer clestering; 2 = active using linearized clustering
TimeDomainReduction: 1 # Time domain reduce (i.e. cluster) inputs based on Demand_data.csv, Generators_variability.csv, and Fuels_data.csv; 0 = not active (use input data as provided); 0 = active (cluster input data, or use data that has already been clustered)
MultiStage: 1 # 0 = Single-stage GenX, 1 = Multi-stage GenX
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
ParameterScale: 1
NetworkExpansion: 1
Trans_Loss_Segments: 1
UCommit: 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ Trans_Loss_Segments: 1 # Number of segments used in piecewise linear approximati
UCommit: 2 # Unit committment of thermal power plants; 0 = not active; 1 = active using integer clestering; 2 = active using linearized clustering
StorageLosses: 1 # Energy Share Requirement and CO2 constraints account for energy lost; 0 = not active (DO NOT account for energy lost); 1 = active systemwide (DO account for energy lost)
HydrogenHourlyMatching: 0 # Hydrogen electrolyzer hourly supply matching required
ParameterScale: 0 # Turn on parameter scaling wherein demand, capacity and power variables are defined in GW rather than MW. 0 = not active; 1 = active systemwide
TimeDomainReduction: 0 # Time domain reduce (i.e. cluster) inputs based on Demand_data.csv, Generators_variability.csv, and Fuels_data.csv; 0 = not active (use input data as provided); 0 = active (cluster input data, or use data that has already been clustered)
WriteShadowPrices: 1 # Write shadow prices of LP or relaxed MILP; 0 = not active; 1 = active
HydrogenMinimumProduction: 1 # Hydrogen production requirement; 0 = not active; 1 = active, meet regional level H2 production requirements
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ CO2Cap: 2 # CO2 emissions cap; 0 = not active (no CO2 emission limit); 1 = mass-
StorageLosses: 1 # Energy Share Requirement and CO2 constraints account for energy lost; 0 = not active (DO NOT account for energy lost); 1 = active systemwide (DO account for energy lost)
MinCapReq: 1 # Activate minimum technology carveout constraints; 0 = not active; 1 = active
MaxCapReq: 0 # Activate maximum technology carveout constraints; 0 = not active; 1 = active
ParameterScale: 1 # Turn on parameter scaling wherein demand, capacity and power variables are defined in GW rather than MW. 0 = not active; 1 = active systemwide
WriteShadowPrices: 1 # Write shadow prices of LP or relaxed MILP; 0 = not active; 1 = active
UCommit: 2 # Unit committment of thermal power plants; 0 = not active; 1 = active using integer clestering; 2 = active using linearized clustering
TimeDomainReduction: 1 # Time domain reduce (i.e. cluster) inputs based on Demand_data.csv, Generators_variability.csv, and Fuels_data.csv; 0 = not active (use input data as provided); 0 = active (cluster input data, or use data that has already been clustered)
1 change: 0 additions & 1 deletion precompile/case/settings/genx_settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ Trans_Loss_Segments: 1
CO2Cap: 2
StorageLosses: 1
MinCapReq: 1
ParameterScale: 1
WriteShadowPrices: 1
UCommit: 2
OverwriteResults: 1
8 changes: 1 addition & 7 deletions src/GenX.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,10 @@ using RecursiveArrayTools
using Statistics
using HiGHS
using Logging
using MacroEnergySystemsScaling

using PrecompileTools: @compile_workload

# Global scaling factor used when ParameterScale is on to shift values from MW to GW
# DO NOT CHANGE THIS (Unless you do so very carefully)
# To translate MW to GW, divide by ModelScalingFactor
# To translate $ to $M, multiply by ModelScalingFactor^2
# To translate $/MWh to $M/GWh, multiply by ModelScalingFactor
const ModelScalingFactor = 1e+3

"""
An abstract type that should be subtyped for users creating GenX resources.
"""
Expand Down
5 changes: 5 additions & 0 deletions src/case_runners/case_runner.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ function run_genx_case_simple!(case::AbstractString, mysetup::Dict, optimizer::A
println("Time elapsed for model building is")
println(time_elapsed)

if mysetup["AutoScaling"] == 1
println("Scaling Constraints")
scale_constraints!(EP, mysetup["ScalingSettings"])
end

println("Solving Model")
EP, solve_time = solve_model(EP, mysetup)
myinputs["solve_time"] = solve_time # Store the model solve time in myinputs
Expand Down
6 changes: 4 additions & 2 deletions src/configure_settings/configure_settings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ function default_settings()
"VirtualChargeDischargeCost" => 1, # $/MWh
"MinCapReq" => 0,
"MaxCapReq" => 0,
"ParameterScale" => 0,
"WriteShadowPrices" => 0,
"UCommit" => 0,
"TimeDomainReduction" => 0,
Expand All @@ -36,7 +35,8 @@ function default_settings()
"ResourcePoliciesFolder" => "policy_assignments",
"SystemFolder" => "system",
"PoliciesFolder" => "policies",
"ObjScale" => 1)
"ObjScale" => 1,
"AutoScaling" => 0,)
end

@doc raw"""
Expand All @@ -60,6 +60,8 @@ function configure_settings(settings_path::String, output_settings_path::String)
settings = default_settings()
merge!(settings, model_settings)

settings["ScalingSettings"] = get_scaling_settings(settings)

output_settings = configure_writeoutput(output_settings_path, settings)
settings["WriteOutputsSettingsDict"] = output_settings

Expand Down
4 changes: 2 additions & 2 deletions src/load_inputs/load_cap_reserve_margin.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
Read input parameters related to planning reserve margin constraints
"""
function load_cap_reserve_margin!(setup::Dict, path::AbstractString, inputs::Dict)
scale_factor = setup["ParameterScale"] == 1 ? ModelScalingFactor : 1


filename = "Capacity_reserve_margin_slack.csv"
if isfile(joinpath(path, filename))
df = load_dataframe(joinpath(path, filename))
inputs["dfCapRes_slack"] = df
inputs["dfCapRes_slack"][!, :PriceCap] ./= scale_factor # Million $/GW if scaled, $/MW if not scaled

end

filename = "Capacity_reserve_margin.csv"
Expand Down
7 changes: 3 additions & 4 deletions src/load_inputs/load_co2_cap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
Read input parameters related to CO$_2$ emissions cap constraints
"""
function load_co2_cap!(setup::Dict, path::AbstractString, inputs::Dict)
scale_factor = setup["ParameterScale"] == 1 ? ModelScalingFactor : 1


filename = "CO2_cap_slack.csv"
if isfile(joinpath(path, filename))
df = load_dataframe(joinpath(path, filename))
inputs["dfCO2Cap_slack"] = df
inputs["dfCO2Cap_slack"][!, :PriceCap] ./= scale_factor # Million $/kton if scaled, $/ton if not scaled

end

filename = "CO2_cap.csv"
Expand All @@ -28,12 +28,11 @@ function load_co2_cap!(setup::Dict, path::AbstractString, inputs::Dict)
# when scaled, the constraint unit is kton
# when not scaled, the constraint unit is ton
mat = extract_matrix_from_dataframe(df, "CO_2_Max_Mtons")
inputs["dfMaxCO2"] = mat * 1e6 / scale_factor
inputs["dfMaxCO2"] = mat * 1e6

elseif setup["CO2Cap"] == 2 || setup["CO2Cap"] == 3
# CO2 emissions rate applied per MWh
mat = extract_matrix_from_dataframe(df, "CO_2_Max_tons_MWh")
# no scale_factor is needed since this is a ratio
inputs["dfMaxCO2Rate"] = mat
end

Expand Down
6 changes: 3 additions & 3 deletions src/load_inputs/load_demand_data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ function load_demand_data!(setup::Dict, path::AbstractString, inputs::Dict)
inputs["INTERIOR_SUBPERIODS"] = setdiff(1:T, inputs["START_SUBPERIODS"]) # set of indexes for all time periods that do not start a subperiod

# Demand in MW for each zone
scale_factor = setup["ParameterScale"] == 1 ? ModelScalingFactor : 1

# Max value of non-served energy
inputs["Voll"] = as_vector(:Voll) / scale_factor # convert from $/MWh $ million/GWh (assuming objective is divided by 1000)
inputs["Voll"] = as_vector(:Voll) # convert from $/MWh $ million/GWh (assuming objective is divided by 1000)
# Demand in MW
inputs["pD"] = extract_matrix_from_dataframe(demand_in,
DEMAND_COLUMN_PREFIX()[1:(end - 1)],
prefixseparator = 'z') / scale_factor
prefixseparator = 'z')

# Cost of non-served energy/demand curtailment
# Cost of each segment reported as a fraction of value of non-served energy - scaled implicitly
Expand Down
4 changes: 2 additions & 2 deletions src/load_inputs/load_energy_share_requirement.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ Read input parameters related to minimum energy share requirement constraints
(e.g. renewable portfolio standard or clean electricity standard policies)
"""
function load_energy_share_requirement!(setup::Dict, path::AbstractString, inputs::Dict)
scale_factor = setup["ParameterScale"] == 1 ? ModelScalingFactor : 1


filename = "Energy_share_requirement_slack.csv"
if isfile(joinpath(path, filename))
df = load_dataframe(joinpath(path, filename))
inputs["dfESR_slack"] = df
inputs["dfESR_slack"][!, :PriceCap] ./= scale_factor # million $/GWh if scaled, $/MWh if not scaled

end

filename = "Energy_share_requirement.csv"
Expand Down
4 changes: 2 additions & 2 deletions src/load_inputs/load_fuels_data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ function load_fuels_data!(setup::Dict, path::AbstractString, inputs::Dict)
fuel_costs = Dict{AbstractString, Array{Float64}}()
fuel_CO2 = Dict{AbstractString, Float64}()

scale_factor = setup["ParameterScale"] == 1 ? ModelScalingFactor : 1


for i in 1:length(fuels)
# fuel cost is in $/MMBTU w/o scaling, $/Billon BTU w/ scaling
fuel_costs[fuels[i]] = costs[:, i] / scale_factor
fuel_costs[fuels[i]] = costs[:, i]
# No need to scale fuel_CO2, fuel_CO2 is ton/MMBTU or kton/Billion BTU
fuel_CO2[fuels[i]] = CO2_content[i]
end
Expand Down
4 changes: 2 additions & 2 deletions src/load_inputs/load_hydrogen_demand.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ function load_hydrogen_demand!(setup::Dict, path::AbstractString, inputs::Dict)
inputs["NumberOfH2DemandReqs"] = nrow(df)
inputs["H2DemandReq"] = df[!, :Hydrogen_Demand_kt]

scale_factor = setup["ParameterScale"] == 1 ? ModelScalingFactor : 1 # Million $/kton if scaled, $/ton if not scaled
# Million $/kton if scaled, $/ton if not scaled

if "PriceCap" in names(df)
inputs["H2DemandPriceCap"] = df[!, :PriceCap] / scale_factor
inputs["H2DemandPriceCap"] = df[!, :PriceCap]
end
println(filename * " Successfully Read!")
end
4 changes: 1 addition & 3 deletions src/load_inputs/load_inputs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ function load_inputs(setup::Dict, path::AbstractString)
end

# Virtual charge discharge cost
scale_factor = setup["ParameterScale"] == 1 ? ModelScalingFactor : 1
inputs["VirtualChargeDischargeCost"] = setup["VirtualChargeDischargeCost"] /
scale_factor
inputs["VirtualChargeDischargeCost"] = setup["VirtualChargeDischargeCost"]

println("CSV Files Successfully Read In From $path")

Expand Down
Loading
Loading