Active Learning Loops

Core Concepts introduced the active-learning cycle at a glance – Sampler -> GroundTruthEvaluator -> ModelTrainer, closing the loop back onto the sampler. This page fills that in properly: the actor interfaces every concrete implementation satisfies, and the flexible, stage-based StagedActiveLearningHandler that drives them.

The actor interfaces

Four roles, each an ABC in remote_handler.workflows.active_learning_base, share one shape: update(calcdir, actor_input, **kwargs) -> None does the iteration’s work (writing into calcdir, typically by building and running a RemoteTask), and a getter hands back the path(s) the next actor consumes.

        flowchart LR
    Sampler["Sampler<br/>get_sampled_configs()"] --> Selector["Selector<br/>get_selected_configs()"]
    Selector --> Eval["GroundTruthEvaluator<br/>get_evaluated_configs()"]
    Eval --> Trainer["ModelTrainer<br/>get_trained_model()"]
    Trainer -.->|"next iteration"| Sampler
    
  • Sampler proposes candidate configurations (e.g. by running MD under the current model).

  • Selector narrows that pool down before the (usually expensive) labelling step – by diversity, uncertainty, novelty relative to already-labelled data, or a fixed stride. It is a peer of the other three actors, not a sampler sub-step, so it can run its own remote job when selection itself is heavy (e.g. a descriptor computation).

  • GroundTruthEvaluator labels the selected configurations (DFT via VASP/ORCA, or a cheap ASE calculator such as EMTEvaluator for testing).

  • ModelTrainer retrains the force field on the accumulated labelled data; the new model feeds the next sampler.

A Schedule can vary an actor’s parameters from one iteration to the next (e.g. ramping a sampler’s temperature, a selector’s n_configs or a trainer’s config_file). Before each update() the handler sets the schedule’s values as attributes of the actor, and it also passes them to update() as keyword arguments. A key that names no attribute of the actor is only passed to update(), as before. That is right for an actor that reads it there, but it is also what a misspelt key looks like. So the handler emits a ScheduleKeyWarning for such keys once, when it is built. Make it an error with warnings.simplefilter("error", ScheduleKeyWarning). An actor can change the defaults with two optional methods: unknown_schedule_keys(kwargs) returns the keys it does not recognise (declare the ones update() reads to silence the warning), and apply_schedule(kwargs) replaces the plain setattr. The shipped actors use them where a plain setattr would not reach the job: SelectorActor forwards keys to its wrapped selector, RemoteSelector accepts the selector’s constructor arguments, the VASP/ORCA/EMT evaluators rebuild calc_config, and NeuralilILTrainer also accepts single hyperparameters (n_epochs, …). The optional pending_manifest hook is what lets a stage reattach to an already-submitted job instead of resubmitting after the driving process dies – see Core Concepts for that detach/reattach lifecycle.

Provided actors

remote_handler ships concrete actors for three of the four roles – evaluation, training and selection – so a project typically only has to write its own Sampler (see Core Concepts’s “one repository per project”). All support a stub=True mode that produces mock outputs without running anything, for exercising a loop’s wiring before paying for real compute. Full parameters are in API Reference.

Each entry below unfolds into a short, real usage snippet – collapsed by default so this stays an index, not a second examples page.

Evaluators (remote_handler.workflows.evaluators)

  • AseCalculatorEvaluator – single-point labelling with any ASE calculator; the base the other three are presets of.

  • VASPEvaluator – DFT ground truth via VASP. Requires: VASP itself, installed on the target cluster – a licensed code, not shipped with remote_handler.

    Usage example
        handler = VASPHandler(
            traj_files=["selected_structures.extxyz"],
            cluster_config=config,
            remote_fs=remote_fs,
            savepath="/scratch/me/vasp",
            num_parallel=10,
            n_processors=16,
            incar_kwargs={
                "xc": "PBE",
                "encut": 400,
                "ediff": 1e-6,
                "ismear": 0,
                "sigma": 0.05,
                "kpts": [3, 3, 1],
            },
        )
    
        # Stage inputs, submit the array, wait, and collect the labelled configs.
        handler.run()
    
  • ORCAEvaluator – DFT ground truth via ORCA. Requires: ORCA itself, installed on the target cluster – also not shipped with remote_handler.

    Usage example
        evaluator = ORCAEvaluator(
            cluster_config=config,
            remote_fs=remote_fs,
            num_parallel=10,
            orcasimpleinput="PBE def2-SVP",
            n_processors=8,
        )
    
        # Label the sampler's candidate configs; calcdir is this iteration's
        # work dir.
        evaluator.update(Path("al_run/0/dft"), Path("sampled_configs.extxyz"))
        labelled = evaluator.get_evaluated_configs()
    
  • EMTEvaluator – ASE’s EMT potential; cheap ground truth for testing a loop end-to-end, not for production labelling.

    Usage example
        evaluator = EMTEvaluator(
            remote_fs=remote_fs,
            cluster_config=cluster_config,
            num_parallel=3,
            remote_savepath=scratch / "eval",
            loop_time=0.3,
        )
    

Trainers (remote_handler.workflows.trainers)

  • MaceModelTrainer – trains an ensemble of MACE models (one array job, one seed per shard). Requires: MACE (mace-torch) installed in the remote conda env this trainer targets; add convert_to_jax=True to also emit a mace-jax bundle per model (needs mace-jax there too).

    Usage example

    Config (mace_config.yaml):

    model: MACE
    r_max: 5.0
    num_channels: 128
    max_L: 1
    max_ell: 3
    E0s: average
    batch_size: 10
    max_num_epochs: 200
    

    Usage:

    if __name__ == "__main__":
        config = ClusterConfig.from_name("datalab")
        remote_fs = RemoteFileSystem(remote_alias="datalab")
    
        trainer = MaceModelTrainer(
            remote_fs=remote_fs,
            cluster_config=config,
            config_file=CONFIG_FILE,
            num_models=3,
            validation_fraction=0.1,
        )
    
        # Train on DFT-labelled configs; calcdir is this iteration's work dir.
        trainer.update(Path("mace_run/0/training"), ["dft_labelled.extxyz"])
        model_paths = trainer.get_trained_model()
    
  • MaceFinetuningTrainer – like MaceModelTrainer, but finetunes from a staged foundation model instead of training from scratch (same requirements and convert_to_jax support).

  • AceModelTrainer – the same ensemble-array shape as MaceModelTrainer, fitting an ACE potential with pacemaker instead. Requires: pacemaker installed in the remote conda env (see the ace extra for the pieces needed to test this locally – it cannot coexist with the grace extra in one environment).

    Usage example

    Config (ace_config.yaml):

    # Minimal illustrative config -- see pacemaker's own docs for the full
    # schema. "data" and "seed" are injected per job, not set here.
    potential:
      deltaSplineBins: 0.001
      elements: [Cu]
    fit:
      loss:
        kappa: 0.3
      maxiter: 200
    backend:
      evaluator: tensorpot
    

    Usage:

    if __name__ == "__main__":
        config = ClusterConfig.from_name("datalab")
        remote_fs = RemoteFileSystem(remote_alias="datalab")
    
        trainer = AceModelTrainer(
            remote_fs=remote_fs,
            cluster_config=config,
            config_file=CONFIG_FILE,
            num_models=3,
            validation_fraction=0.1,
        )
    
        trainer.update(Path("ace_run/0/training"), ["dft_labelled.extxyz"])
        model_paths = trainer.get_trained_model()
    
  • GraceModelTrainer – the same ensemble-array shape as MaceModelTrainer, fitting a GRACE potential with gracemaker instead. Requires: gracemaker installed in the remote conda env (see the grace extra for the pieces needed to test this locally – it cannot coexist with the ace extra in one environment).

    Usage example

    Config (grace_config.yaml):

    # Minimal illustrative config -- see gracemaker's own docs for the full
    # schema. "data" and "seed" are injected per job, not set here.
    cutoff: 5.0
    potential:
      elements: [Cu]
    fit:
      loss: huber
      maxiter: 200
    

    Usage:

    if __name__ == "__main__":
        config = ClusterConfig.from_name("datalab")
        remote_fs = RemoteFileSystem(remote_alias="datalab")
    
        trainer = GraceModelTrainer(
            remote_fs=remote_fs,
            cluster_config=config,
            config_file=CONFIG_FILE,
            num_models=3,
            validation_fraction=0.1,
        )
    
        trainer.update(Path("grace_run/0/training"), ["dft_labelled.extxyz"])
        model_paths = trainer.get_trained_model()
    
  • NeuralilILTrainer – trains NeuralIL models via JAXNEST. Requires: the NeuralIL/JAXNEST stack installed in the remote conda env (see the neuralil extra).

    Usage example
        trainer = NeuralilILTrainer(
            remote_fs=remote_fs,
            cluster_config=config,
            training_kwargs={"n_epochs": 200, "n_ensemble": 10},
        )
    
        # Train on DFT-labelled configs; calcdir is this iteration's work dir.
        trainer.update(Path("neuralil_run/0/training"), ["dft_labelled.extxyz"])
        model_paths = trainer.get_trained_model()
    

Selectors (remote_handler.workflows.selectors)

Pure ConfigSelector strategies (see “Two ways to get a Selector” above) – wrap any of these in SelectorActor:

  • StrideSelector – fixed, deterministic evenly-spaced subsampling.

    Usage example
    >>> from remote_handler.workflows.selectors import StrideSelector
    >>> selector = StrideSelector(n_configs=20)
    >>> # pass the selector to your sampler, e.g. sampler(..., selector=...)
    
  • RandomSelector – uniform random subsampling.

  • LastFrameSelector – the last frame of each group (e.g. trajectory), for grouped input.

  • UncertaintySelector – ranks by a committee/ensemble’s energy and/or force uncertainty, already stored on the Atoms.

  • QUESTSSelector – structural diversity (no reference) or novelty relative to a reference dataset (with one), via QUESTS information entropy. Requires: the quests package installed locally (pip install remote_handler[quests]), since selection runs on the host, not the cluster. This is the selector behind from_actors’s selector_reference_from.

    Usage example
    >>> from remote_handler.workflows.selectors import QUESTSSelector
    >>> selector = QUESTSSelector(n_configs=20, method="msc")
    >>> # With novelty relative to existing training data:
    >>> selector = QUESTSSelector(n_configs=20, reference=train_atoms)
    
  • PipelineSelector – chains several selectors, e.g. an uncertainty pre-filter followed by QUESTS diversity.

    Usage example
    
    pca = PCA(
        n_components=min(2, struct_desc.shape[0], struct_desc.shape[1])
    )
    proj = pca.fit_transform(struct_desc)
    

Stages: a pipeline, not a fixed triple

The original ActiveLearningHandler hardcodes the three-actor loop: its bookkeeping is a fixed [sample, eval, train] done-flag triple, so adding a fourth actor means widening that triple by hand. StagedActiveLearningHandler instead models the loop as an ordered list of uniform Stage objects, each wrapping one actor – so adding the selector (or any other actor) is just inserting one Stage, with no changes to the orchestration code.

By default, stages form a ring: stage N consumes stage N-1’s output from the same iteration, and the first stage consumes the last stage’s output from the previous iteration (closing the loop):

        flowchart LR
    S0["sampler<br/>(it. N)"] --> S1["selector<br/>(it. N)"]
    S1 --> S2["evaluator<br/>(it. N)"]
    S2 --> S3["trainer<br/>(it. N)"]
    S3 -.->|"it. N+1"| S0
    

Each Stage also has a combine flag: when true, its consumer receives that stage’s outputs from all completed iterations (plus the consumer’s seed) rather than only the most recent one – e.g. an evaluator whose labelled data should keep accumulating into the training set.

Beyond the ring, a stage may declare extra_inputs – named secondary streams pulled from any other stage’s outputs via InputSource, optionally accumulated across iterations. This turns the ring into a small DAG, which is what enables novelty selection: a selector receives the evaluator’s accumulated outputs from all previous iterations as a reference extra input and scores candidates by how novel they are relative to the already-labelled data:

        flowchart LR
    S0["sampler"] --> S1["selector"]
    S1 --> S2["evaluator"]
    S2 --> S3["trainer"]
    S3 -.->|"it. N+1"| S0
    S2 -.->|"reference<br/>(accumulated)"| S1
    

Resume works the same way it does for tasks (see Core Concepts): progress is a cursor, not an enumerated flag combination. The handler precomputes a deterministic plan of (iteration, stage) work items from num_iterations and the entry/exit stages, and records each completed item’s outputs in AL_progress.json. Resuming re-runs only the plan items not yet recorded, and each stage actor is transparently reattached to a pending job rather than resubmitted, exactly as ActiveLearningHandler did – but now generically over any stage (see below).

Stage actors don’t have to be one of the four interfaces

A Stage’s actor is not required to subclass Sampler / Selector / GroundTruthEvaluator / ModelTrainer at all – those ABCs exist for the four canonical roles, but the handler itself only ever calls actor.update(calcdir, actor_input, **kwargs) and then looks up an output getter by name (in order: resolve_actor_output() tries get_output, then the four actor-specific getters). Anything exposing that shape works, so a stage that doesn’t fit any of the four roles – a filtering step, a format conversion, an analysis/reporting step you want checkpointed and resumable alongside the rest of the loop – can be plugged in directly by implementing update and get_output, with no interface to import. The optional reattach hooks (pending_manifest / collect_only) are looked up the same duck-typed way, so a plain object without them simply never gets reattached, instead of erroring, and can add them later if it starts doing real remote work.

Building a loop

For the classic three-or-four-actor shape, from_actors() builds the stage list for you and mirrors ActiveLearningHandler’s own arguments, so existing scripts port with minimal changes:

    handler = StagedActiveLearningHandler.from_actors(
        sampler=sampler,
        selector=selector,
        evaluator=evaluator,
        trainer=trainer,
        calchome=run_dir / "calchome",
        num_iterations=num_iterations,
        cycle_exit_point="training",  # every iteration ends with a fit
        initial_trainer_out=HERE / "inputs" / "seed_model.json",
        trainer_output_extension="json",
    )
    handler.run()

Set selector_reference_from="evaluator" on from_actors to switch a novelty-aware selector (such as QUESTSSelector) into the DAG shape above; initial_selector_reference seeds it so novelty scoring is active from iteration 0 instead of falling back to diversity.

For anything beyond that shape – extra actors, a different topology, custom extra_inputs – construct the Stage list and StagedActiveLearningHandler directly; from_actors is a convenience constructor, not a different code path. See Examples for the full runnable driver this snippet is taken from.

The legacy ActiveLearningHandler

ActiveLearningHandler (the fixed sampler/evaluator/trainer triple, no selector) still exists, untouched, but is deprecated – it now raises a DeprecationWarning on construction and will be removed in a future release. Use StagedActiveLearningHandler for new work; from_actors above is its drop-in replacement.

Where to go next

  • Core Concepts – the host/remote split, tasks and executors underneath every actor.

  • Examples – the runnable, no-cluster AL loop this page’s snippet is taken from.

  • API Reference – the full Stage/InputSource/selector-strategy reference.