Skip to content

Commit

Permalink
Log status of fluxsite and comparison runs
Browse files Browse the repository at this point in the history
  • Loading branch information
SeanBryan51 committed May 9, 2024
1 parent fc625c0 commit e267278
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/benchcab/benchcab.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,14 +293,22 @@ def fluxsite_run_tasks(self, config_path: str):
config = self._get_config(config_path)
self._validate_environment(project=config["project"], modules=config["modules"])
tasks = self._get_fluxsite_tasks(config)
n_models = len(self._get_models(config))
n_sites = len(get_met_forcing_file_names(config["fluxsite"]["experiment"]))
n_science_configurations = len(config["science_configurations"])

logger.info("Running fluxsite tasks...")
logger.info(f"Running fluxsite tasks...")
logger.info(f"tasks: {len(tasks)} (models: {n_models}, sites: {n_sites}, science configurations: {n_science_configurations})")
if config["fluxsite"]["multiprocess"]:
ncpus = config["fluxsite"]["pbs"]["ncpus"]
fluxsite.run_tasks_in_parallel(tasks, n_processes=ncpus)
else:
fluxsite.run_tasks(tasks)
logger.info("Successfully ran fluxsite tasks")

tasks_failed = [task for task in tasks if not task.success]
n_failed = len(tasks_failed)
n_success = len(tasks) - n_failed
logger.info(f"{n_failed} failed, {n_success} passed")

def fluxsite_bitwise_cmp(self, config_path: str):
"""Endpoint for `benchcab fluxsite-bitwise-cmp`."""
Expand All @@ -316,14 +324,22 @@ def fluxsite_bitwise_cmp(self, config_path: str):
comparisons = fluxsite.get_fluxsite_comparisons(
self._get_fluxsite_tasks(config)
)
n_models = len(self._get_models(config))
n_sites = len(get_met_forcing_file_names(config["fluxsite"]["experiment"]))
n_science_configurations = len(config["science_configurations"])

logger.info("Running comparison tasks...")
logger.info(f"tasks: {len(comparisons)} (models: {n_models}, sites: {n_sites}, science configurations: {n_science_configurations})")
if config["fluxsite"]["multiprocess"]:
ncpus = config["fluxsite"]["pbs"]["ncpus"]
run_comparisons_in_parallel(comparisons, n_processes=ncpus)
else:
run_comparisons(comparisons)
logger.info("Successfully ran comparison tasks")

tasks_failed = [task for task in comparisons if not task.success]
n_failed = len(tasks_failed)
n_success = len(comparisons) - n_failed
logger.info(f"{n_failed} failed, {n_success} passed")

def fluxsite(self, config_path: str, no_submit: bool, skip: list[str]):
"""Endpoint for `benchcab fluxsite`."""
Expand Down
2 changes: 2 additions & 0 deletions src/benchcab/comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def __init__(
self.files = files
self.task_name = task_name
self.logger = get_logger()
self.success = True

def run(self) -> None:
"""Executes `nccmp -df` on the NetCDF files pointed to by `self.files`."""
Expand All @@ -57,6 +58,7 @@ def run(self) -> None:
)
with output_file.open("w", encoding="utf-8") as file:
file.write(exc.stdout)
self.success = False

self.logger.error(f"Failure: files {file_a.name} {file_b.name} differ. ")
self.logger.error(f"Results of diff have been written to {output_file}")
Expand Down
2 changes: 2 additions & 0 deletions src/benchcab/fluxsite.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def __init__(
self.sci_conf_id = sci_conf_id
self.sci_config = sci_config
self.logger = get_logger()
self.success = True

def get_task_name(self) -> str:
"""Returns the file name convention used for this task."""
Expand Down Expand Up @@ -240,6 +241,7 @@ def run_cable(self):
)
except CalledProcessError as exc:
self.logger.debug(f"Error: CABLE returned an error for task {task_name}")
self.success = False
raise CableError from exc

def add_provenance_info(self):
Expand Down

0 comments on commit e267278

Please sign in to comment.