Context
module crystallize.utils.context
Section titled “module crystallize.utils.context”class FrozenMetrics
Section titled “class FrozenMetrics”Immutable mapping of metric lists with safe append.
method FrozenMetrics.__init__
Section titled “method FrozenMetrics.__init__”__init__() → Nonemethod FrozenMetrics.add
Section titled “method FrozenMetrics.add”add(key: str, value: Any, tags: Optional[Dict[str, Any]] = None) → NoneAppend a value to the metric list, optionally with tags.
method FrozenMetrics.as_dict
Section titled “method FrozenMetrics.as_dict”as_dict() → Mapping[str, Tuple[Any, ...]]method FrozenMetrics.get_tags
Section titled “method FrozenMetrics.get_tags”get_tags(key: str) → Tuple[Dict[str, Any], ...]Return the tags for each recorded value of a metric.
class FrozenContext
Section titled “class FrozenContext”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.method FrozenContext.__init__
Section titled “method FrozenContext.__init__”__init__( initial: Mapping[str, Any], logger: Optional[logging.Logger] = None) → Nonemethod FrozenContext.add
Section titled “method FrozenContext.add”add(key: str, value: Any) → NoneAlias for __setitem__ providing a clearer API.
method FrozenContext.as_dict
Section titled “method FrozenContext.as_dict”as_dict() → Mapping[str, Any]method FrozenContext.get
Section titled “method FrozenContext.get”get(key: str, default: Optional[Any] = None) → AnyReturn the value for key if present else default.
method FrozenContext.record
Section titled “method FrozenContext.record”record( metric_name: str, value: Any, tags: Optional[Dict[str, Any]] = None) → NoneRecord 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"})
class LoggingContext
Section titled “class LoggingContext”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.
method LoggingContext.__init__
Section titled “method LoggingContext.__init__”__init__( ctx: crystallize.utils.context.FrozenContext, logger: Optional[logging.Logger] = None)method LoggingContext.add
Section titled “method LoggingContext.add”add(key: str, value: Any) → Nonemethod LoggingContext.as_dict
Section titled “method LoggingContext.as_dict”as_dict() → Mapping[str, Any]method LoggingContext.get
Section titled “method LoggingContext.get”get(key: str, default: Optional[Any] = None) → Anymethod LoggingContext.record
Section titled “method LoggingContext.record”record( metric_name: str, value: Any, tags: Optional[Dict[str, Any]] = None) → NoneRecord 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"})