optuna_mlflow
See also
Full documentation with examples can be found here: documentation page
Wrapper to log to Optuna and MLflow at the same time.
- class hpoflow.optuna_mlflow.OptunaMLflow(tracking_uri=None, num_name_digits=3, enforce_clean_git=False, optuna_result_name='optuna_result')[source]
Bases:
object
Wrapper to log to Optuna and MLflow at the same time.
Constructor.
- Parameters:
tracking_uri (Optional[str]) – The MLflow tracking URL. Defaults to
None
which logs to the default locale folder./mlruns
or uses theMLFLOW_TRACKING_URI
environment variable if it is available. Also seemlflow.set_tracking_uri()
.num_name_digits (int) – Number of digits for the MLflow
run_name
.enforce_clean_git (bool) – Check and enforce that the GIT repository has no uncommitted changes (see
git.repo.base.Repo.is_dirty()
).optuna_result_name (str) – Name of the metric which is logged to MLflo and is returned by the objective function.
- static _end_run(status, exc_text=None)[source]
End the active MLflow run (see
mlflow.end_run()
).- Parameters:
status (str) – The status of the run (see
mlflow.entities.RunStatus
).
- Return type:
None
- _log_iter(run_name, metrics, step)[source]
Log an iteration or a fold as a nested run (see
mlflow.log_metrics()
).The data is logged only to MLflow and not to Optuna.
- log_iter(metrics, step=None)[source]
Log an iteration or a fold as a nested run (see
mlflow.log_metrics()
).The data is logged to MLflow and also added to Optuna as a user attribute (see
optuna.trial.Trial.set_user_attr()
).
- log_metric(key, value, step=None, optuna_log=True)[source]
Log a metric under the current run.
Wrapper of the corresponding MLflow function (see
mlflow.log_metric()
). The data is logged to MLflow and also added to Optuna as a user attribute (seeoptuna.trial.Trial.set_user_attr()
).
- log_metrics(metrics, step=None, optuna_log=True)[source]
Log multiple metrics for the current run.
Wrapper of the corresponding MLflow function (see
mlflow.log_metrics()
). The data is logged to MLflow and also added to Optuna as a user attribute (seeoptuna.trial.Trial.set_user_attr()
).
- log_param(key, value, optuna_log=True)[source]
Log a parameter under the current run.
Wrapper of the corresponding MLflow function (see
mlflow.log_param()
). The data is logged to MLflow and also added to Optuna as a user attribute (seeoptuna.trial.Trial.set_user_attr()
).
- log_params(params)[source]
Log a batch of params for the current run.
Wrapper of the corresponding MLflow function (see
mlflow.log_params()
). The data is logged to MLflow and also added to Optuna as a user attribute (seeoptuna.trial.Trial.set_user_attr()
).
- report(value, step)[source]
Report an objective function value for a given step.
Wrapper of the corresponding Optuna function (see
optuna.trial.Trial.report()
).
- set_tag(key, value, optuna_log=True)[source]
Set a tag under the current run.
Wrapper of the corresponding MLflow function (see
mlflow.set_tag()
). The data is logged to MLflow and also added to Optuna as a user attribute (seeoptuna.trial.Trial.set_user_attr()
).
- set_tags(tags, optuna_log=True)[source]
Log a batch of tags for the current run.
Wrapper of the corresponding MLflow function (see
mlflow.set_tags()
). The data is logged to MLflow and also added to Optuna as a user attribute (seeoptuna.trial.Trial.set_user_attr()
).
- should_prune()[source]
Suggest whether the trial should be pruned or not.
Wrapper of the corresponding Optuna function (see
optuna.trial.Trial.should_prune()
).- Return type:
- suggest_categorical(name, choices)[source]
Suggest a value for the categorical parameter.
Wrapper of the corresponding Optuna function (see
optuna.trial.Trial.suggest_categorical()
).
- suggest_discrete_uniform(name, low, high, q)[source]
Suggest a value for the discrete parameter.
Wrapper of the corresponding Optuna function (see
optuna.trial.Trial.suggest_discrete_uniform()
).
- suggest_int(name, low, high, step=1, log=False)[source]
Suggest a value for the integer parameter.
Wrapper of the corresponding Optuna function (see
optuna.trial.Trial.suggest_int()
).- Parameters:
name (str) – A parameter name.
low (int) – Lower endpoint of the range of suggested values.
low
is included in the range.high (int) – Upper endpoint of the range of suggested values.
high
is included in the range.step (int) – A step of discretization.
log (bool) – A flag to sample the value from the log domain or not.
- Return type:
- suggest_loguniform(name, low, high)[source]
Suggest a value in the log domain for the continuous parameter.
Wrapper of the corresponding Optuna function (see
optuna.trial.Trial.suggest_loguniform()
).
- suggest_uniform(name, low, high)[source]
Suggest a value for the continuous parameter.
Wrapper of the corresponding Optuna function (see
optuna.trial.Trial.suggest_uniform()
).