From 5f2c4aecc129a019a037a3ef94fb4655b2aa4877 Mon Sep 17 00:00:00 2001 From: "Matthew.Deshotel" Date: Tue, 7 Jul 2026 12:36:18 -0500 Subject: [PATCH 1/2] add retries for esmf mesh creation --- .../NextGen_Forcings_Engine/core/geoMod.py | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/geoMod.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/geoMod.py index 8c5e93e2..c0a62ba8 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/geoMod.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/geoMod.py @@ -1,7 +1,6 @@ from __future__ import annotations import math -from pathlib import Path import numpy as np @@ -15,11 +14,13 @@ except ImportError: import ESMF +import logging from functools import cached_property, wraps from typing import Any -import logging + import xarray as xr +from NextGen_Forcings_Engine_BMI.NextGen_Forcings_Engine.core import err_handler from NextGen_Forcings_Engine_BMI.NextGen_Forcings_Engine.core.config import ( ConfigOptions, ) @@ -28,6 +29,10 @@ log_critical, ) from NextGen_Forcings_Engine_BMI.NextGen_Forcings_Engine.core.parallel import MpiConfig +from NextGen_Forcings_Engine_BMI.NextGen_Forcings_Engine.esmf_utils import ( + esmf_grid_retry, + esmf_mesh_retry, +) LOG = logging.getLogger("FORCING") @@ -352,16 +357,14 @@ def dx_meters(self) -> float: @cached_property def esmf_grid(self) -> ESMF.Grid: """Create the ESMF grid object for the gridded domain.""" - try: - return ESMF.Grid( - np.array([self.ny_global, self.nx_global]), - staggerloc=ESMF.StaggerLoc.CENTER, - coord_sys=ESMF.CoordSys.SPH_DEG, - ) - except Exception as e: - self.config_options.errMsg = f"Unable to create ESMF grid for WRF-Hydro geogrid: {self.config_options.geogrid}" - log_critical(self.config_options, self.mpi_config) - raise e + esmf_grid_retry( + self.mpi_config, + self.config_options, + err_handler, + np.array([self.ny_global, self.nx_global]), + staggerloc=ESMF.StaggerLoc.CENTER, + coord_sys=ESMF.CoordSys.SPH_DEG, + ) @cached_property def esmf_lat(self) -> np.ndarray: @@ -865,16 +868,13 @@ def ny_global(self) -> int: @cached_property def esmf_grid(self) -> ESMF.Mesh: """Create the ESMF Mesh object for the hydrofabric domain.""" - try: - return ESMF.Mesh( - filename=self.config_options.geogrid, filetype=ESMF.FileFormat.ESMFMESH - ) - except Exception as e: - LOG.critical( - f"Unable to create ESMF Mesh: {self.config_options.geogrid} " - f"due to {str(e)}" - ) - raise e + return esmf_mesh_retry( + self.mpi_config, + self.config_options, + err_handler, + filename=self.config_options.geogrid, + filetype=ESMF.FileFormat.ESMFMESH, + ) @cached_property def latitude_grid(self) -> np.ndarray: From fd45d0b59cf87ebc324f9fd8293aca91ec5725bd Mon Sep 17 00:00:00 2001 From: "Matthew.Deshotel" Date: Tue, 7 Jul 2026 13:51:42 -0500 Subject: [PATCH 2/2] return esmf_grid_retry --- .../NextGen_Forcings_Engine/core/geoMod.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/geoMod.py b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/geoMod.py index c0a62ba8..90a225cf 100755 --- a/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/geoMod.py +++ b/NextGen_Forcings_Engine_BMI/NextGen_Forcings_Engine/core/geoMod.py @@ -357,7 +357,7 @@ def dx_meters(self) -> float: @cached_property def esmf_grid(self) -> ESMF.Grid: """Create the ESMF grid object for the gridded domain.""" - esmf_grid_retry( + return esmf_grid_retry( self.mpi_config, self.config_options, err_handler,