mirror of
https://github.com/wassname/optuna-dashboard.git
synced 2026-09-10 12:23:22 +08:00
Merge pull request #563 from moririn2528/preferential-api
add is_preferential flag to StudySummary
This commit is contained in:
@@ -108,6 +108,9 @@ def serialize_study_summary(summary: StudySummary) -> dict[str, Any]:
|
||||
"study_name": summary.study_name,
|
||||
"directions": [d.name.lower() for d in summary.directions],
|
||||
"user_attrs": serialize_attrs(summary.user_attrs),
|
||||
"is_preferential": getattr(summary, "_system_attrs", {}).get(
|
||||
_SYSTEM_ATTR_PREFERENTIAL_STUDY, False
|
||||
),
|
||||
}
|
||||
|
||||
if summary.datetime_start is not None:
|
||||
|
||||
@@ -111,6 +111,7 @@ interface StudySummariesResponse {
|
||||
study_name: string
|
||||
directions: StudyDirection[]
|
||||
user_attrs: Attribute[]
|
||||
is_preferential: boolean
|
||||
datetime_start?: string
|
||||
}[]
|
||||
}
|
||||
@@ -125,6 +126,7 @@ export const getStudySummariesAPI = (): Promise<StudySummary[]> => {
|
||||
study_name: study.study_name,
|
||||
directions: study.directions,
|
||||
user_attrs: study.user_attrs,
|
||||
is_preferential: study.is_preferential,
|
||||
datetime_start: study.datetime_start
|
||||
? new Date(study.datetime_start)
|
||||
: undefined,
|
||||
@@ -139,6 +141,7 @@ interface CreateNewStudyResponse {
|
||||
study_name: string
|
||||
directions: StudyDirection[]
|
||||
user_attrs: Attribute[]
|
||||
is_preferential: boolean
|
||||
datetime_start?: string
|
||||
}
|
||||
}
|
||||
@@ -160,6 +163,7 @@ export const createNewStudyAPI = (
|
||||
directions: study_summary.directions,
|
||||
// best_trial: undefined,
|
||||
user_attrs: study_summary.user_attrs,
|
||||
is_preferential: study_summary.is_preferential,
|
||||
datetime_start: study_summary.datetime_start
|
||||
? new Date(study_summary.datetime_start)
|
||||
: undefined,
|
||||
@@ -178,6 +182,7 @@ type RenameStudyResponse = {
|
||||
study_name: string
|
||||
directions: StudyDirection[]
|
||||
user_attrs: Attribute[]
|
||||
is_prefential: boolean
|
||||
datetime_start?: string
|
||||
}
|
||||
|
||||
@@ -195,6 +200,7 @@ export const renameStudyAPI = (
|
||||
study_name: res.data.study_name,
|
||||
directions: res.data.directions,
|
||||
user_attrs: res.data.user_attrs,
|
||||
is_preferential: res.data.is_prefential,
|
||||
datetime_start: res.data.datetime_start
|
||||
? new Date(res.data.datetime_start)
|
||||
: undefined,
|
||||
|
||||
Vendored
+1
@@ -121,6 +121,7 @@ type StudySummary = {
|
||||
study_name: string
|
||||
directions: StudyDirection[]
|
||||
user_attrs: Attribute[]
|
||||
is_preferential: boolean
|
||||
datetime_start?: Date
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ from __future__ import annotations
|
||||
import optuna
|
||||
from optuna_dashboard._serializer import serialize_attrs
|
||||
from optuna_dashboard._serializer import serialize_study_detail
|
||||
from optuna_dashboard._serializer import serialize_study_summary
|
||||
from optuna_dashboard._storage import get_study_summaries
|
||||
from optuna_dashboard.preferential import create_study
|
||||
|
||||
@@ -41,3 +42,22 @@ def test_get_study_detail_is_not_preferential() -> None:
|
||||
study_summary = study_summaries[0]
|
||||
study_detail = serialize_study_detail(study_summary, [], study.trials, [], [], [], False)
|
||||
assert not study_detail["is_preferential"]
|
||||
|
||||
|
||||
def test_get_study_summary_is_preferential() -> None:
|
||||
storage = optuna.storages.InMemoryStorage()
|
||||
create_study(storage=storage)
|
||||
study_summaries = get_study_summaries(storage)
|
||||
assert len(study_summaries) == 1
|
||||
|
||||
study_summary = serialize_study_summary(study_summaries[0])
|
||||
assert study_summary["is_preferential"]
|
||||
|
||||
|
||||
def test_get_study_summary_is_not_preferential() -> None:
|
||||
storage = optuna.storages.InMemoryStorage()
|
||||
optuna.create_study(storage=storage)
|
||||
study_summaries = get_study_summaries(storage)
|
||||
assert len(study_summaries) == 1
|
||||
study_summary = serialize_study_summary(study_summaries[0])
|
||||
assert not study_summary["is_preferential"]
|
||||
|
||||
Reference in New Issue
Block a user