Skip to content

README

liblaf.cherries.core.assets

Modules:

Classes:

  • AssetPluginProtocol

    Hook surface for plugins that receive artifact paths.

  • AssetsManager

    Resolve experiment paths and flush existing artifacts to plugins.

  • Bundle

    Base class for artifact companion-file discovery.

  • BundleItem

    Related file discovered for a logged artifact.

  • BundleRegistry

    Registry that expands logged artifacts through matching bundles.

Attributes:

bundles module-attribute

AssetPluginProtocol

Bases: Protocol


              flowchart TD
              liblaf.cherries.core.assets.AssetPluginProtocol[AssetPluginProtocol]

              

              click liblaf.cherries.core.assets.AssetPluginProtocol href "" "liblaf.cherries.core.assets.AssetPluginProtocol"
            

Hook surface for plugins that receive artifact paths.

Methods:

  • log_asset

    Record an existing artifact path.

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`.
    """
    ...

AssetsManager

Resolve experiment paths and flush existing artifacts to plugins.

Inputs are reported immediately because they should already exist. Outputs and temporary artifacts are queued until run shutdown so an experiment can create them after configuration is built.

Parameters:

  • working_dir (Path) –

    Directory used as the base for data/ and tmp/ paths.

  • plugins (AssetPluginProtocol) –

    Plugin delegate that receives existing artifacts.

  • bundles (BundleRegistry, default: BundleRegistry(registry=[BundleLandmarks(suffixes={'.vtr', '.vtkhdf', '.obj', '.stl', '.ply', '.vtu', '.vtp', '.vti', '.vts'}), BundleSeries()]) ) –

    Bundle registry used to expand related files.

  • pending (list[PendingAsset], default: <dynamic> ) –

    Built-in mutable sequence.

    If no argument is given, the constructor creates a new empty list. The argument must be an iterable if specified.

  • summary (AssetsSummary, default: <dynamic> ) –

    Paths successfully reported during a run.

    The summary contains only primary artifacts. Bundle companions are sent to plugins, but omitted from this user-facing record.

Methods:

  • end

    Flush queued output and temporary paths.

  • input

    Resolve and immediately log an input path.

  • log_asset

    Log an existing path and any companion files from matching bundles.

  • log_input

    Log path as an input artifact.

  • log_output

    Log path as an output artifact.

  • log_temp

    Log path as a temporary artifact.

  • output

    Resolve an output path and queue it for end-of-run logging.

  • temp

    Resolve a temporary path and queue it for end-of-run logging.

Attributes:

  • bundles (BundleRegistry) –

    Bundle registry used to expand related files.

  • data_dir (Path) –

    Directory containing input and output data files.

  • pending (list[PendingAsset]) –

    Output and temporary paths waiting for run shutdown.

  • plugins (AssetPluginProtocol) –

    Plugin delegate that receives existing artifacts.

  • summary (AssetsSummary) –

    Artifact summary populated by successful log calls.

  • temp_dir (Path) –

    Directory containing temporary artifacts.

  • working_dir (Path) –

    Directory used as the base for data/ and tmp/ paths.

bundles class-attribute instance-attribute

bundles: BundleRegistry = field(default=bundles)

Bundle registry used to expand related files.

data_dir property

data_dir: Path

Directory containing input and output data files.

pending class-attribute instance-attribute

pending: list[PendingAsset] = field(factory=list)

Output and temporary paths waiting for run shutdown.

plugins instance-attribute

Plugin delegate that receives existing artifacts.

summary class-attribute instance-attribute

summary: AssetsSummary = field(factory=AssetsSummary)

Artifact summary populated by successful log calls.

temp_dir property

temp_dir: Path

Directory containing temporary artifacts.

working_dir instance-attribute

working_dir: Path

Directory used as the base for data/ and tmp/ paths.

end

end() -> None

Flush queued output and temporary paths.

Missing queued paths produce warnings and are left out of the summary.

Source code in src/liblaf/cherries/core/assets/_manager.py
def end(self) -> None:
    """Flush queued output and temporary paths.

    Missing queued paths produce warnings and are left out of the summary.
    """
    for asset in self.pending:
        self.log_asset(asset.path, metadata=asset.metadata)

input

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

Resolve and immediately log an input path.

Parameters:

  • name (StrPath) –

    Path below data/.

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

    Extra metadata merged with {"type": "input"}.

Returns:

  • Path

    Resolved input path.

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

    Args:
        name: Path below `data/`.
        metadata: Extra metadata merged with `{"type": "input"}`.

    Returns:
        Resolved input path.
    """
    path: Path = self.data_dir / name
    metadata: dict[str, Any] = _metadata_with_type(metadata, "input")
    self.log_input(path, metadata=metadata)
    return path

log_asset

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

Log an existing path and any companion files from matching bundles.

Missing primary paths are reported as warnings. Missing optional bundle files are ignored, while missing required bundle files are warned.

Source code in src/liblaf/cherries/core/assets/_manager.py
def log_asset(
    self, path: StrPath, *, metadata: Mapping[str, Any] | None = None
) -> None:
    """Log an existing path and any companion files from matching bundles.

    Missing primary paths are reported as warnings. Missing optional bundle
    files are ignored, while missing required bundle files are warned.
    """
    path: Path = Path(path)
    if not path.exists():
        logger.warning("No such file or directory: %s", path)
        return
    if metadata is None:
        self.summary.assets.append(path)
    else:
        match metadata.get("type"):
            case "input":
                self.summary.inputs.append(path)
            case "output":
                self.summary.outputs.append(path)
            case "temp":
                self.summary.temps.append(path)
            case _:
                self.summary.assets.append(path)
    self.plugins.log_asset(path, metadata=metadata, report=True)
    for path_, optional in self.bundles.ls_files(path):
        path: Path = Path(path_)
        if not path.exists():
            if not optional:
                logger.warning("No such file or directory: %s", path)
            continue
        self.plugins.log_asset(path, metadata=metadata, report=False)

log_input

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

Log path as an input artifact.

Source code in src/liblaf/cherries/core/assets/_manager.py
def log_input(
    self, path: StrPath, *, metadata: Mapping[str, Any] | None = None
) -> None:
    """Log `path` as an input artifact."""
    metadata: dict[str, Any] = _metadata_with_type(metadata, "input")
    self.log_asset(path, metadata=metadata)

log_output

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

Log path as an output artifact.

Source code in src/liblaf/cherries/core/assets/_manager.py
def log_output(
    self, path: StrPath, *, metadata: Mapping[str, Any] | None = None
) -> None:
    """Log `path` as an output artifact."""
    metadata: dict[str, Any] = _metadata_with_type(metadata, "output")
    self.log_asset(path, metadata=metadata)

log_temp

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

Log path as a temporary artifact.

Source code in src/liblaf/cherries/core/assets/_manager.py
def log_temp(
    self, path: StrPath, *, metadata: Mapping[str, Any] | None = None
) -> None:
    """Log `path` as a temporary artifact."""
    metadata: dict[str, Any] = _metadata_with_type(metadata, "temp")
    self.log_asset(path, metadata=metadata)

output

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

Resolve an output path and queue it for end-of-run logging.

Parameters:

  • name (StrPath) –

    Path below data/.

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

    Extra metadata merged with {"type": "output"}.

  • mkdir (bool, default: True ) –

    Whether to create the parent directory before returning.

Returns:

  • Path

    Resolved output path.

Source code in src/liblaf/cherries/core/assets/_manager.py
def output(
    self,
    name: StrPath,
    *,
    metadata: Mapping[str, Any] | None = None,
    mkdir: bool = True,
) -> Path:
    """Resolve an output path and queue it for end-of-run logging.

    Args:
        name: Path below `data/`.
        metadata: Extra metadata merged with `{"type": "output"}`.
        mkdir: Whether to create the parent directory before returning.

    Returns:
        Resolved output path.
    """
    path: Path = self.data_dir / name
    if mkdir:
        path.parent.mkdir(parents=True, exist_ok=True)
    metadata: dict[str, Any] = _metadata_with_type(metadata, "output")
    self.pending.append(PendingAsset(path=path, metadata=metadata))
    return path

temp

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

Resolve a temporary path and queue it for end-of-run logging.

Parameters:

  • name (StrPath) –

    Path below tmp/.

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

    Extra metadata merged with {"type": "temp"}.

  • mkdir (bool, default: True ) –

    Whether to create the parent directory before returning.

Returns:

  • Path

    Resolved temporary path.

Source code in src/liblaf/cherries/core/assets/_manager.py
def temp(
    self,
    name: StrPath,
    *,
    metadata: Mapping[str, Any] | None = None,
    mkdir: bool = True,
) -> Path:
    """Resolve a temporary path and queue it for end-of-run logging.

    Args:
        name: Path below `tmp/`.
        metadata: Extra metadata merged with `{"type": "temp"}`.
        mkdir: Whether to create the parent directory before returning.

    Returns:
        Resolved temporary path.
    """
    path: Path = self.temp_dir / name
    if mkdir:
        path.parent.mkdir(parents=True, exist_ok=True)
    metadata: dict[str, Any] = _metadata_with_type(metadata, "temp")
    self.pending.append(PendingAsset(path=path, metadata=metadata))
    return path

Bundle

Bases: ABC


              flowchart TD
              liblaf.cherries.core.assets.Bundle[Bundle]

              

              click liblaf.cherries.core.assets.Bundle href "" "liblaf.cherries.core.assets.Bundle"
            

Base class for artifact companion-file discovery.

Methods:

  • ls_files

    Yield files that should be logged with path.

  • match

    Return whether this bundle can expand path.

ls_files abstractmethod

ls_files(path: Path) -> Iterable[BundleItem]

Yield files that should be logged with path.

Parameters:

  • path (Path) –

    Primary artifact path.

Returns:

  • Iterable[BundleItem]

    Iterable of companion files and their optional/missing-file policy.

Source code in src/liblaf/cherries/core/assets/bundle/_abc.py
@abc.abstractmethod
def ls_files(self, path: Path) -> Iterable[BundleItem]:
    """Yield files that should be logged with `path`.

    Args:
        path: Primary artifact path.

    Returns:
        Iterable of companion files and their optional/missing-file policy.
    """
    raise NotImplementedError

match abstractmethod

match(path: Path) -> bool

Return whether this bundle can expand path.

Parameters:

  • path (Path) –

    Primary artifact path.

Returns:

Source code in src/liblaf/cherries/core/assets/bundle/_abc.py
@abc.abstractmethod
def match(self, path: Path) -> bool:
    """Return whether this bundle can expand `path`.

    Args:
        path: Primary artifact path.

    Returns:
        `True` when [`ls_files`][liblaf.cherries.core.assets.bundle.Bundle.ls_files]
        can yield companion files for `path`.
    """
    raise NotImplementedError

BundleItem

Bases: NamedTuple


              flowchart TD
              liblaf.cherries.core.assets.BundleItem[BundleItem]

              

              click liblaf.cherries.core.assets.BundleItem href "" "liblaf.cherries.core.assets.BundleItem"
            

Related file discovered for a logged artifact.

Attributes:

Parameters:

  • path (ForwardRef, default: None ) –
  • optional (ForwardRef, default: None ) –

optional instance-attribute

optional: bool

path instance-attribute

path: StrPath

BundleRegistry

Registry that expands logged artifacts through matching bundles.

Examples:

>>> registry = BundleRegistry(registry=[])
>>> list(registry.ls_files(Path("mesh.vtu")))
[]

Parameters:

  • registry (list[Bundle], default: [BundleLandmarks(suffixes={'.vtr', '.vtkhdf', '.obj', '.stl', '.ply', '.vtu', '.vtp', '.vti', '.vts'}), BundleSeries()] ) –

Methods:

  • ls_files

    Yield companion files from every bundle that matches path.

  • register

    Append bundle to the registry.

Attributes:

registry class-attribute instance-attribute

registry: list[Bundle] = field(factory=_default_registry)

ls_files

ls_files(path: Path) -> Generator[BundleItem]

Yield companion files from every bundle that matches path.

Source code in src/liblaf/cherries/core/assets/bundle/_registry.py
def ls_files(self, path: Path) -> Generator[BundleItem]:
    """Yield companion files from every bundle that matches `path`."""
    for bundle in self.registry:
        if bundle.match(path):
            yield from bundle.ls_files(path)

register

register(bundle: Bundle) -> None

Append bundle to the registry.

Source code in src/liblaf/cherries/core/assets/bundle/_registry.py
def register(self, bundle: Bundle) -> None:
    """Append `bundle` to the registry."""
    self.registry.append(bundle)