From 92b712b495c8640ab5a9d559b598adf1b8f3f634 Mon Sep 17 00:00:00 2001 From: c-bata Date: Fri, 7 Apr 2023 11:33:13 +0900 Subject: [PATCH 1/2] Update reload interval time for human-in-the-loop optimization --- optuna_dashboard/_app.py | 11 ++++++++++- .../ts/components/StudyDetailBeta.tsx | 15 +++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/optuna_dashboard/_app.py b/optuna_dashboard/_app.py index a72c60c2..2e7b2dcf 100644 --- a/optuna_dashboard/_app.py +++ b/optuna_dashboard/_app.py @@ -158,9 +158,18 @@ def create_new_study( return study_id -def get_trials(storage: BaseStorage, study_id: int, ttl_seconds: int = 10) -> list[FrozenTrial]: +def get_trials(storage: BaseStorage, study_id: int) -> list[FrozenTrial]: with trials_cache_lock: trials = trials_cache.get(study_id, None) + + # Not a big fan of the heuristic, but I can't think of anything better. + if len(trials) < 100: + ttl_seconds = 2 + elif len(trials) < 500: + ttl_seconds = 5 + else: + ttl_seconds = 10 + last_fetched_at = trials_last_fetched_at.get(study_id, None) if ( trials is not None diff --git a/optuna_dashboard/ts/components/StudyDetailBeta.tsx b/optuna_dashboard/ts/components/StudyDetailBeta.tsx index 400fa5cd..6a7ab839 100644 --- a/optuna_dashboard/ts/components/StudyDetailBeta.tsx +++ b/optuna_dashboard/ts/components/StudyDetailBeta.tsx @@ -60,12 +60,23 @@ export const StudyDetailBeta: FC<{ }, []) useEffect(() => { - if (reloadInterval < 0 || page === "trialTable") { + if (reloadInterval < 0) { return } + const nTrials = studyDetail ? studyDetail.trials.length : 0 + let interval = reloadInterval * 1000 + + // For Human-in-the-loop Optimization, the interval is set to 2 seconds + // when the number of trials is small and the page is "trialList". + if (page === "trialList" && nTrials < 100) { + interval = 2000 + } else if (page === "trialList" && nTrials < 500) { + interval = 5000 + } + const intervalId = setInterval(function () { action.updateStudyDetail(studyId) - }, reloadInterval * 1000) + }, interval) return () => clearInterval(intervalId) }, [reloadInterval, studyDetail, page]) From a50639770497bd23c14a3a3b19d1932914e01f15 Mon Sep 17 00:00:00 2001 From: c-bata Date: Thu, 13 Apr 2023 14:21:36 +0900 Subject: [PATCH 2/2] Fix mypy errors --- optuna_dashboard/_app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/optuna_dashboard/_app.py b/optuna_dashboard/_app.py index 2e7b2dcf..48193688 100644 --- a/optuna_dashboard/_app.py +++ b/optuna_dashboard/_app.py @@ -163,7 +163,7 @@ def get_trials(storage: BaseStorage, study_id: int) -> list[FrozenTrial]: trials = trials_cache.get(study_id, None) # Not a big fan of the heuristic, but I can't think of anything better. - if len(trials) < 100: + if trials is None or len(trials) < 100: ttl_seconds = 2 elif len(trials) < 500: ttl_seconds = 5