dgamore.dga_logger#

MPI-aware logging. DgaLogger timestamps messages and, by default, only emits them on the root rank so that parallel runs produce a single clean log stream.

class dgamore.dga_logger.DgaLogger(comm: mpi4py.MPI.Comm, output_path: str = './', filename: str = 'dga.log')[source]#

Bases: object

Handles logging messages in a distributed environment using MPI. Currently, it logs messages to stdout.

Parameters:
  • comm (mpi4py.MPI.Comm)

  • output_path (str)

  • filename (str)

property current_time: str#

The current wall-clock time as a formatted string.

Returns:

The current wall-clock time formatted as "YYYY-MM-DD HH:MM:SS.sss".

debug(message: str, allowed_ranks: tuple = (0,))[source]#

Logs a debug message. This is intended for detailed debugging information that is not usually needed in production.

Parameters:
  • message (str) – The message to log.

  • allowed_ranks (tuple) – The MPI rank(s) permitted to emit this message.

Returns:

None.

info(message: str, allowed_ranks: tuple = (0,))[source]#

Logs an informational message. This is intended for general information about the program’s execution.

Parameters:
  • message (str) – The message to log.

  • allowed_ranks (tuple) – The MPI rank(s) permitted to emit this message.

Returns:

None.

property is_root: bool#

Whether the current process is the root rank.

Returns:

True if the current MPI rank is the root rank (rank 0).

log_memory_usage(obj_name: str, obj, n_exists: int = 1, allowed_ranks: tuple = (0,))[source]#

Logs the memory usage of an object in gigabytes. This is useful for tracking memory consumption in distributed applications, especially when using MPI.

Parameters:
  • obj_name (str) – Human-readable name used in the log line.

  • obj – An object exposing memory_usage_in_gb (e.g. any IHaveMat); ignored if None.

  • n_exists (int) – Multiplicity factor, i.e. how many such objects exist (the reported size is scaled by it).

  • allowed_ranks (tuple) – The MPI rank(s) permitted to emit this message.

Returns:

None.

property total_elapsed_time: str#

Calculates the total elapsed time since the logger was initialized (i.e. almost the same as the runtime of the code).

Returns:

The elapsed time formatted as "DD-HH:MM:SS.mmm".

warning(message: str, allowed_ranks: tuple = (0,))[source]#

Logs a warning message. This is intended for situations that are not errors but may require attention.

Parameters:
  • message (str) – The message to log.

  • allowed_ranks (tuple) – The MPI rank(s) permitted to emit this message.

Returns:

None.