hydronaut package
Subpackages
- hydronaut.hydra package
Submodules
hydronaut.decorator module
Decorators for running code with Hydronaut.
- hydronaut.decorator.with_hydronaut(config_path: str | Path = None) Callable[[Callable[[omegaconf.DictConfig], int | float | Tuple[int | float, ...]] | Callable[[omegaconf.DictConfig], Callable[[], int | float | Tuple[int | float, ...]]]], Callable[[], int | float | Tuple[int | float, ...]]][source]
A decorator to run custom user code with Hydronaut. The user code must be either a class with the following methods:
- __init__(self, config):
An initialization method that accepts the Hydra configuration object as its sole argument.
- __call__(self):
A call method that returns the experiment’s objective values.
- setup(self):
An optional method that will be invoked before __call__ when the experiment is run. This can be used to e.g. prepare data.
or a function that accept the Hydra configuration object as its sole argument and which returns the experiment’s objective values.
- Parameters:
config_path – Passed through to hydronaut.run.Runner.
- Returns:
A callable object that runs the user code within the Hydronaut framework.
hydronaut.experiment module
Experiment base class.
- class hydronaut.experiment.Experiment(config: omegaconf.DictConfig)[source]
Bases:
objectBase class for experiments.
TODO * Add methods for logging parameters, artefacts, etc.
- __init__(config: omegaconf.DictConfig) None[source]
- Parameters:
config – The Hydra configuration object.
- log_artifact(local_path: str | Path, artifact_path: str | Path | None = None) None[source]
Wrapper around mlflow.log_artifact: https://mlflow.org/docs/latest/python_api/mlflow.html#mlflow.log_artifact
- Parameters:
local_path – A path to an existing artifact. The artitfact must already be saved to this path.
artifact_path – An optional path to a directory under artifact_uri in which to log the artifact in MLflow.
- log_artifacts(local_dir: str | Path, artifact_path: str | Path | None = None) None[source]
Wrapper around mlflow.log_artifacts: https://mlflow.org/docs/latest/python_api/mlflow.html#mlflow.log_artifacts
- Parameters:
local_dir – A path to a directory with artifacts.
artifact_path – An optional path to a directory under artifact_uri in which to log the artifact in MLflow.
- log_dict(dictionary: Any, artifact_file: str | Path) None[source]
Wrapper around mlflow.log_dict: https://mlflow.org/docs/latest/python_api/mlflow.html#mlflow.log_dict
- Parameters:
dictionary – A dict object to log.
artifact_file – The run-relative subpath to which to save the data as a JSON or YAML file. The file type will be determined from the extension (“.yaml” or “.json”).
- log_figure(figure: Any, artifact_file: str | Path) None[source]
Wrapper around mlflow.log_figure: https://mlflow.org/docs/latest/python_api/mlflow.html#mlflow.log_figure
- Parameters:
figure – A figure to log. Check the documentation of mlflow.log_figure for supported figure types (e.g. Matplotlib and Plotly.py figures).
artifact_file – The run-relative subpath to which to save the figure.
- log_image(image: Any, artifact_file: str | Path) None[source]
Wrapper around mlflow.log_image: https://mlflow.org/docs/latest/python_api/mlflow.html#mlflow.log_image
- Parameters:
image – An image to log. Check the documentation of mlflow.log_image for supported image types (e.g. numpy.ndarray, Pillow images).
artifact_file – The run-relative subpath to which to save the image.
- log_metric(key: str, value: int | float, step: int | None = None) None[source]
Wrapper around mlflow.log_metric: https://mlflow.org/docs/latest/python_api/mlflow.html#mlflow.log_metric
- Parameters:
key – The metric name.
value – The metric value.
step – The metric step. Defaults to zero if unspecified.
- log_metrics(metrics: dict[str, int | float], step: int | None = None) None[source]
Wrapper around mlflow.log_metrics: https://mlflow.org/docs/latest/python_api/mlflow.html#mlflow.log_metrics
- Parameters:
metrics – A dict mapping metric names to their values.
step – The metric step. Defaults to zero if unspecified.
- log_param(key: str, value: Any) None[source]
Wrapper around mlflow.log_param: https://mlflow.org/docs/latest/python_api/mlflow.html#mlflow.log_param
- Parameters:
key – The parameter name.
value – The parameter value.
- log_params(params: dict[str, Any]) None[source]
Wrapper around mlflow.log_params: https://mlflow.org/docs/latest/python_api/mlflow.html#mlflow.log_params
- Parameters:
params – A dict mapping parameter names to their values.
- log_text(text: str, artifact_file: str | Path) None[source]
Wrapper around mlflow.log_text: https://mlflow.org/docs/latest/python_api/mlflow.html#mlflow.log_text
- Parameters:
text – The text to log.
artifact_file – The run-relative subpath to which to save the text.
hydronaut.file module
File functions.
- hydronaut.file.backup_copy(path: Path) None[source]
Attempt to backup a copy to a timestamped path in the same directory.
- Parameters:
path – The path to back up. If it does not exist then nothing will be done.
- hydronaut.file.safe_open(path: Path, *args: Any, backup: bool = False, **kwargs: Any) TextIOBase[source]
Context manager for safely opening a path by first creating any missing parent directories and then moving any existing file to a backup path.
- Parameters:
path – The path to open.
backup – If True, backup the file at the path if it exists.
*args – Positional arguments passed through to pathlib.Path.open.
**kwargs – Keyword arguments passed through to pathlib.Path.open.
- Returns:
The open file handle.
hydronaut.init module
Initialize a directory with default files for Hydronaut.
- class hydronaut.init.Initializer[source]
Bases:
objectInitialize a directory with default files.
hydronaut.log module
Logging helper functions.
hydronaut.mlflow module
MLflow utility functions.
- class hydronaut.mlflow.MLflowRunner(config: omegaconf.DictConfig, base_dir: str | Path = None)[source]
Bases:
objectContext manager to set up an MLflow run from an Omegaconf configuration object. When used as a context manager, it will configure the tracking URI, experiment, artifact location and run parameters from the configurat object. The context will return the MLflow active run.
hydronaut.paths module
Path management.
- class hydronaut.paths.PathManager(base_dir: str | Path = None, config_path: str | Path = None)[source]
Bases:
objectPath manager. This provides methods to retrieve common paths.
- __init__(base_dir: str | Path = None, config_path: str | Path = None) None[source]
- Parameters:
base_dir – The directory relative to which to interpret paths. If None, the current working directory is used.
- add_python_paths(paths: list[str | Path]) None[source]
Add Paths to the Python system paths list. The resulting list will be the equivalent of concatenating the input paths with the current system paths.
- Parameters:
paths – The paths to add. If relative, they are interpreted relative to the path given by relative_to.
- property config_dir: Path[source]
The resolved path to the current configuration directory as a pathlib.Path object.
- property config_path: Path[source]
The resolved path to the main configuration file as a pathlib.Path object. If the path was not specified during initialization and the environment variable is not set, it returns the default path.
hydronaut.run module
Run an experiment.
- class hydronaut.run.Runner(config_path: str | Path = None)[source]
Bases:
objectExperiment runner.
- __init__(config_path: str | Path = None) None[source]
- Parameters:
config_path – The path to the configuration file. It is passed through to hydronaut.paths.get_config_path to get the main configuration file.
- get_experiment_object() Experiment[source]
Get the experiment class specified by the configuration object.
- Returns:
The experiment instance.
- Raises:
ImportError – The module could not be found.
AttributeError – The module does not contain the expected class name.
- hydronaut.run.main(*args: Any, **kwargs: Any) int | float | Tuple[int | float, ...][source]
Main function to run an experiment with the Hydra configuration.
- Parameters:
*args – Positional arguments passed through to the hydra.main function.
**kwargs – Keyword arguments passed through to the hydra.main function.
- Returns:
The value returned by calling the runner.
hydronaut.types module
Type definitions and functions.
- hydronaut.types.ensure_numeric(value: Any) Generator[Real][source]
Convert values to numeric values. If the value is iterable, then the function will be recursively applied to its elements.
- Parameters:
value – The value to check.
- Returns:
A generator over numeric values (instances of numbers.Real). Values that could not be converted will be returned as NaN values.
Module contents
File stub.