From 0b55091a0f35b79593c96df491d51655ae286a0b Mon Sep 17 00:00:00 2001 From: Ana Mileva Date: Tue, 1 Mar 2022 11:31:59 -0800 Subject: [PATCH] Write subproblem directory if 1 subproblem w stages --- gridpath/auxiliary/scenario_chars.py | 1 - gridpath/get_scenario_inputs.py | 6 +++++- gridpath/run_scenario.py | 12 +++++++++--- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/gridpath/auxiliary/scenario_chars.py b/gridpath/auxiliary/scenario_chars.py index 55744a503..1446f06b6 100644 --- a/gridpath/auxiliary/scenario_chars.py +++ b/gridpath/auxiliary/scenario_chars.py @@ -159,7 +159,6 @@ def get_subproblem_structure_from_disk(scenario_directory): # If we have subproblems, check for stage subdirectories for each # subproblem directory if subproblem_directories: - all_subproblems = subproblem_directories for subproblem in subproblem_directories: subproblem_dir = os.path.join(scenario_directory, str(subproblem)) # Convert to integers diff --git a/gridpath/get_scenario_inputs.py b/gridpath/get_scenario_inputs.py index 9786c7449..ebf6c99f3 100644 --- a/gridpath/get_scenario_inputs.py +++ b/gridpath/get_scenario_inputs.py @@ -50,6 +50,7 @@ def write_model_inputs( scenario_directory, subproblem_structure, + multi_stage, modules_to_use, scenario_id, subscenarios, @@ -81,7 +82,9 @@ def write_model_inputs( delete_prior_aux_files(scenario_directory=scenario_directory) # Determine whether we will have subproblem directories - if len(subproblem_structure.SUBPROBLEM_STAGES) == 1: + # We write the subproblem directories if we have multiple subproblems or if we + # have a single subroblem with stages (the multi_stage flag will be True) + if len(subproblem_structure.SUBPROBLEM_STAGES) == 1 and multi_stage is False: make_subproblem_directories = False else: make_subproblem_directories = True @@ -495,6 +498,7 @@ def main(args=None): write_model_inputs( scenario_directory=scenario_directory, subproblem_structure=subproblem_structure, + multi_stage=stages_flag, modules_to_use=modules_to_use, scenario_id=scenario_id, subscenarios=subscenarios, diff --git a/gridpath/run_scenario.py b/gridpath/run_scenario.py index 0c8203ca3..d8aa82b8f 100644 --- a/gridpath/run_scenario.py +++ b/gridpath/run_scenario.py @@ -255,9 +255,15 @@ def run_optimization_for_subproblem( Check if there are stages in the subproblem; if not solve subproblem; if, yes, solve each stage sequentially """ - # If we only have a single subproblem, set the subproblem_string to an - # empty string (no directory created) - if list(subproblem_structure.SUBPROBLEM_STAGES.keys()) == [1]: + + # If we only have a single subproblem AND it does not have stages, set the + # subproblem_string to an empty string (the subproblem directory should not + # have been created) + # If we have multiple subproblems or a single subproblems with stages, + # we're expecting a subproblem directory + if list(subproblem_structure.SUBPROBLEM_STAGES.keys()) == [ + 1 + ] and subproblem_structure.SUBPROBLEM_STAGES[subproblem] == [1]: subproblem_directory = "" else: subproblem_directory = str(subproblem)