Running experiments
An experiment is a piece of Python code that submits tasks within the
experiment context manager. The context manager owns
the workspace, schedules the submitted jobs, resolves their dependencies, and
serves the monitoring interfaces.
Two ways to run
|
|
|
|---|---|---|
Parameters |
Written in Python |
Read from |
Workspace |
Given explicitly |
Selected from the settings |
Best for |
Notebooks, one-off scripts, tests |
Projects, reproducible runs, parameter sweeps |
Directly, in Python:
from experimaestro import experiment
with experiment("/path/to/workspace", "my-experiment", port=12345) as xp:
model = Learn.C(epochs=100).submit()
Task workers load the task module from its file and do not inherit the
sys.path of the launching script. If your tasks import modules by name at
run time (plugin registries, factories, sibling packages), give the roots of
these packages with python_path — the counterpart of the pythonpath key of
the YAML configuration:
with experiment("/path/to/workspace", "my-experiment", python_path=["src"]) as xp:
...
or through the command line, where the experiment code is a run(helper, cfg)
function and its parameters come from a configuration file:
experimaestro run full.yaml
The second form is the recommended one for anything you intend to re-run — see The CLI experiment runner.
Good practices
Declare your workspace once
A workspace is where jobs and experiments are stored. Rather than repeating
--workdir on every command, declare it in
~/.config/experimaestro/settings.yaml and let experimaestro select it:
workspaces:
- id: neuralir
path: ~/experiments/xpmir
triggers:
- "neuralir-*"
Any experiment whose ID matches a trigger runs in that workspace; --workspace neuralir selects it explicitly. Keep one workspace per project or per storage
tier — jobs are shared within a workspace, so two projects that share tasks
benefit from sharing a workspace. See Settings for the full
reference, and Auxiliary folders when
results must be archived to another filesystem.
Keep task identifiers stable
A job is stored under a directory derived from a hash of its parameters, which is what makes results reusable across runs. Renaming a parameter, changing its type, or renaming a task class changes that hash: previous results become unreachable and are silently recomputed.
give a parameter a default with
field(ignore_default=X)(ignored in the identifier) orfield(default=X)(always part of it), never with a barex: Param[int] = 23pin a task identifier with
__xpmid__so that renaming the class is freewhen a parameter must change, keep the old one alive with
DeprecatedAttribute
See Configurations for the details, and
experimaestro tools deprecated to inspect the identifiers affected by a change.
Running on a cluster
Where a task runs is decided by its launcher, and how the
files are accessed by its connector. A specification
(cuda(mem=24G) & cpu(cores=4)) is matched against the launchers declared in
your settings, so the same experiment code runs locally and on a cluster.
Two things are worth setting up early:
Limit concurrency with a token when a resource is scarce — the scheduler will hold the jobs back rather than let them fail:
with experiment(workdir, "my-experiment") as xp: xp.token = xp.token("main", 4) # at most 4 jobs at a time
Survive walltime limits by deriving long tasks from
ResumableTask: checkremaining_time(), save a checkpoint and raiseGracefulTimeoutbefore the limit is reached. Such a task is retried automatically (max_retries, 3 by default, configurable per workspace or persubmit()) and keeps its directory between attempts. See Tasks.
Monitoring and recovering
An experiment can be followed live, and a workspace inspected long after the fact:
# Terminal UI (add --port to get the web UI instead)
experimaestro --workdir /path/to/workspace monitor --console
# The same, for a workspace on a remote machine
experimaestro -w my-cluster monitor --web
Both are described in Interfaces. Starting a monitor also performs a workspace cleanup: event files are consolidated, and jobs whose process died without leaving a marker are marked as failed, so that the next experiment does not wait on them. Jobs that are no longer part of any experiment are reported rather than deleted:
experimaestro --workdir /path/to/workspace workspace orphans
Iterating without losing work
--run-mode DRY_RUN(andGENERATE_ONLY,PREPARE) walks the experimental plan without executing anything — the fastest way to check what a change would submit--showprints the merged YAML configuration, which usually explains an unexpected parameterkeep
dirty_git: erroron experiments meant to be reproducible, so that a result can always be traced back to a committag the parameters that vary in your plan; the analysis tools then group results by tag rather than by directory name
Experiment services
Experiments can expose long-running services (a TensorBoard instance, a web application) that the monitoring interfaces start, stop, and display. See Services.
Experiment metadata
Each run records the host it was launched from in
experiments/{experiment_id}/{run_id}/environment.json. It is displayed by the
interfaces — useful when experiments of the same workspace are launched from
several machines:
# Shown in brackets after the experiment ID
experimaestro --workdir /path/to/workspace experiments list
# my-experiment [hostname.local] (5/10 jobs)