Skip to content

Treatment


Set up initial context values for a replicate.

Unlike plugins, a treatment does not hook into the execution lifecycle; it simply mutates the :class:FrozenContext before the pipeline starts. The apply argument can be a callable or a mapping providing the context additions.

Args:

  • name: Human-readable identifier for the treatment.
  • apply: Either a callable apply(ctx) or a mapping of keys to insert. Existing keys must not be mutated—FrozenContext enforces this immutability.
__init__(
name: str,
apply: Union[Callable[[crystallize.utils.context.FrozenContext], Any], Mapping[str, Any]]
)


apply(ctx: crystallize.utils.context.FrozenContext) → None

Apply the treatment to the execution context.

Implementations typically add new keys like:

ctx[‘embed_dim’] = 512 ctx.override(step=‘hpo’, param_space={‘lr’: [1e-4, 5e-5]})

Raises: ContextMutationError if attempting to overwrite existing keys.