diff --git a/optuna_dashboard/preferential/_study.py b/optuna_dashboard/preferential/_study.py index 0f2c7d84..585db64d 100644 --- a/optuna_dashboard/preferential/_study.py +++ b/optuna_dashboard/preferential/_study.py @@ -71,7 +71,11 @@ class PreferentialStudy: if not isinstance(worse_trials, list): worse_trials = [worse_trials] - report_preferences(self._study._study_id, self._study._storage, [(b.number, w.number) for b in better_trials for w in worse_trials]) + report_preferences( + self._study._study_id, + self._study._storage, + [(b.number, w.number) for b in better_trials for w in worse_trials], + ) def get_preferences(self, *, deepcopy: bool = True) -> list[tuple[FrozenTrial, FrozenTrial]]: trials = self._study.get_trials(deepcopy=deepcopy) @@ -92,8 +96,8 @@ class PreferentialStudy: else: raise RuntimeError("Unexpected trial type") storage.set_trial_system_attr(trial_id, _SYSTEM_ATTR_COMPARISON_READY, True) - - + + def get_best_trials(study_id: int, storage: optuna.storages.BaseStorage) -> list[FrozenTrial]: ready_trials = [ t @@ -107,7 +111,6 @@ def get_best_trials(study_id: int, storage: optuna.storages.BaseStorage) -> list preferences = get_preferences(study_id, storage) worse_numbers = {worse for _, worse in preferences} return [copy.deepcopy(t) for t in ready_trials if t.number not in worse_numbers] - def create_study( diff --git a/optuna_dashboard/preferential/_system_attrs.py b/optuna_dashboard/preferential/_system_attrs.py index 02e89680..2be921da 100644 --- a/optuna_dashboard/preferential/_system_attrs.py +++ b/optuna_dashboard/preferential/_system_attrs.py @@ -3,18 +3,20 @@ from __future__ import annotations import uuid import optuna +from optuna.storages import BaseStorage from optuna.trial import FrozenTrial from optuna.trial import TrialState -from optuna.storages import BaseStorage + from .._storage import get_study_summary + _SYSTEM_ATTR_PREFIX_PREFERENCE = "preference:values" def report_preferences( study_id: int, storage: BaseStorage, - preferences: list[tuple[int, int]], # element is number of trail + preferences: list[tuple[int, int]], # element is number of trail ) -> None: key = _SYSTEM_ATTR_PREFIX_PREFERENCE + str(uuid.uuid4()) storage.set_study_system_attr(