Runtime backends¶
Where a run executes: this machine, a container, or a Slurm job array.
abmfact.runtime¶
Runtime backends: local, container and Slurm. The container and Slurm backends load on first use.
abmfact.runtime.base¶
Backends: where a prepared run executes (this machine, a container, or a cluster).
- class abmfact.runtime.base.Backend[source]¶
Bases:
ABCBase class for the places a prepared run can execute.
- name¶
The short backend name recorded on each
RunHandle.- Type:
str
- abstractmethod availability() Availability[source]¶
Report whether this backend can run here now, with a reason and, where known, a version.
- abstractmethod submit(prepared: PreparedRun) RunHandle[source]¶
Start a run. Local and container backends finish it before returning.
abmfact.runtime.local¶
The local backend: in-process calls, native commands as subprocesses, and the v0.1 process pool.
- class abmfact.runtime.local.LocalBackend(workers: int = 1, timeout: float | None = None)[source]¶
Bases:
BackendRun on this machine.
An in-process
callruns directly and its exceptions propagate unchanged, as v0.1 adapters always behaved. A nativeargvruns in the prepared work directory with stdout and stderr inrun.log.- availability() Availability[source]¶
Report whether this backend can run here now, with a reason and, where known, a version.
- submit(prepared: PreparedRun) RunHandle[source]¶
Start a run. Local and container backends finish it before returning.
- map(task: Callable[[J], R], jobs: Sequence[J], progress: Callable[[int, int], None] | None = None) list[R][source]¶
Apply
taskto every job, in a process pool whenworkers > 1. Results keep job order.The task is pickled once and installed in each worker. A task that cannot be pickled (a lambda, say) runs serially in this process instead.
- abmfact.runtime.local.run_command(prepared: PreparedRun, argv: list[str], backend: str, timeout: float | None) RunHandle[source]¶
Run
argvin the work directory, logging torun.log; never raises on a failed run.
abmfact.runtime.container¶
The container backend: run a prepared command inside a Docker, Podman or Apptainer image.
The run’s work directory is mounted at /work and used as the working directory, so an engine
prepares the same files and relative command for local and container runs. The image digest is
recorded in the run handle, which pins the engine build in the run record.
- abmfact.runtime.container.REPOSITORY = 'https://github.com/a7med7emedan/ABMfact.git'¶
The repository whose
containers/folder holds the engine images’ Dockerfiles.
- abmfact.runtime.container.build_command(image: str, folder: str, platform: str | None = None, version: str | None = None) str[source]¶
The
docker buildcommand for an engine image, with its Dockerfile fetched from GitHub.A release builds from its own tag, so the image matches the installed code. A development version has no tag and builds from main. Docker fetches
containers/<folder>itself, so no checkout is needed.
- abmfact.runtime.container.detect_runtime(which: ~collections.abc.Callable[[str], str | None] = <function which>, runner: ~collections.abc.Callable[[...], ~typing.Any] = <function run>) str | None[source]¶
The first usable container runtime: Docker or Podman with a running daemon, or Apptainer.
- class abmfact.runtime.container.ContainerBackend(image: str, runtime: str = 'auto', platform: str | None = None, timeout: float | None = None, runner: ~collections.abc.Callable[[...], ~typing.Any] = <function run>, which: ~collections.abc.Callable[[str], str | None] = <function which>)[source]¶
Bases:
BackendRun prepared commands in
image.runtimeis"auto"or one of docker, podman, apptainer, singularity. For Apptainer the image is a.siffile. Extra read-only mounts come fromprepared.context["mounts"](host to container).- property is_oci: bool¶
Whether the runtime is Docker or Podman, which use OCI images rather than
.siffiles.
- availability() Availability[source]¶
Report whether this backend can run here now, with a reason and, where known, a version.
- image_digest() str | None[source]¶
The registry digest when the image was pulled, else its local id; a file hash for
.sif.
- command(prepared: PreparedRun) list[str][source]¶
The full command line that runs
prepared.argvin the image.
- submit(prepared: PreparedRun) RunHandle[source]¶
Start a run. Local and container backends finish it before returning.
abmfact.runtime.slurm¶
The Slurm backend: write one job array for many prepared runs, and submit it only when asked.
Each array task reads its line from manifest.tsv (task index, work directory, command), changes to
the work directory and runs the command with output in run.log. Collect the runs with the engine
once the array has finished.
- class abmfact.runtime.slurm.SlurmBackend(partition: str | None = None, time: str = '01:00:00', mem: str = '4G', cpus_per_task: int = 1, account: str | None = None, max_parallel: int | None = None, job_name: str = 'abmfact', directives: ~collections.abc.Sequence[str] = (), container: ~abmfact.runtime.container.ContainerBackend | None = None, runner: ~collections.abc.Callable[[...], ~typing.Any] = <function run>)[source]¶
Bases:
BackendRun prepared native commands as a Slurm job array, optionally inside a container.
The settings become
#SBATCHlines:partition,time,mem,cpus_per_taskandaccount.max_parallelcaps how many array tasks run at once, anddirectivesadds raw#SBATCHoptions.- availability() Availability[source]¶
Report whether this backend can run here now, with a reason and, where known, a version.
- write_array_script(prepared: Sequence[PreparedRun], path: str | Path) Path[source]¶
Write
path(the sbatch script) andmanifest.tsvbeside it. Nothing is submitted.
- submit_array(prepared: Sequence[PreparedRun], path: str | Path, submit: bool = False) list[RunHandle][source]¶
Write the array script; with
submit=Truealso runsbatchand record the job id.
- submit(prepared: PreparedRun) RunHandle[source]¶
Start a run. Local and container backends finish it before returning.