hydronaut package
Subpackages
- hydronaut.hydra package
Submodules
hydronaut.decorator module
hydronaut.experiment module
Experiment base class.
- class hydronaut.experiment.Experiment(config: omegaconf.DictConfig)[source]
Bases:
object
Base 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, Union[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 and keyword arguments passed through to pathlib.Path.open.
**kwargs –
Positional and 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:
object
Initialize 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:
object
Context 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:
object
Path 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[Union[str, pathlib.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
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.