README
liblaf.cherries
¶
Run Python experiments with typed config, path helpers, and plugins.
Cherries exposes a compact facade around a process-global
Run. Use main to run an
experiment function inside a profile, BaseConfig
for typed settings, and helpers such as output to
queue artifacts for logging at shutdown.
Modules:
Classes:
-
BaseConfig–Base class for experiment configuration models.
-
Run–Mutable state for one Cherries experiment run.
Functions:
-
end–End the process-global run.
-
get_metric– -
get_metrics– -
get_other– -
get_others– -
get_param– -
get_params– -
get_step– -
input– -
log_asset– -
log_input– -
log_metric– -
log_metrics– -
log_other– -
log_others– -
log_output– -
log_param– -
log_params– -
log_temp– -
main–Run an experiment callable inside a Cherries profile.
-
output– -
set_step– -
start–Create, configure, and start a run from
profile. -
temp–
Attributes:
-
__commit_id__(str | None) – -
__version__(str) – -
__version_tuple__(tuple[int | str, ...]) – -
run(Run) –Process-global run used by Cherries convenience functions.
BaseConfig
¶
Bases: BaseSettings
flowchart TD
liblaf.cherries.BaseConfig[BaseConfig]
click liblaf.cherries.BaseConfig href "" "liblaf.cherries.BaseConfig"
Base class for experiment configuration models.
Subclass BaseConfig when an experiment callable should receive structured
settings. main instantiates missing annotated
arguments, logs Pydantic models as parameters, and then calls the
experiment. The default settings config enables CLI parsing and converts
field names to kebab-case flags.
Examples:
>>> class Config(BaseConfig):
... name: str = "world"
... epochs: int = 3
>>> Config.model_fields["name"].default
'world'
Attributes:
-
model_config(SettingsConfigDict) –
model_config
class-attribute
¶
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
implare 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(Path) –Python entrypoint used to derive the experiment name and folders.
-
plugins(PluginManager) – -
project_dir(Path) –Git repository root, or the current directory outside a Git repo.
-
project_name(str) –Project name reported to plugins.
-
repo(Repo | None) – -
run_key(Path) – -
run_name(str) –Run name from
CHERRIES_NAMEor the entrypoint path. -
start_time(datetime) –Timezone-aware timestamp captured when the run object is first used.
-
step(int) –Default metric step.
-
tags(list[str]) –Tags parsed from the
CHERRIES_TAGSenvironment variable. -
working_dir(Path) –Directory used to resolve data, temporary, log, and local snapshot paths.
entrypoint
cached
property
¶
entrypoint: Path
Python entrypoint used to derive the experiment name and folders.
project_dir
cached
property
¶
project_dir: Path
Git repository root, or the current directory outside a Git repo.
start_time
cached
property
¶
start_time: datetime
Timezone-aware timestamp captured when the run object is first used.
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
get_metrics
¶
Return selected metric series concatenated into one dataframe.
get_other
¶
get_others
¶
get_param
¶
get_params
¶
input
¶
Resolve and immediately log an input below data/.
log_asset
¶
Log an existing generic artifact immediately.
log_input
¶
log_metric
¶
log_metric(
name: str,
value: SupportsFloat,
*,
step: int | None = None,
time: datetime | None = None,
) -> None
Log one scalar metric.
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
log_other
¶
log_others
¶
log_output
¶
Log an existing output artifact immediately.
log_param
¶
log_params
¶
log_temp
¶
Log an existing temporary artifact immediately.
output
¶
Resolve an output below data/ and queue it until run end.
Source code in src/liblaf/cherries/core/_run.py
start
¶
Start plugins and record Cherries run metadata.
Source code in src/liblaf/cherries/core/_run.py
summary
¶
Build a JSON/YAML-friendly run summary.
Parameters:
-
prefix(StrPath | None, default:None) –Optional directory to strip from artifact paths.
Returns:
Source code in src/liblaf/cherries/core/_run.py
temp
¶
Resolve a temporary artifact below tmp/ and queue it until run end.
Source code in src/liblaf/cherries/core/_run.py
end
¶
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
main
¶
main[T](
main: Callable[..., Awaitable[T]],
*,
profile: ProfileLike | None = None,
) -> T
main[T](
main: Callable[..., T],
*,
profile: ProfileLike | None = None,
) -> T
Run an experiment callable inside a Cherries profile.
Missing positional and keyword arguments are built from their annotations
when possible. Pydantic models are logged as parameters before the callable
runs. Coroutine results are awaited with asyncio.run().
Parameters:
-
main(Callable[..., Any]) –Experiment callable.
-
profile(ProfileLike | None, default:None) –Profile name, profile instance, or profile class.
Returns:
-
Any–The callable result. If the callable returns a coroutine, Cherries waits
-
Any–for it with
asyncio.run()and returns the awaited value.
Raises:
-
BaseException–Re-raises any exception from the experiment after ending the run with the captured exception.
Examples:
Use a typed config object and a queued output path in an experiment:
from pathlib import Path
from liblaf import cherries
class Config(cherries.BaseConfig):
name: str = "world"
output: Path = cherries.output("hello.txt", mkdir=True)
def experiment(cfg: Config) -> None:
cfg.output.write_text(f"Hello, {cfg.name}!\\n")
cherries.log_metric("message_length", len(cfg.name))
cherries.main(experiment, profile="debug")
Source code in src/liblaf/cherries/_main/_main.py
output
¶
start
¶
start(profile: ProfileLike | None = None) -> Run
Create, configure, and start a run from profile.
Parameters:
-
profile(ProfileLike | None, default:None) –Profile name, instance, class, or
Nonefor environment-based selection.
Returns:
-
Run–Started run.