From d6afe783eb69b9cf3d59fef3d246519aa3ad8c70 Mon Sep 17 00:00:00 2001 From: "Schleifer, Anna" Date: Mon, 5 Oct 2026 23:08:46 -0600 Subject: [PATCH 1/3] Fix some run_pcm bugs --- postprocessing/run_pcm.py | 14 ++++++++++++-- runreeds.py | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/postprocessing/run_pcm.py b/postprocessing/run_pcm.py index 1186f1c19..58af5bbd7 100644 --- a/postprocessing/run_pcm.py +++ b/postprocessing/run_pcm.py @@ -1,6 +1,8 @@ # %% Imports import os +import shutil import subprocess +import sys import argparse import json from glob import glob @@ -9,6 +11,7 @@ from pathlib import Path ## Local imports +sys.path.append(str(Path(__file__).parent.parent)) import reeds from reeds.input_processing import hourly_repperiods from reeds.input_processing import hourly_writetimeseries @@ -16,7 +19,7 @@ # %% Inferred inputs -reeds_path = os.path.dirname(__file__) +reeds_path = Path(__file__).parent.parent # %% Default inputs switch_mods_default = { @@ -166,6 +169,7 @@ def main(casepath, t, switch_mods=switch_mods_default, label='', overwrite=False kwargs: Passed to hourly_reppreiods.main() """ # %% Switch to run folder + casepath = os.path.abspath(casepath) os.chdir(casepath) # %% Get the run settings @@ -233,6 +237,12 @@ def main(casepath, t, switch_mods=switch_mods_default, label='', overwrite=False _iteration = iteration restartfile = os.path.join(casepath, 'g00files', f"{batch_case}_{_t}i{_iteration}.g00") + ## 2_temporal_params.gms reads stress{stress_year}/prm.csv even with no stress periods + prm_src = os.path.join(casepath, 'inputs_case', f'stress{_t}i{_iteration}', 'prm.csv') + if not os.path.isfile(prm_src): + prm_src = os.path.join(casepath, 'inputs_case', f'stress{_t}i0', 'prm.csv') + shutil.copy(prm_src, os.path.join(stresspath, 'prm.csv')) + cmd_gams = solvestring_pcm( batch_case=batch_case, sw=sw_pcm, @@ -374,7 +384,7 @@ def main(casepath, t, switch_mods=switch_mods_default, label='', overwrite=False main(casepath=casepath, t=t, switch_mods=switch_mods, label=label, overwrite=overwrite) else: command_string = ( - f"python run_pcm.py {casepath} " + f"python {str(os.path.abspath(__file__))} {casepath} " f"--year={t} " f"--iteration={iteration} " f"--switch_mods='{json.dumps(switch_mods)}' " diff --git a/runreeds.py b/runreeds.py index 1572ce3ef..d517ed388 100644 --- a/runreeds.py +++ b/runreeds.py @@ -1522,7 +1522,7 @@ def write_batch_script( ### Run dispatch mode if desired if int(caseSwitches['pcm']): OPATH.writelines( - f"\npython {Path('reeds','postprocessing','run_pcm.py')} {casedir} -b\n\n" + f"\npython {Path(reeds_path,'postprocessing','run_pcm.py')} {casedir} -b\n\n" ) From 9c8746d74515bbee1caeca5efa05058471fcfcbb Mon Sep 17 00:00:00 2001 From: "Schleifer, Anna" Date: Tue, 6 Oct 2026 19:21:04 -0600 Subject: [PATCH 2/3] Set USA test case to run --- cases_test.csv | 16 ++++++++++------ postprocessing/run_pcm.py | 12 +++++++----- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/cases_test.csv b/cases_test.csv index 805d5829d..2619de13e 100644 --- a/cases_test.csv +++ b/cases_test.csv @@ -1,9 +1,9 @@ -,Default Value,Pacific,USA_defaults,Mid_Case,USA_decarb,github_Pacific,github_Everything,github_MA_county_CC,Pacific_CC,Pacific_weks,Pacific_full_year,Interday_storage,Pacific_2020,Pacific_rep15,WY_county,WECC_county,PJM_county_CC,NYVT_mixed,OR_water,MonteCarlo_Random,MonteCarlo_LHS,Everything,Simple,USA_fast,USA_faster,MultiMetricRA,Pacific_DR,Pacific_MGA,Pacific_MGA_RV,Pacific_LoadSite95,MARICTNYNJPAOH_Offshore,R2P -ignore,1,0,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +,Default Value,Pacific,USA,Mid_Case,USA_decarb,github_Pacific,github_Everything,github_MA_county_CC,Pacific_CC,Pacific_weks,Pacific_full_year,Interday_storage,Pacific_2020,Pacific_rep15,WY_county,WECC_county,PJM_county_CC,NYVT_mixed,OR_water,MonteCarlo_Random,MonteCarlo_LHS,Everything,Simple,USA_fast,USA_faster,MultiMetricRA,Pacific_DR,Pacific_MGA,Pacific_MGA_RV,Pacific_LoadSite95,MARICTNYNJPAOH_Offshore,R2P +ignore,1,,0,,,,,,,,,,,,,,,,,,,,,,,,,,,,, GSw_Region,cendiv/Pacific,,country/USA,country/USA,country/USA,,st/ID.WY.NE.IA.IL,st/MA,,,,,,,st/WY,interconnect/western,transreg/PJM,st/NY.VT,st/OR,st/NE.NY.PA,st/NE.NY.PA,st/ID.WY.NE.IA.IL,st/KS,country/USA,country/USA,st/NY.NJ,,,,,st/MA.RI.CT.NY.NJ.PA.OH, -endyear,2035,,2050,2050,2050,2030,2060,2030,,,,,,,,,,,2035,2030,2030,2060,2035,2050,2050,2050,,,,,, +endyear,2035,,2035,2050,2050,2030,2060,2030,,,,,,,,,,,2035,2030,2030,2060,2035,2050,2050,2050,,,,,, yearset,,,,,,,2010..2060..10,,,,,,,,,,,,,,,2010..2060..10,2010_2015_2020..2050..3,,2010_2025_2050,,,,,,, -GSw_ZoneSet,,,,,,,z54,z3109,,,,,,,z3109,z3109,z3109,PJMcounty,,,,z54,z134,z54,z48,,,,,,, +GSw_ZoneSet,,,z54,,,,z54,z3109,,,,,,,z3109,z3109,z3109,PJMcounty,,,,z54,z134,z54,z48,,,,,,, GSw_GasCurve,2,,1,1,,,,,,,,,,,,,,,,,,,,1,1,,,,,,, GSw_Geothermal,,,,2,,,,,,,,,,,,,,,,,,,0,,0,,,,,,, GSw_GrowthPenalties,,,,1,,,,,,,,,,,,,,,,,,,,,,,,,,,, @@ -42,8 +42,8 @@ GSw_CO2_Detail,,,,,,,1,,,,,,,,,,,,,,,1,,,,,,,,,, GSw_DAC,,,,,,,1,,,,,,,,,,,,,,,1,,,,,,,,,, GSw_NoFossilOffsetCDR,,,,,,,1,,,,,,,,,,,,,,,1,,,,,,,,,, GSw_Biopower,,,,,,,,,,,,,,,,,,,,,,,0,,0,,,,,,, -GSw_HourlyChunkLengthRep,,,,,,,,,,,,,,,,,,,,,,,6,4,4,,,,,,, -GSw_HourlyChunkLengthStress,,,,,,,,,,,,,,,,,,,,,,,6,4,4,,,,,,, +GSw_HourlyChunkLengthRep,,,2,,,,,,,,,,,,,,,,,,,,6,4,4,,,,,,, +GSw_HourlyChunkLengthStress,,,2,,,,,,,,,,,,,,,,,,,,6,4,4,,,,,,, GSw_LfillGas,,,,,,,,,,,,,,,,,,,,,,,0,,0,,,,,,, GSw_Nuclear,,,,,,,,,,,,,,,,,,,,,,,0,,0,,,,,,, GSw_OpRes,,,,,,,,,,,,,,,,,,,,,,,0,,0,,,,,,, @@ -65,3 +65,7 @@ pras_scheduled_outage,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,0 pras_unitsize_source,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,r2x pras_vre_combine,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,1 pras_samples,,,,,,10,10,10,,,,,,,,,,,,,,,,10,10,,,,,,, +pcm,,,1,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +keep_resource_adequacy_files,,,1,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +dump_alldata,,,1,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +keep_g00_files,,,1,,,,,,,,,,,,,,,,,,,,,,,,,,,,, diff --git a/postprocessing/run_pcm.py b/postprocessing/run_pcm.py index 58af5bbd7..4fe50c321 100644 --- a/postprocessing/run_pcm.py +++ b/postprocessing/run_pcm.py @@ -30,6 +30,8 @@ 'GSw_HourlyChunkLengthStress': 1, 'GSw_HourlyChunkAggMethod': 1, 'GSw_PRM_CapCredit': 0, + 'GSw_H2': 0, + 'GSw_H2_PTC': 0 } @@ -237,11 +239,11 @@ def main(casepath, t, switch_mods=switch_mods_default, label='', overwrite=False _iteration = iteration restartfile = os.path.join(casepath, 'g00files', f"{batch_case}_{_t}i{_iteration}.g00") - ## 2_temporal_params.gms reads stress{stress_year}/prm.csv even with no stress periods - prm_src = os.path.join(casepath, 'inputs_case', f'stress{_t}i{_iteration}', 'prm.csv') - if not os.path.isfile(prm_src): - prm_src = os.path.join(casepath, 'inputs_case', f'stress{_t}i0', 'prm.csv') - shutil.copy(prm_src, os.path.join(stresspath, 'prm.csv')) + # ## 2_temporal_params.gms reads stress{stress_year}/prm.csv even with no stress periods + # prm_src = os.path.join(casepath, 'inputs_case', f'stress{_t}i{_iteration}', 'prm.csv') + # if not os.path.isfile(prm_src): + # prm_src = os.path.join(casepath, 'inputs_case', f'stress{_t}i0', 'prm.csv') + # shutil.copy(prm_src, os.path.join(stresspath, 'prm.csv')) cmd_gams = solvestring_pcm( batch_case=batch_case, From 96e543b88b26592980f1bcd11a5c8374ed0e70b0 Mon Sep 17 00:00:00 2001 From: "Schleifer, Anna" Date: Wed, 7 Oct 2026 13:16:04 -0600 Subject: [PATCH 3/3] Fix domain violation errors in run_pcm.py --- postprocessing/run_pcm.py | 17 +++++++++++------ .../input_processing/hourly_writetimeseries.py | 1 + 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/postprocessing/run_pcm.py b/postprocessing/run_pcm.py index 4fe50c321..b00e8ffd2 100644 --- a/postprocessing/run_pcm.py +++ b/postprocessing/run_pcm.py @@ -233,17 +233,22 @@ def main(casepath, t, switch_mods=switch_mods_default, label='', overwrite=False restartfile = batch_case _iteration = 0 elif iteration == 'last': - restartfile = sorted(glob(os.path.join(casepath, 'g00files', f"{batch_case}_{_t}i*")))[-1] + ## Sort numerically so i10 comes after i9 + restartfile = sorted( + glob(os.path.join(casepath, 'g00files', f"{batch_case}_{_t}i*.g00")), + key=lambda x: int(x[: -len('.g00')].split('i')[-1]), + )[-1] _iteration = int(restartfile[: -len('.g00')].split('i')[-1]) else: _iteration = iteration restartfile = os.path.join(casepath, 'g00files', f"{batch_case}_{_t}i{_iteration}.g00") - # ## 2_temporal_params.gms reads stress{stress_year}/prm.csv even with no stress periods - # prm_src = os.path.join(casepath, 'inputs_case', f'stress{_t}i{_iteration}', 'prm.csv') - # if not os.path.isfile(prm_src): - # prm_src = os.path.join(casepath, 'inputs_case', f'stress{_t}i0', 'prm.csv') - # shutil.copy(prm_src, os.path.join(stresspath, 'prm.csv')) + ## 2_temporal_params.gms reads stress{stress_year}/prm.csv even with no stress periods, + ## so use the PRM from the stress folder that the restart solve (_t, _iteration) used + prm_src = os.path.join(casepath, 'inputs_case', f'stress{_t}i{_iteration}', 'prm.csv') + if not os.path.isfile(prm_src): + raise FileNotFoundError(f'PRM file for {_t}i{_iteration} not found: {prm_src}') + shutil.copy(prm_src, os.path.join(stresspath, 'prm.csv')) cmd_gams = solvestring_pcm( batch_case=batch_case, diff --git a/reeds/input_processing/hourly_writetimeseries.py b/reeds/input_processing/hourly_writetimeseries.py index 38eebf141..1061364ad 100644 --- a/reeds/input_processing/hourly_writetimeseries.py +++ b/reeds/input_processing/hourly_writetimeseries.py @@ -1344,6 +1344,7 @@ def main(sw, reeds_path, inputs_case, periodtype='rep', make_plots=1, logging=Tr .assign(h=cf_out.h.map(chunkmap)) .groupby(['i','c','r','h'], as_index=False) .agg(aggmethod, *args) + [['i','c','r','h','cf']] ) load_long = (