Skip to main content

Table logger using Rich

Project description

tests pypi

rich-logger

Table logger using Rich, aimed at Pytorch Lightning logging

Features

  • display your training logs with pretty rich tables
  • describe your fields with goal ("higher_is_better" or "lower_is_better"), format and name
  • a field descriptor can be matched with any regex
  • a field name can be computed as a regex substitution
  • works in Jupyter notebooks as well as in a command line
  • integrates easily with Pytorch Lightning

Demo

from rich_logger import RichTablePrinter
import time
import random
from tqdm import trange

logger_fields = {
    "step": {},
    "(.*)_precision": {
        "goal": "higher_is_better",
        "format": "{:.4f}",
        "name": r"\1_p",
    },
    "(.*)_recall": {
        "goal": "higher_is_better",
        "format": "{:.4f}",
        "name": r"\1_r",
    },
    "duration": {"format": "{:.1f}", "name": "dur(s)"},
    ".*": True,  # Any other field must be logged at the end
}


def optimization():
    printer = RichTablePrinter(key="step", fields=logger_fields)
    printer.hijack_tqdm()

    t = time.time()
    for i in trange(10):
        time.sleep(random.random() / 3)
        printer.log(
            {
                "step": i,
                "task_precision": i / 10.0 if i < 5 else 0.5 - (i - 5) / 10.0,
            }
        )
        time.sleep(random.random() / 3)
        printer.log(
            {
                "step": i,
                "task_recall": 0.0 if i < 3 else (i - 3) / 10.0,
                "duration": time.time() - t,
            }
        )
        printer.log({"test": i})
        t = time.time()
        for j in trange(5):
            time.sleep(random.random() / 10)

    printer.finalize()


optimization()

Demo

Use it with PytorchLightning

from rich_logger import RichTableLogger

trainer = pl.Trainer(..., logger=[RichTableLogger(key="epoch", fields=logger_fields)])

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rich_logger-0.3.0.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

rich_logger-0.3.0-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

Details for the file rich_logger-0.3.0.tar.gz.

File metadata

  • Download URL: rich_logger-0.3.0.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.10.6 Linux/5.15.0-1023-azure

File hashes

Hashes for rich_logger-0.3.0.tar.gz
Algorithm Hash digest
SHA256 7fa2f51c9900f7f0bddcc523109447197b693957ba0b688b67ca520c6525b5f2
MD5 53dc6ee80380b75460b7de82d224a1a2
BLAKE2b-256 8f28eaf0af5faf4600d5eec0dfc83ba95c5078994112d6c0b89da93a268aa137

See more details on using hashes here.

Provenance

File details

Details for the file rich_logger-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: rich_logger-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 11.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.10.6 Linux/5.15.0-1023-azure

File hashes

Hashes for rich_logger-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8784e5a1692acc62b462d97c2169888c286ed26ce1774d36f505c62c7052d56d
MD5 13a86dd4f56a1f15fbd333a8f0fd1833
BLAKE2b-256 9d124a581432bc9765f77134ddb77ab1e36d4ce64a41bcde91c6962f7f0bb88d

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page