Skip to content

API Reference

Callback mechanism for hydra jobs.

AnyRunCallback

Bases: Callback

Setup function to be run both in single and multirun mode.

on_multirun_end(config, **kwargs)

Execute before a multi run.

on_multirun_start(config, **kwargs)

Execute before a multi run.

on_run_end(config, **kwargs)

Execute before a single run.

on_run_start(config, **kwargs)

Execute before a single run.

ExecShellCommand

Bases: AnyRunCallback

Execute a shell command at the end of the run.

Parameters:

  • run_command (str, default: '' ) –

    command to run at the end of a single run.

  • multirun_command (str, default: '' ) –

    command to run at the end of a multi run.

Examples:

callbacks:
  exec_shell:
    _target_: hydra_callbacks.ExecShellCommand
    run_command: echo "run done"
    multirun_command: echo "multirun done"

on_multirun_end(config, **kwargs)

Execute after a multi run.

on_run_end(config, **kwargs)

Execute after a single run.

GitInfo

Bases: AnyRunCallback

Check git infos and log them.

Parameters:

  • clean (bool, default: False ) –

    if True, will fail if the repo is not clean

Examples:

callbacks:
  git_infos:
    _target_: hydra_callbacks.GitInfo
    clean: true

Bases: Callback

Create a symlink to the latest run in the base output dir.

Parameters:

  • run_base_dir (str, default: 'outputs' ) –

    name of the basedir

  • multirun_base_dir (str, default: 'multirun' ) –

    name of the basedir for multirun

Examples:

callbacks:
  latest_run:
    _target_: hydra_callbacks.LatestRunLink
    run_base_dir: outputs
    multirun_base_dir: multirun

on_multirun_end(config, **kwargs)

Execute after a multi run.

on_run_end(config, **kwargs)

Execute after a single run.

MultiRunGatherer

Bases: Callback

Gather job results from json files after a multirun.

Parameters:

  • result_file (str, default: 'results.json' ) –

    name of the file to gathers from all the jobs.

  • aggregator (Callable[[list[str]], PathLike] | None, default: None ) –

    function to aggregate the results. This function should take a list of filepath as input and process them. By default this assume that each result file is a json file, and will load them as a list of dict, and save them as a csv file.

Examples:

callbacks:
  gather:
    _target_: hydra_callbacks.MultiRunGatherer
    result_file: results.json
    aggregator: hydra_callbacks.MultiRunGatherer._default_aggregator

on_multirun_end(config, **kwargs)

Run after all job have ended.

Will write a DataFrame from all the results. at the run location.

RegisterRun

Bases: Callback

Register the run in a .csv file at the end of the run.

Single and MultiRun are handled in different files. Note that this append one row per config. Only the config is being registered, not the possible output of the run.

Parameters:

  • enabled (bool, default: True ) –

    if True, will register the run.

  • register_file (str, default: 'register.csv' ) –

    name of the file to register the run in.

  • run_base_dir (str, default: 'outputs' ) –

    name of the basedir for single runs.

  • multirun_base_dir (str, default: 'multiruns' ) –

    name of the basedir for multiruns.

Examples:

callbacks:
  register_run:
    _target_: hydra_callbacks.RegisterRun
    enabled: true
    register_file: register.csv
    run_base_dir: outputs
    multirun_base_dir: multiruns

ResourceMonitor

Bases: AnyRunCallback

Sample the cpu and memory usage during job execution.

The collected data (cpu percent, memory usage) is written to a csv file.

TODO: Add GPU support.

Parameters:

  • enabled (bool, default: True ) –

    if True, will log the total runtime.

  • sample_interval (float or int, default: 1 ) –

    The time interval at wat which to sample the process, in seconds.

  • monitoring_file (str, default: 'resource_monitoring.csv' ) –

    The file to write the monitoring data to.

  • gpu_monit (bool, default: False ) –

    Also monitor gpu data.

Examples:

callbacks:
  resource_monitor:
    _target_: hydra_callbacks.ResourceMonitor
    enabled: true
    sample_interval: 1
    monitoring_file: resource_monitoring.csv
    gpu_monit: true

on_job_end(config, job_return, **kwargs)

Execute after a single job.

on_job_start(config, *, task_function, **kwargs)

Execute before a single job.

on_multirun_start(config, **kwargs)

Execute after a multi run.

on_run_start(config, **kwargs)

Execute after a single run.

RuntimePerformance

Bases: AnyRunCallback

Log total runtime infos.

Parameters:

  • enabled (bool, default: True ) –

    if True, will log the total runtime.

Examples:

callbacks:
  perf:
    _target_: hydra_callbacks.RuntimePerformance
    enabled: true

SetEnvironment

Bases: AnyRunCallback

Set environment variables from the config.

The variable are unset at the end of the run.

Parameters:

  • enabled (bool, default: True ) –

    if True, will set the environment variables.

  • env (dict, default: None ) –

    dictionary of environment variables to set.

Examples:

callbacks:
  set_env:
    _target_: hydra_callbacks.SetEnvironment
    enabled: true
    env:
      VAR1: "value1"
      VAR2: "value2"

dummy_run(config, **kwargs)

Do nothing.