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 8, 2024
1 parent 75cfa3d commit 56a4311
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 @@ -291,14 +291,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"])

Check warning on line 296 in src/benchcab/benchcab.py

View check run for this annotation

Codecov / codecov/patch

src/benchcab/benchcab.py#L294-L296

Added lines #L294 - L296 were not covered by tests

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})")

Check warning on line 299 in src/benchcab/benchcab.py

View check run for this annotation

Codecov / codecov/patch

src/benchcab/benchcab.py#L298-L299

Added lines #L298 - L299 were not covered by tests
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")

Check warning on line 309 in src/benchcab/benchcab.py

View check run for this annotation

Codecov / codecov/patch

src/benchcab/benchcab.py#L306-L309

Added lines #L306 - L309 were not covered by tests

def fluxsite_bitwise_cmp(self, config_path: str):
"""Endpoint for `benchcab fluxsite-bitwise-cmp`."""
Expand All @@ -314,14 +322,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"])

Check warning on line 327 in src/benchcab/benchcab.py

View check run for this annotation

Codecov / codecov/patch

src/benchcab/benchcab.py#L325-L327

Added lines #L325 - L327 were not covered by tests

logger.info("Running comparison tasks...")
logger.info(f"tasks: {len(comparisons)} (models: {n_models}, sites: {n_sites}, science configurations: {n_science_configurations})")

Check warning on line 330 in src/benchcab/benchcab.py

View check run for this annotation

Codecov / codecov/patch

src/benchcab/benchcab.py#L330

Added line #L330 was not covered by tests
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")

Check warning on line 340 in src/benchcab/benchcab.py

View check run for this annotation

Codecov / codecov/patch

src/benchcab/benchcab.py#L337-L340

Added lines #L337 - L340 were not covered by tests

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 56a4311

Please sign in to comment.