From aff9dd392d883e457a801db48bedd9afaf4722b4 Mon Sep 17 00:00:00 2001 From: Michael Anstett Date: Mon, 18 Aug 2025 10:44:54 -0400 Subject: [PATCH 1/9] add scratch dir --- .../prepare_config_and_suite.py | 10 +++++++ src/swell/suites/suite_questions.py | 5 +++- src/swell/tasks/base/task_base.py | 17 +++++++++-- src/swell/utilities/question_defaults.py | 30 +++++++++++++++++++ 4 files changed, 58 insertions(+), 4 deletions(-) diff --git a/src/swell/deployment/prepare_config_and_suite/prepare_config_and_suite.py b/src/swell/deployment/prepare_config_and_suite/prepare_config_and_suite.py index 7b6d756bd..6b846cb92 100644 --- a/src/swell/deployment/prepare_config_and_suite/prepare_config_and_suite.py +++ b/src/swell/deployment/prepare_config_and_suite/prepare_config_and_suite.py @@ -11,6 +11,7 @@ import copy import os import yaml +from random import randint from collections.abc import Mapping from typing import Union, Tuple, Optional @@ -334,6 +335,15 @@ def override_with_defaults(self) -> None: if key == 'experiment_id' and val['default_value'] == 'defer_to_code': val['default_value'] = f'swell-{self.suite}' + if key == 'scratch_id' and val['default_value'] == 'defer_to_code': + experiment_id = self.question_dictionary_model_ind['experiment_id']['default_value'] + if experiment_id == 'defer_to_code': + experiment_id = f'swell-{self.suite}' + self.question_dictionary_model_ind['experiment_id']['default_value'] = experiment_id + + scratch_id = f'{experiment_id}-{randint(0, 99999999):08d}' + val['default_value'] = scratch_id + # ---------------------------------------------------------------------------------------------- def override_with_external(self) -> None: diff --git a/src/swell/suites/suite_questions.py b/src/swell/suites/suite_questions.py index 247bee869..9aea065b5 100644 --- a/src/swell/suites/suite_questions.py +++ b/src/swell/suites/suite_questions.py @@ -40,7 +40,10 @@ class SuiteQuestions(QuestionContainer, Enum): qd.start_cycle_point(), qd.final_cycle_point(), qd.model_components(), - qd.runahead_limit() + qd.runahead_limit(), + qd.run_in_scratch(), + qd.scratch_root(), + qd.scratch_id(), ] ) diff --git a/src/swell/tasks/base/task_base.py b/src/swell/tasks/base/task_base.py index 8479d9a78..8713c8b09 100644 --- a/src/swell/tasks/base/task_base.py +++ b/src/swell/tasks/base/task_base.py @@ -81,6 +81,12 @@ def __init__( self.__platform__ = self.config.__platform__ self.__suite_to_run__ = self.config.__suite_to_run__ + # Scratch directory information + # ----------------------------- + self.__run_in_scratch__ = self.config.__run_in_scratch__ + self.__scratch_root__ = self.config.__scratch_root__ + self.__scratch_id__ = self.config.__scratch_id__ + if datetime_input is not None: self.__start_cycle_point__ = Datetime(self.config.__start_cycle_point__) @@ -143,8 +149,13 @@ def experiment_id(self) -> str: # ---------------------------------------------------------------------------------------------- # Method to get the experiment directory - def experiment_path(self) -> str: - return os.path.join(self.__experiment_root__, self.__experiment_id__) + def experiment_path(self, scratch: bool = True) -> str: + if self.__run_in_scratch__ and scratch: + experiment_path = os.path.join(self.__scratch_root__, self.__scratch_id__) + else: + experiment_path = os.path.join(self.__experiment_root__, self.__experiment_id__) + + return experiment_path # ---------------------------------------------------------------------------------------------- @@ -156,7 +167,7 @@ def platform(self) -> str: # Method to get the experiment configuration directory def experiment_config_path(self) -> str: - swell_exp_path = self.experiment_path() + swell_exp_path = self.experiment_path(scratch=False) return os.path.join(swell_exp_path, 'configuration') # ---------------------------------------------------------------------------------------------- diff --git a/src/swell/utilities/question_defaults.py b/src/swell/utilities/question_defaults.py index 2226144e9..72e310893 100644 --- a/src/swell/utilities/question_defaults.py +++ b/src/swell/utilities/question_defaults.py @@ -129,6 +129,36 @@ class runahead_limit(SuiteQuestion): # -------------------------------------------------------------------------------------------------- + @dataclass + class run_in_scratch(SuiteQuestion): + default_value: bool = False + question_name: str = "run_in_scratch" + ask_question: bool = True + prompt: str = ("Should swell run certain tasks in a specified scratch directory?") + widget_type: WType = WType.BOOLEAN + + # -------------------------------------------------------------------------------------------------- + + @dataclass + class scratch_id(SuiteQuestion): + default_value: str = "defer_to_code" + question_name: str = "scratch_id" + ask_question: bool = True + prompt: str = ("Specify an id to place scratch files under the scratch root directory.") + widget_type: WType.STRING + + # -------------------------------------------------------------------------------------------------- + + @dataclass + class scratch_root(SuiteQuestion): + default_value: str = "defer_to_platform" + question_name: str = "scratch_root" + ask_question: bool = True + prompt: str = ("Specify a scratch directory to run tasks in.") + widget_type: WType = WType.STRING + + # -------------------------------------------------------------------------------------------------- + @dataclass class skip_ensemble_hofx(SuiteQuestion): default_value: str = "defer_to_model" From a33caff2930cbd3d218005e6c5b84f5fbd1a99c3 Mon Sep 17 00:00:00 2001 From: Michael Anstett Date: Tue, 19 Aug 2025 12:57:44 -0400 Subject: [PATCH 2/9] Fix --- src/swell/tasks/base/task_base.py | 6 ++++++ src/swell/tasks/eva_increment.py | 2 +- src/swell/tasks/eva_jedi_log.py | 2 +- src/swell/tasks/eva_observations.py | 2 +- src/swell/utilities/question_defaults.py | 2 +- 5 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/swell/tasks/base/task_base.py b/src/swell/tasks/base/task_base.py index 8713c8b09..55e6ab121 100644 --- a/src/swell/tasks/base/task_base.py +++ b/src/swell/tasks/base/task_base.py @@ -172,6 +172,12 @@ def experiment_config_path(self) -> str: # ---------------------------------------------------------------------------------------------- + def eva_config_path(self) -> str: + return os.path.join(self.experiment_path(scratch=False), + self.experiment_id()+'-suite', 'eva') + + # ---------------------------------------------------------------------------------------------- + def get_ensemble_packet(self) -> Optional[str]: return self.__ensemble_packet__ diff --git a/src/swell/tasks/eva_increment.py b/src/swell/tasks/eva_increment.py index c1cedcbe9..a250672bd 100644 --- a/src/swell/tasks/eva_increment.py +++ b/src/swell/tasks/eva_increment.py @@ -33,7 +33,7 @@ def execute(self) -> None: # Read Eva template file into dictionary # -------------------------------------- - eva_path = os.path.join(self.experiment_path(), self.experiment_id()+'-suite', 'eva') + eva_path = self.eva_config_path() eva_config_file = os.path.join(eva_path, f'increment-{model}.yaml') with open(eva_config_file, 'r') as eva_config_file_open: eva_str_template = eva_config_file_open.read() diff --git a/src/swell/tasks/eva_jedi_log.py b/src/swell/tasks/eva_jedi_log.py index 5a73e2558..51de74e3f 100644 --- a/src/swell/tasks/eva_jedi_log.py +++ b/src/swell/tasks/eva_jedi_log.py @@ -30,7 +30,7 @@ def execute(self) -> None: # Read Eva template file into dictionary # -------------------------------------- - eva_path = os.path.join(self.experiment_path(), self.experiment_id()+'-suite', 'eva') + eva_path = self.eva_config_path() eva_config_file = os.path.join(eva_path, f'jedi_log-{model}.yaml') with open(eva_config_file, 'r') as eva_config_file_open: eva_str_template = eva_config_file_open.read() diff --git a/src/swell/tasks/eva_observations.py b/src/swell/tasks/eva_observations.py index 44807a7d7..ad440264c 100644 --- a/src/swell/tasks/eva_observations.py +++ b/src/swell/tasks/eva_observations.py @@ -63,7 +63,7 @@ def execute(self) -> None: # Read Eva template file into dictionary # -------------------------------------- - eva_path = os.path.join(self.experiment_path(), self.experiment_id()+'-suite', 'eva') + eva_path = self.eva_config_path() eva_config_file = os.path.join(eva_path, f'observations-{model}.yaml') with open(eva_config_file, 'r') as eva_config_file_open: eva_str_template = eva_config_file_open.read() diff --git a/src/swell/utilities/question_defaults.py b/src/swell/utilities/question_defaults.py index 72e310893..28ca28b3f 100644 --- a/src/swell/utilities/question_defaults.py +++ b/src/swell/utilities/question_defaults.py @@ -145,7 +145,7 @@ class scratch_id(SuiteQuestion): question_name: str = "scratch_id" ask_question: bool = True prompt: str = ("Specify an id to place scratch files under the scratch root directory.") - widget_type: WType.STRING + widget_type: WType = WType.STRING # -------------------------------------------------------------------------------------------------- From 3571b65753118bf7ad921882dc75bfca01a20160 Mon Sep 17 00:00:00 2001 From: Michael Anstett Date: Fri, 5 Sep 2025 16:51:04 -0400 Subject: [PATCH 3/9] add missing files --- .../nccs_discover_cascade/task_questions.yaml | 3 ++ .../nccs_discover_sles15/task_questions.yaml | 3 ++ src/swell/suites/3dvar/flow.cylc | 9 ++++ src/swell/tasks/clean_scratch.py | 42 +++++++++++++++++++ 4 files changed, 57 insertions(+) create mode 100644 src/swell/tasks/clean_scratch.py diff --git a/src/swell/deployment/platforms/nccs_discover_cascade/task_questions.yaml b/src/swell/deployment/platforms/nccs_discover_cascade/task_questions.yaml index cd3edcf88..639c05965 100644 --- a/src/swell/deployment/platforms/nccs_discover_cascade/task_questions.yaml +++ b/src/swell/deployment/platforms/nccs_discover_cascade/task_questions.yaml @@ -33,3 +33,6 @@ swell_static_files: ioda_locations_not_in_r2d2: default_value: /discover/nobackup/projects/gmao/dadev/rtodling/archive/542/prePP/ioda + +scratch_root: + default_value: /discover/nobackup/projects/gmao/advda/TSE_staging diff --git a/src/swell/deployment/platforms/nccs_discover_sles15/task_questions.yaml b/src/swell/deployment/platforms/nccs_discover_sles15/task_questions.yaml index ea40d746c..f5da7734c 100644 --- a/src/swell/deployment/platforms/nccs_discover_sles15/task_questions.yaml +++ b/src/swell/deployment/platforms/nccs_discover_sles15/task_questions.yaml @@ -33,3 +33,6 @@ swell_static_files: ioda_locations_not_in_r2d2: default_value: /discover/nobackup/projects/gmao/dadev/rtodling/archive/542/prePP/ioda + +scratch_root: + default_value: /discover/nobackup/projects/gmao/advda/TSE_staging diff --git a/src/swell/suites/3dvar/flow.cylc b/src/swell/suites/3dvar/flow.cylc index 3e598bfaa..49c7501fb 100644 --- a/src/swell/suites/3dvar/flow.cylc +++ b/src/swell/suites/3dvar/flow.cylc @@ -89,6 +89,12 @@ """ {% endfor %} + {% for model_component in model_components %} + R1/$ = """ + CleanCycle-{{model_component}} => CleanScratch + """ + {% endfor %} + # -------------------------------------------------------------------------------------------------- [runtime] @@ -175,4 +181,7 @@ script = "swell task CleanCycle $config -d $datetime -m {{model_component}}" {% endfor %} + [[CleanScratch]] + script = "swell task CleanScratch $config" + # -------------------------------------------------------------------------------------------------- diff --git a/src/swell/tasks/clean_scratch.py b/src/swell/tasks/clean_scratch.py new file mode 100644 index 000000000..6be463936 --- /dev/null +++ b/src/swell/tasks/clean_scratch.py @@ -0,0 +1,42 @@ +# (C) Copyright 2021- United States Government as represented by the Administrator of the +# National Aeronautics and Space Administration. All Rights Reserved. + +# This software is licensed under the terms of the Apache Licence Version 2.0 +# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. + + +# -------------------------------------------------------------------------------------------------- + +import os +from swell.tasks.base.task_base import taskBase +import glob +from swell.utilities.shell_commands import run_track_log_subprocess + +# -------------------------------------------------------------------------------------------------- + + +class CleanCycle(taskBase): + + """Cleans current cycle based on list defined in the configuration file + + Parameters + ---------- + All inputs are extracted from the JEDI experiment file configuration. + See the taskBase constructor for more information. + + """ + + def execute(self) -> None: + + if self.config.run_in_scratch(): + scratch_path = self.experiment_path(scratch=True) + experiment_path = self.experiment_path(scratch=False) + + files = glob.glob(os.path.join(scratch_path), '*') + + command = ['cp', '-r'] + files + [experiment_path] + + run_track_log_subprocess(self.logger, command) + +# -------------------------------------------------------------------------------------------------- + From 62145aa123d3c7e02e28d357debf589043495c89 Mon Sep 17 00:00:00 2001 From: Michael Anstett Date: Mon, 8 Sep 2025 10:40:46 -0400 Subject: [PATCH 4/9] add all suites --- src/swell/suites/3dfgat_atmos/flow.cylc | 9 +++++++++ src/swell/suites/3dfgat_cycle/flow.cylc | 10 ++++++++++ src/swell/suites/3dvar_atmos/flow.cylc | 9 +++++++++ src/swell/suites/3dvar_cycle/flow.cylc | 9 +++++++++ src/swell/suites/build_geos/flow.cylc | 5 ++++- src/swell/suites/build_jedi/flow.cylc | 5 ++++- src/swell/suites/convert_ncdiags/flow.cylc | 9 +++++++++ src/swell/suites/forecast_geos/flow.cylc | 9 +++++++++ src/swell/suites/geosadas/flow.cylc | 9 +++++++++ src/swell/suites/hofx/flow.cylc | 9 +++++++++ src/swell/suites/localensembleda/flow.cylc | 10 ++++++++++ src/swell/suites/ufo_testing/flow.cylc | 9 +++++++++ src/swell/tasks/clean_scratch.py | 4 ++-- 13 files changed, 102 insertions(+), 4 deletions(-) diff --git a/src/swell/suites/3dfgat_atmos/flow.cylc b/src/swell/suites/3dfgat_atmos/flow.cylc index 984445c17..0a873ab28 100644 --- a/src/swell/suites/3dfgat_atmos/flow.cylc +++ b/src/swell/suites/3dfgat_atmos/flow.cylc @@ -98,6 +98,12 @@ """ {% endfor %} + {% for model_component in model_components %} + R1/$ = """ + CleanCycle-{{model_component}} => CleanScratch + """ + {% endfor %} + # -------------------------------------------------------------------------------------------------- [runtime] @@ -185,4 +191,7 @@ script = "swell task CleanCycle $config -d $datetime -m {{model_component}}" {% endfor %} + [[CleanScratch]] + script = "swell task CleanScratch $config" + # -------------------------------------------------------------------------------------------------- diff --git a/src/swell/suites/3dfgat_cycle/flow.cylc b/src/swell/suites/3dfgat_cycle/flow.cylc index 9dbdf1b89..8742a26b0 100644 --- a/src/swell/suites/3dfgat_cycle/flow.cylc +++ b/src/swell/suites/3dfgat_cycle/flow.cylc @@ -120,6 +120,13 @@ {% endfor %} """ {% endfor %} + + {% for model_component in model_components %} + R1/$ = """ + CleanCycle-{{model_component}} => CleanScratch + """ + {% endfor %} + # -------------------------------------------------------------------------------------------------- [runtime] @@ -266,4 +273,7 @@ script = "swell task CleanCycle $config -d $datetime -m {{model_component}}" {% endfor %} + [[CleanScratch]] + script = "swell task CleanScratch $config" + # -------------------------------------------------------------------------------------------------- diff --git a/src/swell/suites/3dvar_atmos/flow.cylc b/src/swell/suites/3dvar_atmos/flow.cylc index 19ffe8892..50304f1cf 100644 --- a/src/swell/suites/3dvar_atmos/flow.cylc +++ b/src/swell/suites/3dvar_atmos/flow.cylc @@ -97,6 +97,12 @@ """ {% endfor %} + {% for model_component in model_components %} + R1/$ = """ + CleanCycle-{{model_component}} => CleanScratch + """ + {% endfor %} + # -------------------------------------------------------------------------------------------------- [runtime] @@ -184,4 +190,7 @@ script = "swell task CleanCycle $config -d $datetime -m {{model_component}}" {% endfor %} + [[CleanScratch]] + script = "swell task CleanScratch $config" + # -------------------------------------------------------------------------------------------------- diff --git a/src/swell/suites/3dvar_cycle/flow.cylc b/src/swell/suites/3dvar_cycle/flow.cylc index 8630756b0..e7d447422 100644 --- a/src/swell/suites/3dvar_cycle/flow.cylc +++ b/src/swell/suites/3dvar_cycle/flow.cylc @@ -120,6 +120,12 @@ {% endfor %} """ {% endfor %} + {% for model_component in model_components %} + R1/$ = """ + CleanCycle-{{model_component}} => CleanScratch + """ + {% endfor %} + # -------------------------------------------------------------------------------------------------- [runtime] @@ -266,4 +272,7 @@ script = "swell task CleanCycle $config -d $datetime -m {{model_component}}" {% endfor %} + [[CleanScratch]] + script = "swell task CleanScratch $config" + # -------------------------------------------------------------------------------------------------- diff --git a/src/swell/suites/build_geos/flow.cylc b/src/swell/suites/build_geos/flow.cylc index dce2ce3d2..c297ba090 100644 --- a/src/swell/suites/build_geos/flow.cylc +++ b/src/swell/suites/build_geos/flow.cylc @@ -21,7 +21,7 @@ R1 = """ CloneGeos => BuildGeosByLinking? - BuildGeosByLinking:fail? => BuildGeos + BuildGeosByLinking:fail? => BuildGeos => CleanScratch """ # -------------------------------------------------------------------------------------------------- @@ -53,4 +53,7 @@ --{{key}} = {{value}} {%- endfor %} + [[CleanScratch]] + script = "swell task CleanScratch $config" + # -------------------------------------------------------------------------------------------------- diff --git a/src/swell/suites/build_jedi/flow.cylc b/src/swell/suites/build_jedi/flow.cylc index b7e347dee..e7efc65be 100644 --- a/src/swell/suites/build_jedi/flow.cylc +++ b/src/swell/suites/build_jedi/flow.cylc @@ -21,7 +21,7 @@ R1 = """ CloneJedi => BuildJediByLinking? - BuildJediByLinking:fail? => BuildJedi + BuildJediByLinking:fail? => BuildJedi => CleanScratch """ # -------------------------------------------------------------------------------------------------- @@ -53,4 +53,7 @@ --{{key}} = {{value}} {%- endfor %} + [[CleanScratch]] + script = "swell task CleanScratch $config" + # -------------------------------------------------------------------------------------------------- diff --git a/src/swell/suites/convert_ncdiags/flow.cylc b/src/swell/suites/convert_ncdiags/flow.cylc index c43986dcd..3737ecb2c 100644 --- a/src/swell/suites/convert_ncdiags/flow.cylc +++ b/src/swell/suites/convert_ncdiags/flow.cylc @@ -54,6 +54,12 @@ """ {% endfor %} + {% for model_component in model_components %} + R1/$ = """ + CleanCycle-{{model_component}} => CleanScratch + """ + {% endfor %} + # -------------------------------------------------------------------------------------------------- [runtime] @@ -99,4 +105,7 @@ [[CleanCycle]] script = "swell task CleanCycle $config -d $datetime -m geos_atmosphere" + [[CleanScratch]] + script = "swell task CleanScratch $config" + # -------------------------------------------------------------------------------------------------- diff --git a/src/swell/suites/forecast_geos/flow.cylc b/src/swell/suites/forecast_geos/flow.cylc index cc8d74dea..9e93b839c 100644 --- a/src/swell/suites/forecast_geos/flow.cylc +++ b/src/swell/suites/forecast_geos/flow.cylc @@ -59,6 +59,12 @@ """ {% endfor %} + {% for model_component in model_components %} + R1/$ = """ + CleanCycle-{{model_component}} => CleanScratch + """ + {% endfor %} + # -------------------------------------------------------------------------------------------------- [runtime] @@ -113,4 +119,7 @@ --{{key}} = {{value}} {%- endfor %} + [[CleanScratch]] + script = "swell task CleanScratch $config" + # -------------------------------------------------------------------------------------------------- diff --git a/src/swell/suites/geosadas/flow.cylc b/src/swell/suites/geosadas/flow.cylc index f96b3d58e..42bc2ec06 100644 --- a/src/swell/suites/geosadas/flow.cylc +++ b/src/swell/suites/geosadas/flow.cylc @@ -61,6 +61,12 @@ RunJediVariationalExecutable => CleanCycle """ + {% for model_component in model_components %} + R1/$ = """ + CleanCycle-{{model_component}} => CleanScratch + """ + {% endfor %} + # -------------------------------------------------------------------------------------------------- [runtime] @@ -118,4 +124,7 @@ [[CleanCycle]] script = "swell task CleanCycle $config -d $datetime -m geos_atmosphere" + [[CleanScratch]] + script = "swell task CleanScratch $config" + # -------------------------------------------------------------------------------------------------- diff --git a/src/swell/suites/hofx/flow.cylc b/src/swell/suites/hofx/flow.cylc index af199788d..1ff463063 100644 --- a/src/swell/suites/hofx/flow.cylc +++ b/src/swell/suites/hofx/flow.cylc @@ -83,6 +83,12 @@ """ {% endfor %} + {% for model_component in model_components %} + R1/$ = """ + CleanCycle-{{model_component}} => CleanScratch + """ + {% endfor %} + # -------------------------------------------------------------------------------------------------- [runtime] @@ -161,4 +167,7 @@ script = "swell task CleanCycle $config -d $datetime -m {{model_component}}" {% endfor %} + [[CleanScratch]] + script = "swell task CleanScratch $config" + # -------------------------------------------------------------------------------------------------- diff --git a/src/swell/suites/localensembleda/flow.cylc b/src/swell/suites/localensembleda/flow.cylc index e130348bf..ef8626bec 100644 --- a/src/swell/suites/localensembleda/flow.cylc +++ b/src/swell/suites/localensembleda/flow.cylc @@ -99,6 +99,12 @@ """ {% endfor %} + {% for model_component in model_components %} + R1/$ = """ + CleanCycle-{{model_component}} => CleanScratch + """ + {% endfor %} + # -------------------------------------------------------------------------------------------------- [runtime] @@ -225,4 +231,8 @@ [[sync_point]] script = true + + [[CleanScratch]] + script = "swell task CleanScratch $config" + # -------------------------------------------------------------------------------------------------- diff --git a/src/swell/suites/ufo_testing/flow.cylc b/src/swell/suites/ufo_testing/flow.cylc index 66e8fb888..36bc465a1 100644 --- a/src/swell/suites/ufo_testing/flow.cylc +++ b/src/swell/suites/ufo_testing/flow.cylc @@ -72,6 +72,12 @@ """ {% endfor %} + {% for model_component in model_components %} + R1/$ = """ + CleanCycle-{{model_component}} => CleanScratch + """ + {% endfor %} + # -------------------------------------------------------------------------------------------------- [runtime] @@ -144,4 +150,7 @@ [[CleanCycle]] script = "swell task CleanCycle $config -d $datetime -m geos_atmosphere" + [[CleanScratch]] + script = "swell task CleanScratch $config" + # -------------------------------------------------------------------------------------------------- diff --git a/src/swell/tasks/clean_scratch.py b/src/swell/tasks/clean_scratch.py index 6be463936..c8e5865a4 100644 --- a/src/swell/tasks/clean_scratch.py +++ b/src/swell/tasks/clean_scratch.py @@ -15,7 +15,7 @@ # -------------------------------------------------------------------------------------------------- -class CleanCycle(taskBase): +class CleanScratch(taskBase): """Cleans current cycle based on list defined in the configuration file @@ -32,7 +32,7 @@ def execute(self) -> None: scratch_path = self.experiment_path(scratch=True) experiment_path = self.experiment_path(scratch=False) - files = glob.glob(os.path.join(scratch_path), '*') + files = glob.glob(os.path.join(scratch_path, '*')) command = ['cp', '-r'] + files + [experiment_path] From 84d3472a64b1f642deb6ed746e210d80fb593a9b Mon Sep 17 00:00:00 2001 From: Michael Anstett Date: Mon, 8 Sep 2025 10:54:44 -0400 Subject: [PATCH 5/9] fix for suites --- src/swell/suites/geosadas/flow.cylc | 8 +------- src/swell/suites/localensembleda/flow.cylc | 8 +------- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/src/swell/suites/geosadas/flow.cylc b/src/swell/suites/geosadas/flow.cylc index 42bc2ec06..9a41e189a 100644 --- a/src/swell/suites/geosadas/flow.cylc +++ b/src/swell/suites/geosadas/flow.cylc @@ -58,15 +58,9 @@ GetGeosAdasBackground => RunJediVariationalExecutable # Clean cycle - RunJediVariationalExecutable => CleanCycle + RunJediVariationalExecutable => CleanCycle => CleanScratch """ - {% for model_component in model_components %} - R1/$ = """ - CleanCycle-{{model_component}} => CleanScratch - """ - {% endfor %} - # -------------------------------------------------------------------------------------------------- [runtime] diff --git a/src/swell/suites/localensembleda/flow.cylc b/src/swell/suites/localensembleda/flow.cylc index ef8626bec..4031c45de 100644 --- a/src/swell/suites/localensembleda/flow.cylc +++ b/src/swell/suites/localensembleda/flow.cylc @@ -92,19 +92,13 @@ # Clean up large files EvaObservations-{{model_component}} & SaveObsDiags-{{model_component}} => - CleanCycle-{{model_component}} + CleanCycle-{{model_component}} => CleanScratch {% endif %} {% endfor %} """ {% endfor %} - {% for model_component in model_components %} - R1/$ = """ - CleanCycle-{{model_component}} => CleanScratch - """ - {% endfor %} - # -------------------------------------------------------------------------------------------------- [runtime] From 8e89b9c619982fd6d2d1042dedcaf9e47771b048 Mon Sep 17 00:00:00 2001 From: Michael Anstett Date: Mon, 8 Sep 2025 11:02:34 -0400 Subject: [PATCH 6/9] test fixes --- .../prepare_config_and_suite/prepare_config_and_suite.py | 3 ++- src/swell/tasks/base/task_base.py | 2 +- src/swell/tasks/clean_scratch.py | 1 - src/swell/utilities/question_defaults.py | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/swell/deployment/prepare_config_and_suite/prepare_config_and_suite.py b/src/swell/deployment/prepare_config_and_suite/prepare_config_and_suite.py index 6b846cb92..daad9ea47 100644 --- a/src/swell/deployment/prepare_config_and_suite/prepare_config_and_suite.py +++ b/src/swell/deployment/prepare_config_and_suite/prepare_config_and_suite.py @@ -339,7 +339,8 @@ def override_with_defaults(self) -> None: experiment_id = self.question_dictionary_model_ind['experiment_id']['default_value'] if experiment_id == 'defer_to_code': experiment_id = f'swell-{self.suite}' - self.question_dictionary_model_ind['experiment_id']['default_value'] = experiment_id + self.question_dictionary_model_ind['experiment_id'][ + 'default_value'] = experiment_id scratch_id = f'{experiment_id}-{randint(0, 99999999):08d}' val['default_value'] = scratch_id diff --git a/src/swell/tasks/base/task_base.py b/src/swell/tasks/base/task_base.py index 55e6ab121..5cc153429 100644 --- a/src/swell/tasks/base/task_base.py +++ b/src/swell/tasks/base/task_base.py @@ -154,7 +154,7 @@ def experiment_path(self, scratch: bool = True) -> str: experiment_path = os.path.join(self.__scratch_root__, self.__scratch_id__) else: experiment_path = os.path.join(self.__experiment_root__, self.__experiment_id__) - + return experiment_path # ---------------------------------------------------------------------------------------------- diff --git a/src/swell/tasks/clean_scratch.py b/src/swell/tasks/clean_scratch.py index c8e5865a4..3e754dc93 100644 --- a/src/swell/tasks/clean_scratch.py +++ b/src/swell/tasks/clean_scratch.py @@ -39,4 +39,3 @@ def execute(self) -> None: run_track_log_subprocess(self.logger, command) # -------------------------------------------------------------------------------------------------- - diff --git a/src/swell/utilities/question_defaults.py b/src/swell/utilities/question_defaults.py index 28ca28b3f..8f82e1fb0 100644 --- a/src/swell/utilities/question_defaults.py +++ b/src/swell/utilities/question_defaults.py @@ -136,7 +136,7 @@ class run_in_scratch(SuiteQuestion): ask_question: bool = True prompt: str = ("Should swell run certain tasks in a specified scratch directory?") widget_type: WType = WType.BOOLEAN - + # -------------------------------------------------------------------------------------------------- @dataclass @@ -148,7 +148,7 @@ class scratch_id(SuiteQuestion): widget_type: WType = WType.STRING # -------------------------------------------------------------------------------------------------- - + @dataclass class scratch_root(SuiteQuestion): default_value: str = "defer_to_platform" From bc1bec5c1d5e965b5dcfa1e079063780b50997e8 Mon Sep 17 00:00:00 2001 From: Michael Anstett Date: Thu, 4 Dec 2025 13:59:02 -0500 Subject: [PATCH 7/9] Use shutil --- src/swell/tasks/clean_scratch.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/swell/tasks/clean_scratch.py b/src/swell/tasks/clean_scratch.py index 3e754dc93..a50292e56 100644 --- a/src/swell/tasks/clean_scratch.py +++ b/src/swell/tasks/clean_scratch.py @@ -8,9 +8,10 @@ # -------------------------------------------------------------------------------------------------- import os -from swell.tasks.base.task_base import taskBase +import shutil import glob -from swell.utilities.shell_commands import run_track_log_subprocess + +from swell.tasks.base.task_base import taskBase # -------------------------------------------------------------------------------------------------- @@ -33,9 +34,8 @@ def execute(self) -> None: experiment_path = self.experiment_path(scratch=False) files = glob.glob(os.path.join(scratch_path, '*')) - - command = ['cp', '-r'] + files + [experiment_path] - - run_track_log_subprocess(self.logger, command) + + for file in files: + shutil.copy(file, experiment_path) # -------------------------------------------------------------------------------------------------- From c800fba5957eeba038c94183c22ae18ab1d69b23 Mon Sep 17 00:00:00 2001 From: Michael Anstett Date: Thu, 4 Dec 2025 16:36:31 -0500 Subject: [PATCH 8/9] Fix for comparison tests --- src/swell/tasks/base/task_base.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/swell/tasks/base/task_base.py b/src/swell/tasks/base/task_base.py index 78effeedb..bd8fa623c 100644 --- a/src/swell/tasks/base/task_base.py +++ b/src/swell/tasks/base/task_base.py @@ -83,9 +83,9 @@ def __init__( # Scratch directory information # ----------------------------- - self.__run_in_scratch__ = self.config.__run_in_scratch__ - self.__scratch_root__ = self.config.__scratch_root__ - self.__scratch_id__ = self.config.__scratch_id__ + self.__run_in_scratch__ = self.config.__run_in_scratch__(False) + self.__scratch_root__ = self.config.__scratch_root__(None) + self.__scratch_id__ = self.config.__scratch_id__(None) if datetime_input is not None: self.__start_cycle_point__ = Datetime(self.config.__start_cycle_point__) @@ -152,6 +152,8 @@ def experiment_id(self) -> str: # Method to get the experiment directory def experiment_path(self, scratch: bool = True) -> str: if self.__run_in_scratch__ and scratch: + print(self.__scratch_root__) + print(self.__scratch_id__) experiment_path = os.path.join(self.__scratch_root__, self.__scratch_id__) else: experiment_path = os.path.join(self.__experiment_root__, self.__experiment_id__) From aebd7effb87b311720710d434862e21b077d8409 Mon Sep 17 00:00:00 2001 From: Michael Anstett Date: Thu, 4 Dec 2025 16:46:50 -0500 Subject: [PATCH 9/9] pycodestyle fix --- src/swell/tasks/clean_scratch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/swell/tasks/clean_scratch.py b/src/swell/tasks/clean_scratch.py index a50292e56..324cdb301 100644 --- a/src/swell/tasks/clean_scratch.py +++ b/src/swell/tasks/clean_scratch.py @@ -34,7 +34,7 @@ def execute(self) -> None: experiment_path = self.experiment_path(scratch=False) files = glob.glob(os.path.join(scratch_path, '*')) - + for file in files: shutil.copy(file, experiment_path)