hydronaut.hydra package

Submodules

hydronaut.hydra.config module

Structured configs for Hydra and associated helper functions.

class hydronaut.hydra.config.ExperimentConfig(name: str, description: str, params: dict[str, typing.Any] | None, exp_class: str | None = None, python: ~hydronaut.hydra.config.PythonConfig | None = None, mlflow: ~hydronaut.hydra.config.MLflowConfig | None = None, environment: dict[str, str] | None = None, defaults: list[typing.Any] | None = <factory>)[source]

Bases: object

Experiment configuration.

__init__(name: str, description: str, params: dict[str, typing.Any] | None, exp_class: str | None = None, python: ~hydronaut.hydra.config.PythonConfig | None = None, mlflow: ~hydronaut.hydra.config.MLflowConfig | None = None, environment: dict[str, str] | None = None, defaults: list[typing.Any] | None = <factory>) None[source]
defaults: list[Any] | None[source]
description: str[source]
environment: dict[str, str] | None = None[source]
exp_class: str | None = None[source]
mlflow: MLflowConfig | None = None[source]
name: str[source]
params: dict[str, Any] | None[source]
python: PythonConfig | None = None[source]
class hydronaut.hydra.config.HydronautConfig(defaults: list[typing.Any] | None = <factory>)[source]

Bases: object

Common Hydronaut configuration.

__init__(defaults: list[typing.Any] | None = <factory>) None[source]
defaults: list[Any] | None[source]
class hydronaut.hydra.config.MLflowConfig(start_run: MLflowRunConfig | None = None)[source]

Bases: object

MLflow configuration.

__init__(start_run: MLflowRunConfig | None = None) None[source]
start_run: MLflowRunConfig | None = None[source]
class hydronaut.hydra.config.MLflowRunConfig(run_id: str | None = None, run_name: str | None = None, nested: bool = False, tags: dict[str, str] | None = None, description: str | None = '${experiment.description}-run_${hydra:job.name}_${hydra:job.num}')[source]

Bases: object

Parameters for mlflow.start_run(), except for experiment_id which is set from the experiment name. For details, see https://mlflow.org/docs/latest/python_api/mlflow.html

__init__(run_id: str | None = None, run_name: str | None = None, nested: bool = False, tags: dict[str, str] | None = None, description: str | None = '${experiment.description}-run_${hydra:job.name}_${hydra:job.num}') None[source]
description: str | None = '${experiment.description}-run_${hydra:job.name}_${hydra:job.num}'[source]
nested: bool = False[source]
run_id: str | None = None[source]
run_name: str | None = None[source]
tags: dict[str, str] | None = None[source]
class hydronaut.hydra.config.PythonConfig(paths: list[str] | None = <factory>)[source]

Bases: object

Pyton configuration.

__init__(paths: list[str] | None = <factory>) None[source]
paths: list[str] | None[source]
hydronaut.hydra.config.configure_environment() None[source]

Save the current Hydra configuration to fully resolved OmegaConf files and set environment variables for subprocesses to re-initialize the current configuration.

hydronaut.hydra.config.configure_hydra(from_env: bool = False) None[source]

Configure the config store, resolvers and global configs as necessary.

Parameters:

from_env – If True, re-initialize the Hydra configuration object from environment variables set by configure_environment().

hydronaut.hydra.config.get_config_path(get_hydra: bool = False) Path[source]

Get the path to this run’s resolved configuration file. This can be useful for running external code that cannot be invoked directly with the configuration file object.

Parameters:

get_hydra – If True, return the path to the configuration file with the Hydra-specific configuration. If False (the default), return the experiment configuration file path.

Returns:

The pathlib.Path object pointing to the requested configuration file, or None if the path is not available. The configuration file is fully resolved prior to saving and can therefore be used as a normal YAML input file.

hydronaut.hydra.config.save_config(config: omegaconf.OmegaConf, path: Path, resolve: bool = False, overwrite: bool = False) None[source]

Save a config to a path.

Parameters:
  • config – An OmegaConf configuration object.

  • path – The output path.

  • resolve – Resolve all resolvers before saving the config.

hydronaut.hydra.info module

Hydra utility functions.

hydronaut.hydra.info.get_sweep_number() int[source]

Get the number of the current sweep.

Returns:

An int between in the range [0, n-1] where n is the number of sweep runs.

hydronaut.hydra.omegaconf module

Omegaconf utility functions.

hydronaut.hydra.omegaconf.get(config: omegaconf.DictConfig, name: str, default: Any = None) Any[source]

Get a nested parameter such as foo.bar.baz from an Omegaconf configuration object, with default value.

Parameters:
  • config – The configuration object.

  • name – The nested parameter name. It will be split on “.”.

  • default – An optional default value. Default: None

Returns:

The parameter value, or the default value if any of the nested values are missing or the resulting value is None.

hydronaut.hydra.omegaconf.get_container(config: omegaconf.DictConfig, name: str, *, default: Any = None, resolve: bool = True) Any[source]

A wrapper around get() that transforms the result with OmegaConf.to_container.

Parameters:
  • config – Same as get().

  • name – Same as get().

  • default – Same as get().

  • resolve – Passed through to to_container(). If True, the resolvers will be resolved before creating the container.

Returns:

The container returned by a call to OmegaConf.to_conainer if the result of get() is an OmegaConf configuration object, otherwise the value returned by get().

hydronaut.hydra.omegaconf.set_globals(config: omegaconf.DictConfig, name: str, *, module: str | None = None, resolve: bool = True) None[source]

Set or update global values in a loaded module with values from the configuration object. This is mainly useful for speeding up calculations that would otherwise suffer from repeated lookups up the values within the OmegaConf configuration object.

Parameters:
  • config – Same as get().

  • name – Same as get().

  • module – An optional module or module name. If not given then the module from which this function was invoked is used.

  • resolve – Same as get_container().

hydronaut.hydra.resolvers module

Hydra resolvers.

hydronaut.hydra.resolvers.get_cwd(*args)[source]

The current working directory from which the main function was launched.

Parameters:
  • resolve – If True, resolve symlinks in the path.

  • uri – If True, return the path as a URI.

Returns:

The resulting string.

hydronaut.hydra.resolvers.get_n_cpu(*args)[source]

Get the number of available CPUs. Optionally accept an integer argument which will be used to divide the result.

Parameters:

*args – An optional single integer argument. If given, the number of CPUs will be divided by this number.

Returns:

The number of available CPUs. If a divisior is given then this will always return a value of at least 1.

hydronaut.hydra.resolvers.get_n_gpu_pytorch(*args)[source]

Get the number of available PyTorch GPUs. Optionally accept an integer argument which will be used to divide the result.

Parameters:

*args – An optional single integer argument. If given, the number of CPUs will be divided by this number.

Returns:

The number of available PyTorch GPUs. If the number is greater than 0 than a value of at least 1 will always be returned when an optional divisor is given.

hydronaut.hydra.resolvers.register() dict[str, str][source]

Register custom resolvers.

Returns:

A dict mapping resolver names to their descriptions.

hydronaut.hydra.resolvers.reregister() None[source]

Reregister custom and Hydra resolvers. This is necessary due to a bug in the process launcher.

Module contents

File stub.