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 = attrs.field(
    default=attrs.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:

  • store_root (Path | None, default: None ) –
  • run_id (str, default: '2d5f1da1-ac6c-41b3-8f36-55cdae4dbcc7' ) –
  • store (Store | None, default: None ) –
  • active (bool, default: False ) –
  • record_result (dict[str, Any] | None, default: None ) –
  • 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:

  • abort_start –

    Retain an incomplete stage when source or startup recording fails.

  • end –

    Persist required local evidence; recording failures propagate.

  • 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 –

    Copy verified input bytes into the active run and record their origin.

  • log_asset –

    Retain an explicit artifact as an independent file inside the active run.

  • log_input –

    Copy and retain an existing input in the active run.

  • 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 –

    Copy or register an existing output inside the active run.

  • log_param –

    Log one parameter value.

  • log_params –

    Log multiple parameter values.

  • log_temp –

    Promote a temporary file into retained run artifacts.

  • output –

    Declare a required output in the active run; missing outputs fail saving.

  • set_step –

    Set the default metric step.

  • start –

    Allocate local work and capture evidence before calling user code.

  • summary –

    Build a JSON/YAML-friendly run summary.

  • temp –

    Return a disposable scratch path in the active run.

Attributes:

active class-attribute instance-attribute

active: bool = False

entrypoint cached property

entrypoint: Path

Python entrypoint used to derive the experiment name and folders.

plugins class-attribute instance-attribute

plugins: PluginManager = attrs.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.

record_result class-attribute instance-attribute

record_result: dict[str, Any] | None = None

repo cached property

repo: Repo | None

run_id class-attribute instance-attribute

run_id: str = attrs.field(factory=lambda: str(uuid.uuid4()))

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.

store class-attribute instance-attribute

store: Store | None = attrs.field(default=None, repr=False)

store_root class-attribute instance-attribute

store_root: Path | None = None

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.

abort_start

abort_start(error: BaseException) -> None

Retain an incomplete stage when source or startup recording fails.

Source code in src/liblaf/cherries/core/_run.py
def abort_start(self, error: BaseException) -> None:
    """Retain an incomplete stage when source or startup recording fails."""
    self._close_logging()
    if (
        self.store is not None
        and (self.store.root / "pending" / f"{self.run_id}.json").exists()
    ):
        self.store.append_event(
            "recording-incomplete", self.run_id, {"reason": str(error)}
        )
    self._assets.active = False
    self.active = False

end

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

Persist required local evidence; recording failures propagate.

Source code in src/liblaf/cherries/core/_run.py
def end(self, exc: BaseException | None = None) -> None:
    """Persist required local evidence; recording failures propagate."""
    if not self.active or self.store is None:
        msg = "no active Cherries run"
        raise RuntimeError(msg)
    if isinstance(exc, SystemExit) and exc.code in (None, 0):
        # ``sys.exit(0)`` has the same process outcome as returning from a
        # normal Python experiment.  Seal it before main() re-raises the
        # exception so the interpreter can still exit successfully.
        exc = None
    self.log_other("cherries/end_time", datetime.now().astimezone())
    try:
        self._join_writers()
        if exc is not None:
            diagnostic = "".join(traceback.format_exception(exc))[-65536:]
            self.log_other("cherries/exception", diagnostic)
            self.plugins.delegate("end", exc=exc)
            self._close_logging()
            failure = {
                "exception": diagnostic,
                "execution": "failed",
                "name": self.run_name,
                "source": self._source_evidence,
            }
            if (
                self._settings.get("execution", {}).get(
                    "failure_payload", "discard"
                )
                == "discard"
            ):
                self.store.cancel_failed_work(self.run_id, failure)
            else:
                self.store.append_event("execution-failed", self.run_id, failure)
            return
        self._assets.end()
        end_source = capture_source(
            self.project_dir,
            self.entrypoint,
            self.working_dir / "source-end",
            self._settings,
        )
        stable = self._source_evidence.get("fingerprint") == end_source.get(
            "fingerprint"
        )
        config = self.working_dir / "config"
        config.mkdir(parents=True, exist_ok=True)
        (config / "resolved.json").write_text(
            json.dumps(
                _json_safe(self.get_params()),
                default=str,
                sort_keys=True,
                indent=2,
                allow_nan=False,
            )
            + "\n"
        )
        (config / "bindings.json").write_text(
            json.dumps(self._assets.bindings, default=str, sort_keys=True, indent=2)
            + "\n"
        )
        metrics = self.get_metrics().to_dicts() if self._metrics.metrics else []
        (self.working_dir / "logs/metrics.json").write_text(
            json.dumps(
                _json_safe(metrics),
                default=str,
                sort_keys=True,
                indent=2,
                allow_nan=False,
            )
            + "\n"
        )
        (self.working_dir / "RUN.md").write_text(
            f"# {self.run_name}\n\nRun: `{self.run_id}`\n\nExecution: succeeded. Review: unreviewed.\n\nSource stable across execution: {stable}. Replay has not been verified.\n"
        )
        self.plugins.delegate("end", exc=None)
        self._close_logging()
        self.record_result = self.store.seal(
            self.run_id,
            {
                "kind": "experiment",
                "name": self.run_name,
                "tags": self.tags,
                "command": shlex.join(sys.orig_argv),
                "argv": sys.argv[1:],
                "entrypoint": str(
                    relative_or_absolute(self.entrypoint, self.project_dir)
                ),
                "execution": {"status": "succeeded", "exit_code": 0},
                "validation": {"status": "not_evaluated"},
                "params": _json_safe(self.get_params()),
                "others": json.loads(
                    json.dumps(
                        _json_safe(self.get_others()), default=str, allow_nan=False
                    )
                ),
                "input_bindings": self._assets.bindings,
                "bundles": self._assets.retained_bundles,
                "source": self._source_evidence,
                "source_stability": stable,
                "replay_verified": False,
            },
            self.working_dir,
        )
        logger.info("Saved Cherries run %s", self.run_id)
    except BaseException as failure:
        self.store.append_event(
            "recording-incomplete",
            self.run_id,
            {"reason": str(failure), "work": str(self.working_dir)},
        )
        raise
    finally:
        self._close_logging()
        self._assets.active = False
        self.active = False

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,
    *,
    name: StrPath | None = None,
    source_run: str | None = None,
    metadata: Mapping[str, Any] | None = None,
) -> Path

Copy verified input bytes into the active run and record their origin.

Source code in src/liblaf/cherries/core/_run.py
def input(
    self,
    path: StrPath,
    *,
    name: StrPath | None = None,
    source_run: str | None = None,
    metadata: Mapping[str, Any] | None = None,
) -> Path:
    """Copy verified input bytes into the active run and record their origin."""
    return self._assets.input(
        path, name=name, source_run=source_run, metadata=metadata
    )

log_asset

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

Retain an explicit artifact as an independent file inside the active run.

Source code in src/liblaf/cherries/core/_run.py
def log_asset(
    self,
    path: StrPath,
    metadata: Mapping[str, Any] | None = None,
    *,
    name: StrPath | None = None,
) -> Path:
    """Retain an explicit artifact as an independent file inside the active run."""
    return self._assets.log_asset(path, metadata=metadata, name=name)

log_input

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

Copy and retain an existing input in the active run.

Source code in src/liblaf/cherries/core/_run.py
def log_input(
    self,
    path: StrPath,
    metadata: Mapping[str, Any] | None = None,
    *,
    name: StrPath | None = None,
) -> Path:
    """Copy and retain an existing input in the active run."""
    return self._assets.log_input(path, metadata=metadata, name=name)

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,
    *,
    name: StrPath | None = None,
) -> Path

Copy or register an existing output inside the active run.

Source code in src/liblaf/cherries/core/_run.py
def log_output(
    self,
    path: StrPath,
    metadata: Mapping[str, Any] | None = None,
    *,
    name: StrPath | None = None,
) -> Path:
    """Copy or register an existing output inside the active run."""
    return self._assets.log_output(path, metadata=metadata, name=name)

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,
    *,
    name: StrPath | None = None,
) -> Path

Promote a temporary file into retained run artifacts.

Source code in src/liblaf/cherries/core/_run.py
def log_temp(
    self,
    path: StrPath,
    metadata: Mapping[str, Any] | None = None,
    *,
    name: StrPath | None = None,
) -> Path:
    """Promote a temporary file into retained run artifacts."""
    return self._assets.log_temp(path, metadata=metadata, name=name)

output

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

Declare a required output in the active run; missing outputs fail saving.

Source code in src/liblaf/cherries/core/_run.py
def output(
    self,
    path: StrPath,
    *,
    metadata: Mapping[str, Any] | None = None,
    mkdir: bool = True,
) -> Path:
    """Declare a required output in the active run; missing outputs fail saving."""
    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

Allocate local work and capture evidence before calling user code.

Source code in src/liblaf/cherries/core/_run.py
def start(self) -> None:
    """Allocate local work and capture evidence before calling user code."""
    if self.active:
        msg = "a Cherries run is already active"
        raise RuntimeError(msg)
    self.run_id = str(uuid.uuid4())
    self.start_time = datetime.now().astimezone()
    self._settings = load_settings(self.project_dir)
    self.store = Store(self.store_root or storage_root(self.project_dir))
    self.store.ensure_initialized(self._settings.get("collection", {}).get("id"))
    self.working_dir = self.store.start_work(
        self.run_id,
        {
            "pid": os.getpid(),
            "name": self.run_name,
            "machine_id": self.store.machine_id,
        },
    )
    parent = os.environ.get("CHERRIES_PARENT_RUN")
    if parent:
        self.store.register_parent(self.run_id, self.store.resolve_id(parent))
    self._assets = AssetsManager(
        working_dir=self.working_dir,
        plugins=cast("AssetPluginProtocol", self.plugins),
        active=True,
        store=self.store,
        run_id=self.run_id,
    )
    self._metrics = self._default_metrics()
    self._params = self._default_params()
    self._others = self._default_others()
    self.record_result = None
    self.active = True
    logs = self.working_dir / "logs"
    logs.mkdir(parents=True)
    handler = logging.FileHandler(logs / "run.log", encoding="utf-8")
    handler.setFormatter(
        logging.Formatter("%(asctime)s %(levelname)s %(name)s: %(message)s")
    )
    logging.getLogger().addHandler(handler)
    self._file_handler = handler
    self._source_evidence = capture_source(
        self.project_dir,
        self.entrypoint,
        self.working_dir / "source",
        self._settings,
    )
    capture_environment(self.project_dir, self.working_dir / "environment")
    self.plugins.delegate("start")
    self._thread_ids = {thread.ident for thread in threading.enumerate()}
    self._child_pids = self._children()
    self.log_other("cherries/cmd", shlex.join(sys.orig_argv))
    self.log_other(
        "cherries/entrypoint",
        relative_or_absolute(self.entrypoint, self.project_dir),
    )
    self.log_other("cherries/exp_dir", self.working_dir)
    self.log_other("cherries/start_time", self.start_time)
    self.log_other("cherries/run_id", self.run_id)

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

Return a disposable scratch path in the active run.

Source code in src/liblaf/cherries/core/_run.py
def temp(
    self,
    path: StrPath,
    *,
    metadata: Mapping[str, Any] | None = None,
    mkdir: bool = True,
) -> Path:
    """Return a disposable scratch path in the active run."""
    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,
    *,
    name: StrPath | None = None,
    source_run: str | None = None,
    metadata: Mapping[str, Any] | None = None,
) -> Path

log_asset

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

log_input

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

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,
    name: StrPath | None = None,
) -> Path

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,
    name: StrPath | None = None,
) -> Path

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