clabe.launcher ¶
Launcher ¶
Launcher(
*,
settings: LauncherCliArgs,
attached_logger: Logger | None = None,
client: Client | None = None,
)
Base class for experiment launchers. Provides functionality for managing configuration files, directories, and experiment execution.
This class serves as the foundation for launcher implementations, providing session management, directory handling, validation, and lifecycle management.
Properties
logger: The logger instance used by the launcher settings: The launcher configuration settings session: The registered session model session_directory: The path to the session directory
Methods:
| Name | Description |
|---|---|
register_session |
Registers a session model with the launcher |
run_experiment |
Main entry point for launcher execution |
copy_logs |
Closes file handlers and copies temporary data |
make_header |
Creates a formatted header string for the launcher |
validate |
Validates dependencies required for the launcher |
save_temp_model |
Saves a temporary JSON representation of a schema model |
create_directory |
Creates a directory at the specified path |
Initializes the Launcher instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings
|
LauncherCliArgs
|
The settings for the launcher |
required |
attached_logger
|
Logger | None
|
An attached logger instance. Defaults to None |
None
|
client
|
Client | None
|
The user interface (console, TUI, ...). Defaults to the backend selected by
|
None
|
Source code in src/clabe/launcher/_base.py
client
property
writable
¶
client: Client
The user interface this launcher asks and informs through outside a run (and drives the run with).
session_directory
property
¶
session_directory: Path
Returns the session directory path.
Returns:
| Name | Type | Description |
|---|---|---|
Path |
Path
|
The session directory path |
Raises:
| Type | Description |
|---|---|
ValueError
|
If session_name is not set in the session schema |
session_directories
property
¶
session_directories: list[Path | PureWindowsPath]
Every session folder of this run: this machine's, then its others, then every other machine's through its network share.
- This machine's other folders are the ones added with
add_session_directory, in that order. - Another machine's folder is listed once it was registered with
RemoteRepository.register_sessionin a step of this run.
Give it to the watchdog to upload the data of every folder:
WatchdogDataTransferService(source=launcher.session_directories, ...).
Raises:
| Type | Description |
|---|---|
ValueError
|
If session_name is not set in the session schema |
session
property
¶
Returns the registered session model.
Returns:
| Name | Type | Description |
|---|---|---|
Session |
Session
|
The session model |
Raises:
| Type | Description |
|---|---|
ValueError
|
If session is not set |
manifest
property
¶
The run manifest (run.json) of the run going on, once it has started.
logger
property
¶
logger: Logger
Returns the logger instance used by the launcher.
Returns:
| Type | Description |
|---|---|
Logger
|
logging.Logger: The logger instance |
settings
property
¶
settings: LauncherCliArgs
Returns the launcher settings.
Returns:
| Name | Type | Description |
|---|---|---|
LauncherCliArgs |
LauncherCliArgs
|
The launcher settings |
add_session_directory ¶
Adds another session folder on this machine to session_directories, e.g. where an app on this PC records
to its own data folder. The folder is created if missing (an existing one, e.g. found after a crash, is fine).
It is recorded in the run's run.json (extra_session_directories). Logs are still copied to
session_directory only. Adding the session folder, or a folder already added, does nothing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
PathLike | str
|
The folder, e.g. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
The folder, as given. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no session is registered yet. |
Source code in src/clabe/launcher/_base.py
register_session ¶
Registers the session model with the launcher, creates the session data directory structure, and saves repository-state metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
The session model to register |
required |
data_directory
|
PathLike
|
The root data directory for the session |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
The updated instance |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a session is already registered |
Source code in src/clabe/launcher/_base.py
run_experiment ¶
run_experiment(
experiment: Workflow | ExperimentCallable,
) -> None
Main entry point for the launcher execution.
Accepts a Workflow, or a (launcher) function (sync or async) run as a workflow of
one step, and executes it as a run driven by this launcher's client. Unless in debug mode,
validate runs as the run's first step (clabe_preflight). The run's records are written to
temp_dir. Orchestrates the complete launcher workflow including validation, execution and cleanup.
Steps (including a function's single step) run on a dedicated run thread, not the main thread; code that must
run on the main thread (e.g. signal.signal, some GUI toolkits) cannot be called from a step.
A launcher runs a single experiment: create a new launcher for another run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
experiment
|
Workflow | ExperimentCallable
|
The workflow, or the callable taking the launcher as its argument, to run |
required |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If this launcher has already run an experiment. |
Example
Source code in src/clabe/launcher/_base.py
update_manifest ¶
update_manifest(
change: Callable[[RunManifest], None],
) -> None
Applies change to the run manifest and rewrites run.json (nothing happens without a run).
For what only becomes known during the run, e.g. the other machines it used (see clabe.remote).
Thread-safe.
Source code in src/clabe/launcher/_base.py
copy_logs ¶
Closes the file handlers of the launcher and copies the temporary data to the session directory.
This method is typically called at the end of the launcher by a registered callable that transfers data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dst
|
PathLike | None
|
Destination path for logs. If None, uses session_directory/suffix. Defaults to None |
None
|
suffix
|
str
|
Suffix to append to session directory path. Defaults to "Behavior/Logs" |
'Behavior/Logs'
|
Source code in src/clabe/launcher/_base.py
make_header ¶
make_header() -> str
Creates a formatted header string for the launcher.
Generates a header containing the CLABE ASCII art logo and version information for the launcher and schema models.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The formatted header string |
Source code in src/clabe/launcher/_base.py
report_info ¶
What this launcher knows about the session, as ReportInfo fields.
Session id, subject and experimenter once a session is registered; the repository's folder name and head commit. Never raises: what cannot be read is left out.
Source code in src/clabe/launcher/_base.py
validate ¶
Validates the dependencies required for the launcher to run.
Checks Git repository state, handles dirty repository conditions, and ensures all prerequisites are met for experiment execution.
Example
launcher = MyLauncher(...) try: launcher.validate() print("Validation successful") except Exception as e: print(f"Validation failed: {e}")
Source code in src/clabe/launcher/_base.py
create_directory
staticmethod
¶
create_directory(directory: PathLike) -> None
Creates a directory at the specified path if it does not already exist.
To prevent deadlocks from network issues/auth, this function will run on a separate thread and timeout after 2 seconds.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
directory
|
PathLike
|
The path of the directory to create |
required |
Raises:
| Type | Description |
|---|---|
OSError
|
If the directory creation fails |
TimeoutError
|
If the directory creation times out after 2 seconds |
Source code in src/clabe/launcher/_base.py
save_temp_model ¶
Saves a temporary JSON representation of a schema model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
BaseModel
|
The schema model to save |
required |
directory
|
PathLike | None
|
The directory to save the file in. Defaults to temp_dir if None |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Path |
Path
|
The path to the saved file |
Source code in src/clabe/launcher/_base.py
LauncherCliArgs ¶
Bases: ServiceSettings
CLI arguments for the launcher using Pydantic for validation and configuration.
Provides command-line argument parsing and validation for launcher operations.
settings_customise_sources
classmethod
¶
settings_customise_sources(
settings_cls: type[BaseSettings],
init_settings: PydanticBaseSettingsSource,
env_settings: PydanticBaseSettingsSource,
dotenv_settings: PydanticBaseSettingsSource,
file_secret_settings: PydanticBaseSettingsSource,
) -> tuple[PydanticBaseSettingsSource, ...]
Customizes the settings sources to include the safe YAML settings source.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings_cls
|
type[BaseSettings]
|
The settings class |
required |
init_settings
|
PydanticBaseSettingsSource
|
The initial settings source |
required |
env_settings
|
PydanticBaseSettingsSource
|
The environment settings source |
required |
dotenv_settings
|
PydanticBaseSettingsSource
|
The dotenv settings source |
required |
file_secret_settings
|
PydanticBaseSettingsSource
|
The file secret settings source |
required |
Returns:
| Type | Description |
|---|---|
tuple[PydanticBaseSettingsSource, ...]
|
Tuple[PydanticBaseSettingsSource, ...]: A tuple of settings sources |