Launchers
Launchers, together with the Connector, specify how a task should be launched. There exist two types of launchers at the moment, direct launcher (starting a new process) or through slurm
Priority
All launchers have a priority property (default: 0) that determines their preference
when used with a DynamicLauncher. Higher priority
values indicate more preferred launchers.
from experimaestro.launchers.slurm import SlurmLauncher
# Create launchers with different priorities
fast_launcher = SlurmLauncher(options=SlurmOptions(partition="fast"), priority=10)
slow_launcher = SlurmLauncher(options=SlurmOptions(partition="slow"), priority=1)
Types
Direct
By default, jobs are launched directly by the scheduler using python scripts.
DirectLauncher - Launcher that runs tasks directly as local processes without any job scheduler.
Slurm
The Slurm workload manager launcher is supported.
It is possible to use different settings for different jobs by using the config
method of the launcher
from experimaestro.launchers.slurm import SlurmLauncher
launcher = SlurmLauncher(nodes=1)
gpulauncher = launcher.config(gpu_per_node=1)
with experiment(launcher=launcher):
# Default
mytask().submit()
# If needed, options can be used
mytask().submit(launcher=gpulauncher)
SlurmOptions - Configuration options for SLURM jobs (nodes, time, partition, GPUs, etc.).
SlurmLauncher - Launcher that submits tasks to the SLURM workload manager.
Pilot allocations (beta)
Warning
This feature is in beta: the options and the files it writes may change.
Important
Pilots are coordinated through files in the pilots/ folder of the workspace:
the workspace must be on a file system shared by the submission host and the
compute nodes (e.g. NFS or Lustre), and the experiment must submit to SLURM
from a cluster host (local connector, not an SSH connector). The pilots run the
same Python interpreter as the experiment (XPM_PILOT_PYTHON overrides it),
which must thus be reachable from the compute nodes.
When many short jobs request the same resources, waiting in the SLURM queue
for each of them can take longer than running them. With the pilot option, a
SLURM launcher submits pilot jobs instead: each pilot holds an allocation for
up to time and runs queued jobs one after another, until not enough time is
left or it has nothing to do (see Stopping below).
from experimaestro.launchers.slurm import PilotOptions, SlurmLauncher, SlurmOptions
launcher = SlurmLauncher(
options=SlurmOptions(partition="gpu", gpus_per_node=1, time="1:00:00"),
pilot=PilotOptions(time="20:00:00", idle_timeout=600, max_pilots=4),
)
Job duration: the
timeSLURM option of the job’s launcher is its time limit. A pilot only takes a job if it can finish in time (plus amargin), and stops the job (SIGTERM, thenSIGKILLafterkill_waitseconds) when the time limit is reached: the job then fails with a timeout, so a resumable task is retried andremaining_time()gives the time left before the job’s own time limit (or the pilot’s end, if earlier).Pools: the pilots that can run a job form a pool, stored in the
pilots/<pool>folder of the workspace.<pool>is the first 16 hexadecimal digits of a SHA-256 hash of:the path of the SLURM commands (
binpathof the launcher),the SLURM options except
time(options that are not set are left out),all the
PilotOptions(time,idle_timeout,max_pilots,margin,kill_wait,poll_interval,linger).
Two launchers that only differ by
time(e.g. built bylaunchers.pyfor requirements with different durations) thus share a pool, while changing any other SLURM or pilot option gives a different pool. The output of a pilot is inpilots/<pool>/pilots/<pilot>.{out,err}.Sharing between experiments: a pool belongs to a workspace, not to an experiment. Experiments running in the same workspace with the same options use the same pool, and any of its pilots can run any of their jobs (whichever experiment submitted them, and whichever submitted the pilot). Experiments in different workspaces never share pilots. Jobs without a
timeoption, or longer than a pilot (time+marginabove the pilottime), do not use pilots and are submitted withsbatchas usual.Starting pilots: experiments waiting for jobs of a pool check it every
poll_intervalseconds. The waiting jobs are matched (longest first) with the pilots that can take a job: pilots still pending in the SLURM queue (they will have their fulltime) and idle running pilots whose remaining time covers the job’stimeplusmargin. A new pilot is submitted for each job left without one, so a job that does not fit in what remains of a running pilot gets a new pilot, and so do jobs that become ready while all pilots are busy.max_pilotscaps the number of pilots of the pool (pending or running): above it, jobs wait until a pilot is free — or stops, in which case a new one is submitted. A pilot takes the oldest waiting job that fits in its remaining time, by exclusively creating a claim file with a hard link (reliable on NFS), so that a job is run only once even when several pilots look at the queue.Stopping: an idle pilot stops after
idle_timeoutseconds, orlingerseconds (1 minute by default) after no experiment has jobs in its pool (each experiment renews a lease while it has jobs queued or running in the pool), so that allocations are released soon after the experiments end.experimaestro workspace pilots --stopasks all the pilots to stop taking jobs.Failures: a job is marked as failed if its pilot ends while running it (e.g. the pilot is cancelled, or a node fails); a timeout of the pilot is reported as a timeout of the job. Killing a job only stops this job, not the pilot.
In launchers.py, the policy is plain Python, e.g. to only pack short jobs:
PILOT = PilotOptions(time="20:00:00")
def find_launcher(requirements: HostRequirement, tags=set()):
if match := requirements.match(HostSpecification(...)):
duration = match.requirement.duration
return SlurmLauncher(
options=SlurmOptions(time=SlurmOptions.format_time(duration)),
pilot=PILOT if duration <= 4 * 3600 else None,
)
The job details (TUI and web UI) show where a job runs (e.g. running in
pilot SLURM job 1234 on node12, time limit at 2026-11-05 14:00) or that it
waits for a pilot, and experimaestro workspace pilots lists the pilots of a
workspace (pending, running with their current job, idle) and the waiting jobs
(--all also shows the stopped pilots).
PilotOptions - Options of the pilot allocations.
Python environments chosen on the node
On a cluster whose nodes differ, a single Python environment may not run on all of them: a PyTorch build only has kernels for some GPU generations (e.g. the CUDA 13 builds have none for Pascal or Volta GPUs, and the CUDA 12.6 ones none for Blackwell GPUs), and an x86 environment does not run on ARM nodes. Since the partition, and thus the node, is only known once SLURM starts the job, the job script can choose the Python environment on the node.
This is opt-in: the environment that runs the experiment (sys.prefix, e.g. a
uv .venv) lists other environments in a experimaestro-envs.json file at its
root:
{"environments": [
{"python": "/home/user/project/.venv-arm/bin/python",
"when": "[ \"$(uname -m)\" = aarch64 ]"},
{"python": "/home/user/project/.venv-cu126/bin/python",
"when": "nvidia-smi --query-gpu=compute_cap --format=csv,noheader | head -n 1 | grep -Eq '^(6\\.|7\\.0$)'"}
]}
Each
whenis a shell command, run on the node (in a subshell, with its output discarded) beforesrun: the job runs with thepythonof the first one that succeeds, and otherwise with the interpreter of the experiment. The job script thus ends with:XPM_PYTHON=/home/user/project/.venv/bin/python if ( [ "$(uname -m)" = aarch64 ] ) >/dev/null 2>&1; then XPM_PYTHON=/home/user/project/.venv-arm/bin/python elif ... fi echo "experimaestro: Python interpreter $XPM_PYTHON" >&2 srun "$XPM_PYTHON" ./task.py
The selected interpreter is reported in the standard error of the job.
Without the file, job scripts do not change (
srun ./task.py, whose first line gives the Python interpreter of the experiment).This also applies to the jobs run by pilot allocations, which run the job script.
The environments should have the same packages (e.g. created from the same lock file), and be created on a node with internet access (compute nodes often have none), e.g. the login node.
experimaestro tools environments lists the environments of the current one,
and with --check, runs their tests to show the interpreter jobs would use on
the current node (e.g. in an interactive SLURM job).
Example: PyTorch with several CUDA versions
xpm-torch provides
xpm-torch uv-cuda-sync, which creates one uv environment per CUDA build of
torch (e.g. cu126 for the older GPUs, cu130 for the newer ones) and writes this
file, with tests on the GPU of the node: an environment is used when its torch
build has kernels for the GPU and the driver supports its CUDA version:
uv run xpm-torch uv-cuda-sync && uv run experimaestro run ...
python_environments() - The environments listed by the current environment.
PythonEnvironment - A Python environment and its shell test.
Dynamic Launcher
The DynamicLauncher allows dynamic selection
from a list of launchers based on their priorities. This is useful when you have
multiple execution options (e.g., different SLURM partitions or clusters) and want
to select the best one at runtime.
from experimaestro.launchers import DynamicLauncher
from experimaestro.launchers.slurm import SlurmLauncher, SlurmOptions
# Create launchers with different priorities
fast_partition = SlurmLauncher(
options=SlurmOptions(partition="fast", time="1:00:00"), priority=10
)
slow_partition = SlurmLauncher(
options=SlurmOptions(partition="slow", time="24:00:00"), priority=1
)
# By default, selects highest priority (fast_partition)
# If priorities tie, samples uniformly among tied launchers
dynamic = DynamicLauncher([fast_partition, slow_partition])
# With sample=True, samples proportionally to priority
# fast_partition has 10/(10+1) ≈ 91% chance of being selected
dynamic_sampled = DynamicLauncher([fast_partition, slow_partition], sample=True)
with experiment(launcher=dynamic):
mytask().submit()
Selection Modes
Default mode (
sample=False): Selects the launcher with the highest priority. If multiple launchers share the highest priority, one is chosen uniformly at random.Sampling mode (
sample=True): Samples a launcher with probability proportional to its priority. All priorities must be positive in this mode.
Extending DynamicLauncher
You can subclass DynamicLauncher and override the update() method to refresh
the launcher list before each job submission. This is useful for checking cluster
availability or queue status:
class ClusterAwareLauncher(DynamicLauncher):
def update(self):
# Check cluster availability and update priorities
for launcher in self._launchers:
if is_cluster_available(launcher):
launcher.priority = 10
else:
launcher.priority = 0
DynamicLauncher - Launcher that dynamically selects from a list of launchers based on priority.
Launcher file
The launchers.py file dictates how a given requirement (e.g., 2 CPU with
64Go of memory) is mapped to a given Launcher configuration.
Requirements
HostRequirement- Abstract base representing a disjunction of host requirements (alternatives).HostSimpleRequirement- A single host requirement specifying CPU, GPU, and duration constraints.AcceleratorSpecification- Generic accelerator (GPU) specification that matches any accelerator type.CudaSpecification- Specifies NVIDIA CUDA GPU requirements (dedicated memory).MPSSpecification- Specifies Apple Metal Performance Shaders requirements (unified memory).CPUSpecification- Specifies CPU requirements (cores, memory).
Accelerator Types
The launcher finder supports multiple accelerator (GPU) types:
CUDA (
cuda()): NVIDIA GPUs with dedicated memory. Use when you specifically need CUDA support.MPS (
mps()): Apple Silicon GPUs with unified memory (shared with CPU). Use for macOS Metal support.Generic (
gpu()): Matches any accelerator type. Use for cross-platform compatibility.
Tip
If your code runs on any accelerator (e.g., PyTorch code that works on both
CUDA and MPS backends), prefer the generic gpu(...) over cuda(...): the
same requirement will then match an NVIDIA GPU on a Linux cluster and an
Apple Silicon GPU on a laptop. Reserve cuda(...) for code that genuinely
requires CUDA (e.g., custom CUDA kernels or CUDA-only libraries).
Note
MPS uses unified memory - the GPU shares RAM with the CPU. When matching MPS requirements, the combined CPU + GPU memory request must not exceed the total system memory.
Parsing requirements
parse() - Parses a requirement specification string into a HostRequirement object.
Syntax elements:
duration=<N><unit>: Job duration (units: h/hours, d/days, m/mins)cpu(mem=<size>, cores=<N>): CPU requirementscuda(mem=<size>) * <N>: NVIDIA CUDA GPU requirements (memory and count)mps(mem=<size>) * <N>: Apple MPS GPU requirements (unified memory)gpu(mem=<size>) * <N>: Generic GPU requirements (matches any accelerator)Memory sizes:
<N>G,<N>GiB,<N>M,<N>MiB
Note
Memory sizes require an explicit unit: cuda(mem=32) is rejected with a
ValueError (use cuda(mem=32G)).
Examples:
from experimaestro.launcherfinder.parser import parse
# Request 8 NVIDIA GPUs with 32GB each
req = parse("duration=40h & cpu(mem=700GiB) & cuda(mem=32GiB) * 8")
# Cross-platform code: generic GPU requirement (matches any accelerator)
req = parse("duration=2h & gpu(mem=4GiB)")
# Equivalent explicit alternative: CUDA on Linux/Windows OR MPS on macOS
req = parse("duration=4h & cuda(mem=8GiB) | duration=4h & mps(mem=8GiB)")
Requirements can be manipulated:
duration can be multiplied by a given coefficient using
req.multiply_duration. For instance,req.multiply_duration(2)multiplies all the duration by 2.
Example
To construct launchers given a specification, you have to use a launchers.py
file within the configuration directory.
from typing import Set
from experimaestro.launcherfinder import (
HostRequirement,
HostSpecification,
AcceleratorSpecification,
CudaSpecification,
MPSSpecification,
CPUSpecification,
)
from experimaestro.launchers.slurm import SlurmLauncher, SlurmOptions
from experimaestro.launchers.direct import DirectLauncher
from experimaestro.connectors.local import LocalConnector
def find_launcher(requirements: HostRequirement, tags: Set[str] = set()):
"""Find a launcher"""
if match := requirements.match(HostSpecification(accelerators=[])):
# No GPU: run directly
return DirectLauncher(connector=LocalConnector.instance())
# CUDA cluster with SLURM
if match := requirements.match(
HostSpecification(
max_duration=100 * 3600,
cpu=CPUSpecification(cores=32, memory=129 * (1024**3)),
accelerators=[CudaSpecification(memory=24 * (1024**3)) for _ in range(8)],
)
):
if len(match.requirement.accelerators) > 0:
return SlurmLauncher(
connector=LocalConnector.instance(),
options=SlurmOptions(gpus_per_node=len(match.requirement.accelerators)),
)
# Apple Silicon with MPS (unified memory)
if match := requirements.match(
HostSpecification(
cpu=CPUSpecification(cores=8, memory=32 * (1024**3)),
accelerators=[MPSSpecification(memory=32 * (1024**3))],
)
):
return DirectLauncher(connector=LocalConnector.instance())
# Could not find a host
return None
Note
The cuda= parameter is still supported for backwards compatibility but
accelerators= is preferred for new code as it supports all accelerator types.
Jobs longer than the partition time limit
A cluster usually caps job duration (e.g. SLURM MaxTime), while a training
task may legitimately request more (duration=120h). Rather than lowering the
requirement in every experiment, launchers.py can accept the total duration
and run resumable tasks in slices: the job is
submitted with the partition limit and, on timeout, resubmitted by the
scheduler (up to max_retries, 3 by default) and restarts from its
checkpoints.
Whether a job is resumable is only known at submission, so this is done with a
submit listener (addListener()),
which receives the Job and can
replace its launcher. Non-resumable tasks are refused when the experiment
starts, instead of being rejected by SLURM later.
from experimaestro import Job
from experimaestro.launcherfinder import HostRequirement, HostSpecification
from experimaestro.launchers.slurm import SlurmLauncher, SlurmOptions
# Hard limit of the SLURM partitions
PARTITION_MAX_DURATION = 48 * 3600
# Total duration accepted for resumable tasks (several 48h runs)
MAX_DURATION = 196 * 3600
def cap_duration(job: Job):
if not job.resumable:
raise ValueError(
f"{job.config.__xpmtype__.identifier} requests more than"
f" {PARTITION_MAX_DURATION // 3600}h but is not a ResumableTask"
)
job.launcher = job.launcher.config(
time=SlurmOptions.format_time(PARTITION_MAX_DURATION)
)
def find_launcher(requirements: HostRequirement, tags=set()):
if match := requirements.match(
# (with the other limits of the host: CPUs, memory, accelerators)
HostSpecification(max_duration=MAX_DURATION)
):
duration = match.requirement.duration
launcher = SlurmLauncher(
options=SlurmOptions(
time=SlurmOptions.format_time(min(duration, PARTITION_MAX_DURATION)),
# ... and the other SLURM options (partition, GPUs, ...)
)
)
if duration > PARTITION_MAX_DURATION:
launcher.addListener(cap_duration)
return launcher
Note
The listener replaces job.launcher (using
config()) instead of
modifying the launcher options in place: the same launcher instance is
usually shared by many jobs, some of which may not be resumable.
Debugging the launcher file
You can query the launcher finder directly — without running an experiment — to check which launcher a given requirement resolves to.
From the command line
The find-launchers command loads launchers.py from the configuration
directory (~/.config/experimaestro by default, or the directory given with
--config) and prints the launcher returned for a requirement specification:
experimaestro tools find-launchers 'duration=1h & cuda(mem=32G) * 1 & cpu(cores=8)'
# With an explicit configuration directory
experimaestro tools find-launchers --config /path/to/config-dir 'duration=1h & cuda(mem=32G) * 1'
From Python
The same query can be run from a REPL, which is convenient for inspecting intermediate objects:
from pathlib import Path
from experimaestro.launcherfinder import LauncherRegistry, find_launcher
# Optional: use a non-default configuration directory
LauncherRegistry.set_config_dir(Path("/path/to/config-dir"))
launcher = find_launcher("duration=1h & cuda(mem=32G) * 1 & cpu(cores=8)")
print(launcher)
find_launcher raises a LauncherNotFoundError when no launcher matches; the
lower-level LauncherRegistry.instance().find(...) returns None instead.
Checking how a specification is parsed
If the returned launcher is not the one you expect, first check that the specification string is parsed the way you intend:
Note that memory sizes require an explicit unit: cuda(mem=32) raises a
ValueError instead of being silently interpreted as 32 bytes. Use
cuda(mem=32G) instead.
Tracing the matching process
Since launchers.py is plain Python, you can add logging.debug calls in your
find_launcher function (e.g., to print every matching host specification and
its score) and enable debug logging when querying:
import logging
logging.basicConfig(level=logging.DEBUG)