mirror of
https://github.com/wassname/optuna-dashboard.git
synced 2026-09-09 11:28:14 +08:00
Merge branch 'main' into settting-api
This commit is contained in:
@@ -8,7 +8,11 @@ from optuna import get_all_study_summaries
|
||||
from optuna.study import StudyDirection
|
||||
from optuna_dashboard._app import create_app
|
||||
from optuna_dashboard._app import create_new_study
|
||||
from optuna_dashboard._preferential_history import NewHistory
|
||||
from optuna_dashboard._preference_setting import register_preference_feedback_component_type
|
||||
from optuna_dashboard._preferential_history import remove_history
|
||||
from optuna_dashboard._preferential_history import report_history
|
||||
from optuna_dashboard._serializer import serialize_preference_history
|
||||
from optuna_dashboard.preferential import create_study
|
||||
|
||||
from .wsgi_client import send_request
|
||||
@@ -234,6 +238,82 @@ class APITestCase(TestCase):
|
||||
assert len(best_trials) == 1
|
||||
assert best_trials[0].number == 2
|
||||
|
||||
def test_remove_history(self) -> None:
|
||||
storage = optuna.storages.InMemoryStorage()
|
||||
study = create_study(storage=storage, n_generate=3)
|
||||
for _ in range(3):
|
||||
study.ask()
|
||||
|
||||
app = create_app(storage)
|
||||
study_id = study._study._study_id
|
||||
history_id = report_history(
|
||||
study_id,
|
||||
storage,
|
||||
NewHistory(
|
||||
mode="ChooseWorst",
|
||||
candidates=[0, 1, 2],
|
||||
clicked=2,
|
||||
),
|
||||
)
|
||||
histories = serialize_preference_history(storage.get_study_system_attrs(study_id))
|
||||
assert len(histories) == 1
|
||||
assert not histories[0]["is_removed"]
|
||||
|
||||
status, _, _ = send_request(
|
||||
app,
|
||||
f"/api/studies/{study_id}/preference/{history_id}",
|
||||
"DELETE",
|
||||
content_type="application/json",
|
||||
)
|
||||
self.assertEqual(status, 204)
|
||||
histories = serialize_preference_history(storage.get_study_system_attrs(study_id))
|
||||
assert len(histories) == 1
|
||||
assert histories[0]["is_removed"]
|
||||
assert len(study.get_preferences()) == 0
|
||||
|
||||
def test_restore_history(self) -> None:
|
||||
storage = optuna.storages.InMemoryStorage()
|
||||
study = create_study(storage=storage, n_generate=3)
|
||||
for _ in range(3):
|
||||
study.ask()
|
||||
|
||||
app = create_app(storage)
|
||||
study_id = study._study._study_id
|
||||
history_id = report_history(
|
||||
study_id,
|
||||
storage,
|
||||
NewHistory(
|
||||
mode="ChooseWorst",
|
||||
candidates=[0, 1, 2],
|
||||
clicked=2,
|
||||
),
|
||||
)
|
||||
remove_history(study_id, storage, history_id)
|
||||
histories = serialize_preference_history(storage.get_study_system_attrs(study_id))
|
||||
assert len(histories) == 1
|
||||
assert histories[0]["is_removed"]
|
||||
assert len(study.get_preferences()) == 0
|
||||
|
||||
status, _, _ = send_request(
|
||||
app,
|
||||
f"/api/studies/{study_id}/preference/{history_id}",
|
||||
"POST",
|
||||
content_type="application/json",
|
||||
)
|
||||
self.assertEqual(status, 204)
|
||||
histories = serialize_preference_history(storage.get_study_system_attrs(study_id))
|
||||
assert len(histories) == 1
|
||||
assert not histories[0]["is_removed"]
|
||||
preferences = study.get_preferences()
|
||||
preferences.sort(key=lambda x: (x[0].number, x[1].number))
|
||||
assert len(preferences) == 2
|
||||
better, worse = preferences[0]
|
||||
assert better.number == 0
|
||||
assert worse.number == 2
|
||||
better, worse = preferences[1]
|
||||
assert better.number == 1
|
||||
assert worse.number == 2
|
||||
|
||||
def test_create_study(self) -> None:
|
||||
for name, directions, expected_status in [
|
||||
("single-objective success", ["minimize"], 201),
|
||||
|
||||
Reference in New Issue
Block a user