clabe.remote ¶
Running on other machines: a checkout of this repository on another rig (RemoteRepository), reached
through that machine's clabe daemon, which runs jobs and keeps files for the run that leased it.
WorkerClient ¶
WorkerClient(settings: WorkerClientSettings)
Talks to the worker role of another machine's daemon.
Jobs and files need the worker's lease when someone holds it: lease takes it (and keeps renewing
it in the background) so that no other run uses the machine meanwhile; release gives it back.
Source code in src/clabe/remote/_client.py
info ¶
info() -> WorkerInfo
The worker, as seen for the configured repository.
Source code in src/clabe/remote/_client.py
shares ¶
lease ¶
Takes the worker for this run and keeps renewing it until release.
Raises:
| Type | Description |
|---|---|
WorkerError
|
423 if another run holds it, 409 if the machine runs an experiment of its own. |
Source code in src/clabe/remote/_client.py
release ¶
release(*, stop_jobs: bool = False) -> None
Gives the worker back; stop_jobs also stops the jobs still running there.
Source code in src/clabe/remote/_client.py
submit_command ¶
Starts a command in the background; the current trace context goes along.
Source code in src/clabe/remote/_client.py
jobs_of ¶
jobs_of(run_id: str) -> list[JobSummary]
The jobs of run run_id not yet collected (running, or finished with an unread result).
Source code in src/clabe/remote/_client.py
get_result ¶
A job's state, with its output once it ended (the worker forgets it once read).
is_running ¶
list_jobs ¶
job_output ¶
A running job's output lines after line after.
Source code in src/clabe/remote/_client.py
stop_job ¶
wait_for_result ¶
Waits for a job to end (see monitor in the settings) and returns its result.
Raises:
| Type | Description |
|---|---|
TimeoutError
|
The job did not end in time (or, when monitoring, stopped being seen running). |
Source code in src/clabe/remote/_client.py
run_command ¶
run_command(
cmd_args: list[str] | str,
timeout: float | None = None,
cwd: str | None = None,
) -> JobResult
Runs a command and waits for its result.
Source code in src/clabe/remote/_client.py
upload_file ¶
upload_file(
local_path: str | Path,
remote_filename: str | None = None,
overwrite: bool = True,
) -> FileInfo
Uploads a file to the worker's transfer directory.
Source code in src/clabe/remote/_client.py
upload_bytes ¶
Uploads content as a file of the worker's transfer directory.
Source code in src/clabe/remote/_client.py
upload_model ¶
Uploads a pydantic model as a JSON file.
Source code in src/clabe/remote/_client.py
download_file ¶
Downloads a file of the worker's transfer directory (to local_path, default its name here).
Source code in src/clabe/remote/_client.py
list_files ¶
delete_all_files ¶
Deletes every file of the worker's transfer directory; returns their names.
run ¶
run(command: Command) -> CommandResult
run_async
async
¶
run_async(command: Command) -> CommandResult
Runs command on the worker, e.g. await app.run_async(executor=client).
WorkerClientSettings ¶
Bases: ServiceSettings
Settings of a WorkerClient (worker_client: in clabe.yml).
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 |
Source code in src/clabe/settings.py
WorkerError ¶
Bases: RuntimeError
The worker refused or failed a request; status is the HTTP status.
Source code in src/clabe/remote/_client.py
RemoteExecutor ¶
RemoteExecutor(
client: WorkerClient,
timeout: float | None = None,
poll_interval: float | None = None,
cwd: str | None = None,
path_mapping: Mapping[str, str] | None = None,
)
Runs commands on a worker; any app runs on it unchanged (app.run(executor=...)).
Inputs a command declares (Command.inputs) are sent along with it, and path_mapping rewrites local path
prefixes to their location on the worker. A cancelled run_async (e.g. the run was aborted) stops the job on
the worker. To run apps in a checkout of this repository on another machine, use
RemoteRepository, which builds on this executor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
WorkerClient
|
The worker's client. |
required |
timeout
|
float | None
|
Seconds to wait for a job (see the client's |
None
|
poll_interval
|
float | None
|
Seconds between checks of a job; the client's by default. |
None
|
cwd
|
str | None
|
Working directory on the worker; the repository's by default. |
None
|
path_mapping
|
Mapping[str, str] | None
|
Local path prefixes to rewrite in commands, mapped to their location on the worker. |
None
|
Source code in src/clabe/remote/_executor.py
host
property
¶
host: str | None
The worker's host name (apps use it to reach services the command starts there).
run ¶
run(command: Command[Any]) -> CommandResult
Runs the command on the worker and waits for it; inside a run its output shows as a live activity.
Source code in src/clabe/remote/_executor.py
wait ¶
wait(
job_id: str, description: str = "job"
) -> CommandResult
Waits for a job already on the worker (e.g. one a crashed launcher started) and returns its result.
Source code in src/clabe/remote/_executor.py
run_async
async
¶
run_async(command: Command[Any]) -> CommandResult
Runs the command on the worker without blocking the event loop; cancelling it stops the job. Inside a run its output shows as a live activity.
Source code in src/clabe/remote/_executor.py
wait_async
async
¶
wait_async(
job_id: str, description: str = "job"
) -> CommandResult
Asynchronous wait; cancelling it stops the job.
Source code in src/clabe/remote/_executor.py
FileInfo ¶
Bases: BaseModel
A file in the worker's transfer directory.
JobResult ¶
Bases: BaseModel
A job's state, and its output once it ended.
JobSummary ¶
Bases: BaseModel
A job, as listed for the run it belongs to.
Lease ¶
Bases: BaseModel
The worker taken by a run; requests carrying it (X-Clabe-Lease) are served, others refused.
Share ¶
Bases: BaseModel
A folder the worker's machine shares on the network.
WorkerInfo ¶
Bases: BaseModel
A worker, as seen for one of its repositories.
RemoteRepository ¶
RemoteRepository(
client: WorkerClient,
path: str | None = None,
*,
local_path: PathLike | str = ".",
data_roots: Mapping[str, str] | None = None,
detach_on_abort: bool = False,
)
A checkout of this repository on another machine, reached through that machine's clabe daemon (its worker).
The repository must be one the remote daemon offers (found under its roots, or in
DAEMON_CLABE_REPOSITORIES); commands run in it and in its environment by default. The first command (or lease) takes the worker's lease, so no other
run uses the machine meanwhile; it is renewed in the background and given back by release (or at exit).
Example
remote = RemoteRepository.from_computer_name("rig-b", data_roots={r"D:\data": r"\\rig-b\data"})
remote.ensure_running()
remote.verify()
remote.register_session(session, fip_rig.data_directory)
fip_app = AindBehaviorServicesBonsaiApp("./Aind.Physiology.Fip/src/main.bonsai", rig=fip_rig, session=session)
await fip_app.run_async(executor=remote)
source = remote.session_directory_unc # e.g. \\rig-b\data\<session name>
Initializes the remote repository.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
WorkerClient
|
Client of the remote machine's worker (its |
required |
path
|
str | None
|
Path of the repository on the remote machine. Defaults to the worker's repository.
When given, |
None
|
local_path
|
PathLike | str
|
Path of the local repository the remote one is compared against. |
'.'
|
data_roots
|
Mapping[str, str] | None
|
Maps data directories on the remote machine to the network shares exposing them,
e.g. |
None
|
detach_on_abort
|
bool
|
Keep the commands running on the remote machine when the run does not complete (e.g. a recording that must outlive the launcher). By default they are stopped with the run. |
False
|
Source code in src/clabe/remote/_repository.py
data_directory
property
¶
data_directory: PurePath
Root data directory on the remote machine, set by register_session.
session_directory
property
¶
session_directory: PurePath
Session directory as the remote machine sees it, e.g. to configure where an app saves its data.
session_directory_unc
property
¶
session_directory_unc: PureWindowsPath
Session directory as other machines reach it through its network share, e.g. for watchdog or mappers.
from_computer_name
classmethod
¶
from_computer_name(
computer_name: str,
port: int = DEFAULT_PORT,
path: str | None = None,
*,
repository: str | None = None,
local_path: PathLike | str = ".",
data_roots: Mapping[str, str] | None = None,
) -> Self
Connects to the daemon of a machine by its computer name, e.g. a rig's computer_name: nothing to
configure. The other client settings (a token, timeouts), when needed, come from the experiment's
worker_client section.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
computer_name
|
str
|
Network name of the remote machine. |
required |
port
|
int
|
Port of its daemon. |
DEFAULT_PORT
|
path
|
str | None
|
Path of the repository on the remote machine. See |
None
|
repository
|
str | None
|
The remote daemon's name for the repository; by default this repository's folder name. |
None
|
local_path
|
PathLike | str
|
Path of the local repository the remote one is compared against. |
'.'
|
data_roots
|
Mapping[str, str] | None
|
Maps data directories on the remote machine to the network shares exposing them. Defaults to the drives' administrative shares. |
None
|
Source code in src/clabe/remote/_repository.py
info ¶
info(refresh: bool = False) -> WorkerInfo
Returns the remote worker's information, fetching it on first use or when refresh is True.
Source code in src/clabe/remote/_repository.py
lease ¶
lease(run_id: str | None = None) -> None
Takes the remote machine for this run (the first command does it anyway); renewed until released.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
run_id
|
str | None
|
The run to take it for; by default the running one. A restarted launcher passes the run id of
the session it recovers (see |
None
|
Raises:
| Type | Description |
|---|---|
WorkerError
|
423 if another run holds the machine, 409 if it runs an experiment of its own. |
Source code in src/clabe/remote/_repository.py
reattach ¶
reattach(run_id: str) -> list[JobSummary]
Takes the remote machine back for run run_id and returns that run's jobs still there.
For recovering a session after the launcher crashed: its jobs kept running on the remote machine, and for a
grace period after its lease expired only the same run may take the machine back. The run id and the
machine are in the crashed session's run.json (run_id, workers). Collect each job's result with
wait_for.
Source code in src/clabe/remote/_repository.py
wait_for ¶
wait_for(job_id: str) -> CommandResult
Waits for a job already on the remote machine (see reattach) and returns its result.
wait_for_async
async
¶
wait_for_async(job_id: str) -> CommandResult
release ¶
release(*, stop_jobs: bool = False) -> None
Gives the remote machine back; stop_jobs also stops what still runs there.
ensure_running ¶
Starts the remote daemon through its scheduled task (clabe daemon install) if it does not respond.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout
|
float
|
Seconds to wait for the daemon to respond after starting the task. |
60.0
|
poll_interval
|
float
|
Seconds between connection attempts. |
1.0
|
Raises:
| Type | Description |
|---|---|
ConnectionError
|
If the remote machine's name cannot be resolved to an address. |
TimeoutError
|
If the daemon does not respond within |
Source code in src/clabe/remote/_repository.py
verify ¶
verify(allow_dirty: bool = False) -> None
Checks that the remote repository runs the same code as the local one.
Compares the worker's repository path, and the repository URL and commit of the repository and each submodule. Because the lockfile is tracked, a matching clean commit also implies the same locked dependencies. A different clabe version of the daemon is only warned about.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
allow_dirty
|
bool
|
Whether to accept uncommitted changes in the remote repository. |
False
|
Raises:
| Type | Description |
|---|---|
RepositoryMismatchError
|
Listing every difference found. |
Source code in src/clabe/remote/_repository.py
to_unc ¶
to_unc(path: PathLike | str) -> PureWindowsPath
Translates a path on the remote machine to the network share path other machines reach it by.
Paths under none of the data_roots are reached through the drive's administrative share; see
to_unc.
Raises:
| Type | Description |
|---|---|
ValueError
|
If the path is under none of the |
Source code in src/clabe/remote/_repository.py
register_session ¶
Registers the session this machine records data for, and creates its session directory there.
The remote counterpart of register_session. Optional: only
data_directory, session_directory and session_directory_unc need it.
Raises:
| Type | Description |
|---|---|
ValueError
|
If a session is already registered, or the session has no name. |
Source code in src/clabe/remote/_repository.py
mkdir ¶
Creates a directory, and its missing parents, on the remote machine.
write_file ¶
Writes a file on the remote machine, creating its directory if needed.
The content is uploaded to the worker's transfer directory and then moved into place. It is limited to the
client's max_file_size.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
PathLike | str
|
The file, as the remote machine sees it. Replaced if it exists. |
required |
content
|
str | bytes
|
The content. Text is written as UTF-8. |
required |
Source code in src/clabe/remote/_repository.py
run ¶
run(command: Command[Any]) -> CommandResult
Runs a command in the remote repository and waits for it (an Executor).
Paths under the local repository are rewritten to the remote one, and the command's inputs are copied
to the remote machine.
Raises:
| Type | Description |
|---|---|
CommandError
|
If the command exits with a non-zero code. |
Source code in src/clabe/remote/_repository.py
run_async
async
¶
run_async(command: Command[Any]) -> CommandResult
Asynchronous version of run, e.g. await app.run_async(executor=remote); cancelling it stops
the command on the remote machine.
Source code in src/clabe/remote/_repository.py
RepositoryMismatchError ¶
Bases: RuntimeError
Raised when a remote repository does not match the local one.
to_unc ¶
to_unc(
path: PathLike | str,
data_roots: Mapping[str, str] | None = None,
host: str | None = None,
) -> PureWindowsPath
Translates a path on another machine to the network share path it is reached by.
Needs no connection to that machine, e.g. to find the data of a session recorded there earlier. A path under
none of the data_roots is reached through its drive's administrative share on host, e.g. D:\data
on rig-b as \\rig-b\D$\data, which needs administrator rights on that machine.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
PathLike | str
|
An absolute path on the other machine. |
required |
data_roots
|
Mapping[str, str] | None
|
Maps data directories on that machine to the network shares exposing them,
e.g. |
None
|
host
|
str | None
|
Name of the other machine, for its administrative shares. |
None
|
Returns:
| Type | Description |
|---|---|
PureWindowsPath
|
The same location under its network share. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the path is under none of the |