diff --git a/optuna_dashboard/_app.py b/optuna_dashboard/_app.py index caf2be02..65a5bb00 100644 --- a/optuna_dashboard/_app.py +++ b/optuna_dashboard/_app.py @@ -249,19 +249,17 @@ def create_app(storage: BaseStorage, debug: bool = False) -> Bottle: return {"reason": "You need to set study_name and direction"} try: - study_id = storage.create_new_study(study_name) + study_id = storage.create_new_study( + study_name, + directions=[ + StudyDirection.MAXIMIZE if d.lower() == "maximize" else StudyDirection.MINIMIZE + for d in directions + ], + ) except DuplicatedStudyError: response.status = 400 # Bad request return {"reason": f"'{study_name}' is already exists"} - storage.set_study_directions( - study_id, - [ - StudyDirection.MAXIMIZE if d.lower() == "maximize" else StudyDirection.MINIMIZE - for d in directions - ], - ) - summary = get_study_summary(storage, study_id) if summary is None: response.status = 500 # Internal server error diff --git a/python_tests/test_api.py b/python_tests/test_api.py index 5a795c71..ead1ffc0 100644 --- a/python_tests/test_api.py +++ b/python_tests/test_api.py @@ -2,6 +2,7 @@ import json from unittest import TestCase import optuna +from optuna.study import StudyDirection from optuna import get_all_study_summaries from optuna_dashboard._app import create_app @@ -16,8 +17,8 @@ def objective(trial: optuna.trial.Trial) -> float: class APITestCase(TestCase): def test_get_study_summaries(self) -> None: storage = optuna.storages.InMemoryStorage() - storage.create_new_study("foo1") - storage.create_new_study("foo2") + storage.create_new_study(study_name="foo1", directions=[StudyDirection.MINIMIZE]) + storage.create_new_study(study_name="foo2", directions=[StudyDirection.MINIMIZE]) app = create_app(storage) status, _, body = send_request( @@ -126,7 +127,7 @@ class APITestCase(TestCase): def test_create_study_duplicated(self) -> None: storage = optuna.storages.InMemoryStorage() - storage.create_new_study("foo") + storage.create_new_study(study_name="foo", directions=[StudyDirection.MINIMIZE]) self.assertEqual(len(get_all_study_summaries(storage)), 1) app = create_app(storage) @@ -146,8 +147,8 @@ class APITestCase(TestCase): def test_delete_study(self) -> None: storage = optuna.storages.InMemoryStorage() - storage.create_new_study("foo1") - storage.create_new_study("foo2") + storage.create_new_study(study_name="foo1", directions=[StudyDirection.MINIMIZE]) + storage.create_new_study(study_name="foo2", directions=[StudyDirection.MINIMIZE]) self.assertEqual(len(get_all_study_summaries(storage)), 2) app = create_app(storage)