mirror of
https://github.com/wassname/optuna-dashboard.git
synced 2026-09-12 12:40:33 +08:00
fix by lint
This commit is contained in:
@@ -28,6 +28,7 @@ from ._bottle_util import json_api_view
|
||||
from ._cached_extra_study_property import get_cached_extra_study_property
|
||||
from ._importance import get_param_importance_from_trials_cache
|
||||
from ._pareto_front import get_pareto_front_trials
|
||||
from ._preferential_history import report_choice
|
||||
from ._rdb_migration import register_rdb_migration_route
|
||||
from ._serializer import serialize_study_detail
|
||||
from ._serializer import serialize_study_summary
|
||||
@@ -39,8 +40,6 @@ from ._storage_url import get_storage
|
||||
from .artifact._backend import delete_all_artifacts
|
||||
from .artifact._backend import register_artifact_route
|
||||
from .artifact._backend_to_store import to_artifact_store
|
||||
from .preferential._history import FeedbackMode
|
||||
from .preferential._history import report_choice
|
||||
from .preferential._study import _SYSTEM_ATTR_PREFERENTIAL_STUDY
|
||||
from .preferential._study import get_best_trials as get_best_preferential_trials
|
||||
from .preferential._system_attrs import report_skip
|
||||
@@ -273,7 +272,6 @@ def create_app(
|
||||
try:
|
||||
candidate_trials = [int(d) for d in request.json.get("candidate_trials", [])]
|
||||
preferences = [(int(d[0]), int(d[1])) for d in request.json.get("preferentials", [])]
|
||||
mode = FeedbackMode[request.json.get("mode", "auto").upper()]
|
||||
except ValueError:
|
||||
response.status = 400
|
||||
return {"reason": "Invalid request."}
|
||||
@@ -281,7 +279,7 @@ def create_app(
|
||||
response.status = 400 # Bad request
|
||||
return {"reason": "You need to set best_trials and worst_trials"}
|
||||
|
||||
report_choice(study_id, storage, candidate_trials, preferences, mode, datetime.now())
|
||||
report_choice(study_id, storage, candidate_trials, preferences, datetime.now())
|
||||
|
||||
response.status = 204
|
||||
return {}
|
||||
|
||||
@@ -17,7 +17,7 @@ class Choice(TypedDict):
|
||||
uuid: str
|
||||
candidate_trials: list[int]
|
||||
preference_uuid: str
|
||||
timestamp: datetime
|
||||
timestamp: str
|
||||
|
||||
|
||||
def report_choice(
|
||||
@@ -31,7 +31,7 @@ def report_choice(
|
||||
"uuid": str(uuid.uuid4()),
|
||||
"candidate_trials": candidate_trials,
|
||||
"preference_uuid": report_preferences(study_id, storage, preferences),
|
||||
"timestamp": timestamp,
|
||||
"timestamp": timestamp.isoformat(),
|
||||
}
|
||||
key = _SYSTEM_ATTR_PREFIX_HISTORY + choice["uuid"]
|
||||
storage.set_study_system_attr(
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime
|
||||
import json
|
||||
from typing import Any
|
||||
from typing import TYPE_CHECKING
|
||||
@@ -14,8 +15,8 @@ from optuna.trial import FrozenTrial
|
||||
from . import _note as note
|
||||
from ._form_widget import get_form_widgets_json
|
||||
from ._named_objectives import get_objective_names
|
||||
from ._preferential_history import _SYSTEM_ATTR_PREFIX_HISTORY
|
||||
from .artifact._backend import list_trial_artifacts
|
||||
from .preferential._history import _SYSTEM_ATTR_PREFIX_HISTORY
|
||||
from .preferential._study import _SYSTEM_ATTR_PREFERENTIAL_STUDY
|
||||
from .preferential._system_attrs import _SYSTEM_ATTR_PREFIX_PREFERENCE
|
||||
|
||||
@@ -344,5 +345,5 @@ def serialize_preference_history(
|
||||
_SYSTEM_ATTR_PREFIX_PREFERENCE + choice["preference_uuid"], []
|
||||
)
|
||||
history.append(choice)
|
||||
history.sort(key=lambda c: c["timestamp"])
|
||||
history.sort(key=lambda c: datetime.fromisoformat(c["timestamp"]))
|
||||
return history
|
||||
|
||||
@@ -140,7 +140,6 @@ class APITestCase(TestCase):
|
||||
{
|
||||
"candidate_trials": [0, 1, 2],
|
||||
"preferentials": [[0, 1], [2, 1]],
|
||||
"mode": "choose_worst",
|
||||
}
|
||||
),
|
||||
content_type="application/json",
|
||||
|
||||
@@ -3,13 +3,12 @@ from __future__ import annotations
|
||||
from datetime import datetime
|
||||
from typing import Callable
|
||||
|
||||
from optuna_dashboard._preferential_history import report_choice
|
||||
from optuna_dashboard._serializer import serialize_preference_history
|
||||
from optuna_dashboard.preferential import create_study
|
||||
from optuna_dashboard.preferential._history import FeedbackMode
|
||||
from optuna_dashboard.preferential._history import report_choice
|
||||
|
||||
from ..storage_supplier import parametrize_storages
|
||||
from ..storage_supplier import StorageSupplier
|
||||
from .storage_supplier import parametrize_storages
|
||||
from .storage_supplier import StorageSupplier
|
||||
|
||||
|
||||
@parametrize_storages
|
||||
@@ -27,7 +26,6 @@ def test_report_and_get_choices(storage_supplier: Callable[[], StorageSupplier])
|
||||
storage=storage,
|
||||
candidate_trials=[0, 2, 3, 4],
|
||||
preferences=[(2, 0), (3, 0), (4, 0)],
|
||||
feedback_mode=FeedbackMode.CHOOSE_WORST,
|
||||
timestamp=datetime(2020, 1, 1, 10, 0, 1),
|
||||
)
|
||||
report_choice(
|
||||
@@ -35,7 +33,6 @@ def test_report_and_get_choices(storage_supplier: Callable[[], StorageSupplier])
|
||||
storage=storage,
|
||||
candidate_trials=[0, 1, 2],
|
||||
preferences=[(0, 1), (2, 1)],
|
||||
feedback_mode=FeedbackMode.CHOOSE_WORST,
|
||||
timestamp=datetime(2020, 1, 1, 10, 0, 0),
|
||||
)
|
||||
|
||||
@@ -47,7 +44,6 @@ def test_report_and_get_choices(storage_supplier: Callable[[], StorageSupplier])
|
||||
assert len(history[0]["preferences"][i]) == 2
|
||||
assert history[0]["preferences"][i][0] == best
|
||||
assert history[0]["preferences"][i][1] == worst
|
||||
assert history[0]["feedback_mode"] == FeedbackMode.CHOOSE_WORST.name
|
||||
assert history[0]["timestamp"] == "2020-01-01T10:00:00"
|
||||
assert history[1]["candidate_trials"] == [0, 2, 3, 4]
|
||||
assert len(history[1]["preferences"]) == 3
|
||||
@@ -55,5 +51,4 @@ def test_report_and_get_choices(storage_supplier: Callable[[], StorageSupplier])
|
||||
assert len(history[1]["preferences"][i]) == 2
|
||||
assert history[1]["preferences"][i][0] == best
|
||||
assert history[1]["preferences"][i][1] == worst
|
||||
assert history[1]["feedback_mode"] == FeedbackMode.CHOOSE_WORST.name
|
||||
assert history[1]["timestamp"] == "2020-01-01T10:00:01"
|
||||
|
||||
Reference in New Issue
Block a user