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

771 bugerror writing cost when we have resources that are not new build and not eligible for retirement #796

Merged
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ charge and storage variables (#760 and #763).
the charging capacity of the storage component in VRE_STOR (#770).
- Update `getproperty` function for vectors of resources to ensure compatibility
with Julia v1.11 (#785).
- Fixed cost calculation in `write_costs.jl` when no resources are present in
a zone. (#796)

## [0.4.1] - 2024-08-20

Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "GenX"
uuid = "5d317b1e-30ec-4ed6-a8ce-8d2d88d7cfac"
authors = ["Bonaldo, Luca", "Chakrabarti, Sambuddha", "Cheng, Fangwei", "Ding, Yifu", "Jenkins, Jesse D.", "Luo, Qian", "Macdonald, Ruaridh", "Mallapragada, Dharik", "Manocha, Aneesha", "Mantegna, Gabe ", "Morris, Jack", "Patankar, Neha", "Pecci, Filippo", "Schwartz, Aaron", "Schwartz, Jacob", "Schivley, Greg", "Sepulveda, Nestor", "Xu, Qingyu", "Zhou, Justin"]
version = "0.4.1-dev.14"
version = "0.4.1-dev.15"

[deps]
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
Expand Down
2 changes: 1 addition & 1 deletion src/write_outputs/write_costs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ function write_costs(path::AbstractString, inputs::Dict, setup::Dict, EP::Model)
ELECTROLYZERS_ZONE = intersect(inputs["ELECTROLYZER"], Y_ZONE)
CCS_ZONE = intersect(inputs["CCS"], Y_ZONE)

eCFix = sum(value.(EP[:eCFix][Y_ZONE]))
eCFix = sum(value.(EP[:eCFix][Y_ZONE]), init = 0.0)
tempCFix += eCFix
tempCTotal += eCFix

Expand Down
77 changes: 77 additions & 0 deletions test/writing_outputs/test_zone_no_resources.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
module TestZoneNoResources

using Test
using DataFrames

include(joinpath(@__DIR__, "../utilities.jl"))

function prepare_costs_test(test_path, inputs, genx_setup, EP)
settings = GenX.default_settings()
merge!(settings, genx_setup)
GenX.write_costs(test_path, inputs, settings, EP)
costs_path = joinpath(test_path, "costs.csv")
costs_test = CSV.read(costs_path, DataFrame)
costs_test[!, :Zone1] = tryparse.(Float64, replace(costs_test[!, :Zone1], "-" => "0.0"))
costs_test[!, :Zone2] = tryparse.(Float64, replace(costs_test[!, :Zone2], "-" => "0.0"))
costs_test[!, :Zone2] = replace(costs_test[!, :Zone2], nothing => 0.0)
return costs_test
end

function prepare_costs_true()
df = DataFrame(
["cTotal" 5.177363815260002e12 4.027191550200002e12 1.1501722650599993e12;
"cFix" 0.0 0.0 0.0;
"cVar" 5.849292224195126e-8 0.0 5.849292224195126e-8;
"cFuel" 0.0 0.0 0.0;
"cNSE" 5.177363815260002e12 4.027191550200002e12 1.1501722650599993e12;
"cStart" 0.0 0.0 0.0;
"cUnmetRsv" 0.0 0.0 0.0;
"cNetworkExp" 0.0 0.0 0.0;
"cUnmetPolicyPenalty" 0.0 0.0 0.0;
"cCO2" 0.0 0.0 0.0],
[:Costs, :Total, :Zone1, :Zone2])

df[!, :Costs] = convert(Vector{String}, df[!, :Costs])
df[!, :Total] = convert(Vector{Float64}, df[!, :Total])
df[!, :Zone1] = convert(Vector{Float64}, df[!, :Zone1])
df[!, :Zone2] = convert(Vector{Float64}, df[!, :Zone2])
return df
end

function test_case()
test_path = joinpath(@__DIR__, "zone_no_resources")
obj_true = 5.1773638153e12
costs_true = prepare_costs_true()

# Define test setup
genx_setup = Dict("NetworkExpansion" => 1,
"Trans_Loss_Segments" => 1,
"UCommit" => 2,
"CO2Cap" => 2,
"StorageLosses" => 1,
"WriteShadowPrices" => 1)

# Run the case and get the objective value and tolerance
EP, inputs, _ = redirect_stdout(devnull) do
run_genx_case_testing(test_path, genx_setup)
end
obj_test = objective_value(EP)
optimal_tol_rel = get_attribute(EP, "dual_feasibility_tolerance")
optimal_tol = optimal_tol_rel * obj_test # Convert to absolute tolerance

# Test the objective value
test_result = @test obj_test≈obj_true atol=optimal_tol

# Test the costs
costs_test = prepare_costs_test(test_path, inputs, genx_setup, EP)
test_result = @test costs_test[!, Not(:Costs)] ≈ costs_true[!, Not(:Costs)]

# Remove the costs file
rm(joinpath(test_path, "costs.csv"))

return nothing
end

test_case()

end # module TestZoneNoResources
11 changes: 11 additions & 0 deletions test/writing_outputs/zone_no_resources/highs_settings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# HiGHS Solver Parameters
# Common solver settings
Feasib_Tol: 1.0e-05 # Primal feasibility tolerance # [type: double, advanced: false, range: [1e-10, inf], default: 1e-07]
Optimal_Tol: 1.0e-05 # Dual feasibility tolerance # [type: double, advanced: false, range: [1e-10, inf], default: 1e-07]
TimeLimit: 1.0e23 # Time limit # [type: double, advanced: false, range: [0, inf], default: inf]
Pre_Solve: choose # Presolve option: "off", "choose" or "on" # [type: string, advanced: false, default: "choose"]
Method: ipm #HiGHS-specific solver settings # Solver option: "simplex", "choose" or "ipm" # [type: string, advanced: false, default: "choose"]

# run the crossover routine for ipx
# [type: string, advanced: "on", range: {"off", "on"}, default: "off"]
run_crossover: "on"
3 changes: 3 additions & 0 deletions test/writing_outputs/zone_no_resources/policies/CO2_cap.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
,Network_zones,CO_2_Cap_Zone_1,CO_2_Cap_Zone_2,CO_2_Max_tons_MWh_1,CO_2_Max_tons_MWh_2,CO_2_Max_Mtons_1,CO_2_Max_Mtons_2
MA,z1,1,0,0.05,0,0.018,0
CT,z2,0,1,0,0.05,0,0.025
2 changes: 2 additions & 0 deletions test/writing_outputs/zone_no_resources/resources/Storage.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Resource,Zone,Model,New_Build,Can_Retire,Existing_Cap_MW,Existing_Cap_MWh,Max_Cap_MW,Max_Cap_MWh,Min_Cap_MW,Min_Cap_MWh,Inv_Cost_per_MWyr,Inv_Cost_per_MWhyr,Fixed_OM_Cost_per_MWyr,Fixed_OM_Cost_per_MWhyr,Var_OM_Cost_per_MWh,Var_OM_Cost_per_MWh_In,Self_Disch,Eff_Up,Eff_Down,Min_Duration,Max_Duration,Reg_Max,Rsv_Max,Reg_Cost,Rsv_Cost,region,cluster
CT_battery,2,1,1,0,0,0,-1,-1,0,0,19584,22494,4895,5622,0.15,0.15,0,0.92,0.92,1,10,0,0,0,0,CT,0
2 changes: 2 additions & 0 deletions test/writing_outputs/zone_no_resources/resources/Thermal.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Resource,Zone,Model,New_Build,Can_Retire,Existing_Cap_MW,Max_Cap_MW,Min_Cap_MW,Inv_Cost_per_MWyr,Fixed_OM_Cost_per_MWyr,Var_OM_Cost_per_MWh,Heat_Rate_MMBTU_per_MWh,Fuel,Cap_Size,Start_Cost_per_MW,Start_Fuel_MMBTU_per_MW,Up_Time,Down_Time,Ramp_Up_Percentage,Ramp_Dn_Percentage,Min_Power,Reg_Max,Rsv_Max,Reg_Cost,Rsv_Cost,region,cluster
CT_natural_gas_combined_cycle,2,1,1,0,0,-1,0,65400,10287,3.55,7.43,CT_NG,250,91,2,6,6,0.64,0.64,0.468,0.25,0.5,0,0,CT,1
3 changes: 3 additions & 0 deletions test/writing_outputs/zone_no_resources/resources/Vre.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Resource,Zone,Num_VRE_Bins,New_Build,Can_Retire,Existing_Cap_MW,Max_Cap_MW,Min_Cap_MW,Inv_Cost_per_MWyr,Fixed_OM_Cost_per_MWyr,Var_OM_Cost_per_MWh,Reg_Max,Rsv_Max,Reg_Cost,Rsv_Cost,region,cluster
CT_onshore_wind,2,1,0,0,0,-1,0,97200,43205,0.1,0,0,0,0,CT,1
CT_solar_pv,2,1,0,0,0,-1,0,85300,18760,0,0,0,0,0,CT,1
121 changes: 121 additions & 0 deletions test/writing_outputs/zone_no_resources/system/Demand_data.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
Voll,Demand_Segment,Cost_of_Demand_Curtailment_per_MW,Max_Demand_Curtailment,$/MWh,Rep_Periods,Timesteps_per_Rep_Period,Sub_Weights,Time_Index,Demand_MW_z1,Demand_MW_z2
50000,1,1.0,1.0,2000,5,24,24.0,1,7822.0,2234.0
,2,0.9,0.04,1800,,,2592.0,2,7494.0,2140.0
,3,0.55,0.024,1100,,,6096.0,3,7343.0,2097.0
,4,0.2,0.003,400,,,24.0,4,7289.0,2082.0
,,,,,,,24.0,5,7482.0,2137.0
,,,,,,,,6,8142.0,2325.0
,,,,,,,,7,9388.0,2681.0
,,,,,,,,8,10233.0,2922.0
,,,,,,,,9,10494.0,2997.0
,,,,,,,,10,10665.0,3046.0
,,,,,,,,11,10780.0,3079.0
,,,,,,,,12,10817.0,3089.0
,,,,,,,,13,10743.0,3068.0
,,,,,,,,14,10657.0,3044.0
,,,,,,,,15,10516.0,3003.0
,,,,,,,,16,10468.0,2990.0
,,,,,,,,17,10788.0,3081.0
,,,,,,,,18,11254.0,3214.0
,,,,,,,,19,11088.0,3167.0
,,,,,,,,20,10715.0,3060.0
,,,,,,,,21,10312.0,2945.0
,,,,,,,,22,9767.0,2790.0
,,,,,,,,23,9041.0,2582.0
,,,,,,,,24,8305.0,2372.0
,,,,,,,,25,7611.0,2174.0
,,,,,,,,26,7284.0,2080.0
,,,,,,,,27,7110.0,2031.0
,,,,,,,,28,7082.0,2023.0
,,,,,,,,29,7266.0,2075.0
,,,,,,,,30,7941.0,2268.0
,,,,,,,,31,9190.0,2625.0
,,,,,,,,32,9935.0,2837.0
,,,,,,,,33,10145.0,2897.0
,,,,,,,,34,10199.0,2913.0
,,,,,,,,35,10213.0,2917.0
,,,,,,,,36,10135.0,2895.0
,,,,,,,,37,9964.0,2845.0
,,,,,,,,38,9842.0,2811.0
,,,,,,,,39,9677.0,2764.0
,,,,,,,,40,9588.0,2739.0
,,,,,,,,41,9757.0,2786.0
,,,,,,,,42,10423.0,2976.0
,,,,,,,,43,10732.0,3065.0
,,,,,,,,44,10465.0,2989.0
,,,,,,,,45,10112.0,2888.0
,,,,,,,,46,9608.0,2744.0
,,,,,,,,47,8902.0,2543.0
,,,,,,,,48,8169.0,2333.0
,,,,,,,,49,7338.0,2096.0
,,,,,,,,50,6938.0,1982.0
,,,,,,,,51,6751.0,1928.0
,,,,,,,,52,6676.0,1907.0
,,,,,,,,53,6840.0,1953.0
,,,,,,,,54,7300.0,2085.0
,,,,,,,,55,8454.0,2414.0
,,,,,,,,56,9469.0,2704.0
,,,,,,,,57,10006.0,2858.0
,,,,,,,,58,10341.0,2954.0
,,,,,,,,59,10626.0,3035.0
,,,,,,,,60,10780.0,3079.0
,,,,,,,,61,10849.0,3099.0
,,,,,,,,62,10977.0,3135.0
,,,,,,,,63,10950.0,3127.0
,,,,,,,,64,10892.0,3111.0
,,,,,,,,65,10868.0,3104.0
,,,,,,,,66,10767.0,3075.0
,,,,,,,,67,10550.0,3013.0
,,,,,,,,68,10414.0,2974.0
,,,,,,,,69,10478.0,2992.0
,,,,,,,,70,10018.0,2861.0
,,,,,,,,71,9029.0,2579.0
,,,,,,,,72,8087.0,2309.0
,,,,,,,,73,10503.0,3000.0
,,,,,,,,74,9889.0,2825.0
,,,,,,,,75,9493.0,2711.0
,,,,,,,,76,9245.0,2640.0
,,,,,,,,77,9268.0,2647.0
,,,,,,,,78,9643.0,2754.0
,,,,,,,,79,10684.0,3051.0
,,,,,,,,80,12036.0,3437.0
,,,,,,,,81,13120.0,3747.0
,,,,,,,,82,14080.0,4021.0
,,,,,,,,83,14910.0,4258.0
,,,,,,,,84,15478.0,4421.0
,,,,,,,,85,15870.0,4533.0
,,,,,,,,86,16225.0,4633.0
,,,,,,,,87,16448.0,4698.0
,,,,,,,,88,16617.0,4746.0
,,,,,,,,89,16717.0,4774.0
,,,,,,,,90,16579.0,4735.0
,,,,,,,,91,16199.0,4626.0
,,,,,,,,92,15701.0,4484.0
,,,,,,,,93,15416.0,4403.0
,,,,,,,,94,14854.0,4243.0
,,,,,,,,95,13581.0,3878.0
,,,,,,,,96,12317.0,3518.0
,,,,,,,,97,7899.0,2256.0
,,,,,,,,98,7613.0,2174.0
,,,,,,,,99,7477.0,2135.0
,,,,,,,,100,7470.0,2134.0
,,,,,,,,101,7699.0,2199.0
,,,,,,,,102,8428.0,2407.0
,,,,,,,,103,9761.0,2787.0
,,,,,,,,104,10471.0,2991.0
,,,,,,,,105,10643.0,3040.0
,,,,,,,,106,10719.0,3061.0
,,,,,,,,107,10802.0,3085.0
,,,,,,,,108,10835.0,3095.0
,,,,,,,,109,10820.0,3090.0
,,,,,,,,110,10811.0,3087.0
,,,,,,,,111,10750.0,3070.0
,,,,,,,,112,10888.0,3110.0
,,,,,,,,113,11635.0,3323.0
,,,,,,,,114,12129.0,3464.0
,,,,,,,,115,12036.0,3437.0
,,,,,,,,116,11714.0,3346.0
,,,,,,,,117,11207.0,3201.0
,,,,,,,,118,10396.0,2969.0
,,,,,,,,119,9383.0,2680.0
,,,,,,,,120,8476.0,2420.0
122 changes: 122 additions & 0 deletions test/writing_outputs/zone_no_resources/system/Fuels_data.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
Time_Index,CT_NG,None
0,0.05306,0.0
1,5.45,0.0
2,5.45,0.0
3,5.45,0.0
4,5.45,0.0
5,5.45,0.0
6,5.45,0.0
7,5.45,0.0
8,5.45,0.0
9,5.45,0.0
10,5.45,0.0
11,5.45,0.0
12,5.45,0.0
13,5.45,0.0
14,5.45,0.0
15,5.45,0.0
16,5.45,0.0
17,5.45,0.0
18,5.45,0.0
19,5.45,0.0
20,5.45,0.0
21,5.45,0.0
22,5.45,0.0
23,5.45,0.0
24,5.45,0.0
25,4.09,0.0
26,4.09,0.0
27,4.09,0.0
28,4.09,0.0
29,4.09,0.0
30,4.09,0.0
31,4.09,0.0
32,4.09,0.0
33,4.09,0.0
34,4.09,0.0
35,4.09,0.0
36,4.09,0.0
37,4.09,0.0
38,4.09,0.0
39,4.09,0.0
40,4.09,0.0
41,4.09,0.0
42,4.09,0.0
43,4.09,0.0
44,4.09,0.0
45,4.09,0.0
46,4.09,0.0
47,4.09,0.0
48,4.09,0.0
49,1.82,0.0
50,1.82,0.0
51,1.82,0.0
52,1.82,0.0
53,1.82,0.0
54,1.82,0.0
55,1.82,0.0
56,1.82,0.0
57,1.82,0.0
58,1.82,0.0
59,1.82,0.0
60,1.82,0.0
61,1.82,0.0
62,1.82,0.0
63,1.82,0.0
64,1.82,0.0
65,1.82,0.0
66,1.82,0.0
67,1.82,0.0
68,1.82,0.0
69,1.82,0.0
70,1.82,0.0
71,1.82,0.0
72,1.82,0.0
73,1.89,0.0
74,1.89,0.0
75,1.89,0.0
76,1.89,0.0
77,1.89,0.0
78,1.89,0.0
79,1.89,0.0
80,1.89,0.0
81,1.89,0.0
82,1.89,0.0
83,1.89,0.0
84,1.89,0.0
85,1.89,0.0
86,1.89,0.0
87,1.89,0.0
88,1.89,0.0
89,1.89,0.0
90,1.89,0.0
91,1.89,0.0
92,1.89,0.0
93,1.89,0.0
94,1.89,0.0
95,1.89,0.0
96,1.89,0.0
97,2.78,0.0
98,2.78,0.0
99,2.78,0.0
100,2.78,0.0
101,2.78,0.0
102,2.78,0.0
103,2.78,0.0
104,2.78,0.0
105,2.78,0.0
106,2.78,0.0
107,2.78,0.0
108,2.78,0.0
109,2.78,0.0
110,2.78,0.0
111,2.78,0.0
112,2.78,0.0
113,2.78,0.0
114,2.78,0.0
115,2.78,0.0
116,2.78,0.0
117,2.78,0.0
118,2.78,0.0
119,2.78,0.0
120,2.78,0.0
Loading
Loading