diff --git a/optuna/study/study.py b/optuna/study/study.py index 59aab1cd1e..07140c14ce 100644 --- a/optuna/study/study.py +++ b/optuna/study/study.py @@ -333,6 +333,19 @@ def system_attrs(self) -> dict[str, Any]: return copy.deepcopy(self._storage.get_study_system_attrs(self._study_id)) + @property + @experimental_func("3.4.0") + def metric_names(self) -> list[str] | None: + """Return metric names. + + .. note:: + Use :meth:`~optuna.study.Study.set_metric_names` to set the metric names first. + + Returns: + A list with names for each dimension of the returned values of the objective function. + """ + return self._storage.get_study_system_attrs(self._study_id).get(_SYSTEM_ATTR_METRIC_NAMES) + def optimize( self, func: ObjectiveFuncType, diff --git a/tests/study_tests/test_study.py b/tests/study_tests/test_study.py index 0aba2e13ef..51411e54d8 100644 --- a/tests/study_tests/test_study.py +++ b/tests/study_tests/test_study.py @@ -1601,3 +1601,18 @@ def test_set_invalid_metric_names() -> None: study = create_study(directions=["minimize", "minimize"]) with pytest.raises(ValueError): study.set_metric_names(metric_names) + + +def test_get_metric_names() -> None: + study = create_study() + assert study.metric_names is None + study.set_metric_names(["v0"]) + assert study.metric_names == ["v0"] + study.set_metric_names(["v1"]) + assert study.metric_names == ["v1"] + + +def test_get_metric_names_experimental_warning() -> None: + study = create_study() + with pytest.warns(ExperimentalWarning): + study.metric_names