Skip to content

Context


Immutable mapping of metric lists with safe append.

__init__() → None

add(key: str, value: Any, tags: Optional[Dict[str, Any]] = None) → None

Append a value to the metric list, optionally with tags.


as_dict() → Mapping[str, Tuple[Any, ...]]

get_tags(key: str) → Tuple[Dict[str, Any], ...]

Return the tags for each recorded value of a metric.


Immutable execution context shared between pipeline steps.

Once a key is set its value cannot be modified. Attempting to do so raises :class:ContextMutationError. This immutability guarantees deterministic provenance during pipeline execution.

Attributes:

- <b>`metrics`</b>: :class:`FrozenMetrics` used to accumulate lists of metric values. artifacts: :class:`ArtifactLog` collecting binary artifacts to be saved
- <b>`by `</b>: class:`~crystallize.plugins.plugins.ArtifactPlugin`. logger: :class:`logging.Logger` used for debug and info messages.
__init__(
initial: Mapping[str, Any],
logger: Optional[logging.Logger] = None
) → None

add(key: str, value: Any) → None

Alias for __setitem__ providing a clearer API.


as_dict() → Mapping[str, Any]

get(key: str, default: Optional[Any] = None) → Any

Return the value for key if present else default.


record(
metric_name: str,
value: Any,
tags: Optional[Dict[str, Any]] = None
) → None

Record a metric value with optional tags.

This is a more explicit alternative to ctx.metrics.add().

Parameters ---------- metric_name: Name of the metric to record. value: The metric value. tags: Optional dictionary of tags for categorization and filtering.

Example ------- ctx.record("loss", 0.5, tags={"epoch": 1, "split": "train"})


A FrozenContext proxy that records every key read and emits DEBUG lines.

Parameters ---------- ctx: The original, immutable context created by the Experiment runner. logger: The logger to use for DEBUG instrumentation.

__init__(
ctx: crystallize.utils.context.FrozenContext,
logger: Optional[logging.Logger] = None
)

add(key: str, value: Any) → None

as_dict() → Mapping[str, Any]

get(key: str, default: Optional[Any] = None) → Any

record(
metric_name: str,
value: Any,
tags: Optional[Dict[str, Any]] = None
) → None

Record a metric value with optional tags.

This is a more explicit alternative to ctx.metrics.add().

Parameters ---------- metric_name: Name of the metric to record. value: The metric value. tags: Optional dictionary of tags for categorization and filtering.

Example ------- ctx.record("loss", 0.5, tags={"epoch": 1, "split": "train"})