From 60a3552f05a884083d52869a013f5975eb12a115 Mon Sep 17 00:00:00 2001 From: xadrianzetx Date: Sun, 17 Sep 2023 10:56:17 +0200 Subject: [PATCH] Use `metric_names` attribute instead of querying the storage directly --- optuna/study/_dataframe.py | 5 +---- optuna/study/study.py | 4 +--- optuna/visualization/_pareto_front.py | 5 +---- 3 files changed, 3 insertions(+), 11 deletions(-) diff --git a/optuna/study/_dataframe.py b/optuna/study/_dataframe.py index b311443055..84131526e9 100644 --- a/optuna/study/_dataframe.py +++ b/optuna/study/_dataframe.py @@ -8,7 +8,6 @@ import optuna from optuna._imports import try_import -from optuna.study.study import _SYSTEM_ATTR_METRIC_NAMES from optuna.trial._state import TrialState @@ -41,9 +40,7 @@ def _create_records_and_aggregate_column( column_agg: DefaultDict[str, Set] = collections.defaultdict(set) non_nested_attr = "" - metric_names = study._storage.get_study_system_attrs(study._study_id).get( - _SYSTEM_ATTR_METRIC_NAMES - ) + metric_names = study.metric_names records = [] for trial in study.get_trials(deepcopy=False): diff --git a/optuna/study/study.py b/optuna/study/study.py index 07140c14ce..eae8fd0993 100644 --- a/optuna/study/study.py +++ b/optuna/study/study.py @@ -1088,9 +1088,7 @@ def _log_completed_trial(self, trial: trial_module.FrozenTrial) -> None: if not _logger.isEnabledFor(logging.INFO): return - metric_names = self._storage.get_study_system_attrs(self._study_id).get( - _SYSTEM_ATTR_METRIC_NAMES - ) + metric_names = self.metric_names if len(trial.values) > 1: trial_values: list[float] | dict[str, float] diff --git a/optuna/visualization/_pareto_front.py b/optuna/visualization/_pareto_front.py index 05365a5583..c7f8a0f809 100644 --- a/optuna/visualization/_pareto_front.py +++ b/optuna/visualization/_pareto_front.py @@ -11,7 +11,6 @@ from optuna.exceptions import ExperimentalWarning from optuna.study import Study from optuna.study._multi_objective import _get_pareto_front_trials_by_trials -from optuna.study.study import _SYSTEM_ATTR_METRIC_NAMES from optuna.trial import FrozenTrial from optuna.trial import TrialState from optuna.visualization._plotly_imports import _imports @@ -343,9 +342,7 @@ def _infer_n_targets( ) if target_names is None: - metric_names = study._storage.get_study_system_attrs(study._study_id).get( - _SYSTEM_ATTR_METRIC_NAMES - ) + metric_names = study.metric_names if metric_names is None: target_names = [f"Objective {i}" for i in range(n_targets)] else: