logging

Utility functions for logging.

Functions

atomic_print

Decorator to prevent interleaved output in distributed/multi-threaded environments.

capture_io

Capture stdout and stderr within the invoked context.

no_stdout

Silences stdout within the invoked context.

num2hrb

Convert big floating number to human readable string.

print_rank_0

Prints only on the master process.

silence_matched_warnings

Silences warnings that match a given pattern.

warn_rank_0

Issues a warning only on the master process.

exception DeprecatedError

Bases: NotImplementedError

Error for deprecated functions.

atomic_print(func)

Decorator to prevent interleaved output in distributed/multi-threaded environments.

capture_io(capture_stderr=True)

Capture stdout and stderr within the invoked context.

Parameters:

capture_stderr (bool) – Whether to capture stderr. Defaults to True.

Returns:

An iterator that yields a StringIO object that contains the captured output.

Return type:

Iterator[StringIO]

Example:

with capture_io() as buf:
    print("Hello, world!")
print(buf.getvalue())
no_stdout()

Silences stdout within the invoked context.

num2hrb(num, suffix='')

Convert big floating number to human readable string.

Parameters:

num (float)

Return type:

str

print_rank_0(*args, **kwargs)

Prints only on the master process.

silence_matched_warnings(pattern=None)

Silences warnings that match a given pattern.

Parameters:

pattern (str) – The pattern to match against warning messages. Defaults to None.

warn_rank_0(message, *args, **kwargs)

Issues a warning only on the master process.