ard.utils.logging#

Functions

component_log_capture(compute_func[, iter])

Decorator that redirects stdout and stderr to component-wise and rank-wise logfiles.

extract_iter(component)

Extract the iter_count iff it exists, otherwise return None

get_storage_directory(component[, ...])

Get a storage directory for the component constructed here.

name_create_log(component[, iter])

For a given component, clean and create component- and rank-unique logfiles.

prepend_tabs_to_stdio(func[, tabs])

ard.utils.logging.extract_iter(component)[source]#

Extract the iter_count iff it exists, otherwise return None

Extract the iteration count from a component's associated model. This function attempts to retrieve the iteration count from a component by traversing through its problem metadata and model reference. It safely handles cases where any of the required attributes or keys don't exist.

Parameters:

component (An object that may contain a _problem_meta attribute with) -- model reference information.

Returns:

int or None: The iteration count from the model if it exists and is

accessible, otherwise None.

The function returns None in the following cases: - component doesn't have a _problem_meta attribute - problem_meta doesn't contain a "model_ref" key - the model doesn't have an iter_count attribute

ard.utils.logging.get_storage_directory(component, storage_type='logs', get_iter=False, clean=False)[source]#

Get a storage directory for the component constructed here.

Take a component and create a storage directory (for, e.g. logs or init files), mirroring the OpenMDAO model structure as subdirectories, returning a pathlib.Path to the storage directory.

Parameters:
  • component (openmdao.core.Component) -- an OpenMDAO component for which we want to create a storage directory

  • storage_type (str, optional) -- the type of storage sub-directory to make, by default "logs"

  • get_iter (bool, optional) -- should the storage directory tree be given an iteration subdirectory, by default False

  • clean (bool, optional) -- should the directory tree, if it already exists, be cleaned out, by default False

Returns:

the path to the storage subdirectory created

Return type:

pathlib.Path

ard.utils.logging.name_create_log(component, iter=None)[source]#

For a given component, clean and create component- and rank-unique logfiles.

Take a component and create logs, parallel to the reports file, mirroring the OpenMDAO model structure with stdout and stderr files for each rank, and finally return the file paths for the component to redirect stdout and stderr to.

Parameters:
  • component (openmdao.core.component.Component) -- An OpenMDAO component that we want to capture stdout/stderr for

  • iter (int)

Returns:

  • pathlib.Path -- a path to in the log system to dump stdout to

  • pathlib.Path -- a path to in the log system to dump err to

ard.utils.logging.component_log_capture(compute_func, iter=None)[source]#

Decorator that redirects stdout and stderr to component-wise and rank-wise logfiles.

This decorator will redirect stdout and stderr to component-wise and rank-wise logfiles, which are determined by the name_create_log function. The decorator uses context managers to redirect output streams to these files, ensuring that all print statements and errors within the function are logged appropriately.

funcCallable

The function to be decorated. It should be a method of a class, as self is expected as the first argument.

Callable

The wrapped function with stdout and stderr redirected to log files during its execution.

Parameters:

iter (int)

ard.utils.logging.prepend_tabs_to_stdio(func, tabs=1)[source]#