MolecularDiffusion.utils.io

Classes

CaptureStdIO

RankState

RankedLogger

A multi-GPU-friendly python command line logger.

Functions

capture_rdkit_log()

Context manager to capture all rdkit loggings.

input_choice(prompt[, choice])

Print a prompt on the command line and wait for a choice.

literal_eval(string)

Evaluate an expression into a Python literal structure.

no_rdkit_log()

Context manager to suppress all rdkit loggings.

rank_prefixed_message(→ str)

Module Contents

class MolecularDiffusion.utils.io.CaptureStdIO(stdout=True, stderr=False)

Bases: object

file
stderr = False
stdout = True
class MolecularDiffusion.utils.io.RankState
classmethod get_rank() int
classmethod set_rank(value: int)
rank: int | None = None
class MolecularDiffusion.utils.io.RankedLogger(name: str = __name__, rank_zero_only: bool = False, extra: Mapping[str, object] | None = None)

Bases: logging.LoggerAdapter

A multi-GPU-friendly python command line logger.

Initialize the adapter with a logger and a dict-like object which provides contextual information. This constructor signature allows easy stacking of LoggerAdapters, if so desired.

You can effectively pass keyword arguments as shown in the following example:

adapter = LoggerAdapter(someLogger, dict(p1=v1, p2=”v2”))

log(level: int, msg: str, rank: int | None = None, *args, **kwargs) None

Delegate a log call to the underlying logger, after adding contextual information from this adapter instance.

rank_zero_only = False
MolecularDiffusion.utils.io.capture_rdkit_log()

Context manager to capture all rdkit loggings.

Example:

>>> with utils.capture_rdkit_log() as log:
>>>     ...
>>> print(log.content)
MolecularDiffusion.utils.io.input_choice(prompt, choice=('y', 'n'))

Print a prompt on the command line and wait for a choice.

Parameters:
  • prompt (str) – prompt string

  • choice (tuple of str, optional) – candidate choices

MolecularDiffusion.utils.io.literal_eval(string)

Evaluate an expression into a Python literal structure.

MolecularDiffusion.utils.io.no_rdkit_log()

Context manager to suppress all rdkit loggings.

MolecularDiffusion.utils.io.rank_prefixed_message(msg: str, rank: int) str