Skip to content

README

liblaf.cherries.core

Modules:

Classes:

  • Plugin

    Base class for Cherries plugins.

  • PluginProtocol

    Complete hook surface implemented by Cherries plugin delegates.

  • Run

    Mutable state for one Cherries experiment run.

Functions:

Attributes:

  • run (Run) –

    Process-global run used by Cherries convenience functions.

run module-attribute

run: Run = Run()

Process-global run used by Cherries convenience functions.

Plugin

Base class for Cherries plugins.

Attributes:

Parameters:

name class-attribute instance-attribute

name: PluginName = field(
    default=Factory(_default_name, takes_self=True),
    kw_only=True,
)

PluginProtocol

Bases: AssetPluginProtocol, MetricPluginProtocol, OtherPluginProtocol, ParamPluginProtocol, Protocol


              flowchart TD
              liblaf.cherries.core.PluginProtocol[PluginProtocol]
              liblaf.cherries.core.assets._protocol.AssetPluginProtocol[AssetPluginProtocol]
              liblaf.cherries.core.metrics._protocol.MetricPluginProtocol[MetricPluginProtocol]
              liblaf.cherries.core.others._protocol.OtherPluginProtocol[OtherPluginProtocol]
              liblaf.cherries.core.params._protocol.ParamPluginProtocol[ParamPluginProtocol]

                              liblaf.cherries.core.assets._protocol.AssetPluginProtocol --> liblaf.cherries.core.PluginProtocol
                
                liblaf.cherries.core.metrics._protocol.MetricPluginProtocol --> liblaf.cherries.core.PluginProtocol
                
                liblaf.cherries.core.others._protocol.OtherPluginProtocol --> liblaf.cherries.core.PluginProtocol
                
                liblaf.cherries.core.params._protocol.ParamPluginProtocol --> liblaf.cherries.core.PluginProtocol
                


              click liblaf.cherries.core.PluginProtocol href "" "liblaf.cherries.core.PluginProtocol"
              click liblaf.cherries.core.assets._protocol.AssetPluginProtocol href "" "liblaf.cherries.core.assets._protocol.AssetPluginProtocol"
              click liblaf.cherries.core.metrics._protocol.MetricPluginProtocol href "" "liblaf.cherries.core.metrics._protocol.MetricPluginProtocol"
              click liblaf.cherries.core.others._protocol.OtherPluginProtocol href "" "liblaf.cherries.core.others._protocol.OtherPluginProtocol"
              click liblaf.cherries.core.params._protocol.ParamPluginProtocol href "" "liblaf.cherries.core.params._protocol.ParamPluginProtocol"
            

Complete hook surface implemented by Cherries plugin delegates.

Methods:

  • end

    End a run.

  • log_asset

    Record an existing artifact path.

  • log_metric

    Record one metric sample.

  • log_metrics

    Record a batch of already-flattened metric samples.

  • log_other

    Record one flattened metadata value.

  • log_others

    Record multiple already-flattened metadata values.

  • log_param

    Record one flattened parameter value.

  • log_params

    Record multiple already-flattened parameter values.

  • start

    Start a run.

end

end(exc: BaseException | None = None) -> None

End a run.

Parameters:

  • exc (BaseException | None, default: None ) –

    Exception raised by the experiment, if any.

Source code in src/liblaf/cherries/core/_protocol.py
def end(self, exc: BaseException | None = None) -> None:
    """End a run.

    Args:
        exc: Exception raised by the experiment, if any.
    """
    raise NotImplementedError

log_asset

log_asset(
    path: Path,
    *,
    metadata: Mapping[str, Any] | None = None,
    report: bool = True,
) -> None

Record an existing artifact path.

Parameters:

  • path (Path) –

    Existing file or directory to record.

  • metadata (Mapping[str, Any] | None, default: None ) –

    Optional artifact metadata, usually including type.

  • report (bool, default: True ) –

    Whether the path is the primary user-facing artifact. Companion files are logged with report=False.

Source code in src/liblaf/cherries/core/assets/_protocol.py
def log_asset(
    self,
    path: Path,
    *,
    metadata: Mapping[str, Any] | None = None,
    report: bool = True,
) -> None:
    """Record an existing artifact path.

    Args:
        path: Existing file or directory to record.
        metadata: Optional artifact metadata, usually including `type`.
        report: Whether the path is the primary user-facing artifact.
            Companion files are logged with `report=False`.
    """
    ...

log_metric

log_metric(
    name: str, value: float, *, step: int, time: datetime
) -> None

Record one metric sample.

Source code in src/liblaf/cherries/core/metrics/_protocol.py
def log_metric(
    self, name: str, value: float, *, step: int, time: datetime.datetime
) -> None:
    """Record one metric sample."""
    ...

log_metrics

log_metrics(
    metrics: dict[str, float], *, step: int, time: datetime
) -> None

Record a batch of already-flattened metric samples.

Source code in src/liblaf/cherries/core/metrics/_protocol.py
def log_metrics(
    self, metrics: dict[str, float], *, step: int, time: datetime.datetime
) -> None:
    """Record a batch of already-flattened metric samples."""
    ...

log_other

log_other(name: str, value: Any) -> None

Record one flattened metadata value.

Source code in src/liblaf/cherries/core/others/_protocol.py
7
8
9
def log_other(self, name: str, value: Any) -> None:
    """Record one flattened metadata value."""
    ...

log_others

log_others(others: dict[str, Any]) -> None

Record multiple already-flattened metadata values.

Source code in src/liblaf/cherries/core/others/_protocol.py
def log_others(self, others: dict[str, Any]) -> None:
    """Record multiple already-flattened metadata values."""
    ...

log_param

log_param(name: str, value: Any) -> None

Record one flattened parameter value.

Source code in src/liblaf/cherries/core/params/_protocol.py
7
8
9
def log_param(self, name: str, value: Any) -> None:
    """Record one flattened parameter value."""
    ...

log_params

log_params(params: dict[str, Any]) -> None

Record multiple already-flattened parameter values.

Source code in src/liblaf/cherries/core/params/_protocol.py
def log_params(self, params: dict[str, Any]) -> None:
    """Record multiple already-flattened parameter values."""
    ...

start

start() -> None

Start a run.

Source code in src/liblaf/cherries/core/_protocol.py
def start(self) -> None:
    """Start a run."""
    raise NotImplementedError

Run

Mutable state for one Cherries experiment run.

A Run owns plugin registration, path helpers, metrics, parameters, and miscellaneous metadata. Profiles configure the process-global run, while main starts and ends it around an experiment callable.

Parameters:

  • plugins (PluginManager, default: <dynamic> ) –

    Register plugins and delegate hook calls in dependency order.

    Only methods decorated with impl are invoked. Hook order is cached per method and recalculated whenever a plugin is registered.

Methods:

  • end

    Flush artifacts, record shutdown metadata, and end plugins.

  • get_metric

    Return one metric series.

  • get_metrics

    Return selected metric series concatenated into one dataframe.

  • get_other

    Return one flattened metadata value.

  • get_others

    Return logged metadata as a nested dictionary.

  • get_param

    Return one flattened parameter value.

  • get_params

    Return logged parameters as a nested dictionary.

  • get_step

    Return the default metric step.

  • input

    Resolve and immediately log an input below data/.

  • log_asset

    Log an existing generic artifact immediately.

  • log_input

    Log an existing input artifact immediately.

  • log_metric

    Log one scalar metric.

  • log_metrics

    Log multiple scalar metrics, flattening nested mappings with /.

  • log_other

    Log one metadata value.

  • log_others

    Log multiple metadata values.

  • log_output

    Log an existing output artifact immediately.

  • log_param

    Log one parameter value.

  • log_params

    Log multiple parameter values.

  • log_temp

    Log an existing temporary artifact immediately.

  • output

    Resolve an output below data/ and queue it until run end.

  • set_step

    Set the default metric step.

  • start

    Start plugins and record Cherries run metadata.

  • summary

    Build a JSON/YAML-friendly run summary.

  • temp

    Resolve a temporary artifact below tmp/ and queue it until run end.

Attributes:

entrypoint cached property

entrypoint: Path

Python entrypoint used to derive the experiment name and folders.

plugins class-attribute instance-attribute

plugins: PluginManager = field(factory=PluginManager)

project_dir cached property

project_dir: Path

Git repository root, or the current directory outside a Git repo.

project_name cached property

project_name: str

Project name reported to plugins.

repo cached property

repo: Repo | None

run_key cached property

run_key: Path

run_name cached property

run_name: str

Run name from CHERRIES_NAME or the entrypoint path.

start_time cached property

start_time: datetime

Timezone-aware timestamp captured when the run object is first used.

step property writable

step: int

Default metric step.

tags cached property

tags: list[str]

Tags parsed from the CHERRIES_TAGS environment variable.

working_dir cached property

working_dir: Path

Directory used to resolve data, temporary, log, and local snapshot paths.

end

end(exc: BaseException | None = None) -> None

Flush artifacts, record shutdown metadata, and end plugins.

Parameters:

  • exc (BaseException | None, default: None ) –

    Exception raised by the experiment, if any.

Source code in src/liblaf/cherries/core/_run.py
def end(self, exc: BaseException | None = None) -> None:
    """Flush artifacts, record shutdown metadata, and end plugins.

    Args:
        exc: Exception raised by the experiment, if any.
    """
    self.log_other("cherries/end_time", datetime.now().astimezone())
    if exc is not None:
        self.log_other(
            "cherries/exception", "\n".join(traceback.format_exception_only(exc))
        )
    self._assets.end()
    self.plugins.delegate("end", exc=exc)

get_metric

get_metric(name: str) -> DataFrame

Return one metric series.

Source code in src/liblaf/cherries/core/_run.py
def get_metric(self, name: str) -> pl.DataFrame:
    """Return one metric series."""
    return self._metrics.get_metric(name)

get_metrics

get_metrics(
    metrics: Iterator[str] | None = None,
) -> DataFrame

Return selected metric series concatenated into one dataframe.

Source code in src/liblaf/cherries/core/_run.py
def get_metrics(self, metrics: Iterator[str] | None = None) -> pl.DataFrame:
    """Return selected metric series concatenated into one dataframe."""
    return self._metrics.get_metrics(metrics)

get_other

get_other(name: str) -> Any

Return one flattened metadata value.

Source code in src/liblaf/cherries/core/_run.py
def get_other(self, name: str) -> Any:
    """Return one flattened metadata value."""
    return self._others.get_other(name)

get_others

get_others() -> dict[str, Any]

Return logged metadata as a nested dictionary.

Source code in src/liblaf/cherries/core/_run.py
def get_others(self) -> dict[str, Any]:
    """Return logged metadata as a nested dictionary."""
    return self._others.get_others()

get_param

get_param(name: str) -> Any

Return one flattened parameter value.

Source code in src/liblaf/cherries/core/_run.py
def get_param(self, name: str) -> Any:
    """Return one flattened parameter value."""
    return self._params.get_param(name)

get_params

get_params() -> dict[str, Any]

Return logged parameters as a nested dictionary.

Source code in src/liblaf/cherries/core/_run.py
def get_params(self) -> dict[str, Any]:
    """Return logged parameters as a nested dictionary."""
    return self._params.get_params()

get_step

get_step() -> int

Return the default metric step.

Source code in src/liblaf/cherries/core/_run.py
def get_step(self) -> int:
    """Return the default metric step."""
    return self.step

input

input(
    path: StrPath,
    *,
    metadata: Mapping[str, Any] | None = None,
) -> Path

Resolve and immediately log an input below data/.

Source code in src/liblaf/cherries/core/_run.py
def input(
    self, path: StrPath, *, metadata: Mapping[str, Any] | None = None
) -> Path:
    """Resolve and immediately log an input below `data/`."""
    return self._assets.input(path, metadata=metadata)

log_asset

log_asset(
    path: StrPath, metadata: Mapping[str, Any] | None = None
) -> None

Log an existing generic artifact immediately.

Source code in src/liblaf/cherries/core/_run.py
def log_asset(
    self, path: StrPath, metadata: Mapping[str, Any] | None = None
) -> None:
    """Log an existing generic artifact immediately."""
    self._assets.log_asset(path, metadata=metadata)

log_input

log_input(
    path: StrPath, metadata: Mapping[str, Any] | None = None
) -> None

Log an existing input artifact immediately.

Source code in src/liblaf/cherries/core/_run.py
def log_input(
    self, path: StrPath, metadata: Mapping[str, Any] | None = None
) -> None:
    """Log an existing input artifact immediately."""
    self._assets.log_input(path, metadata=metadata)

log_metric

log_metric(
    name: str,
    value: SupportsFloat,
    *,
    step: int | None = None,
    time: datetime | None = None,
) -> None

Log one scalar metric.

Source code in src/liblaf/cherries/core/_run.py
def log_metric(
    self,
    name: str,
    value: SupportsFloat,
    *,
    step: int | None = None,
    time: datetime | None = None,
) -> None:
    """Log one scalar metric."""
    self._metrics.log_metric(name, value, step=step, time=time)

log_metrics

log_metrics(
    metrics: MetricsLike,
    *,
    step: int | None = None,
    time: datetime | None = None,
) -> None

Log multiple scalar metrics, flattening nested mappings with /.

Source code in src/liblaf/cherries/core/_run.py
def log_metrics(
    self,
    metrics: MetricsLike,
    *,
    step: int | None = None,
    time: datetime | None = None,
) -> None:
    """Log multiple scalar metrics, flattening nested mappings with `/`."""
    self._metrics.log_metrics(metrics, step=step, time=time)

log_other

log_other(name: str, value: Any) -> None

Log one metadata value.

Source code in src/liblaf/cherries/core/_run.py
def log_other(self, name: str, value: Any) -> None:
    """Log one metadata value."""
    self._others.log_other(name, value)

log_others

log_others(others: Mapping[str, Any]) -> None

Log multiple metadata values.

Source code in src/liblaf/cherries/core/_run.py
def log_others(self, others: Mapping[str, Any]) -> None:
    """Log multiple metadata values."""
    self._others.log_others(others)

log_output

log_output(
    path: StrPath, metadata: Mapping[str, Any] | None = None
) -> None

Log an existing output artifact immediately.

Source code in src/liblaf/cherries/core/_run.py
def log_output(
    self, path: StrPath, metadata: Mapping[str, Any] | None = None
) -> None:
    """Log an existing output artifact immediately."""
    self._assets.log_output(path, metadata=metadata)

log_param

log_param(name: str, value: Any) -> None

Log one parameter value.

Source code in src/liblaf/cherries/core/_run.py
def log_param(self, name: str, value: Any) -> None:
    """Log one parameter value."""
    self._params.log_param(name, value)

log_params

log_params(params: Mapping[str, Any]) -> None

Log multiple parameter values.

Source code in src/liblaf/cherries/core/_run.py
def log_params(self, params: Mapping[str, Any]) -> None:
    """Log multiple parameter values."""
    self._params.log_params(params)

log_temp

log_temp(
    path: StrPath, metadata: Mapping[str, Any] | None = None
) -> None

Log an existing temporary artifact immediately.

Source code in src/liblaf/cherries/core/_run.py
def log_temp(
    self, path: StrPath, metadata: Mapping[str, Any] | None = None
) -> None:
    """Log an existing temporary artifact immediately."""
    self._assets.log_temp(path, metadata=metadata)

output

output(
    path: StrPath,
    *,
    metadata: Mapping[str, Any] | None = None,
    mkdir: bool = True,
) -> Path

Resolve an output below data/ and queue it until run end.

Source code in src/liblaf/cherries/core/_run.py
def output(
    self,
    path: StrPath,
    *,
    metadata: Mapping[str, Any] | None = None,
    mkdir: bool = True,
) -> Path:
    """Resolve an output below `data/` and queue it until run end."""
    return self._assets.output(path, metadata=metadata, mkdir=mkdir)

set_step

set_step(step: int) -> None

Set the default metric step.

Source code in src/liblaf/cherries/core/_run.py
def set_step(self, step: int) -> None:
    """Set the default metric step."""
    self.step = step

start

start() -> None

Start plugins and record Cherries run metadata.

Source code in src/liblaf/cherries/core/_run.py
def start(self) -> None:
    """Start plugins and record Cherries run metadata."""
    self.plugins.delegate("start")
    entrypoint: Path = relative_or_absolute(self.entrypoint, self.project_dir)
    exp_dir: Path = relative_or_absolute(self.working_dir, self.project_dir)
    self.log_other("cherries/cmd", shlex.join(sys.orig_argv))
    self.log_other("cherries/entrypoint", entrypoint)
    self.log_other("cherries/exp_dir", exp_dir)
    self.log_other("cherries/start_time", self.start_time)

summary

summary(prefix: StrPath | None = None) -> dict[str, Any]

Build a JSON/YAML-friendly run summary.

Parameters:

  • prefix (StrPath | None, default: None ) –

    Optional directory to strip from artifact paths.

Returns:

  • dict[str, Any]

    Run metadata, parameters, artifact paths, and user metadata.

Source code in src/liblaf/cherries/core/_run.py
def summary(self, prefix: StrPath | None = None) -> dict[str, Any]:
    """Build a JSON/YAML-friendly run summary.

    Args:
        prefix: Optional directory to strip from artifact paths.

    Returns:
        Run metadata, parameters, artifact paths, and user metadata.
    """
    summary: dict[str, Any] = {"name": self.run_name}
    if self.tags:
        summary["tags"] = self.tags
    others: dict[str, Any] = self.get_others()
    summary.update(others.pop("cherries"))
    summary["params"] = self.get_params()
    summary.update(self._assets.summary.to_dict(prefix=prefix))
    summary["others"] = others
    return summary

temp

temp(
    path: StrPath,
    *,
    metadata: Mapping[str, Any] | None = None,
    mkdir: bool = True,
) -> Path

Resolve a temporary artifact below tmp/ and queue it until run end.

Source code in src/liblaf/cherries/core/_run.py
def temp(
    self,
    path: StrPath,
    *,
    metadata: Mapping[str, Any] | None = None,
    mkdir: bool = True,
) -> Path:
    """Resolve a temporary artifact below `tmp/` and queue it until run end."""
    return self._assets.temp(path, metadata=metadata, mkdir=mkdir)

end

end(exc: BaseException | None = None) -> None

get_metric

get_metric(name: str) -> DataFrame

get_metrics

get_metrics(
    metrics: Iterator[str] | None = None,
) -> DataFrame

get_other

get_other(name: str) -> Any

get_others

get_others() -> dict[str, Any]

get_param

get_param(name: str) -> Any

get_params

get_params() -> dict[str, Any]

get_step

get_step() -> int

impl

impl[F: Callable[..., Any]](
    func: F,
    /,
    *,
    after: Iterable[PluginName] = (),
    before: Iterable[PluginName] = (),
) -> F
impl[F: Callable[..., Any]](
    *,
    after: Iterable[PluginName] = (),
    before: Iterable[PluginName] = (),
) -> Callable[[F], F]

Mark a method as a plugin hook implementation.

Parameters:

  • func (Callable[..., Any] | None, default: None ) –

    Method being decorated.

  • **kwargs (Any, default: {} ) –

    Ordering metadata accepted by [ImplInfo][liblaf.cherries.core.ImplInfo].

Examples:

>>> @impl(before=("Comet",))
... def log_metric():
...     return None
>>> get_impl_info(log_metric).before
('Comet',)
Source code in src/liblaf/cherries/core/plugin/_impl.py
def impl(func: Callable[..., Any] | None = None, /, **kwargs: Any) -> Any:
    """Mark a method as a plugin hook implementation.

    Args:
        func: Method being decorated.
        **kwargs: Ordering metadata accepted by [`ImplInfo`][liblaf.cherries.core.ImplInfo].

    Examples:
        >>> @impl(before=("Comet",))
        ... def log_metric():
        ...     return None
        >>> get_impl_info(log_metric).before
        ('Comet',)
    """
    if func is None:
        return functools.partial(impl, **kwargs)
    info = ImplInfo(**kwargs)
    func.__cherries_impl__ = info  # ty:ignore[unresolved-attribute]
    return func

input

input(
    path: StrPath,
    *,
    metadata: Mapping[str, Any] | None = None,
) -> Path

log_asset

log_asset(
    path: StrPath, metadata: Mapping[str, Any] | None = None
) -> None

log_input

log_input(
    path: StrPath, metadata: Mapping[str, Any] | None = None
) -> None

log_metric

log_metric(
    name: str,
    value: SupportsFloat,
    *,
    step: int | None = None,
    time: datetime | None = None,
) -> None

log_metrics

log_metrics(
    metrics: MetricsLike,
    *,
    step: int | None = None,
    time: datetime | None = None,
) -> None

log_other

log_other(name: str, value: Any) -> None

log_others

log_others(others: Mapping[str, Any]) -> None

log_output

log_output(
    path: StrPath, metadata: Mapping[str, Any] | None = None
) -> None

log_param

log_param(name: str, value: Any) -> None

log_params

log_params(params: Mapping[str, Any]) -> None

log_temp

log_temp(
    path: StrPath, metadata: Mapping[str, Any] | None = None
) -> None

output

output(
    path: StrPath,
    *,
    metadata: Mapping[str, Any] | None = None,
    mkdir: bool = True,
) -> Path

set_step

set_step(step: int) -> None

start

start() -> None

temp

temp(
    path: StrPath,
    *,
    metadata: Mapping[str, Any] | None = None,
    mkdir: bool = True,
) -> Path