Telemetry Callback#

Telemetry callback utilities#

Structured logging of metrics, losses, and state during training/evaluation.

This module provides two callbacks:

  • TelemetryLogger: appends JSON records to a JSONL file with periodic flush, suitable for long runs.

  • MemoryLogger: collects records in memory for debugging or tests.

class qmlhc.callbacks.telemetry.MemoryLogger[source]#

Bases: Callback

In-memory telemetry collector.

Useful for unit tests or quick debugging sessions where file I/O is undesirable. Each call appends a small dictionary to records.

on_epoch_begin(epoch, context)[source]#

Record the beginning of an epoch.

Return type:

None

on_epoch_end(epoch, context)[source]#

Record the end of an epoch.

Return type:

None

Notes

context is converted to a plain dict to keep a JSON-safe record.

on_error(error, context)[source]#

Record an error event.

Parameters:
  • error (Exception) – The encountered exception.

  • context (Mapping[str, Any]) – Additional context at the time of the error.

Return type:

None

on_step_begin(step, context)[source]#

Record the beginning of a step.

Return type:

None

on_step_end(step, context)[source]#

Record the end of a step.

Return type:

None

Notes

context is converted to a plain dict to avoid surprises with non-serializable payloads during debugging.

class qmlhc.callbacks.telemetry.TelemetryLogger(path='telemetry.jsonl', flush_interval=1)[source]#

Bases: Callback

JSONL-based telemetry logger.

Records tagged events (e.g., step/epoch begin/end, errors) into an internal buffer and flushes to a JSONL file either when the buffer reaches a given length or when a time threshold elapses.

Parameters:
  • path (str or Path, optional) – Output path for the JSONL file. Defaults to "telemetry.jsonl".

  • flush_interval (int, optional) – Flush after this many buffered entries (minimum = 1). Defaults to 1.

Notes

Each JSON line includes:
  • ts (float): UNIX timestamp (seconds).

  • tag (str): event tag ("step_begin", "epoch_end", etc.).

  • Any extra payload fields provided by the caller.

on_epoch_begin(epoch, context)[source]#

Record the beginning of an epoch.

Return type:

None

on_epoch_end(epoch, context)[source]#

Record the end of an epoch.

Return type:

None

Notes

context is converted to a plain dict to ensure JSON safety.

on_error(error, context)[source]#

Record an error event.

Parameters:
  • error (Exception) – The encountered exception.

  • context (Mapping[str, Any]) – Additional context at the time of the error.

Return type:

None

on_step_begin(step, context)[source]#

Record the beginning of a step.

Return type:

None

on_step_end(step, context)[source]#

Record the end of a step.

Return type:

None

Notes

context is converted to a plain dict to ensure JSON safety.