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:
-
config– -
core– -
plugins– -
profiles– -
records–Immutable, content-addressed experiment records.
-
utils–
Classes:
-
BaseConfig–Base class for experiment configuration models.
-
Run–Mutable state for one Cherries experiment run.
-
RunAccessor–Read verified assets while holding the source record locally.
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.
-
open_run– -
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.
__version_tuple__
module-attribute
¶
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:
-
store_root(Path | None, default:None) – -
run_id(str, default:'f30a73e7-ab30-4645-82d2-6b54ba3ae030') – -
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
implare invoked. Hook order is cached per method and recalculated whenever a plugin is registered.
-
API Reference
README
cherriesrun -
API Reference
README
cherriesstart -
API Reference
README
README
corerun -
API Reference
README
README
pluginsCometrun -
API Reference
README
README
pluginsGitrun -
API Reference
README
README
pluginsLocalrun -
API Reference
README
README
pluginsLoggingrun -
API Reference
README
README
Comet
cometCometrun -
API Reference
README
README
Git
gitGitrun -
API Reference
README
README
Local
localLocalrun -
API Reference
README
README
Logging
loggingLoggingrun -
API Reference
README
README
profilesProfileinit -
API Reference
README
README
profilesProfileDebuginit -
API Reference
README
README
profilesProfileDefaultinit
-
API Reference
README
cherriesrun -
API Reference
README
README
corerun -
API Reference
README
README
pluginsComet -
API Reference
README
README
pluginsGit -
API Reference
README
README
pluginsLocal -
API Reference
README
README
pluginsLogging -
API Reference
README
README
Comet
cometComet -
API Reference
README
README
Git
gitGit -
API Reference
README
README
Local
localLocal -
API Reference
README
README
Logging
loggingLogging
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(bool) – -
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.
-
record_result(dict[str, Any] | None) – -
repo(Repo | None) – -
run_id(str) – -
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.
-
store(Store | None) – -
store_root(Path | None) – -
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.
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.
run_id
class-attribute
instance-attribute
¶
start_time
cached
property
¶
start_time: datetime
Timezone-aware timestamp captured when the run object is first used.
store
class-attribute
instance-attribute
¶
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
end
¶
end(exc: BaseException | None = None) -> None
Persist required local evidence; recording failures propagate.
Source code in src/liblaf/cherries/core/_run.py
356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 | |
get_metrics
¶
Return selected metric series concatenated into one dataframe.
get_other
¶
get_others
¶
get_param
¶
get_params
¶
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
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
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
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_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
log_param
¶
log_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
output
¶
Declare a required output in the active run; missing outputs fail saving.
Source code in src/liblaf/cherries/core/_run.py
start
¶
Allocate local work and capture evidence before calling user code.
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
¶
Return a disposable scratch path in the active run.
Source code in src/liblaf/cherries/core/_run.py
RunAccessor
¶
Read verified assets while holding the source record locally.
Methods:
Attributes:
Source code in src/liblaf/cherries/_access.py
__exit__
¶
close
¶
path
¶
Source code in src/liblaf/cherries/_access.py
end
¶
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_output
¶
log_output(
path: StrPath,
*,
metadata: Mapping[str, Any] | None = None,
name: StrPath | None = None,
) -> Path
log_temp
¶
log_temp(
path: StrPath,
*,
metadata: Mapping[str, Any] | None = None,
name: StrPath | None = None,
) -> Path
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"
def experiment(cfg: Config) -> None:
output = cherries.output("hello.txt")
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
open_run
¶
open_run(
run_id: str,
*,
workspace: Path | None = None,
store: Store | None = None,
) -> RunAccessor
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.