Core Concepts
=============
This page introduces the main abstractions in ``remote_handler`` and the
boundaries between them, independently of any particular cluster or workflow.
It is the mental model the rest of the documentation assumes; the
:doc:`api/index` fills in the concrete classes.
The big picture
---------------
``remote_handler`` orchestrates **active-learning workflows for machine-learned
force fields** across remote HPC clusters. The guiding idea is a strict split
between the **host** (your laptop / login node, where orchestration logic
lives) and one or more **remotes** (clusters, where the actual compute runs).
The host never does science; it moves files, launches jobs, and collects
results. The science runs on the remote, inside its own environment.
The package is organised in three layers:
``core/``
Transport and execution primitives: SSH/SFTP connections, filesystem
handlers, the executor abstraction, and the task definitions.
Dependency-light and host-side.
``workflows/``
The active-learning loop and its actors. Pure orchestration built on top of
``core``.
``scripts/``
**Remote payloads** -- shipped to the cluster and executed in its conda
environment, never imported on the host. This is the only layer that
depends on the heavy ML stacks (MACE, jax, ...).
A useful test for *where new code belongs*: if it needs an ML framework at
import time, it is a ``scripts/`` payload; if it decides *what* to run and
*where*, it is ``core``/``workflows``.
The host / remote boundary
--------------------------
Every file operation goes through a single interface,
:class:`~remote_handler.core.file_handler.FileSystemHandlerBase`, with two
interchangeable implementations. The same task code therefore runs unchanged
whether the "remote" is a cluster over SFTP or just the local disk:
.. mermaid::
flowchart LR
T["task / workflow code"] --> FS{"FileSystemHandlerBase"}
FS --> L["LocalFileSystem
(subprocess on this machine)"]
FS --> R["RemoteFileSystem
(paramiko SFTP over SSH)"]
Both implementations expose the same verbs (``put`` / ``get`` / ``makedirs`` /
``read_ase`` / ``run_command`` / ...). ``run_command`` runs a shell command
*where the filesystem lives* -- a local subprocess, or one exec over the
same authenticated SSH connection -- which is what lets execution happen
without a scheduler (see below). Remote hosts are resolved through your
``~/.ssh/config`` (key-based auth, ``ProxyJump`` supported).
Tasks: the unit of remote work
------------------------------
A :class:`~remote_handler.core.tasks.RemoteTask` is the central execution
abstraction. It answers three questions and an optional fourth, and nothing
else:
- **What to transfer?** ``allocate_data`` -- stage inputs onto the remote.
- **How to start it?** ``submit`` -- launch the job(s).
- **How to collect?** ``collect_results`` -- bring outputs back.
- *(optional)* **Did it really finish?** ``finish_check`` -- e.g. look for
a sentinel file, independent of what the scheduler thinks.
The lifecycle of a run is always the same shape:
.. mermaid::
sequenceDiagram
participant Task as RemoteTask
participant FS as remote_fs
participant Ex as Executor
Task->>FS: allocate_data() -- transfer inputs
Task->>Ex: submit()
Ex-->>Task: (job running on target)
Task->>Ex: wait_until_finished()
Task->>FS: collect_results() -- retrieve outputs
The two concrete tasks are
:class:`~remote_handler.core.tasks.SingleScriptTask` (one script, one input)
and :class:`~remote_handler.core.tasks.ArrayScriptTask` (the same script across
many shards, one per sub-directory). Crucially, a task describes *what* to run
-- it does **not** know *how* the job is actually launched. That is the
executor's job.
The lifecycle above assumes one long-lived process drives the whole run. A
task can equally be **detached and collected later, from a different
process** -- the same shape, split across a process boundary:
.. mermaid::
sequenceDiagram
participant P1 as process 1
participant FS as remote_fs
participant P2 as process 2 (later)
P1->>FS: allocate_data()
P1->>FS: submit(only_start=True) -- detach()
P1-->>P1: write_manifest() -- task_manifest.json
Note over P1,P2: process 1 exits, job keeps running on the target
P2->>FS: TaskHandle.from_file(...).wait()
P2->>FS: ArrayScriptTask.from_manifest(...) -- collect_only, no re-allocation
P2->>FS: finish_check() / collect_results()
``ArrayScriptTask.from_manifest`` / ``SingleScriptTask.from_manifest``
reconstruct the *full* task object -- not just an executor handle -- from the
manifest written by ``detach``/``write_manifest``: same resolved
``remote_savepath``, cluster config, and (for arrays) ``num_array_tasks``, so
``finish_check()`` and ``collect_results()`` behave exactly as they would in
the original process, without ever calling ``allocate_data()`` again. See
:doc:`cli` for the lower-level ``TaskHandle``/manifest CLI this builds on.
Executors: the pluggable backend seam
-------------------------------------
How a task's scripts actually run is decided by the ``executor`` field of its
:class:`~remote_handler.core.cluster_config.ClusterConfig`. A task builds its
backend through a factory rather than hard-wiring a scheduler, so the same task
runs with or without one:
.. mermaid::
flowchart TB
Task["SingleScriptTask / ArrayScriptTask"]
Task --> SF["make_single_executor()"]
Task --> AF["make_array_executor()"]
SF -->|"'slurm'"| SJH["SlurmJobHandler"]
SF -->|"'direct'"| DSE["DirectSingleExecutor"]
AF -->|"'slurm'"| SAH["SlurmArrayHandler"]
AF -->|"'direct'"| DAE["DirectArrayExecutor"]
Both backends satisfy the same small contract
(:class:`~remote_handler.core.executors.Executor`: ``submit`` /
``wait_until_finished``, plus ``write_jobfile`` and a ``calcdir``). The SLURM
backend submits with ``sbatch`` and polls the queue; the ``direct`` backend
writes a launch script, runs it detached over ``run_command``, and polls for a
completion sentinel -- no scheduler required. Cluster JSONs without an
``executor`` key default to ``slurm``, so existing setups are unaffected.
The active-learning loop
------------------------
The ``workflows`` layer composes tasks into the active-learning cycle. At its
core, three roles hand artifacts to the next:
.. mermaid::
flowchart TB
Sampler["Sampler"] -->|"candidate configs (.extxyz)"| Eval["GroundTruthEvaluator"]
Eval -->|"labelled configs (DFT)"| Trainer["ModelTrainer"]
Trainer -->|"retrained MLFF model"| Sampler
Each actor can run on a *different* machine, and each typically does its work
by constructing and running a ``RemoteTask``. In practice the loop usually
grows a fourth role -- a ``Selector`` that filters a sampler's candidates
before they are sent for (expensive) ground-truth labelling -- and the
pipeline is driven by the flexible, stage-based
:class:`~remote_handler.workflows.staged_active_learning.StagedActiveLearningHandler`,
which owns the bookkeeping (a resumable ``AL_progress.json`` cache) generically
over any list of stages. See :doc:`active_learning` for the full picture,
including the actor interfaces and how stages compose.
Trajectory processing
---------------------
Besides the loop, the package has a second, independent workflow: running
per-configuration work (relaxation, structural descriptors such as the RDF or
Steinhardt order parameters) over large trajectories.
:class:`~remote_handler.processing.handler.RemoteTrajectoryProcessor` shards
the trajectories into one array task per shard, a small driver runs an ordered
list of *processors* on each shard on the cluster, and the annotated
configurations come back in the layout of the input files. Processors are
plugins: a downstream package can define and register its own, and the stock
driver picks it up. See :doc:`processing`.
Configuration
-------------
Two configuration objects, at two scopes, keep the above wired together:
:class:`~remote_handler.core.cluster_config.ClusterConfig`
*Per remote target.* Where and as whom work runs (SSH alias, conda env,
save path) plus policy (connection resilience, which ``executor`` to use).
Backend-agnostic -- consumed by every executor. Loaded from a JSON with
``ClusterConfig.from_name("lugus")`` or ``from_file(...)``.
``RemoteHandlerConfig`` (via ``get_config()``)
*Global.* Where cluster JSONs and templates live, and the defaults offered
when creating new ones. Resolved once, with precedence
*environment variables > persisted config file > built-in defaults*.
Both are normally managed for you by the ``remote_handler`` command-line tool
(see :doc:`cli`), so day-to-day you refer to clusters by name and never touch
the underlying files by hand.
One repository per project
--------------------------
``remote_handler`` is a **library, not an application**. It is not where an
active-learning campaign lives; it is the reusable machinery a campaign builds
on. The intended layout splits across **separate repositories, each a
dependency of the next** -- so the parts that churn fast never sit in the same
repo as the parts that must stay stable:
.. mermaid::
flowchart TB
subgraph P["AL project (repo)"]
RUN["Sampler adapter + run script
+ cluster configs"]
end
RUN -->|depends on| SAMP["sampling code
(library — separate repo)
the sampling method, standalone"]
RUN -->|depends on| RH["remote_handler
(library — separate repo)
transport · DFT/ORCA evaluation · MACE training · AL loop"]
The two libraries are independent -- only the project ties them together.
Three roles, ordered by how fast the code changes:
- **``remote_handler`` -- stable core.** Transport, the executor backends, the
DFT/ORCA evaluators, MACE/NeuralIL training, and the active-learning loop
itself change slowly. It also *defines* the actor interfaces (the
:class:`~remote_handler.workflows.active_learning_base.Sampler` /
``GroundTruthEvaluator`` / ``ModelTrainer`` ABCs). Tested, released, and
versioned here, and reused by every project.
- **Sampling code -- its own library, its own repo.** The actual sampling
method, where most development happens and the code churns the most. It is a
*standalone* package: it knows nothing about ``remote_handler`` or active
learning, so it can evolve on its own schedule and be reused outside this
context entirely.
- **The AL project -- thin glue.** A per-campaign repo that pins both libraries
as dependencies and provides the bridge between them: a small
:class:`~remote_handler.workflows.active_learning_base.Sampler` adapter that
drives the sampling library, a run script wiring it to the shipped
evaluators/trainers, and the cluster configs and inputs for *this* run.
This keeps fast-moving, half-finished sampling experiments out of the core
entirely -- they are not even in the same repository -- so ``remote_handler``
(and the reusable training / DFT evaluation it provides) stays clean, broadly
tested, and shared. The sampling library, owing nothing to ``remote_handler``,
stays independently useful too. Pinning to tags
(``... @ git+@v0.2.0``) means a project only picks up changes from either
library when it deliberately bumps the pin.
Where to go next
----------------
- :doc:`installation` -- install the host driver and the right extras.
- :doc:`active_learning` -- the actor interfaces and the staged AL loop.
- :doc:`processing` -- sharded trajectory analysis and custom processors.
- :doc:`cli` -- configure clusters and diagnose your setup.
- :doc:`quickstart` -- a first end-to-end run.
- :doc:`api/index` -- the concrete classes behind every concept above.
- :doc:`contributing` -- how the layers map onto where code should live.