1
Fork 0
This repository has been archived on 2026-08-15. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
2026SEL3-project-Brittle_St.../src/experiment_logger
2026-04-22 18:47:35 +02:00
..
__init__.py chore(log): remove dead code 2026-04-16 14:35:23 +02:00
config_logger.py feat: configure checkpoints saving 2026-04-16 15:10:21 +02:00
README.md fix: mypy complaints 2026-04-09 00:02:18 +02:00
simple_logger.py refactor(log): use dataclass for config 2026-04-16 15:18:40 +02:00
unified_logger.py feat: adapted simulate to trained config 2026-04-22 18:47:35 +02:00
wandb_utils.py fix: linting 2026-04-09 00:37:02 +02:00

Experiment Logger

A standardized, unified interface for logging experiments across multiple backends (WandB, TensorBoard, and Local Disk).

This library is designed to be a standalone package that decouples the logging logic from the core training routines in the brittle_star_project.

Quick Start

The recommended way to use the logger is through the get_logger() singleton:

from experiment_logger import UnifiedLogger, get_logger

# Initialize at the start of your script (e.g., in train.py)
logger = UnifiedLogger(
    run_name="my_experiment_run",
    config={"learning_rate": 3e-4},
    project_name="MyProject",
    base_dir="runs",
    use_wandb=True
)

# In other files, retrieve the initialized singleton:
# logger = get_logger()

# Log metrics (Scalar values, numpy scalars, or JAX types)
logger.log({"loss": 0.5, "accuracy": 0.98}, step=100)

# Standard logging (Mirrored to disk and stdout)
logger.info("Training started")
logger.warning("Learning rate is very high")

# Save checkpoints (Automatically synced to WandB as artifacts)
logger.save_checkpoint(params, step=5000)

Logger Classes

UnifiedLogger

The full suite for production training. It manages:

  • WandB: Syncs metrics and uploads model checkpoints as artifacts.
  • TensorBoard: Writes events for local visualization.
  • Local Disk: Stores metrics in metrics.yaml and textual logs in run.log.

SimpleLogger

A zero-dependency fallback that uses standard Python print() statements. Use this for standalone testing or minimal environments where you don't need persistent monitoring.

from experiment_logger import SimpleLogger
logger = SimpleLogger(run_name="test_run")

API Features

logger.progress_bar(iterable, **kwargs)

A smart wrapper around tqdm that automatically detects its environment.

  • Interactive Terminal: Displays a normal progress bar.
  • Non-Interactive (HPC): Automatically disables the bar to prevent log file bloat in slurm.out.

logger.log_non_interactive(msg: str)

Prints a message only when running in non-interactive environments. Useful for high-level progress tracking (e.g., "Epoch 5 Complete") without interactive noise.

logger.save_checkpoint(params, step, prefix="checkpoint")

Saves model parameters using Flax serialization.

  • Local Location: runs/<run_name>/checkpoints/
  • WandB Logic: Automatically uploads the .flax file as a model artifact for lineage tracking.